I have 2 queries I need to run against my DB. One loo开发者_Go百科ks for ManufacturerID and the other looks for ManufacturerID and SalesRepID.
Should I have 1 index on ManufacturerID and 1 index on SalesRepID
OR
1 Index on ManufacturerID and 1 Index on ManufacturerID and SalesRepID?
It depends. If your table is big enough, and your data is sparse enough, it might make sense to have:
- Index on
ManufacturerID
- Index on
ManufacturerID
,SalesRepID
On the other hand, if you have just a few different SalesRepID
for each ManufacturerID
, then both queries will be probably very well optimized just by using index on ManufacturerID
.
Normally, you'd only need one index on both one index on ManufacturerID and SalesRepID.
A search on ManufacturerID should still use this composite index as long it is the left hand column on the index key columns.
精彩评论