|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 10:46 AM
Points: 7,
Visits: 19
|
|
In my table (large one) there is mainly three select queries: 1) select * from Product where productid=101 Here productid is primary key so it is clustered index, so no problem here.
2) select * from Product where IsDeleted=0 order by SubmitDate Desc 3) select * from Product where SubmitDate>=' ' and SubmitDate<' ' and IsDeleted=0 order by SubmitDate Desc
for 2) and 3) IsDeleted is a bit type contains duplicate values, and SubmitDate is datetime contains duplicate values.
How to set index for 2) and 3)
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 38,086,
Visits: 30,378
|
|
Index on IsDeleted, SubmitDate DESC
Probably won't be used unless there's a small number of rows that qualify or you can get rid of that SELECT * , retrieve only the columns required and make the index covering.
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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
prakash.kumar3669 (1/17/2013) In my table (large one) there is mainly three select queries: 1) select * from Product where productid=101 Here productid is primary key so it is clustered index, so no problem here.
2) select * from Product where IsDeleted=0 order by SubmitDate Desc 3) select * from Product where SubmitDate>=' ' and SubmitDate<' ' and IsDeleted=0 order by SubmitDate Desc
for 2) and 3) IsDeleted is a bit type contains duplicate values, and SubmitDate is datetime contains duplicate values.
How to set index for 2) and 3) Do you always require "SELECT *" in your every query ?
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 10:46 AM
Points: 7,
Visits: 19
|
|
Do you always require "SELECT *" in your every query ? the number of columns i need to display is 6-7 so i have put on * for the reference, in other words covering queries in not an option i guess.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 38,086,
Visits: 30,378
|
|
prakash.kumar3669 (1/17/2013) in other words covering queries in not an option i guess.
Why not?
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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 10:46 AM
Points: 7,
Visits: 19
|
|
Why not? I don't know, i have no experience of implementing indexing till now. What i have read from online articles, its important to index the columns which comes in where condition. if i have 5 columns to retrieve in my queries then what's the best way of indexing ?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
prakash.kumar3669 (1/17/2013) What i have read from online articles, its important to index the columns which comes in where condition. Not only Where BUT group by, order by , JOIN's ON clause , Partititon by , and also the SELECT's columns. See this http://www.sqlservercentral.com/articles/Indexing/68439/
prakash.kumar3669 (1/17/2013) if i have 5 columns to retrieve in my queries then what's the best way of indexing ? then those columns should be part of Covering index INCLUDE's part. For better solution.post that Query
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 10:46 AM
Points: 7,
Visits: 19
|
|
For better solution.post that Query select ProdName,Category,TotalStock,Price from Product where SubmitDate>=' ' and SubmitDate<' ' and IsDeleted=0 order by SubmitDate Desc
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 38,086,
Visits: 30,378
|
|
Index on (IsDeleted, SubmitDate DESC) include (ProdName,Category,TotalStock,Price)
btw, that's a rather odd predicate on the date column...
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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, January 18, 2013 10:46 AM
Points: 7,
Visits: 19
|
|
GilaMonster (1/17/2013) Index on (IsDeleted, SubmitDate DESC) include (ProdName,Category,TotalStock,Price) What would be the exact sql query to create the index.
btw, that's a rather odd predicate on the date column... how can you ellaborate ?
|
|
|
|