We help IT Professionals succeed at work.

First_rows hint not working

sakthikumar asked
Dear Experts,

I heard first_rows hint will retrieve the query fast for n rows.
But there is no difference with or without the hint.

Are there any conditions for this.?
Watch Question

PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

what version of Oracle is it? (the full version string please)

how are you using that hint?
can we see the query?

have you looked at the explain plan?


Oracle Database 11g Enterprise Edition Release - 64bit Production
PL/SQL Release - Production
CORE      Production
TNS for HPUX: Version - Production
NLSRTL Version - Production

Same 12 seconds with or with out hint

select  /*+ FIRST_ROWS(20) */ *
  from gcb_dba.bol b
 where exists (select 1
          from gcb_dba.gcb_cargo_cat_mapping d
         where b.bol_no = d.bol_no)
   and not exists (select 1
          from gcb_dba.gcb_charge_collection c
         where b.dpc_boe_no = c.doc_no)

                                                                                                                          Cost   Cardinality     Bytes            
SELECT STATEMENT, GOAL = HINT: FIRST_ROWS                                           20      1      484
 NESTED LOOPS ANTI                                                      20      1      484
  HASH JOIN SEMI                                                                       15      1      471
   VIEW      GC_STAGING      BOL                                                            11      21      9786
     TABLE ACCESS FULL      OPCSJAD_DBA.BOL                                           4      10      2850
     TABLE ACCESS FULL      OPCSPRD_DBA.BOL                          2      11      3168
   TABLE ACCESS FULL      GCB_DBA      GCB_CARGO_CAT_MAPPING       2      612      3060
  INDEX SKIP SCAN      GCB_DBA      GCB_CHARGE_COLLECTION_IDX_03       5      1      13
Senior Oracle DBA
Assuming that your statistics are correct, it doesn't look like the hint would help because the tables are so small.  My guess is that it would be slower if it used indexes (assuming they are there).

Essentially, the FIRST_ROWS hint will tend to use nested loops rather than hash or merge joins.  There really is no guarantee about getting rows faster.  It is a join hint.
Geert GOracle dba
Top Expert 2009

usually a skip scan is very slow

have you tried adding an index on gcb_dba.gcb_charge_collection with only dpc_boe_no ?


So, Can i use this for hint for online queries,(I mean queries to display results in front end)
Geert GOracle dba
Top Expert 2009
a front-end usually has this same parameter, it's best to use the same value

if your front-end grid wants to display data in grid-mode per 25 lines then it's best to also use first_rows(25)
otherwise ... grid-mode: 25 lines, first_rows(5)
will give the first 5 rows to the grid, but the grid will wait until it gets at least 25 lines to display anything