Do a lot of error checks affect query performance and is it bad practice?
1
vote
1
answer
257
views
If I have a stored procedure with a handful of error checks that come before the queries are executed and throw exceptions as necessary, could this affect performance? Is it bad practice to do this?
For example, say I had 10 logical case checks against the parameters of this stored procedure, would that be fine?...What if I had 100 check cases?
(The functional programmer in me wants to not leave any holes, but the relational developer in me feels like this could lead to a bad query plan being generated.)
Example of how I'm doing the error checking:
IF @Parameter1 IS NULL OR @Parameter2 IS NULL OR @Parameter3 IS NULL
BEGIN
THROW 50000, 'Error Message 1', 1;
END
ELSE IF @Parameter1 = 'Value1' AND @Parameter2 @Parameter3
BEGIN
THROW 50001, 'Error Message 2', 1;
END
Asked by J.D.
(40903 rep)
Nov 12, 2019, 10:12 PM
Last activity: Nov 12, 2019, 11:04 PM
Last activity: Nov 12, 2019, 11:04 PM