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: FIRST_ROWS vs. ALL_ROWS

Re: FIRST_ROWS vs. ALL_ROWS

From: Stephane Faroult <sfaroult_at_oriole.com>
Date: Mon, 03 Dec 2001 11:34:40 -0800
Message-ID: <F001.003D393E.20011203112039@fatcity.com>

"Carle, William T (Bill), NLCIO" wrote:
>
> Howdy,
>
> I have a query which was taking an extremely long time
> to complete. The OPTIMIZER_MODE in the init.ora file is set to CHOOSE,
> meaning it will use the ALL_ROWS method to determine its access paths. I
> determined the query was not using the indexes I thought it should. When I
> changed to use the FIRST_ROWS optimizer_mode, the query ran in under a
> second. Now FIRST_ROWS is used to minimize response time; ALL_ROWS is used
> to minimize total execution time. I'm trying to figure out the difference.
> Using FIRST_ROWS, this is the output from tkprof:
>

Bill,

   very roughly, FIRST_ROWS favours nested loop over hash join and ALL_ROWS does the reverse. Hash join is by far the most efficient when you do a 'full join' on big tables. By 'full join', I mean that there is no screening condition but the joind condition (or something which is not very discriminant). However, a hash join means a first pass on the smallest table to build a hash table, then a full scan on the second table, hashing the key each time and checking the hash table. It can take sometime before the first line pops up (actually, all the preliminary work of building the hash table). A nested loop answers faster. The factor which makes the difference in your case is 'rownum < 5' - if you say that hash join as a high fixed cost and a low marginal one compared to nested loops, the rownum condition do not let you return enough rows to make the gain on marginal cost counterbalance the loss on fixed one.

-- 
HTH,

Stephane Faroult
Oriole Corporation
Voice:  +44  (0) 7050-696-269 
Fax:    +44  (0) 7050-696-449 
Performance Tools & Free Scripts
--------------------------------------------------------------
http://www.oriole.com, designed by Oracle DBAs for Oracle DBAs
--------------------------------------------------------------
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Stephane Faroult
  INET: sfaroult_at_oriole.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Mon Dec 03 2001 - 13:34:40 CST

Original text of this message

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