isnull and performance

  • Hi,

    I was using data from two tables by joining them.

    Initially, I simply joined the two tables on the basis of common column without using isnull.

    Later on I found that the columns used for joining were NULLable. Thus, I enclosed the join columns in isnull function in a legal way (no problem with syntax error or the sort).

    After the use of isnull, the performance of the query dipped significantly.

    Does isnull affect performance?

  • It's not so much isnull as it is the fact that you're invoking functions in the join clause. Function used on indexed fields in the WHERE and ON clauses essentially prevent efficient use of said indexes on those fields.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Depending on your situation, you may want to consider COALESCE as an alternative.

  • In terms of a join, don't adjust anything. If the column is null, it doesn't equal anything and that row won't be returned which is as it should be.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply