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: Stop Criteria for Sql Execution

Re: Stop Criteria for Sql Execution

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Mon, 7 Mar 2005 16:56:33 -0000
Message-ID: <00e901c52336$9e15c480$6702a8c0@Primary>


This is 9.2.0.6 (I don't have 8.1 available at the moment) with autotrace on.

Select /*+ all_rows */ * from t1 Where n1 = 20 and n1=10 /

Execution Plan


   0 SELECT STATEMENT Optimizer=HINT: ALL_ROWS (Cost=2 Card=1 Bytes=13)    1 0 FILTER
   2 1 TABLE ACCESS (FULL) OF 'T1' (Cost=2 Card=1 Bytes=13)

Note the filter line: In this case the filter line stops the tablescan from taking place because Oracle sees the contradiction.
(The filter is: n1 = 10 and n1 = 20)

Select /*+ all_rows */ * from t1 Where n1 is null and n1=10

Execution Plan


   0 SELECT STATEMENT Optimizer=HINT: ALL_ROWS (Cost=2 Card=1 Bytes=13)    1 0 TABLE ACCESS (FULL) OF 'T1' (Cost=2 Card=1 Bytes=13)

No filter - ouch !
That's just one of the nasty little things with nulls. Even after

    alter table t1 modify n1 not null;
we don't get a filter.

It's quite funny what happens if you create the null constraint and then check the query:

Select /*+ all_rows */ * from t1 Where n1 is null and n1 is not null;

The tablescan takes place, and every row is tested for 'n1 is null'.

Proper execution plan (not autotrace)
  Id Par Pos Ins Plan
---- ---- ---- ---- ----------------

   0 4 SELECT STATEMENT (hint: all_rows)    1 0 1 1 TABLE ACCESS (analyzed) TEST_USER T1 (full) Filter ("T1"."N1" IS NULL) Note how the filter (after the row fetch) has eliminated the 'is not null' predicate as redundant because there is an 'is not null' constraint, and STILL tests the predicate 'is null'.

Regards

Jonathan Lewis

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

http://www.jlcomp.demon.co.uk/seminar.html Public Appearances - schedule updated Jan 21st 2005

Why does Oracle have to execute the sql and scan data in a table for a sql like this:

Select * from table
Where column1 is null and column1=3D10

Or=20

Select * from table
Where column1=3D10 and column1=3D20

All the research money going to optimize the optimizer, and still can't take care of simple stuff like this.

Am I missing something?

I will probably start searching for smarter databases :)

Waleed
--

http://www.freelists.org/webpage/oracle-l

--

http://www.freelists.org/webpage/oracle-l Received on Mon Mar 07 2005 - 11:59:45 CST

Original text of this message

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