sql-execution-plan

DBMS_XPLAN.DISPLAY_CURSOR vs Explain Plan if not using gather_plan_statistics hint

折月煮酒 提交于 2019-12-04 03:46:15
Just requesting some clarification on the difference between the 2. From what I understand, EXPLAIN PLAN gives you the theoretical execution plan while DBMS_XPLAN.DISPLAY_CURSOR gives you the actual execution plan with execution statistics for the statement. EXPLAIN PLAN stores this data in a PLAN_TABLE while DBMS_XPLAN uses the V$SQL_PLAN, V$SQL_PLAN_STATISTICS and V$SQL_PLAN_STATISTICS_ALL views for its information. However, for DISPLAY_CURSOR to collect the actual runtime statistics for that statment, one needs to set the /*+ gather_plan_statistics */ hint. Otherwise, only V$SQL_PLAN is

Why are the performances of these 2 queries so different?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 01:41:07
I have a stored proc that searches for products (250,000 rows) using a full text index. The stored proc takes a parameter that is the full text search condition. This parameter can be null, so I added a null check and the query suddenly started running orders of magnitude slower. -- This is normally a parameter of my stored proc DECLARE @Filter VARCHAR(100) SET @Filter = 'FORMSOF(INFLECTIONAL, robe)' -- #1 - Runs < 1 sec SELECT TOP 100 ID FROM dbo.Products WHERE CONTAINS(Name, @Filter) -- #2 - Runs in 18 secs SELECT TOP 100 ID FROM dbo.Products WHERE @Filter IS NULL OR CONTAINS(Name, @Filter)

Programatically read SQL Server's query plan suggested indexes for a specific execution of SQL?

删除回忆录丶 提交于 2019-12-03 15:08:00
If I run this command in SSMS: set showplan_xml on GO exec some_procedure 'arg1', 'arg2','arg3' GO set showplan_xml off GO I get XML output of the full call stack involved in the query execution, as well as any suggested indexes etc. How might one read this from C#? (One use case might be to periodically enable this and log these results in a production environment to keep an eye on index suggestions.) This is, for the most part, two separate (though related) questions. Is it possible to capture or somehow get the Missing Index information? If you want only the Suggested Indexes (and don't

How can LIKE '%…' seek on an index?

巧了我就是萌 提交于 2019-12-03 13:47:02
I would expect these two SELECT s to have the same execution plan and performance. Since there is a leading wildcard on the LIKE , I expect an index scan. When I run this and look at the plans, the first SELECT behaves as expected (with a scan). But the second SELECT plan shows an index seek, and runs 20 times faster. Code: -- Uses index scan, as expected: SELECT 1 FROM AccountAction WHERE AccountNumber LIKE '%441025586401' -- Uses index seek somehow, and runs much faster: declare @empty VARCHAR(30) = '' SELECT 1 FROM AccountAction WHERE AccountNumber LIKE '%441025586401' + @empty Question:

Why is Oracle ignoring index with ORDER BY?

▼魔方 西西 提交于 2019-12-03 11:53:27
问题 My intention is to obtain a paginated resultset of customers. I am using this algorithm, from Tom: select * from ( select /*+ FIRST_ROWS(20) */ FIRST_NAME, ROW_NUMBER() over (order by FIRST_NAME) RN from CUSTOMER C ) where RN between 1 and 20 order by RN; I also have an index defined on the column "CUSTOMER"."FIRST_NAME": CREATE INDEX CUSTOMER_FIRST_NAME_TEST ON CUSTOMER (FIRST_NAME ASC); The query returns the expected resultset, but from the explain plan I notice that the index is not used:

What “Clustered Index Scan (Clustered)” means on SQL Server execution plan?

点点圈 提交于 2019-12-03 10:49:48
问题 I have a query that fails to execute with "Could not allocate a new page for database 'TEMPDB' because of insufficient disk space in filegroup 'DEFAULT'". On the way of trouble shooting I am examining the execution plan. There are two costly steps labeled "Clustered Index Scan (Clustered)". I have a hard time find out what this means? I would appreciate any explanations to "Clustered Index Scan (Clustered)" or suggestions on where to find the related document? 回答1: I would appreciate any

Tools for visualising execution xml plans as HTML

佐手、 提交于 2019-12-03 06:08:11
问题 Are there any tools / XSLT style sheets around for transforming the XML execution plans returned by Microsoft Visual Studio into HTML? Failing that, does anyone know of any techniques that can be used to display charts in HTML suitable for displaying execution plans? 回答1: I couldn't find one so I made one myself https://github.com/JustinPealing/html-query-plan Its currently being used on the Stack Exchange Data Explorer, Paste the Plan and Azure Data Studio. 来源: https://stackoverflow.com

How do I use EXPLAIN to *predict* performance of a MySQL query?

断了今生、忘了曾经 提交于 2019-12-03 03:27:32
问题 I'm helping maintain a program that's essentially a friendly read-only front-end for a big and complicated MySQL database -- the program builds ad-hoc SELECT queries from users' input, sends the queries to the DB, gets the results, post-processes them, and displays them nicely back to the user. I'd like to add some form of reasonable/heuristic prediction for the constructed query's expected performance -- sometimes users inadvertently make queries that are inevitably going to take a very long

How to Clear down Query Execution Statistics in SQL Server 2005/2008

岁酱吖の 提交于 2019-12-03 03:08:11
问题 Based on getting Query Execution Statistics using this extremely useful piece of SQL obtained from this post Most Executed Stored Procedure - Stack Overflow: SELECT TOP 100 qt.TEXT AS 'SP Name', SUBSTRING(qt.text, qs.statement_start_offset/2, CASE WHEN (qs.statement_end_offset = -1) THEN LEN(qt.text) ELSE (qs.statement_end_offset - qs.statement_start_offset)/2 END) AS actual_query, qs.execution_count AS 'Execution Count', qs.total_worker_time/qs.execution_count AS 'AvgWorkerTime', qs.total

What “Clustered Index Scan (Clustered)” means on SQL Server execution plan?

北战南征 提交于 2019-12-03 02:26:18
I have a query that fails to execute with "Could not allocate a new page for database 'TEMPDB' because of insufficient disk space in filegroup 'DEFAULT'". On the way of trouble shooting I am examining the execution plan. There are two costly steps labeled "Clustered Index Scan (Clustered)". I have a hard time find out what this means? I would appreciate any explanations to "Clustered Index Scan (Clustered)" or suggestions on where to find the related document? Neeraj Prasad Sharma I would appreciate any explanations to "Clustered Index Scan (Clustered)" I will try to put in the easiest manner,