Oracle FAQ Your Portal to the Oracle Knowledge Grid

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Doing battle with the CBO in 9i (

RE: Doing battle with the CBO in 9i (

From: Bobak, Mark <>
Date: Tue, 10 Jul 2007 17:35:44 -0400
Message-ID: <>

Is there a way to force a USE_CONCAT to do the union all? I tried giving it a USE_CONCAT, but, it had no effect. The 9i manual mentions that it's costed, and will only do the transformation if the cost is cheaper?



Mark J. Bobak
Senior Database Administrator, System & Product Technologies ProQuest
789 E. Eisenhower, Parkway, P.O. Box 1346 Ann Arbor MI 48106-1346
734.997.4059  or 800.521.0600 x 4059

ProQuest...Start here.

-----Original Message-----

From: Jonathan Lewis [] Sent: Tuesday, July 10, 2007 5:03 PM
To: Bobak, Mark; oracle-l
Subject: Re: Doing battle with the CBO in 9i (

It's the necessary plan
Hacking the predicates to make things clearer:


        :1 = 'XXX'
or (:2 != 'XXX' and FPGI.PC_ID = :3)

If you enter 'XXX' as the value for :1, then Oracle MUST return every row in the table. If you give it an index hint, and there is an index with a non-null column, Oracle HAS to do a full scan to get every row.

The optimizer can only generate one static plan that has to work for all possible sets of inputs.

What you really want to see is a use_concat plan - where Oracle turns your query into UNION ALL of two non-overlapping data sets.


Jonathan Lewis

Author: Cost Based Oracle: Fundamentals

The Co-operative Oracle Users' FAQ


Having a bit of a problem with the CBO on, and I wonder if anyone can offer any advice?

I have a query that looks like this:

SELECT FPGI.FPGI_ID L_FPGI_ID,        FPGI.FPGI_UMI_PAGE_NUMBER DSP_FPGI_UMI_PAGE_NUMBER,        FPGI.PC_ID DSP_PC_ID   FROM FULL_PAGE_IMAGES FPGI  WHERE ( ( :1='ENTER-QUERY')     OR ( ( NOT :2='ENTER-QUERY')    AND ( /* CG$MDTU_VWC_START DOC.FPGI */ (FPGI.PC_ID = :3) /* CG$MDTU_VWC_END DOC.FPGI */ ) ) ); As some of you may recognize, this query is generated by Oracle Forms, as part of an LOV population. (That's where all those parentheses and the 'ENTER-QUERY' business comes in.) So, as this is generated, I have no control over the code, and can't change it.

It's doing a FULL TABLE SCAN on the table, rather than an INDEX RANGE SCAN on the index on the PC_ID column. So, after playing with it a bit, it seems that the thing that's screwing it up is those extra predicates that Forms is adding, regarding the query mode. If I modify the query and remove those extraneous predicates, the query does the right thing (INDEX RANGE SCAN). But, I can't touch the query, cause it's generated.

So, says I, I'll use stored outlines, and no problem, be on my way.....

Well, after struggling to get stored outlines to work (what an awkward interface! I can't wait till 10g and SQL Profiles!), I see that I've in fact, created a larger problem. The "fixed" plan is in place, via stored outline, and my performance is WORSE than the FTS! After scratching my head for a while, I realized that, even with an INDEX hint correctly specified and correctly choosing the index, the reason that the performance is worse, is that the optimizer is choosing to do an INDEX FULL SCAN, followed by a TABLE ACCESS BY ROWID on every row in the table, which is FAR worse than the FTS I started with! The problem is that an INDEX hint specifies (correctly) which index to use, but it does NOT specify what type of scan operation (unique, range, or full) Oracle will do on said index! It seems that in the presence of those aforementioned, extraneous predicates, forces the CBO into doing a full scan rather than range scan! I did a 10053 trace, to try to get some insight, and found that there are no differences in the trace, up to the SINGLE TABLE ACCESS PATH. At that point, they diverge significantly. Here's what I have in each trace file:

-- Received on Tue Jul 10 2007 - 16:35:44 CDT

Original text of this message