English 中文(简体)
我的执行计划声称,我25个长期储存的程序中有93%花在2个很长的问询上。 如何做到这一点?
原标题:My execution plan claims that 93% of my 25s long stored procedure were spent on a 2s long query. How is that possible?

我用储存的程序来抓捕约25人。

我先利用SSMS的执行计划特征来追踪业绩瓶颈,并发现我有一个非常宽广的问询,我曾多次从单一的角度进行自我参与。 我将这一报告附在一份联合评估报告中,再次启动了我的储存程序,检查了我的批量中这一具体询问的相对权重从30%降至2%,并开始寻找进一步优化的机会。

实际上,我刚才所听到的观点在整个地方都得到了利用,因此,我决定将我所需要的价值储存在“当地桌上,并在我所储存的程序中把这个表放在任何地方。 我的批量中有93%现在用于这一行:

insert into @vwActivityCache
select * from vwActivity where n in (@n,@n-1,@n-2) 

And this line takes around 2s to execute. (@vwActivityCache contains around 10k rows)

迄今为止,情况良好。

我所储存的程序仍需要25人才能执行。 (在第一个需要更长时间的外壳之后)

我试图在以上段落之后对所有问题发表评论,而按预期执行涉及2个问题。

I ve speculated that it could be caused by the time needed to transfer the data back to my sql client (despite the client statistics didn t imply this at all), so I tried removing the final select of the procedure (which now returns nothing), but I m still stuck at 25s. I ve also tried executing directly from the sql server box, 25s as well.

如果我删除除当地表格声明外的一切,加上填表的文字,则所储存的程序按预期需要执行2项。

For each query making use of my @vwActivityCache table that I uncomment, the execution time increases by a few seconds (even-though the execution plan claims the uncommented query took 0% of the batch time to execute), till I reach my initial 25s when everything is uncommented.

Unfortunately I can t post the stored procedure nor the execution plan here, but I was wondering if someone had any idea of the reasons that could cause a 2s query to take 93% of the execution time of a 25s procedure !

Update : switching @vwActivityCache to a temp table (#vwActivityCache ) reduced the execution time from 25s to 6s.

最佳回答

The costs shown in even the actual Execution plan are based on estimates and need to be taken with a big pinch of salt.

当你提出表格变数时,估计数很可能是错误的,因为表变量没有保持统计数据,而且假设表变量只有一行。

You could try a #temporary table as at least that will have statistics created for it meaning the costs shown in the plan may be a bit more accurate (and it might then choose a different plan based on this anyway) .

问题回答

How many records you have in @vwActivityCache?

几个格乌斯:

If there are many of them (depends on number of records and record size) temporary table could be better, because you can create index on it.

如果你从<条码>@vwActectiveCache中选择几个数值。 或许应该将其复制到另一个变量表?





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签