Morning
I have a stored procedure that contains a user defined function that slows considerably the performance of the SP. Extract as below
The problem is not with the performance dive, which is expected, but the fact that the usf is only necessary if (@tinPostcodeCheckType (input parameter) has a value <> 0.
I tried
but the sp is still slow if @tinPostcodeCheckType = 0.
Is my only option
Which is fast when @tinPostcodeCheckType = 0. Not particularly happy repeating the select with just the usf check different in each.
Is it just the presence of the usf in the select (even though logically never run) that triggers a non-set base run?
Any better approach?
Thanks
Robert
I have a stored procedure that contains a user defined function that slows considerably the performance of the SP. Extract as below
Code:
WHERE
dbo.usf_PostCodeRules(@tinPostcodeCheckType, C_Postcode) = 0
The problem is not with the performance dive, which is expected, but the fact that the usf is only necessary if (@tinPostcodeCheckType (input parameter) has a value <> 0.
I tried
Code:
WHERE
Case @tinPostcodeCheckType
When 0 Then 0
Else dbo.usf_PostCodeRules(@tinPostcodeCheckType, C_Postcode)
End = 0
but the sp is still slow if @tinPostcodeCheckType = 0.
Is my only option
Code:
IF @tinPostcodeCheckType = 0
Begin
...
WHERE
<no usf check>
End
Else
Begin
...
WHERE
dbo.usf_PostCodeRules(@tinPostcodeCheckType, C_Postcode) = 0
End
Which is fast when @tinPostcodeCheckType = 0. Not particularly happy repeating the select with just the usf check different in each.
Is it just the presence of the usf in the select (even though logically never run) that triggers a non-set base run?
Any better approach?
Thanks
Robert