Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
michaelj
Starting Member
2 Posts |
Posted - 2005-04-04 : 12:06:42
|
| I have a stored procedure that retuens several recordsets of data for reportingeach of selects looks similar to thisSELECTcount(I.AdId) as Qty,PlacementName as Placement FROMtbl_AdImpressionLog IJOIN tbl_PageViewLog L ON I.PageViewId = L.IdJOIN tbl_Ads A ON I.AdId = A.AdIdJOIN tbl_AdCustomers C ON A.AdCustomer = C.AdCustomerIdJOIN tbl_AdPlacements P ON I.PlacementBit = P.PlacementBitWHEREC.AdCustomerId = @iAdvertiserIdAND L.ViewDate >= @datFirstDateAND L.ViewDate < @datLastDategroup by PlacementNameorder by Qty DESCThere are indexes on al related columnstbl_AdImpressionLog has > 20 million rowsthe dates are in tbl_PageViewLog it has ~ 1 million rowsWould it help significantly to move the dates into the tbl_AdImpressionLog table?At what point should I consider breaking this data down into monthly databases or tables?mj |
|
|
PW
Yak Posting Veteran
95 Posts |
Posted - 2005-04-04 : 12:49:37
|
| >>There are indexes on al related columnsThat info needs to be expanded, type of index clustered or non, and which columns are in the index & their order in the index.eg: If you had a clustered index on tbl_PageViewLog, with ViewDate as the 1st column in the index, it would very likely be used by the optimizer since you're querying date ranges.What is the current result of SHOWPLAN on the query ? Index seeks, index scans or tablescans ? |
 |
|
|
michaelj
Starting Member
2 Posts |
Posted - 2005-04-04 : 13:55:18
|
| Indexes for tbl_PageViewLog arePrimary Key clustered column IDnon clustered index on catIndnon clustered index on ViewDatenon clustered index on AdImpressionsshould I consider changing the clustered index to the viewdate?The execution plan shows 56% on the join between the tbl_PageViewLog and tbl_AdImpressionLog and 31% on a table scan of tbl_AdImpressionLogI am not real familiar with this stuff but that table scan seems to seem like a bad idea with 20 million rows. |
 |
|
|
PW
Yak Posting Veteran
95 Posts |
Posted - 2005-04-04 : 16:13:18
|
| Indeed, a tablescan on 20 million records is never good.Is tbl_AdImpressionLog.AdID indexed ? If you are querying by @iAdvertiserId, this resolves into a set of AdID's, and an index on AdID in tbl_AdImpressionLog should be used by the optimizer (assuming it is selective enough). |
 |
|
|
|
|
|