I have a large temp table (~160 million rows) #itemsTemp
itemId | style | styleWeight
--------------------------------
int | smallint | float(53)
and the following query on it:
select
itemId,
style,
SUM(styleWeight) itemCount
from
#itemsTemp
group by itemId,style
Currently #itemsTemp
has no indexes. I'm a little confused about what would be best here:
itemId
and style
(and probably include
styleWeight)itemId
and style
Which way should I go? Why? Any other options?
Composite index on itemId
and style
with styleWeight
included would be the best option.
This will allow Stream Aggregate
without sorting and/or clustered seek/RID lookup overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With