Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sort works on one index and doesn't work on the other?


Sort works on one index and doesn't work on the other?

Author
Message
curious_sqldba
curious_sqldba
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1543 Visits: 3573
I have a query which does a order by at the end.


where WFID ='Something'
Order by Rkey asc, NFD desc




And my index is:

CREATE NONCLUSTERED INDEX [temp] ON [dbo].[WrkFS]
(
   [WFid] ASC,
   [SId] ASC,
   [NFTId] ASC,
   [AId] ASC,
   [RKey] asc,
   [NFD] desc
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



With above index i still see a sort operator, even though the two columns are added to the index key columns.

With below index i don't see sort operator

CREATE NONCLUSTERED INDEX [temp] ON [dbo].[WrkFS]
(
   [WFId] ASC,
   [RKey] asc,
   [NFD] desc
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



Any thoughts on why 2nd one works and 1st one doesn't?
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24169 Visits: 37934
sqldba_newbie (3/21/2013)
I have a query which does a order by at the end.


where WFID ='Something'
Order by Rkey asc, NFD desc




And my index is:

CREATE NONCLUSTERED INDEX [temp] ON [dbo].[WrkFS]
(
   [WFid] ASC,
   [SId] ASC,
   [NFTId] ASC,
   [AId] ASC,
   [RKey] asc,
   [NFD] desc
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



With above index i still see a sort operator, even though the two columns are added to the index key columns.

With below index i don't see sort operator

CREATE NONCLUSTERED INDEX [temp] ON [dbo].[WrkFS]
(
   [WFId] ASC,
   [RKey] asc,
   [NFD] desc
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



Any thoughts on why 2nd one works and 1st one doesn't?


Yes, the columns between WFId and RKey. With those columns, the values in RKey and NFD are not sorted as they are in the second index.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
curious_sqldba
curious_sqldba
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1543 Visits: 3573
Lynn Pettis (3/21/2013)
sqldba_newbie (3/21/2013)
I have a query which does a order by at the end.


where WFID ='Something'
Order by Rkey asc, NFD desc




And my index is:

CREATE NONCLUSTERED INDEX [temp] ON [dbo].[WrkFS]
(
   [WFid] ASC,
   [SId] ASC,
   [NFTId] ASC,
   [AId] ASC,
   [RKey] asc,
   [NFD] desc
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



With above index i still see a sort operator, even though the two columns are added to the index key columns.

With below index i don't see sort operator

CREATE NONCLUSTERED INDEX [temp] ON [dbo].[WrkFS]
(
   [WFId] ASC,
   [RKey] asc,
   [NFD] desc
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO



Any thoughts on why 2nd one works and 1st one doesn't?


Yes, the columns between WFId and RKey. With those columns, the values in RKey and NFD are not sorted as they are in the second index.


hmmm...so in that case i need specific indices ONLY for those two columns on which sort is done?
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47183 Visits: 44356
DEpends whether the sort's expensive enough to justify a duplicate index.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search