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

Home -> Community -> Usenet -> c.d.o.server -> Reordering the from-clause changes the query plan?

Reordering the from-clause changes the query plan?

From: <fredrik.groups_at_gmail.com>
Date: 15 Aug 2005 09:03:35 -0700
Message-ID: <1124121815.929797.125010@o13g2000cwo.googlegroups.com>


Hi all!

I am using Oracle 10.1.0.3 on a Red Hat Enterprise Linux server (see below for kernel version and so on).

I have a complex query (joining quite a few tables) that is using full table scans in some places where I think that access by indexes would be more efficient. While experimening, I noticed that changing the order of the tables in the from-clause sometimes caused the query plan to change.

I was under the impression that changing the order of the tables in the from-clause should not change the execution of the query while using the cost-based optimizer. Is this not correct?

A (hopefully) complete test case follows below. Since this is my first usenet post in several years, I apologize in advance if I have messed up the formatting.

The queries below are (obviously) simplified versions of the original queries. Right now, I am most interested in the possible reasons for the changing plan when only reordering the from-clause.

Thank you in advance for any ideas or pointers to documentation.

/Fredrik

SQL*Plus: Release 10.1.0.4.0 - Production on Mon Aug 15 17:12:12 2005

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

Server: Red Hat Enterprise Linux ES release 3 (Taroon Update 2) Linux xxx.yyy.zzz 2.4.21-32.0.1.EL #1 SMP Tue May 17 17:52:26 EDT 2005

                  x86_64 x86_64 x86_64 GNU/Linux


drop table t;
drop table t_ws;

create table t_ws as select * from t where 1 = 2;

insert into t
select rownum, 1, 1, 1, 1, 0, 0, systimestamp, user, 0, 0, rownum, 1 from all_objects where rownum < 25000;

insert into t_ws
select rownum, 1, 1, 1, 1, 183541, 0, systimestamp, user, 0, 0, rownum, 1
from all_objects where rownum < 25000;

create index t_idx on t (parent_oid, parent_otype); create index t_ws_idx on t_ws (parent_oid, parent_otype);

create unique index t_ws_unique_cid_idx on t_ws (dp_lock, dp_otype, dp_oid, dp_ctype, dp_occurrence);
create unique index t_unique_cid_idx on t (dp_otype, dp_oid, dp_ctype, dp_occurrence);

rows will be truncated

Statistics


          0  recursive calls
          0  db block gets
        315  consistent gets
          0  physical reads
          0  redo size
        345  bytes sent via SQL*Net to client
        435  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          4  rows processed



rows will be truncated

Statistics


          0  recursive calls
          0  db block gets
         18  consistent gets
          0  physical reads
          0  redo size
        345  bytes sent via SQL*Net to client
        435  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          4  rows processed
Received on Mon Aug 15 2005 - 11:03:35 CDT

Original text of this message

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