sql-execution-plan

Execution plan for functions in PostgreSQL

早过忘川 提交于 2019-12-11 07:23:59
问题 If I change user-defined function (UDF) that is in use in another UDF will the PostgreSQL rebuild execution plan for both of them or only for changed one? 回答1: If a function is unchanged, the execution plans for all its queries should remain cached. So only the execution plans for the function you changed will be recalculated. You can use the SQL statement DISCARD PLANS to discard all cached plans. 来源: https://stackoverflow.com/questions/46659067/execution-plan-for-functions-in-postgresql

Resetting Execution Plans

廉价感情. 提交于 2019-12-11 07:15:58
问题 I am optimizing a query and am worried that SQL Server is caching execution plans so want to wipe them. How do I do this? 回答1: You should do this: DBCC FREEPROCCACHE; I also do this DBCC DROPCLEANBUFFERS; Use DBCC DROPCLEANBUFFERS to test queries with a cold buffer cache without shutting down and restarting the server. To drop clean buffers from the buffer pool, first use CHECKPOINT to produce a cold buffer cache. This forces all dirty pages for the current database to be written to disk and

A query that does a lot of reads, but plan is OK

萝らか妹 提交于 2019-12-11 06:07:07
问题 I'm experiencing a strange behaviour in a specific query in the SQL Server 2008 R2 . I've got a query that does 19 million reads and is very time-consuming and when I try to check its cached plan, the plan is OK, without any problem what so ever. After doing the DBCC FREEPROCCACHE , the same query does 400 reads (taking 16 ms). The conclusion is that somehow the query is executed with the wrong plan, but that's not the information I got from the SQL Server. Does anyone have any idea what is

How to consider Explain plan as good- Oracle 10G

余生长醉 提交于 2019-12-11 03:13:50
问题 When an oracle explained plan is consider good? I'm try to refactor a DB Schema, and there are so many query in view and packages that are so slow. For example, this is one of the most orrible query, and give me this explain plan: Plan ALL_ROWSCost: 18,096 Bytes: 17 Cardinality: 1 I don't ask how to fix a query, just how to consider the explain plan as good. Thanks!! 回答1: Before considering the result of an Explain Plan we need to understand following terminologies, Cardinality– Estimate of

20s of PAGEIOLATCH_SH on Azure SQL Database with execution plan of 0.06 subtree cost

爷,独闯天下 提交于 2019-12-11 02:47:10
问题 (Azure support is giving vague answers, so I'm turning to Stack Overflow with hope! :)) Situation User complains of timeout errors on a query. I run the same query twice (same parameters) from MSMS. First run takes looong (23s or sometimes 50s), second, third, etc. runs take <1s. Execution Plans are identical and have a subtree cost of 0.0671.. The difference I do notice is a WaitStats section in the first Execution Plan with the following values: WaitCount: 2751 WaitTimeMS: 6 WaitType:

TSQL IVF causing timeout in ASP.net application

岁酱吖の 提交于 2019-12-11 01:19:25
问题 Hi and thanks for your attention. First some background on the question: I have an Inline Table Function which is used ubiquitously throughout an ASP.net application I have developed, running on IIS7. It's the basis for 30 or more stored procedures, all of while will normally process in a maximum of 200ms (more than fast enough). The application always uses the same connection string for all database connections. The function itself runs in a maximum of ~10ms. Occasionally a call to a page

Why CTE calculation is duplicated in query plan and how to optimize it without duplicating code?

元气小坏坏 提交于 2019-12-11 01:08:46
问题 Calculation of grp_set is duplicated 4 times in query plan of this query (distinct sort takes 23% each time, so it takes 23 * 4 = 92% of all resources): with grp_set as (select distinct old_num,old_tbl,old_db,old_val_num from err_calc) ,grp as (select id = row_number() over (order by old_num),* from grp_set) ,leaf as (select grp.id ,c.* ,sort = convert(varchar(max),old_col) + " - " + severity + " - " + err from grp join err_calc c on c.old_num = grp.old_num and c.old_tbl = grp.old_tbl and c

Optional parameters, “index seek” plan

て烟熏妆下的殇ゞ 提交于 2019-12-11 01:03:23
问题 In my SELECT statement i use optional parameters in a way like this: DECLARE @p1 INT = 1 DECLARE @p2 INT = 1 SELECT name FROM some_table WHERE (id = @p1 OR @p1 IS NULL) AND (name = @p2 OR @p2 IS NULL) In this case the optimizer generates "index scan" (not seek) operations for the entity which is not most effective when parameters are supplied with not null values. If i add the RECOMPILE hint to the query the optimizer builds more effective plan which uses "seek". It works on my MSSQL 2008 R2

Stored Procedure is taking time in execution

a 夏天 提交于 2019-12-10 21:44:15
问题 I am facing a very strange issue with SQL Server that I have a stored procedure and I am executing the procedure from C# code. The procedure will return a datatable / dataset. My problem is that procedure is taking too much time in execution from C# code / ADO.NET code (around 2 minutes). But when I execute the same query from SQL Server, it's executing within a second. Also I have tried by create new procedure with the same code (old procedure code) and when I am executing this new procedure

How do not scan all records to query top rows by complex condition

家住魔仙堡 提交于 2019-12-10 19:19:49
问题 I have a table and data like this: create table AmountObjects ( objectId integer, unixTimestamp integer, amount integer, PRIMARY KEY ( [objectId] ASC, [unixTimestamp] ASC ) ); insert into AmountObjects values (1, 1, 33); insert into AmountObjects values (1, 2, 33); insert into AmountObjects values (1, 3, 33); insert into AmountObjects values (1, 4, 33); insert into AmountObjects values (1, 5, 33); insert into AmountObjects values (1, 6, 33); insert into AmountObjects values (1, 7, 33); insert