CBO Friday Fun!

From: McPeak, Matt <vxsmimmcp_at_subaru.com>
Date: Fri, 6 Jun 2014 21:17:42 +0000
Message-ID: <D7864FA3E7830B428CB2A5A5301B63EE017232032C_at_S7041VA005.soa.soaad.com>



Hi, Gurus!

I have a query that someone gave me. I've been looking at a 10053 event trace for it, trying to figure out why CBO will not come up with the "obvious" plan without a hint.

I've boiled the query down to a relatively simple form, and here is what I find:

  • If I explain plan the query, the cost is 1,918
  • If I put an /*+ ORDERED */ hint in the query and explain plan that one, the cost is 959

I'll paste the two queries below, for reference.

My question is: does the fact that the cost is lower on the hinted version mean that CBO is simply not considering the join order?

In the 10053 trace, all the join orders considered want to go to table vvmi2 before oel2 (joining on the car_line column instead of the stars_model_item_id which has a unique index). That move makes that cardinality going into the CROSS JOIN on so2 much higher than 1, making that cross join too expensive.

Anyway, at this point, I guess I'm wondering why the CBO doesn't look at and choose the plan with the 959 cost without needing me to specify /*+ ORDERED */.

Thanks, in advance, for your thoughts. The queries are below. (The purpose of the query is to find orders that are potential duplicates with a given order).

Thanks,
Matt

  • This query explains with a cost of 1,918 *** SELECT MIN (so2.order_number) dup_order FROM verp_om_sold_orders so1 CROSS JOIN verp_om_sold_orders so2 INNER JOIN oe_order_lines_all oel1 ON oel1.header_id = so1.order_header_id AND oel1.item_type_code = 'MODEL' INNER JOIN verp_vps_model_items vvmi1 ON oel1.inventory_item_id = vvmi1.stars_model_item_id INNER JOIN oe_order_lines_all oel2 ON oel2.header_id = so2.order_header_id AND oel2.item_type_code = 'MODEL' INNER JOIN verp_vps_model_items vvmi2 ON vvmi2.stars_model_item_id = oel2.inventory_item_id WHERE 1 = 1 AND so1.order_header_id = 41356864 AND so2.order_header_id != 41356864 AND so2.entered_date > to_date('06-JAN-2014') AND NVL (so2.cancelled_flag, 'N') = 'N'
    • Is duplicate AND (so1.email_address = so2.email_address OR (so1.person_last_name = so2.person_last_name AND so1.postal_code = so2.postal_code)) AND vvmi1.car_line = vvmi2.car_line
  • This query explains with a cost of 959 *** SELECT /*+ ORDERED */ MIN (so2.order_number) dup_order FROM verp_om_sold_orders so1 CROSS JOIN verp_om_sold_orders so2 INNER JOIN oe_order_lines_all oel1 ON oel1.header_id = so1.order_header_id AND oel1.item_type_code = 'MODEL' INNER JOIN verp_vps_model_items vvmi1 ON oel1.inventory_item_id = vvmi1.stars_model_item_id INNER JOIN oe_order_lines_all oel2 ON oel2.header_id = so2.order_header_id AND oel2.item_type_code = 'MODEL' INNER JOIN verp_vps_model_items vvmi2 ON vvmi2.stars_model_item_id = oel2.inventory_item_id WHERE 1 = 1 AND so1.order_header_id = 41356864 AND so2.order_header_id != 41356864 AND so2.entered_date > to_date('06-JAN-2014') AND NVL (so2.cancelled_flag, 'N') = 'N'
    • Is duplicate AND (so1.email_address = so2.email_address OR (so1.person_last_name = so2.person_last_name AND so1.postal_code = so2.postal_code)) AND vvmi1.car_line = vvmi2.car_line
--
http://www.freelists.org/webpage/oracle-l
Received on Fri Jun 06 2014 - 23:17:42 CEST

Original text of this message