I have a pretty big temp table (~5 million rows) that I need to update a few fields on.
Here's an example update statement:
UPDATE T
SET CarModel =
CASE
WHEN CarModel = '350z' AND ModelYear = 2008 AND CarMake NOT LIKE '%DATSUN%' THEN '370z Nismo'
ELSE CarModel
END,
IsMidTierCar =
CASE
WHEN NumberOfCarsSold >= 500000 AND <= 1000000 THEN IsMidTierCar
ELSE NULL
END,
IsRareCarMakeModel =
CASE
WHEN CarModel = '350z' AND SpecialEditioName != '' AND ModelYear = 2008 THEN 1
ELSE 0
END
FROM #CarsTempTable AS T
WHERE IsRareCarMakeModel IS NULL
The catch is the IsRareCarMakeModel field is NULL for every single row in the temp table before this update runs. Right now the fastest time I see it run in is when I don't create any index on my temp table. Any other index combination I've tried runs in at least 5x as long (and usually I just end up killing it instead of waiting for it to finish.)
Is no index going to be the best I'll ever get because of the cardinality of the temp table's IsRareCarMakeModel field is extremely low therefor a table scan is always going to be the best course of action for the optimizer?
null
, why are you checking that on the where clause? Do you execute that update more than once before dropping that temp table? Could you add the execution plan to your question? Since it's about performance I believe it might be useful.