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 -> Re: UNION: SQL-tuning

Re: UNION: SQL-tuning

From: Niall Litchfield <niall.litchfield_at_dial.pipex.com>
Date: Thu, 12 Sep 2002 09:13:08 +0100
Message-ID: <3d804c93$0$1286$cc9e4d1f@news.dial.pipex.com>

"Andrei Romazanov" <romazanov.andrei_at_gfos.de> wrote in message news:alpddu$1rt0js$1_at_ID-70985.news.dfncis.de...
> Hello all,
>
> I have performance-problem in a UNION.
> Normally I can separated optimize the parts from UNION,
> in this case however show both part-SELECTS good performance,
> but in UNION suddenly appears FULL TABLE SCAN. Could someone explain to
 me
> this
> behavior of the Optimizer?

Assuming stats are up to date then it probably goes someting like this. I have two queries q1 and q2 that select the same result columns from the same table for different subsets of data. they both return say 10% of the rows in the table. This means that an index access path is quite likely to be chosen since you are selecting a relatively small part of the data. Now I decide to UNION them and so am selecting 20% of the table. As I'm now selecting quite a large amount of the table Oracle decides that it will be quicker to to a scan through the table (reading db_multiblock_read_count worth of data at a time) than to revisit many table blocks many times as implied by an index access path.

You can test tis out by putting index hints in the subqueries and comparing the performance.

--
Niall Litchfield
Oracle DBA
Audit Commission UK
*****************************************
Please include version and platform
and SQL where applicable
It makes life easier and increases the
likelihood of a good answer
******************************************
Received on Thu Sep 12 2002 - 03:13:08 CDT

Original text of this message

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