The strategy selected by the query optimiser to process a query.

learn more… | top users | synonyms (2)

2
votes
1answer
51 views

Recompile not working for DELETE statement

I want to optimize a deletion from my tables. I have a table-variable input for my usp of following type: CREATE TYPE [AddressInfoParts] AS TABLE( ( [TcpInfoId] [BIGINT] NULL INDEX ...
1
vote
0answers
59 views

Logical read when use Offset in SQL

When I execute this script SET STATISTICS IO ON SELECT *, ROW_NUMBER() OVER (ORDER BY [Date] DESC) AS [ROW_NO] FROM vwTblTest WHERE ([Factor] >= 139501 AND [Factor] < ...
2
votes
1answer
46 views

Make index work on join to table variable

I a table with several columns, but the most importants are: DocumentId(bigint), StatusId(int) and ReceiveDateTime(datetimeoffset(3)). CREATE TABLE [DocumentInfo]( [DocumentId] [bigint] NOT NULL, ...
3
votes
1answer
58 views

Clustered Index Scan (Clustered) vs. Index Seek (NonClustered) + Key Lookup (Clustered)

I have the following tables and content create table t(i int primary key, j int, k char(6000)) create index ix on t(j) insert into t values(1,1,1) insert into t values(2,1,1) insert into t values(3,...
3
votes
1answer
230 views

How to avoid implicit conversion for an Integer column

SELECT [BusinessEntityID],[NationalIDNumber],[LoginID],[OrganizationNode] FROM [AdventureWorks2014].[HumanResources].[Employee] where BusinessEntityID = 5 I get convert_implicit() function ...
6
votes
2answers
127 views

Estimated Operator Cost Calculation

Everywhere I have read says that the Estimated Operator Cost is the sum of the Estimated CPU Cost and the and the Estimated I/O Cost. However, in many operators I see, this is not the case. Here is an ...
1
vote
1answer
22 views

Postgres permission for EXPLAIN

I would like to give user a permission to perform EXPLAIN but not to execute the SELECT itself. Is this doable in PostgreSQL?
1
vote
0answers
35 views

SQL query fills up RDS free storage space after upgrade to MySQL 5.7

After the upgrade to MySQL 5.7 the execution of a SQL query fills up the free storage space. The upgrade was performed through the AWS console, selecting the automatic procedure to upgrade the RDS ...
0
votes
0answers
31 views

How to visualize Redshift EXPLAIN query plan?

I've tried many different tools such as pgAdmin, DataGrip, http://explain.depesz.com, etc. None of them, however, seem to support Redshift's query plan with what I've tried. For simple queries, the ...
4
votes
1answer
347 views

Why does my execution plan (sometimes) include a left join?

I found a similar question and am aware that in order for a query of the form SELECT COUNT(1) FROM foo f LEFT OUTER JOIN bar b ON f.Value = b.Value AND f.Value = b.Value2 to perform without ...
0
votes
2answers
114 views

Inserting 500K records into SQL Server 2008 is taking 15s; how to optimize?

I have a SQL Server 2008 machine that is running backed by a SAN (not entirely certain of the SAN configuration). I've been noticing that some queries are slow to respond, so have been running some ...
0
votes
1answer
50 views

how to judge sql performance through these two explain?

If I give you 2 explain results from MySQL,how do you know which query is better? the first sql explain *************************** 1. row *************************** id: 1 select_type: ...
1
vote
1answer
53 views

How Plan Explorer Group Operators in Query Columns Tab

The two Index Seek (highlighted in green and red) are for filtering, they did not group in Query Columns tab. But the two Object3 highlighted in red are grouped together instead. Here is the XML Plan. ...
-1
votes
1answer
70 views

Meaning of terms in SQL Server execution plan [closed]

I am finding difficulty in understanding the output of execution plan. Execution plan consist of terms like "Estimated sub tree cost", "Estimated I/O cost" etc. I can find the definition of those on ...
4
votes
2answers
143 views

Execution plan percentages don't add up to 100% [closed]

I am referring to SQL Server query execution plans to take query cost and then optimize the required things by looking at the plan. But the total of individual query costs adds up to more than 100%. ...
20
votes
1answer
315 views

SQL Server 2014: any explanation for inconsistent self join cardinality estimate?

Consider the following query plan in SQL Server 2014: In the query plan, a self-join ar.fId = ar.fId yields an estimate of 1 row. However, this is a logically inconsistent estimate: ar has 20,608 ...
1
vote
2answers
49 views

MySQL Stored Procedure - no of times executed

My question is simple, is there any way to calculate, number of times a stored procedure is called on applications or executed on MySQL server. For example: Procedure name: sptest Executing ...
0
votes
1answer
23 views

Howto transfer tracefile into a trace table without loosing the sort order?

I have traced some data into a trace table into Sql Server using the Profiler GUI. This table has the following structure: It contains the SQL statements as well as execution plans in the TEXTDATA ...
1
vote
1answer
85 views

Why is it faster to do four simple selects instead of one select with left joins?

I need to find a single value from a table A containing three foreign keys to two other tables B and C. For the sake of experiment, I tested two ways to query the value: Multiple queries: declare @...
9
votes
2answers
334 views

Odd Stream Aggregate behaviour

Query: declare @X xml = ' <item ID = "0"/> <item ID = "1"/> <item/> <item/>'; select I.X.value('@ID', 'int') from @X.nodes('/item') as I(X); Result: ----------- 0 1 ...
4
votes
2answers
173 views

Clarification on Clustered index scan and Clustered Index Seek

I have created one table with 80000 records with Cluster Index on CustomerID column. When I queried the following statements the execution plan behaves in differently. Can anyone clarify the same. ...
5
votes
3answers
111 views

Clustered Index Scan when using greater than in WHERE clause

I have the following table create table t1( col1 varchar(255) NOT NULL, col2 varchar(255) NULL, col3 bigint NULL, CONSTRAINT PK_t1 PRIMARY KEY CLUSTERED ( col1 asc ) ) CREATE NONCLUSTERED INDEX ...
0
votes
1answer
45 views

Does Oracle randomly switch execution plans to check if there is a better solution?

I had a talk with an external colleague about oracle "swinging in" its performance. In detail it was about, that oracle optimizes its execution plans for the same query by time. I don't talk about ...
2
votes
1answer
84 views

Is it worth to optimize queries with EarlyTermination Timeout?

Right after running Ola's IndexOptimize to rebuild all indexes and statistics, I cleared the data and plan cache and ran a very complex ugly query to get a baseline of it's performance. The query ...
3
votes
1answer
121 views

.Net Application Using Inefficient Query Plan - caused by ARITHABORT setting?

One of our applications is causing a problem in that there is a stored procedure that returns fine in SSMS, in under 1 sec, but in the application its taking anything up to 10 minutes, depending on ...
6
votes
2answers
185 views

Running query against DMVs for Query Stats and Execution Plans joined to sys.databases

I originally posted this as a different question in Twitter #sqlhelp, but wanted to post it here differently. I'm trying to create a job that tracks worst performing statements for various statistics ...
0
votes
0answers
91 views

SQL query too slow to fetch single row of data

we have this SP, running extremely slow to fetch a single row of data from tables within 100K rows, which seems not that big. It takes onn avg 15-20 mins to complete. We have tried to remove all ...
3
votes
2answers
219 views

IN Clause - performance difference between listing values and query

I changed this query SELECT ... FROM linkedServer.DB.Schema.Table1 t1 LEFT JOIN linkedServer.DB.Schema.Table2 t2 ON t1.ORDER_ID = t2.ORDER_ID WHERE t1.BRANCH_ID NOT IN ( '009991', '009992', '...
7
votes
1answer
155 views

Two columns with and without index in where clause - How index works

I am executing a query on SQL Server 2008: SELECT col1 FROM table1 WHERE col2=val2 AND col3=val3 Here col2 has a non-clustered index, col1 is the PRIMARY KEY, and col3 does not have any index. ...
0
votes
1answer
51 views

How to make a query on multiple columns without writting all possible permutations?

I'm at my first question on stackexchange, as i have a few days since I struggle on this matter: I want to make a complex query(PLSQL) on a table that has col1,col2,col3,col4,col5 having values like (...
12
votes
2answers
175 views

Queries without Good Enough Plan Found

I have a SQL Server 2012 database. I noticed value of Reason for early termination of statement optimization for some queries and all gave Good Enough Plan Found. Now my questions are: What are all ...
6
votes
3answers
120 views

Query wont compile/run

I have a query that won't run on the production server but it runs on the test server. It seems like the query plan won't compile or its compiling a very bad query plan. I have updated all statistics ...
3
votes
1answer
69 views

Inconsistent Execution Plan for Stored Procedure

We have a business-critical stored procedure that normally runs daily at 2am from a scheduled job (in an SSIS package) on the production DB server. The same procedure/package is called from a second ...
5
votes
3answers
194 views

Cardinality Estimator Question after 2014 SP1 + CU4 Upgrade

We recently upgraded from SQL Server 2008R2 to SQL Server 2014 SP1 + CU4. After a couple of weeks, there were problems with execution plans not properly estimating row counts. The problem got so bad ...
3
votes
1answer
81 views

Finding hash match aggregate

After reading following blogs, I understand that hash match aggregate causes blocking. Using appropriate indexes it can be made as stream aggregate. Blocking/non-blocking aggregate operators The ...
7
votes
3answers
265 views

Execution Plan is NOT using INDEX, It uses Table Scan

I know when it comes to using an index or a table scan, SQL Server uses statistics to see which one is better. I have a table with 20 million rows. I have an index on (SnapshotKey, Measure) and this ...
5
votes
1answer
156 views

how to ignore the SSMS (sql server management studio) sql server ansi settings?

The options in Management Studio On Management studio Tools->Options->Query Execution->SQL Server there are options that are set and these prevail over the same options that are set on database level....
15
votes
1answer
499 views

Where do this Constant Scan and Left Outer Join come from in a trivial SELECT query plan?

I have this table: CREATE TABLE [dbo].[Accounts] ( [AccountId] UNIQUEIDENTIFIER UNIQUE NOT NULL DEFAULT NEWID(), -- WHATEVER other columns ); GO CREATE UNIQUE CLUSTERED INDEX [AccountsIndex] ...
1
vote
1answer
40 views

how to clear only the query plans from the current session?

I am working on tuning a query on a very busy server, where I don't want to clear the cache, using DBCC FREEPROCCACHE; I know it will cause at least a CPU spike, and in this case I don't want it. ...
1
vote
2answers
109 views

OrderBy int slow for large table join

I have roughly 1.5 million records. This query works fine for smaller data, but it gets a second slower for every few hundred thousand records. For 1.5 million, the query is noticeably struggling. I ...
4
votes
1answer
142 views

Actual Number of rows is too high even with new tables

I have a query based on two newly created tables in SQL Server 2005. I have index created on these tables. But when I write a query with JOIN condition, the number of actual rows returned is too high ...
6
votes
2answers
131 views

how to get estimated subtree cost?

If I have a query that returns a query_plan, for instance like this: SELECT TOP 1000 st.TEXT ,cp.size_in_bytes ,cp.plan_handle ,QP.query_plan FROM sys.dm_exec_cached_plans AS cp CROSS ...
-1
votes
1answer
70 views

Why switch execution plan for consecutive, identical queries? [closed]

This question is not about 'What should be'. The situation is the situation. I'm just seeking understanding (at this point). Select statement specifies 13 fields to return but only provides five ...
2
votes
1answer
71 views

Incorrect statistics are used on index seek

I have a table-valued function and ordinary table and need to perform INNER JOIN on them. Because, the engine thinks that the function is returning always one row, I try to store the results in ...
2
votes
2answers
62 views

SQL Server - SQL Plan Management for baseline

I am a .Net developer. I have a database upgrade coming up (from SQL Server 2005 to SQL Server 2012). The database team will be handling the migration. But I have seen forums posts saying that after ...
6
votes
1answer
151 views

Set statistics I/O for nested loops

Consider the below query: CREATE PROC dbo.GetPage @orderid AS INT = 0, -- anchor sort key @pagesize AS BIGINT = 25 AS SELECT TOP (@pagesize) orderid, orderdate, custid, empid FROM ...
1
vote
2answers
103 views

Why query plan changes by number of rows

I execute following two queries on an oracle database: select * from qsn join plc on plc.fk_qsn = qsn.id where rownum < 48507 which returns result in less than a second and with following ...
7
votes
1answer
323 views

Better execution plan if parameter is stored in local variable

I have two stored procedures. This one is incredibly fast (~ 2 seconds) CREATE PROCEDURE [schema].[Test_fast] @week date AS BEGIN declare @myweek date = @week select distinct serial ...
0
votes
0answers
41 views

How to make sure vacuum is happening in postgres sql db

I have created a table with two columns and created index for the first column. Then inserted 2 million data using generate series function for first column (2nd column is having null). And executed ...
6
votes
2answers
314 views

SQL Server changes execution plan - Part 2

Previous question: SQL Server changes execution plan We are using SQL Server 2014 Developer Edition. SQL Server changes execution plan on identical query and the same database and SQL Server (I ...