RE: Query Transformation

  • From: Noveljic Nenad <nenad.noveljic@xxxxxxxxxxxx>
  • To: "jolliffe@xxxxxxxxx" <jolliffe@xxxxxxxxx>, oracle-l <oracle-l@xxxxxxxxxxxxx>
  • Date: Mon, 25 Jan 2021 10:07:30 +0000

Hi Patrick,

Isn’t it OR expansion (OR condition was rewritten to UNION)?

Best regards,

Nenad
From: oracle-l-bounce@xxxxxxxxxxxxx <oracle-l-bounce@xxxxxxxxxxxxx> On Behalf 
Of Patrick Jolliffe
Sent: Montag, 25. Januar 2021 10:40
To: oracle-l <oracle-l@xxxxxxxxxxxxx>
Subject: Query Transformation

Dear List,
On Oracle 19c been looking at a poorly performing plan for a little while now.  
I've simplified it somewhat as per the details below.
I've resolved the problem itself by
1) creating an extended statistic for column group GMOBJ, GMSUB (which were 
correlated)
2) getting developers to replace the 2 binds :nc1 and :nc2 with a single bind, 
as the values are actually the same although the optimizer doesn't know this, 
so this limits it's options.
However I've got myself bogged down in trying to understand the transformation 
that has taken place, really for intellectual curiosity.
I think it's some variation on "cost based or expansion", but how has it 
transformed into a union of 3 different parts?
Any help greatly appreciated
Patrick

SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(FORMAT=>'ALLSTATS LAST'));

PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  5f67d104uv8ht, child number 0
-------------------------------------
SELECT /*+gather_plan_statistics Y */ null FROM P, C1, C2 WHERE (  (
C1.RZVR01 = :nc1 AND C2.GMOBJ BETWEEN  '2201' AND '2299')       OR    (
C1.RZVR01 = :nc2 AND C2.GMOBJ = '2019' AND C2.GMSUB = 'IDT'  )   )  AND
    ( P.RYPYID = C1.RZPYID AND P.RYGLBA = C2.GMAID )

Plan hash value: 1470685083

---------------------------------------------------------------------------------------------------
| Id  | Operation                       | Name  | Starts | E-Rows | A-Rows |   
A-Time   | Buffers |
---------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |       |      1 |        |      0 
|00:00:00.18 |   89916 |
|   1 |  CONCATENATION                  |       |      1 |        |      0 
|00:00:00.18 |   89916 |
|   2 |   NESTED LOOPS                  |       |      1 |      1 |      0 
|00:00:00.18 |   89886 |
|   3 |    NESTED LOOPS                 |       |      1 |      1 |  89115 
|00:00:00.13 |     771 |
|   4 |     NESTED LOOPS                |       |      1 |      1 |  89115 
|00:00:00.06 |     745 |
|   5 |      INLIST ITERATOR            |       |      1 |        |      3 
|00:00:00.01 |       8 |
|*  6 |       INDEX RANGE SCAN          | C1_I  |      2 |      3 |      3 
|00:00:00.01 |       8 |
|*  7 |      INDEX RANGE SCAN           | C21I  |      3 |      1 |  89115 
|00:00:00.05 |     737 |
|*  8 |     INDEX UNIQUE SCAN           | P_PK  |  89115 |      1 |  89115 
|00:00:00.04 |      26 |
|*  9 |    TABLE ACCESS BY INDEX ROWID  | P     |  89115 |      1 |      0 
|00:00:00.05 |   89115 |
|  10 |   NESTED LOOPS                  |       |      1 |      1 |      0 
|00:00:00.01 |      26 |
|  11 |    NESTED LOOPS                 |       |      1 |      1 |      3 
|00:00:00.01 |      15 |
|* 12 |     INDEX RANGE SCAN            | C1_I  |      1 |      1 |      3 
|00:00:00.01 |       4 |
|  13 |     TABLE ACCESS BY INDEX ROWID | P     |      3 |      1 |      3 
|00:00:00.01 |      11 |
|* 14 |      INDEX UNIQUE SCAN          | P_PK  |      3 |      1 |      3 
|00:00:00.01 |       8 |
|* 15 |    INDEX RANGE SCAN             | C21I  |      3 |      1 |      0 
|00:00:00.01 |      11 |
|  16 |   NESTED LOOPS                  |       |      1 |      1 |      0 
|00:00:00.01 |       4 |
|  17 |    NESTED LOOPS                 |       |      1 |      1 |      0 
|00:00:00.01 |       4 |
|  18 |     NESTED LOOPS                |       |      1 |      1 |      0 
|00:00:00.01 |       4 |
|* 19 |      INDEX RANGE SCAN           | C1_I  |      1 |      1 |      0 
|00:00:00.01 |       4 |
|  20 |      TABLE ACCESS BY INDEX ROWID| P     |      0 |      1 |      0 
|00:00:00.01 |       0 |
|* 21 |       INDEX UNIQUE SCAN         | P_PK  |      0 |      1 |      0 
|00:00:00.01 |       0 |
|* 22 |     INDEX UNIQUE SCAN           | C2_PK |      0 |      1 |      0 
|00:00:00.01 |       0 |
|* 23 |    TABLE ACCESS BY INDEX ROWID  | C2    |      0 |      1 |      0 
|00:00:00.01 |       0 |
---------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   6 - access(("C1"."RZVR01"=:NC1 OR "C1"."RZVR01"=:NC2))
   7 - access("C2"."GMOBJ"=U'2019' AND "C2"."GMSUB"=U'IDT')
       filter((("C1"."RZVR01"=:NC1 AND "C2"."GMOBJ">=U'2201' AND 
"C2"."GMOBJ"<=U'2299') OR
              ("C1"."RZVR01"=:NC2 AND "C2"."GMOBJ"=U'2019' AND 
"C2"."GMSUB"=U'IDT')))
   8 - access("P"."RYPYID"="C1"."RZPYID")
   9 - filter("P"."RYGLBA"="C2"."GMAID")
  12 - access("C1"."RZVR01"=:NC2)
       filter(("C1"."RZVR01"=:NC1 OR "C1"."RZVR01"=:NC2))
  14 - access("P"."RYPYID"="C1"."RZPYID")
  15 - access("C2"."GMOBJ"=U'2019' AND "C2"."GMSUB"=U'IDT' AND 
"P"."RYGLBA"="C2"."GMAID")
       filter(("C2"."GMOBJ"<=U'2299' AND "C2"."GMOBJ">=U'2201' AND
              (LNNVL("C2"."GMSUB"=U'IDT') OR LNNVL("C2"."GMOBJ"=U'2019'))))
  19 - access("C1"."RZVR01"=:NC1)
       filter(("C1"."RZVR01"=:NC1 OR "C1"."RZVR01"=:NC2))
  21 - access("P"."RYPYID"="C1"."RZPYID")
  22 - access("P"."RYGLBA"="C2"."GMAID")
  23 - filter(("C2"."GMOBJ"<=U'2299' AND "C2"."GMOBJ"<=U'2299' AND 
"C2"."GMOBJ">=U'2201'
              AND "C2"."GMOBJ">=U'2201' AND (LNNVL("C1"."RZVR01"=:NC2) OR 
LNNVL("C2"."GMOBJ"=U'2019') OR
              LNNVL("C2"."GMSUB"=U'IDT')) AND (LNNVL("C2"."GMSUB"=U'IDT') OR
              LNNVL("C2"."GMOBJ"=U'2019'))))
