Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Index seek and Index scan ....order of columns Expand / Collapse
Author
Message
Posted Thursday, September 26, 2013 4:25 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, July 21, 2014 3:43 PM
Points: 1,274, Visits: 2,936
Below is my query and i have two different NC indices. Now when i have the first index, below query is doing a cluster index scan and if i have the second index query is doing a seek. I have two questions.


Does order of index matter on the columns which you are joining and using a where condition.Which column should come first , should i use the column where i am using '='operator or the one on which i am joining


Create Index Test_NC1 On RcrdSt
( Rkey,
Tid)

Create Index Test_NC2 On RcrdSt
( Tid,Rkey)



select Rkey,Tid from Rgrst
inner RcrdSt RTS_P
on R.ID = RTS_P.RKey
AND RTS_P.TID = 11


Post #1499103
Posted Thursday, September 26, 2013 4:31 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:05 PM
Points: 42,462, Visits: 35,522
Primary purpose of an index is to reduce the number of rows in consideration for a query as early as possible. Which reduces row count, a filter or a join?


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1499104
Posted Thursday, September 26, 2013 9:34 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, July 21, 2014 3:43 PM
Points: 1,274, Visits: 2,936
GilaMonster (9/26/2013)
Primary purpose of an index is to reduce the number of rows in consideration for a query as early as possible. Which reduces row count, a filter or a join?


Makes perfect sense, filter gives less rows.
Post #1499159
Posted Thursday, September 26, 2013 9:43 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, July 21, 2014 3:43 PM
Points: 1,274, Visits: 2,936
GilaMonster (9/26/2013)
Primary purpose of an index is to reduce the number of rows in consideration for a query as early as possible. Which reduces row count, a filter or a join?


Another question on the same line. I have a clustered index on two columns C1 accepts NULL and C2 doesn't. Now in my nc index when i dont include C2 it is still using the right index, but when i dont include c1 it is not using the right index. Is it because c1 has null values?
Post #1499160
Posted Friday, September 27, 2013 1:48 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:05 PM
Points: 42,462, Visits: 35,522
No, that won't be a cause.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1499233
Posted Friday, September 27, 2013 6:33 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 14, 2014 4:48 AM
Points: 2,834, Visits: 3,950
curious_sqldba (9/26/2013)
[quote][b]Now in my nc index when i dont include C2 it is still using the right index, but when i dont include c1 it is not using the right index. Is it because c1 has null values?

Because INdex helps when your query's filter/clause has LEFT most column of the index.

Lets say : if index is on col1 and col2

then col1 must be part of query then only index will be used.
but if you ignore col1 and use ONLY col2 then this index will not get used.


-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1499348
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse