Which is quicker COALESCE OR ISNULL?

前端 未结 6 880
忘了有多久
忘了有多久 2020-12-01 23:20

I understand the difference between these functions but my question is when checking for a single null value would ISNULL be any quicker than using COALESCE?

e.g

6条回答
  •  孤街浪徒
    2020-12-01 23:52

    I just ran a test on my own db. About 700k rows.

    SELECT COUNT(*) FROM table WHERE COALESCE(field_1,field_2,field_3,field_4) IS NOT NULL
    

    Result of 12106 obtained in 56 seconds.

    SELECT COUNT(*) FROM table WHERE field_1 IS NOT NULL OR field_2 IS NOT NULL OR field_3 IS NOT NULL OR field_4 IS NOT NULL
    

    Result of 12106 obtained in 0.00 seconds.

提交回复
热议问题