Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Performance Difference Between != and <>?

Re: Performance Difference Between != and <>?

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Fri, 22 Sep 2006 21:34:20 +0100
Message-ID: <004401c6de86$7bd04af0$0300a8c0@Primary>

Try running your query through explain plan (or autotrace) and see what that says -

SQL> select count(*) from t1 where id != 99;



| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |


| 0 | SELECT STATEMENT | | 1 | 5 | 599 (6)| 00:00:08 |
| 1 | SORT AGGREGATE | | 1 | 5 | | |
|* 2 | INDEX FAST FULL SCAN| T1_PK | 999K| 4882K| 599 (6)| 00:00:08 |

Predicate Information (identified by operation id):

   2 - filter("ID"<>99)

According to this, "!=" is considered to be the same as "<>". Similarly:

select count(*) from t1 where small_vc ='x' and exists (

    select 1 from t1 where small_vc != 'Y' )



| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |


| 0 | SELECT STATEMENT | | 1 | 11 | 9633 (2)| 00:01:56 |
| 1 | SORT AGGREGATE | | 1 | 11 | | |
|*  2 |   FILTER            |      |       |       |            |          |
|*  3 |    TABLE ACCESS FULL| T1   |     1 |    11 |  4816   (2)| 00:00:58 |
|*  4 |    TABLE ACCESS FULL| T1   |   999K|    10M|  4816   (2)| 00:00:58 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
   2 - filter( EXISTS (SELECT 0 FROM "T1" "T1" WHERE "SMALL_VC"<>'Y'))
   3 - filter("SMALL_VC"='x')
   4 - filter("SMALL_VC"<>'Y')


This was 10.2.0.1 - I'd be very surprised if any other version of Oracle were significantly different.

Regards

Jonathan Lewis
http://www.oracle.com/technology/community/oracle_ace/ace1.html#lewis

The Co-operative Oracle Users' FAQ
http://www.jlcomp.demon.co.uk/faq/ind_faq.html

Cost Based Oracle: Fundamentals
http://www.jlcomp.demon.co.uk/cbo_book/ind_book.html

  Does anyone know why there's a big performance difference when using != vs. <>? I was just looking at a query that was written both ways and there is a big difference in how long it takes to return data. The query is:  

Select count(*) from claws_doc_table where claws_doc_id = :id and exists (select 1 from claws_person_id where status != 0);  

If you use !=, it returns sub-second. If you use <>, it takes 7 seconds to return. Both return the right answer. I've looked in the Oracle documentation and can't find anything that would explain this. The documentation says that they are interchangeable.  

We are running Oracle 10.2.0.2 on Solaris 10, 64-bit.  

Thank you,  

Scott Canaan '88 (Scott.Canaan_at_rit.edu)

(585) 475-7886

"Life is like a sewer, what you get out of it depends on what you put into it." - Tom Lehrer.

--
http://www.freelists.org/webpage/oracle-l
Received on Fri Sep 22 2006 - 15:34:20 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US