sql-execution-plan

SQL poor stored procedure execution plan performance - parameter sniffing

女生的网名这么多〃 提交于 2019-11-27 01:38:28
I have a stored procedure that accepts a date input that is later set to the current date if no value is passed in: CREATE PROCEDURE MyProc @MyDate DATETIME = NULL AS IF @MyDate IS NULL SET @MyDate = CURRENT_TIMESTAMP -- Do Something using @MyDate I'm having problems whereby if @MyDate is passed in as NULL when the stored procedure is first compiled, the performance is always terrible for all input values ( NULL or otherwise), wheras if a date / the current date is passed in when the stored procedure is compiled performance is fine for all input values ( NULL or otherwise). What is also

What is a “Bitmap heap scan” in a query plan?

让人想犯罪 __ 提交于 2019-11-27 00:09:18
问题 I want to know the principle of "Bitmap heap scan", I know this often happens when I execute a query with OR in the condition. Who can explain the principle behind a "Bitmap heap scan"? 回答1: The best explanation comes from Tom Lane, which is the algorithm's author unless I'm mistaking. See also the wikipedia article. In short, it's a bit like a seq scan. The difference is that, rather than visiting every disk page, a bitmap index scan ANDs and ORs applicable indexes together, and only visits

Performance of SQL “EXISTS” usage variants

与世无争的帅哥 提交于 2019-11-26 19:51:24
问题 Is there any difference in the performance of the following three SQL statements? SELECT * FROM tableA WHERE EXISTS (SELECT * FROM tableB WHERE tableA.x = tableB.y) SELECT * FROM tableA WHERE EXISTS (SELECT y FROM tableB WHERE tableA.x = tableB.y) SELECT * FROM tableA WHERE EXISTS (SELECT 1 FROM tableB WHERE tableA.x = tableB.y) They all should work and return the same result set. But does it matter if the inner SELECT selects all fields of tableB, one field, or just a constant? Is there any

SQL Server Plans : difference between Index Scan / Index Seek

别说谁变了你拦得住时间么 提交于 2019-11-26 18:56:17
问题 In a SQL Server Execution plan what is the difference between an Index Scan and an Index Seek I'm on SQL Server 2005. 回答1: An index scan is where SQL server reads the whole of the index looking for matches - the time this takes is proportional to the size of the index. An index seek is where SQL server uses the b-tree structure of the index to seek directly to matching records (see http://mattfleming.com/node/192 for an idea on how this works) - time taken is only proportional to the number

How do you interpret a query's explain plan?

折月煮酒 提交于 2019-11-26 18:47:35
问题 When attempting to understand how a SQL statement is executing, it is sometimes recommended to look at the explain plan. What is the process one should go through in interpreting (making sense) of an explain plan? What should stand out as, "Oh, this is working splendidly?" versus "Oh no, that's not right." 回答1: I shudder whenever I see comments that full tablescans are bad and index access is good. Full table scans, index range scans, fast full index scans, nested loops, merge join, hash

Shredding XML From Execution Plans

淺唱寂寞╮ 提交于 2019-11-26 18:33:37
问题 I'll preface this by saying that I hate XML, horrible stuff to work with, but necessary sometimes. My current issue is that I'm trying to take the XML from an execution plan (supplied by a user, so could be any size) and shred this into a table for further manipulation. I'm down to two options at the moment; I could work out the maximum amount of nodes available for an execution plan (I suspect this would be a lot) and create the whole script that could be used for any XML input. This would

Redundant data in update statements

若如初见. 提交于 2019-11-26 14:06:08
问题 Hibernate generates UPDATE statements, which include all columns, regardless of whether I'm changing the value in that columns, eg: tx.begin(); Item i = em.find(Item.class, 12345); i.setA("a-value"); tx.commit(); issues this UPDATE statement: update Item set A = $1, B = $2, C = $3, D = $4 where id = $5 so columns B, C, D are updated, while I didn't change them. Say, Items are updated frequently and all columns are indexed. The question is: does it make sense to optimize the Hibernate part to

Why does the Execution Plan include a user-defined function call for a computed column that is persisted?

给你一囗甜甜゛ 提交于 2019-11-26 12:28:28
问题 I have a table with 2 computed columns, both of which has \"Is Persisted\" set to true . However, when using them in a query the Execution Plan shows the UDF used to compute the columns as part of the plan. Since the column data is calculated by the UDF when the row is added/updated why would the plan include it? The query is incredibly slow (>30s) when these columns are included in the query, and lightning fast (<1s) when they are excluded. This leads me to conclude that the query is

Measuring Query Performance : “Execution Plan Query Cost” vs “Time Taken”

痞子三分冷 提交于 2019-11-26 10:21:53
问题 I\'m trying to determine the relative performance of two different queries and have two ways of measuring this available to me: 1. Run both and time each query 2. Run both and get \"Query Cost\" from the actual execution plan Here is the code I run to time the queries... DBCC FREEPROCCACHE GO DBCC DROPCLEANBUFFERS GO DECLARE @start DATETIME SET @start = getDate() EXEC test_1a SELECT getDate() - @start AS Execution_Time GO DBCC FREEPROCCACHE GO DBCC DROPCLEANBUFFERS GO DECLARE @start DATETIME

SQL poor stored procedure execution plan performance - parameter sniffing

独自空忆成欢 提交于 2019-11-26 09:44:55
问题 I have a stored procedure that accepts a date input that is later set to the current date if no value is passed in: CREATE PROCEDURE MyProc @MyDate DATETIME = NULL AS IF @MyDate IS NULL SET @MyDate = CURRENT_TIMESTAMP -- Do Something using @MyDate I\'m having problems whereby if @MyDate is passed in as NULL when the stored procedure is first compiled, the performance is always terrible for all input values ( NULL or otherwise), wheras if a date / the current date is passed in when the stored