Re: Efficiency of is null v\s nullif
From: prabhakar (prabhakarnarvekar_at_msn.com)
Date: 02/15/05
- Next message: David Gugick: "Re: Log everything"
- Previous message: David Gugick: "Re: Efficiency of is null v\s nullif"
- In reply to: David Gugick: "Re: Efficiency of is null v\s nullif"
- Next in thread: David Gugick: "Re: Efficiency of is null v\s nullif"
- Reply: David Gugick: "Re: Efficiency of is null v\s nullif"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 15 Feb 2005 14:12:05 +0530
I am comparing two fields in a table to check if they are not equal.This can
be done in following two ways
1) select * from tablefornull where ((col1 <> col2) or (col1 is null and
col2 is not null) or (col1 is not null and col2 is null))
2) select * from tablefornull where not(nullif(col1,col2) is null and
nullif(col2,col1) is null)
which one will be more efficient? The qeury execution plan is same for both
"David Gugick" <davidg-nospam@imceda.com> wrote in message
news:uJFAyhzEFHA.2572@tk2msftngp13.phx.gbl...
> prabhakar wrote:
>> hi ,
>> i am querying for data in which i compare nulls . And null = null for
>> my scenario. Thus i need to either use extra where conditions in the
>> query to check if the two compared fields are nulls. This i can do
>> either by using is null or nullif function. Which of the two options
>> will be more efficient for SQL to execute considering large data
>> scenario? eg:
>>
>> Use NULLIF function
>> where (nullif(col1,col2) is null and nullif(col2,col1) is null
>> where not(nullif(col1,col2) is null and nullif(col2,col1) is null)
>>
>>
>> Use IS NULL construct
>>
>> where ((col1 = col2) or (col1 is null and col2 is null)) where ((col1
>> <> col2) or (col1 is null and col2 is not null) or (col1 is not null
>> and col2 is null))
>
> Not sure I understand. You have two WHERE clauses in each example. Can you
> post the real SELECTs you are comparing. You can also check the execution
> plans to see which one is cleaner.
>
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
- Next message: David Gugick: "Re: Log everything"
- Previous message: David Gugick: "Re: Efficiency of is null v\s nullif"
- In reply to: David Gugick: "Re: Efficiency of is null v\s nullif"
- Next in thread: David Gugick: "Re: Efficiency of is null v\s nullif"
- Reply: David Gugick: "Re: Efficiency of is null v\s nullif"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|