Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, naren.

Asked: November 03, 2016 - 2:31 am UTC

Last updated: November 17, 2016 - 2:29 am UTC

Version: 12.1.0.2

Viewed 10K+ times! This question is

You Asked

Hi Tom,
I have one query that is running for a really long time. I was playing with the ordered hint and I noticed that SQL performs much better..I am not sure why though. Can you please explain a scenario where ordered or leading hint will actually help?


below is my SQL:
SELECT /*+ ORDERED */
PO.po_number,
PO.po_header_id,
GCC.concatenated_segments,
GCC.segment1,
GCC.segment2,
GCC.segment3,
GCC.segment4,
GCC.segment5,
GCC.segment6,
GCC.segment7,
NVL (GJL.entered_dr, 0) - NVL (GJL.entered_cr, 0)
FROM UP_PO_ENCUMB_RELIEF_PO2_STG PO,
xla.xla_transaction_entities XTE,
apps.xla_ae_headers XAH,
apps.xla_ae_lines XAL,
apps.gl_import_references GIR,
gl_je_lines GJL,
gl_je_headers GJH,
gl_code_combinations_kfv GCC
WHERE XTE.application_id = 201
AND XTE.source_id_int_1 = PO.po_header_id
AND XAH.application_id = XTE.application_id
AND XAH.entity_id = XTE.entity_id
AND XAL.application_id = XAH.application_id
AND XAL.ae_header_id = XAH.ae_header_id
AND GIR.gl_sl_link_id = XAL.gl_sl_link_id
AND GIR.gl_sl_link_table = XAL.gl_sl_link_table
AND GJL.je_header_id = GIR.je_header_id
AND GJL.je_line_num = GIR.je_line_num
AND ( NVL (GJL.entered_dr, 0) != 0 OR NVL (GJL.entered_cr, 0) != 0)
AND GJL.code_combination_id = PO.code_combination_id
AND GJL.code_combination_id = GCC.code_combination_id
AND GJH.je_header_id = GJL.je_header_id
AND GJH.status = 'P'
AND GCC.enabled_flag = 'Y'
AND GJH.je_source = 'Purchasing'
AND GJH.je_category = 'Purchases'
AND GJH.encumbrance_type_id IN (1001, 1002)
AND GJH.actual_flag = 'E';

and Connor said...

I prefer LEADING to ORDERED, but with *any* hint, my thought process is normally:

a) put the hint in, either directly or via baseline/profile/etc to solve the problem in the short term

b) investigate why the optimizer did not derive the correct plan in the first place.

If (b) can be solved, then take the necessary action and remove the hint.

If (b) cannot be solved, then leave the hint in

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Suggest

Gh, November 03, 2016 - 5:49 am UTC

Split the query using the with clause.
Use the ansi joins
Let the less selective non fact tables eg those with ggh, ggc. .. be the driving ones.
Remove the nvl from the predicate

Maybe adding a virtual col say VC as NVL (GJL.entered_dr, 0) - NVL (GJL.entered_cr, 0)
Then index on this col
Then condition vc

But anyway the first suggestions above are to consider.


ANSI Joins

John Keymer, November 16, 2016 - 3:14 pm UTC

Why would using ANSI joins make the query perform any better?
Connor McDonald
November 17, 2016 - 2:29 am UTC

I've no idea :-) I'll leave that to the person that offered the suggestion

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.