____________________________________________________
Please consider the environment before printing this e-mail.
Bitte denken Sie an die Umwelt, bevor Sie dieses E-Mail drucken.

<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">p { font-family: Arial;font-size:9pt }</style>
</head>
<body>
<p>
<br>Important Notice</br>
<br />
This message is intended only for the individual named. It may contain 
confidential or privileged information. If you are not the named addressee you 
should in particular not disseminate, distribute, modify or copy this e-mail. 
Please notify the sender immediately by e-mail, if you have received this 
message by mistake and delete it from your system.<br />
Without prejudice to any contractual agreements between you and us which shall 
prevail in any case, we take it as your authorization to correspond with you by 
e-mail if you send us messages by e-mail. However, we reserve the right not to 
execute orders and instructions transmitted by e-mail at any time and without 
further explanation.<br />
E-mail transmission may not be secure or error-free as information could be 
intercepted, corrupted, lost, destroyed, arrive late or incomplete. Also 
processing of incoming e-mails cannot be guaranteed. All liability of Vontobel 
Holding Ltd. and any of its affiliates (hereinafter collectively referred to as 
"Vontobel Group") for any damages resulting from e-mail use is excluded. You 
are advised that urgent and time sensitive messages should not be sent by 
e-mail and if verification is required please request a printed version.</br>
Please note that all e-mail communications to and from the Vontobel Group are 
subject to electronic storage and review by Vontobel Group. Unless stated to 
the contrary and without prejudice to any contractual agreements between you 
and Vontobel Group which shall prevail in any case, e-mail-communication is for 
informational purposes only and is not intended as an offer or solicitation for 
the purchase or sale of any financial instrument or as an official confirmation 
of any transaction.<br />
The legal basis for the processing of your personal data is the legitimate 
interest to develop a commercial relationship with you, as well as your consent 
to forward you commercial communications. You can exercise, at any time and 
under the terms established under current regulation, your rights. If you 
prefer not to receive any further communications, please contact your client 
relationship manager if you are a client of Vontobel Group or notify the sender.
Please note for an exact reference to the affected group entity the corporate 
e-mail signature.
For further information about data privacy at Vontobel Group please consult <a 
href="https://www.vontobel.com";>www.vontobel.com</a>.<br />
</p>
</body>
</html>

Other related posts: