I have worked out all the implicit conversions, but I still see mentions of it in the plan. I have attached the plan, and any recommendation will help.
select cardholder_index, sum(value) as [RxCost]
into #rxCosts
from RiskPredictionStatistics with (nolock) where model_name = 'prescription_cost_12_months'
and model_set_name = 'rx_updated' and run_id in (select value from #runIds)
and exists (select 1 from StringContainsHelper with (nolock) where IntValue = cardholder_index and ReferenceId = @stringContainsHelperRefId)
group by cardholder_index
Best Answer
It looks like when you populate the
#runIds
table -- and I'm just taking a wild guess here -- you're using a string splitter function that outputs the values asNVARCHAR(MAX)
.You could try converting the values there to get rid of the implicit conversion warnings.
Another possible improvement would be to alter the
NonClustereIndex-Cardholder
index on RiskProductionStatistics to havemodel_set_name
as a key column, andmodel_name, run_id, value
as included columns. This would address the Key Lookup.You may also want to check the datatype of
model_name
. It appears in a Filter operator, and my fear is that it's a MAX datatype, which may prevent the predicate from being pushed down.Since this is an estimated plan, and you haven't included any metrics about the query, it's hard to say how much improvement these changes will have.