Re: Optimizer ignoring hints

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Sat, 14 Sep 2013 06:47:26 +0100
Message-ID: <AAB877835B19492B865CB9A86936814F_at_Primary>


Your hints "leading" and "use_nl" hints are invalid - they refer to objects that aren't in the query block where you've put the hint (and because of the nature of the leading hint you can't put it into the query block that is going to be unnested to make it possible for flv to be the leading table in the join order).

It's a matter of luck that you get the plan you want when you replace the binds with SYSDATE - presumably the statistics of the run-time value of the bind when the query is optimised causes a different path to be taken. It's possible, though, that since you have some predicates involving the nvl() function combined with the binds that the optimizer has produced a plan with binds that will give the right answer whether or not the bind is null - since SYSDATE is never null its presence may allow the optimizer to choose a different path. (The latter point is a generic warning - I'm not sure it's relevant in this case).

If you want to replay the SYSDATE plan, use the 'outline' option to get the set of hints that the optimizer generates for the plan and paste all the structural (e.g. leading, unnest, push_subq) , access, and join method hints back into the text. That may be sufficient.

Regards

Jonathan Lewis
http://jonathanlewis.wordpress.com/all-postings

Author: Oracle Core (Apress 2011)
http://www.apress.com/9781430239543

  • Original Message ----- From: "Hameed, Amir" <Amir.Hameed_at_xerox.com> To: "'ORACLE-L'" <oracle-l_at_freelists.org> Sent: Thursday, September 12, 2013 3:16 PM Subject: Optimizer ignoring hints

|I have a SQL statement that is part of a PL/SQL package. I have fudged
values in the statement for privacy reasons.
| SELECT oel.header_id, oel.line_id, oel.org_id,
| oel.ordered_item part_number_ordered,
| ship_from_org.organization_code source_location,
| ...
| oel.flow_status_code line_status, oel.ship_from_org_id,
| oel.subinventory, sources.NAME order_source
| FROM oe_order_lines_all oel,
| oe_order_headers_all h,
| oe_order_sources sources,
| hz_cust_site_uses_all ship_su,
| mtl_parameters ship_from_org,
| (SELECT mic2.inventory_item_id, mic2.organization_id
| FROM mtl_item_categories_v mic2
| WHERE mic2.category_set_name = 'WWWWW'
| AND mic2.segment1 IN ('XXXXX', 'YYYYY', 'ZZZZZZ')
| AND NVL (mic2.category_disable_date, :b1 + 5) >= :b1
| AND mic2.enabled_flag = 'Y') mic
| WHERE oel.header_id = h.header_id
| AND NVL (oel.line_category_code, 'ORDER') <> 'RETURN'
| AND sources.order_source_id = oel.order_source_id
| AND ship_su.site_use_id(+) = oel.ship_to_org_id
| AND oel.ship_from_org_id = ship_from_org.organization_id(+)
| AND (oel.creation_date > :b2 OR oel.last_update_date > :b2)
| AND mic.inventory_item_id = oel.inventory_item_id
| AND mic.organization_id = oel.ship_from_org_id
| AND oel.flow_status_code IN
| ('AAAAAA', 'BBBBBB', 'CCCCCC', 'DDDDDD')
| AND EXISTS (
| SELECT 'Y'
| FROM oe_order_headers_all oeh
| WHERE oeh.header_id = oel.header_id
| AND oeh.flow_status_code IN ('MMMMMM', 'NNNNNN', 'OOOOOO'))
| AND EXISTS (
| SELECT 'Y'
| FROM txrlo0_lookups tl2
| WHERE tl2.lookup_type = 'FFFFFFFFFFFFFFFF'
| AND NVL (tl2.start_dat_active, :b1 - 5) <= :b1
| AND NVL (tl2.end_date_active, :b1 + 5) >= :b1
| AND tl2.enabled_flag = 'Y'
| AND ship_from_org.organization_code = tl2.lookup_code)
| AND EXISTS (
| SELECT DISTINCT 'Y'
| FROM (SELECT lookup_code, meaning
| FROM txrlo0_lookups tl2
| WHERE tl2.lookup_type

' FFFFFFFFFFFFFFFF'

| AND NVL (tl2.start_dat_active, :b1 - 5) <=
:b1
| AND NVL (tl2.end_date_active, :b1 + 5) >=
:b1
| AND tl2.enabled_flag = 'Y') l1,
| (SELECT lookup_code, meaning, attribute2
| FROM fnd_lookup_values flv
| WHERE flv.lookup_type = 'GGGGGGGGGGGGGG'
| AND flv.LANGUAGE = 'US'
| AND NVL (flv.start_date_active, :b1 - 5)
<= :b1
| AND NVL (flv.end_date_active, :b1 + 5) >=
:b1
| AND flv.enabled_flag = 'Y') l2
| WHERE DECODE (l1.meaning, 'HHHHHH', '99999',
l1.meaning)
l2.attribute2
| AND ship_su.LOCATION = l2.lookup_code)
| ORDER BY header_id, inventory_item_id
| ;
|
| The current explain plan is sub-optimal and is causing the statement to
run for a long time. When I try to drive a specific plan by adding the following hints to the statement, the optimizer seems to ignore the hints as I see the same sub-optimal explain plan even after adding the hints:
| SELECT /*+ LEADING(flv tl2) USE_NL(flv tl2) INDEX(oel
OE_ORDER_LINES_N2) */ oel.header_id, oel.line_id, oel.org_id
|
| However, if I put the statement in a script and replace the bind
variables with SYSDATE and use hints, the optimizer takes the hints and produces the plan I am trying to drive.
|
| Does anyone know any reason, why the optimizer would ignore hints when
used with binds (in the package) but take the hints when binds are replaced with literals.
|
| Thanks,
| Amir
|
| --
| http://www.freelists.org/webpage/oracle-l
|
|
|
|
| -----
| No virus found in this message.
| Checked by AVG - www.avg.com
| Version: 2013.0.3392 / Virus Database: 3222/6656 - Release Date: 09/11/13
|
--
http://www.freelists.org/webpage/oracle-l
Received on Sat Sep 14 2013 - 07:47:26 CEST

Original text of this message