Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hints in oracle

I am trying to apply hints to my query but the explain plan does not change to the hint being used.

my query

select/*+ USE_HASH(master_flight)*/ bid, b.fno, seat, flight_date from
master_booking b, master_flight f where b.fno = f.fno and rownum <
120000

explain plan

119999 COUNT STOPKEY (cr=11336 pr=446 pw=0 time=240292 us)
119999 NESTED LOOPS (cr=11336 pr=446 pw=0 time=120236 us)
800 TABLE ACCESS FULL ASS2MASTER_FLIGHT (cr=936 pr=441 pw=0 time=22455 us)
119999 TABLE ACCESS CLUSTER ASS2MASTER_BOOKING (cr=10400 pr=5 pw=0 time=6858 us)
800 INDEX UNIQUE SCAN FNO_INDEX (cr=1600 pr=5 pw=0 time=4717 us)(object id 332468)

as you can see i am forcing the cluster to use hash join instead of nested loop. but the explain plan still shows that it is using nested loop.

like image 473
paktrick Avatar asked Jun 02 '26 16:06

paktrick


1 Answers

In general, if you're using a hint, you need to reference the aliases, not the table name. And USE_HASH requires two table names. So you'd need something like

SELECT /*+ use_hash(b f) */ 
       bid, b.fno, seat, flight_date
  FROM master_booking b,
       master_flight  f
 WHERE b.fno = f.fno
   AND rownum < 120000

Of course, if you find yourself needing to hint a query, that generally implies that your statistics are incorrect. And you're generally better off fixing whatever problem you have with the statistics so that the optimizer chooses the more efficient plan on its own.

like image 174
Justin Cave Avatar answered Jun 05 '26 06:06

Justin Cave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!