Skip to Main Content
  • Questions
  • PL/SQL Collection as bind variable causes cardinality wrong estimation

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Alessabdra.

Asked: May 28, 2024 - 7:08 am UTC

Last updated: November 26, 2024 - 1:52 pm UTC

Version: 19.21

Viewed 1000+ times

You Asked

Dear AskTom Team,
first of all thanks for all the support you are giving all of as for some many years.
I already read many of your answer about the topic PL/SQL Collection slowing sql execution.
I alredy tried all the hints (such for example the cardinality hint) you suggested but there was no way to tune my query.
The only solution I found is to use Global Temporary Table, but I would need an inline solution.
The problem is exactly there: TABLE(NUMBER_TBL( <<number>>,<<number>>,...)) nrs

CREATE OR REPLACE TYPE APP_FDB."NUMBER_TBL" AS TABLE OF NUMBER;
/


select * from 
    (
              SELECT distinct(column_value) a from TABLE(NUMBER_TBL( 102798692,102799603)) nrs

    )) prcdnrs  

This piece of SQL is joined with many other tables in a more complex query. Anyway it'S very clear that if I replace this piece with a UNION or with GTT the query becomes very very fast.

and Chris said...

We're going to see the full example of the problem you're hitting - the SQL statements and their plans.

Using the dynamic_sampling or cardinality hints on 19.22, the optimizer gives correct estimates in these tests:

CREATE OR REPLACE TYPE NUMBER_TBL AS TABLE OF NUMBER;
/
set serveroutput off
select * from (
  select /*+ dynamic_sampling (nrs 10) */distinct(column_value) a 
  from   table(number_tbl( 1, 2 )) nrs
) prcdnrs;

select * from dbms_xplan.display_cursor( format => 'TYPICAL LAST');

------------------------------------------------------------------------------------------------
| Id  | Operation                               | Name | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                        |      |       |       |    12 (100)|          |
|   1 |  VIEW                                   |      |     2 |    26 |    12   (9)| 00:00:01 |
|   2 |   HASH UNIQUE                           |      |     2 |     4 |    12   (9)| 00:00:01 |
|   3 |    COLLECTION ITERATOR CONSTRUCTOR FETCH|      |     2 |     4 |    11   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

select * from (
  select /*+ dynamic_sampling (nrs 10) */distinct(column_value) a 
  from   table(number_tbl( 1, 2, 3 )) nrs
) prcdnrs;

select * from dbms_xplan.display_cursor( format => 'TYPICAL LAST');

------------------------------------------------------------------------------------------------
| Id  | Operation                               | Name | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                        |      |       |       |    12 (100)|          |
|   1 |  VIEW                                   |      |     3 |    39 |    12   (9)| 00:00:01 |
|   2 |   HASH UNIQUE                           |      |     3 |     6 |    12   (9)| 00:00:01 |
|   3 |    COLLECTION ITERATOR CONSTRUCTOR FETCH|      |     3 |     6 |    11   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

select * from (
  SELECT /*+ cardinality (nrs 2) */distinct(column_value) a 
  from   TABLE(NUMBER_TBL( 1, 2 )) nrs
) prcdnrs;

select * from dbms_xplan.display_cursor( format => 'TYPICAL LAST');

------------------------------------------------------------------------------------------------
| Id  | Operation                               | Name | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                        |      |       |       |    30 (100)|          |
|   1 |  VIEW                                   |      |     2 |    26 |    30   (4)| 00:00:01 |
|   2 |   HASH UNIQUE                           |      |     2 |     4 |    30   (4)| 00:00:01 |
|   3 |    COLLECTION ITERATOR CONSTRUCTOR FETCH|      |     2 |     4 |    29   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------
 

select * from (
  SELECT /*+ cardinality (nrs 3) */distinct(column_value) a 
  from   TABLE(NUMBER_TBL( 1, 2, 3 )) nrs
) prcdnrs;

select * from dbms_xplan.display_cursor( format => 'TYPICAL LAST');

------------------------------------------------------------------------------------------------
| Id  | Operation                               | Name | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                        |      |       |       |    30 (100)|          |
|   1 |  VIEW                                   |      |     3 |    39 |    30   (4)| 00:00:01 |
|   2 |   HASH UNIQUE                           |      |     3 |     6 |    30   (4)| 00:00:01 |
|   3 |    COLLECTION ITERATOR CONSTRUCTOR FETCH|      |     3 |     6 |    29   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------


So either there's an issue with how the hints are written or the issue is caused by something else that switching to GTTs/UNION ALL happens to avoid.

Rating

  (19 ratings)

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

Comments

Alessandra, May 29, 2024 - 3:15 pm UTC

Running in my environment ..is because we have cursor_sharing=FORCE ?
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID 6nrsh2a6wbjkd, child number 0
-------------------------------------
select * from ( SELECT /*+ dynamic_sampling (nsr 10)
*/distinct(column_value) a from TABLE(NUMBER_TBL(
:"SYS_B_0",:"SYS_B_1")) nrs ) prcdnrs

Plan hash value: 2030300303

--------------------------------------------------------------------------------
----------------


PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%
CPU)| Time |

--------------------------------------------------------------------------------
----------------

| 0 | SELECT STATEMENT | | | | 4 (
100)| |

| 1 | VIEW | | 8168 | 103K| 4
(25)| 00:00:01 |

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------

| 2 | HASH UNIQUE | | 8168 | 16336 | 4
(25)| 00:00:01 |

| 3 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | 8168 | 16336 | 3
(0)| 00:00:01 |

--------------------------------------------------------------------------------
----------------

Alessandra, May 29, 2024 - 3:17 pm UTC

I tried with alter session set cursor_sharing=exact;
Cardinality still wrong.

Alessandra, May 29, 2024 - 3:18 pm UTC

The hint is used.
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Hint Report (identified by operation id / Query Block Name / Object Alias):
Total hints for statement: 1 (N - Unresolved (1))
---------------------------------------------------------------------------

2 - SEL$335DD26A
N - dynamic_sampling (nsr 10)


24 Zeilen ausgewõhlt.

Solved the problem with the unsolved hint but the problm in the big query remains

Alessandra, May 29, 2024 - 7:28 pm UTC


set timing on
set heading off;
set sqlblanklines on;

SET FEEDBACK ON SQL_ID;
set feedback only;

with
t_ctis_error
AS
( SELECT ctxd.ctxd_ctrs_id ctrs_id, MAX (1) error
FROM ct_xml_data ctxd
INNER JOIN ct_staging_xml_data csxd
ON ctxd.ctxd_id = csxd.csxd_ctxd_id
AND csxd.csxd_logging_info IS NOT NULL
WHERE ctxd.ctxd_valid_to IS NULL
GROUP BY ctxd.ctxd_ctrs_id),
t_t_deatline
AS
(
SELECT DISTINCT
FIRST_VALUE (tide.tide_ctis_due_date)
OVER (PARTITION BY proc.tita_prcd_id
ORDER BY tide.tide_day) AS ctis_due_date,
proc.tita_prcd_id prcd_id
FROM (
SELECT FIRST_VALUE (tide_day)
OVER (PARTITION BY prcd_id
ORDER BY tide_day NULLS LAST)
AS min_day,
prcd_id,
tide_tita_id,
tide_ddln_step_compl_date,
tide_day,
tide_ctis_due_date,
max_tide_ddln_step_compl_date
FROM (
SELECT FIRST_VALUE (tide_ddln_step_compl_date)
OVER (
PARTITION BY prcd_id
ORDER BY
tide_ddln_step_compl_date DESC NULLS LAST)
AS max_tide_ddln_step_compl_date,
proc.prcd_id,
deadline.tide_tita_id,
deadline.tide_ddln_step_compl_date,
deadline.tide_day,
deadline.tide_ctis_due_date
FROM timetable_deadline deadline,
proc_timetable timetable,
procedure proc
WHERE
timetable.tita_prcd_id = proc.prcd_id
AND deadline.tide_tita_id =
timetable.tita_id)
WHERE NVL (tide_ddln_step_compl_date, SYSDATE) =
NVL (max_tide_ddln_step_compl_date, SYSDATE)
)
base,
proc_timetable proc
INNER JOIN timetable_deadline tide
ON tide.tide_tita_id = proc.tita_id
WHERE proc.tita_prcd_id = base.prcd_id
AND tide.tide_ddln_step_compl_date IS NULL
AND tide.tide_day >= base.min_day
),
role_base
AS
(SELECT role_prty_id, role_prcd_id
FROM pty_role
WHERE role_roltc_id =
HEXTORAW ('A443E226873F0087E0540010E0683AC2')),
meldein
AS
(
SELECT role_prcd_id,
prty.prty_id,
prty.prty_name,
addr.addr_street,
addr.addr_street_number,
addr.addr_street_number_addition,
addr.addr_post_code,
addr.addr_city,
ctrc.ctrc_name
FROM role_base role
INNER JOIN pty_party prty
ON role.role_prty_id = prty.prty_id
/*LEFT JOIN pty_person pers
ON prty.prty_id = pers.pers_prty_id*/
INNER JOIN pty_contact_details codt
ON codt.codt_prty_id = prty.prty_id
INNER JOIN pty_address addr
ON addr.addr_codt_id = codt.codt_id
INNER JOIN ctl_country ctrc
ON addr.addr_crtc_id = ctrc.ctrc_crtc_id
INNER JOIN ctl_language lngc
ON ctrc.ctrc_lngc_id = lngc.lngc_id
WHERE lngc.LNGC_ISO_639_1 = 'DE')
SELECT /*+ index(ct_xml_data CTXD_IDX_ID_CTRS_VALID) */
t.prcd_ref_nr
prcd_ref_nr,
TO_CHAR (u.prfa_ref_num_folder)
prfa_ref_num_folder,
NVL2 (
meldein.prty_id,
meldein.prty_name
|| ', '
|| meldein.addr_street
|| ' '
|| meldein.addr_street_number
|| ' '
|| meldein.addr_street_number_addition
|| ', '
|| meldein.addr_post_code
|| ' '
|| meldein.addr_city
|| ', '
|| meldein.ctrc_name,
u.prfa_name_folder)
AS prfa_name_folder,
t.prcd_proc_id
prcd_proc_id,
t.prcd_pttc_id
prcd_pttc_id,
t.prcd_prsc_id
prcd_prsc_id,
t.prcd_comment_prcd_state
prcd_comment_prcd_state,
t.prcd_priority
prcd_priority,
t.prcd_submission_date
prcd_submission_date,
CASE
WHEN s.ctst_scope = 'AMG' AND ctrs.ctrs_id IS NULL
THEN
s.ctst_eudract_nr
WHEN ctrs.ctrs_id IS NULL
THEN
s.ctst_eudamed_civ_id
ELSE
NULL -- nur wenn es sich um keine CTIS handelt
END
ctst_eudract_nr,
DECODE (ctrs.ctrs_id,
NULL, ctl.cssc_name,
ctrs.ctrs_sponsorkategorie)
AS cssc_name,
ctl.cssc_name
orig,
DECODE (
ctrs.ctrs_id,
NULL, -- wenn nicht neues CT dann
(SELECT LISTAGG (
(SELECT tphc_name
FROM ctl_ct_phase
WHERE ctl_ct_phase.tphc_id =
ctr_phase_asgn.ctpa_tphc_id),
';')
WITHIN GROUP (ORDER BY 1)
FROM ctr_phase_asgn
WHERE ctr_phase_asgn.ctpa_ctst_id = s.ctst_id),
ctrs.ctrs_part1phase)
AS tphc_name,
(SELECT LISTAGG (
(SELECT tphc_name
FROM ctl_ct_phase
WHERE ctl_ct_phase.tphc_id =
ctr_phase_asgn.ctpa_tphc_id),
';')
WITHIN GROUP (ORDER BY 1)
FROM ctr_phase_asgn
WHERE ctr_phase_asgn.ctpa_ctst_id = s.ctst_id)
AS phase_orig,
(CASE
WHEN EXISTS
(SELECT ctob_scope
FROM ctr_object_ivd_md
WHERE ctr_object_ivd_md.ctob_ctst_id =
s.ctst_id
AND ctob_scope = 'IVD')
AND ctrs.ctrs_id IS NULL
THEN
1
WHEN NOT EXISTS
(SELECT ctob_scope
FROM ctr_object_ivd_md
WHERE ctr_object_ivd_md.ctob_ctst_id =
s.ctst_id
AND ctob_scope = 'IVD')
AND ctrs.ctrs_id IS NULL
THEN
0
ELSE
NULL
END)
AS ctob_scope,
(CASE
WHEN EXISTS
(SELECT ctob_has_ce_mark
FROM ctr_object_ivd_md
WHERE ctr_object_ivd_md.ctob_ctst_id =
s.ctst_id
AND ctob_has_ce_mark = '1')
AND ctrs.ctrs_id IS NULL
THEN
1
WHEN NOT EXISTS
(SELECT ctob_has_ce_mark
FROM ctr_object_ivd_md
WHERE ctr_object_ivd_md.ctob_ctst_id =
s.ctst_id
AND ctob_has_ce_mark = '1')
AND ctrs.ctrs_id IS NULL
THEN
0
ELSE
NULL
END)
AS ctob_has_ce_mark,
CASE WHEN mafo.mafo_ref_num_folder IS NULL THEN 0 ELSE 1 END
AS has_mafo,
DECODE (ctrs.ctrs_id, NULL, m.eqpf_gectc_id, NULL)
AS eqpf_gectc_id -- Kategorie
,
DECODE (ctrs.ctrs_id, NULL, m.eqpf_subject, NULL)
AS eqpf_subject -- Betreff
,
DECODE (ctrs.ctrs_id, NULL, s.ctst_crptc_id, NULL)
AS ctst_crptc_id -- Meldeverfahren
,
(CASE
WHEN ctst_scope = 'AMG'
THEN
ctim.ctim_display_name
WHEN ctst_scope = 'MPG'
THEN
(CASE
WHEN ctob.ctob_ext_seq_number IS NOT NULL
THEN
'PR' || ctob.ctob_ext_seq_number || ': '
ELSE
''
END)
|| COALESCE (ctob.ctob_product_name,
ctob.ctob_product_name_lay,
ctob.ctob_product_name_en)
WHEN ctrs.ctrs_id IS NOT NULL
THEN
ctmd.ctmd_main_product
END)
AS main_product -- Pruefprodukt
,
DECODE (ctrs.ctrs_id,
NULL, ctob.ctob_is_aimd_dir_90_385_eec,
NULL)
AS ctob_is_aimd_dir_90_385_eec -- Klassifizierung
,
DECODE (ctrs.ctrs_id, NULL, ctob.ctob_is_mdrc_dir_93_42_eec, NULL)
AS ctob_is_mdrc_dir_93_42_eec,
DECODE (ctrs.ctrs_id, NULL, ctob.ctob_ctmtc_id, NULL)
AS ctob_ctmtc_id,
DECODE (ctrs.ctrs_id, NULL, ctob.ctob_ctitc_id, NULL)
AS ctob_ctitc_id,
DECODE (ctrs.ctrs_id, NULL, ctob.ctob_is_intended_use, NULL)
AS ctob_is_intended_use -- Anw. in ZB
,
DECODE (ctrs.ctrs_id, NULL, s.ctst_has_paed_subj, NULL)
AS ctst_has_paed_subj -- <18
,
DECODE (ctrs.ctrs_id,
NULL, (SELECT SIGN (COUNT (tsgc.term_id))
FROM ctr_subj_group_asgn ctsa
JOIN all_tsgc_valid tsgc
ON tsgc.term_id = ctsa.ctsa_tsgtc_id
AND tsgc.term_code IN
('TSGTC_PREGNANT_WOMEN',
'TSGTC_NURS_WOMEN',
'TSGTC_EMERG_SITUATION',
'TSGTC_SUBJ_NOT_CONSENT')
WHERE ctsa.ctsa_ctst_id = s.ctst_id),
NULL)
AS risk_factor -- Risikofaktor
,
CASE
WHEN ctrs.ctrs_id IS NULL THEN s.ctst_is_combined_study
ELSE ctmd.ctmd_amg_mpg_comb
END
AS ctst_is_combined_study -- Kombistudie
,
DECODE (ctrs.ctrs_id, NULL, ctim.ctim_is_somatic_thrpy_mp, NULL)
AS ctim_is_somatic_thrpy_mp -- ATMP
,
DECODE (ctrs.ctrs_id, NULL, ctim.ctim_is_gene_therapy_mp, NULL)
AS ctim_is_gene_therapy_mp,
DECODE (ctrs.ctrs_id, NULL, ctim.ctim_is_tissue_eng_mp, NULL)
AS ctim_is_tissue_eng_mp,
DECODE (ctrs.ctrs_id, NULL, ctim.ctim_has_chem_origin, NULL)
AS ctim_has_chem_origin -- Chemical/biological origin
,
DECODE (ctrs.ctrs_id, NULL, ctim.ctim_has_bio_origin, NULL)
AS ctim_has_bio_origin,
DECODE (
ctrs.ctrs_id,
NULL, (SELECT CASE
WHEN ctam_has_chg_app_form = 1
AND ctst_scope = 'AMG'
THEN
'CTA, '
END
|| CASE
WHEN ctam_has_chg_prot = 1
AND ctst_scope = 'AMG'
THEN
'PROT, '
END
|| CASE
WHEN ctam_has_chg_app_form = 1
AND ctst_scope = 'MPG'
THEN
'CIA, '
END
|| CASE
WHEN ctam_has_chg_prot = 1
AND ctst_scope = 'MPG'
THEN
'CIP, '
END
|| CASE ctam_has_chg_ib WHEN 1 THEN 'IB, ' END
|| CASE
WHEN ctam_has_chg_impd = 1
AND ctst_scope = 'AMG'
THEN
'IMPD, '
END
|| CASE
WHEN ctam_has_chg_invstg_prod = 1
AND ctst_scope = 'MPG'
THEN
'MD/IVD, '
END
|| CASE
WHEN ctam_has_chg_pl_nr_sub_glob = 1
AND ctst_scope = 'MPG'
THEN
'NUMB, '
END
|| CASE ctam_has_chg_other_doc
WHEN 1 THEN 'SONST, '
END
|| CASE ctam_has_chg_add_sites
WHEN 1 THEN 'ZENTRUM, '
END
|| CASE ctam_is_ntf_tmp_halt
WHEN 1 THEN 'HALT, '
END
|| CASE ctam_is_req_restart
WHEN 1 THEN 'RESTART, '
END AS content_amd
FROM ctr_amendment ctam
WHERE ctam.ctam_ctst_id = s.ctst_id),
NULL
)
AS content_amendment -- Inhalt AMD
,
ctim.ctim_imp_has_ma
AS ctim_imp_has_ma,
t.prcd_pros_status_sum,
tide.ctis_due_date
AS ctis_due_date,
CASE
WHEN NVL (ctob.ctob_is_aimd_dir_90_385_eec, 0) = 1
THEN
'AIMD'
WHEN NVL (ctob.ctob_is_mdrc_dir_93_42_eec, 0) = 1
THEN
(SELECT name
FROM all_ctmc_valid
WHERE id = ctob.ctob_ctmc_id)
WHEN NVL (ctob.ctob_in_house_ivd, 0) = 1
THEN
'In-house IVD'
WHEN NVL (ctob.ctob_dir_98_79_ec_ivd, 0) = 1
THEN
(SELECT name
FROM all_ctic_valid
WHERE id = ctob.ctob_ctic_id)
WHEN NVL (ctob.ctob_dir_2017_746_ivdr, 0) = 1
THEN
(SELECT name
FROM all_ccac_valid
WHERE id = ctob.ctob_ccac_id)
END
klassifizierung,
s.ctst_xml_raw
xml_data,
s.ctst_scope
scope,
ctpf.ctpf_ctst_id
ctst_id,
crcc.name
AS risikokategorie,
DECODE (ctrs.ctrs_part,
0, 'Part I ' || CHR (38) || ' Part II',
1, 'Part I',
2, 'Part II',
NULL)
AS applicationscope,
ctrs.ctrs_reportingmemberstate
AS rms,
t.prcd_grouping_pooling
AS europ_verfahrensnummer,
t_ctis_error.error
is_ctis_error
FROM
(
select * from procedure,
(
select * from
(
SELECT /*+ dynamic_sampling (nrs 3) */distinct(column_value) a from TABLE(NUMBER_TBL( 102798692,102799603)) nrs

)) prcdnrs
where
prcdnrs.a = PRCD_REF_NR
)t
-- procedure t
INNER JOIN proc_folder_asgn u ON t.prcd_id = u.prfa_prcd_id
INNER JOIN proc_folder v ON u.prfa_prof_id = v.prof_id
LEFT JOIN general_enquiry_proc_folder m
ON m.eqpf_prof_id = u.prfa_prof_id
LEFT JOIN ctr_proc_folder ctpf ON v.prof_id = ctpf.ctpf_prof_id
LEFT JOIN ctr_study s ON s.ctst_id = ctpf_ctst_id
LEFT JOIN ctl_ct_spons_stat ctl ON ctl.cssc_id = s.ctst_cssc_id
LEFT JOIN master_folder mafo
ON mafo.mafo_ref_num_folder = u.prfa_ref_num_folder
AND mafo.mafo_folder_state_term_code = 'FOSTC_GA'
LEFT JOIN ctr_object_ivd_md ctob
ON s.ctst_ctob_main_id = ctob.ctob_id
LEFT JOIN ctr_study_imp ctim ON ctim.ctim_id = s.ctst_ctim_main_id
LEFT JOIN t_t_deatline tide ON tide.prcd_id = t.prcd_id
LEFT JOIN ct_procedure_proc_folder ctrf
ON ctrf.ctrf_prof_id = v.prof_id
LEFT JOIN ct_regulation_study ctrs
ON ctrs.ctrs_ctrf_id = ctrf.ctrf_id
LEFT JOIN t_ctis_error ON t_ctis_error.ctrs_id = ctrs.ctrs_id
LEFT JOIN ct_main_data ctmd ON ctmd.ctmd_ctrs_id = ctrs.ctrs_id
LEFT JOIN all_crcc_valid crcc ON crcc.id = ctmd.ctmd_crcc_id
LEFT JOIN meldein ON meldein.role_prcd_id = t.prcd_id;


--end;


Trying to compare the execution plan of the GTT version with the one with table of number

Alessandra, May 29, 2024 - 7:37 pm UTC

Let you know

Comapred the union with the table of number

A reader, May 30, 2024 - 6:02 am UTC

The only difference in the query is (is there a prpblem with PL/SQL and join?):
(
select /*+ index(procedure PRCD_IX_REF_NR) */ * from procedure,

(select * from
(
select 102798692 a from dual
union
select 102799603 a from dual
))
prcdnrs
where PRCD_REF_NR = prcdnrs.a ) t
Chris Saxon
May 30, 2024 - 12:59 pm UTC

What are the plans for the two queries?

Be sure to capture plan stats by running this before the queries

alter session set statistics_level = all;


And get all stats for the plans like this:

select * from dbms_xplan.display_cursor( format => 'ALLSTATS LAST');

Execution Plan of the fast version shows STATISTIC COLLERCTOR in use

Alessandra, May 30, 2024 - 2:08 pm UTC

Hi Chris,
I found out in the slow version (that with the UNION) execution plan that
the STATISTIC COLLECTOR has been used.
How can I enable it for the version with table of number?

Chris Saxon
May 31, 2024 - 5:13 pm UTC

Can you share a small, complete example showing this?

Explain Plan

Alessandra, May 30, 2024 - 2:18 pm UTC

Hi Chris,
the explain Plan are not really readable if I cut and paste them here.
Anyway the slow one shows COLLECTION ITERATOR CONTRUCTOR FETCH before the two line that differ between the twoe queries.
The good one (the one with the UNION) shows STATISTICS COLLECTOR.
Fron this point further the choise of the Optimizer begin to differ.
Chris Saxon
May 31, 2024 - 5:14 pm UTC

A straight copy-paste of the plan output is fine - use the code tag above the form to preserve the of format the plan

Alessandra, May 30, 2024 - 2:20 pm UTC

| 72 | H COLLECTION ITERATOR CONSTRUCTOR FETC |
| 1 | 2 | 2 |00:00:00.01 | 0 |
0 | 0 | | | | |

| 73 | TABLE ACCESS BY INDEX ROWID BATCHED | PROCEDURE

| 2 | 1 | 2 |00:00:00.01 | 8 |
0 | 0 | | | | |

|* 74 | INDEX RANGE SCAN | PRCD_IX_R
EF_NR | 2 | 1 | 2 |00:00:00.01 | 6 |

In the good one Execution Plan I see - this is an adaptive plan

Alessandra, May 30, 2024 - 2:27 pm UTC

Note
-----
- dynamic statistics used: dynamic sampling (level=AUTO)
- this is an adaptive plan
- 11 Sql Plan Directives used for this statement

What can I do to have an adaptive plan for the version with
Table of number ?

SLOW (with PL/SQL Collection)Execution Plans

A reader, May 31, 2024 - 7:35 pm UTC









SQL_ID  0q9tufsxw1umg, child number 1                                           
-------------------------------------                                           
with        t_ctis_error         AS             (  SELECT                       
ctxd.ctxd_ctrs_id ctrs_id, MAX (:"SYS_B_00") error                              
FROM ct_xml_data ctxd                       INNER JOIN                          
ct_staging_xml_data csxd                           ON     ctxd.ctxd_id          
= csxd.csxd_ctxd_id                              AND                            
csxd.csxd_logging_info IS NOT NULL                 WHERE                        
ctxd.ctxd_valid_to IS NULL              GROUP BY ctxd.ctxd_ctrs_id),            
     t_t_deatline         AS             (             SELECT DISTINCT          
                   FIRST_VALUE (tide.tide_ctis_due_date)                        
         OVER (PARTITION BY proc.tita_prcd_id                                   
    ORDER BY tide.tide_day)    AS ctis_due_date,                                

proc.tita_prcd_id                    prcd_id                FROM (              
          SELECT FIRST_VALUE (tide_day)                                         
OVER (PARTITION BY prcd_id                                       ORDER          
BY tide_day NULLS LAST)                                 AS min_day              
                                                                                
Plan hash value: 3524221536                                                     
                                                                                
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------                           
                                                                                
| Id  | Operation                                                    | Name     
                           | Starts | E-Rows | A-Rows |   A-Time   | Buffers | R

eads  | Writes |  OMem |  1Mem | Used-Mem | Used-Tmp|                           
                                                                                
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-----------------------------------------------------                           
                                                                                
|   0 | SELECT STATEMENT                                             |          
                           |      1 |        |      2 |00:00:11.16 |    1510K|  
 1465K|  42642 |       |       |          |         |                           
                                                                                
|   1 |  TABLE ACCESS BY INDEX ROWID                                 | CTL_CT_PH
ASE                        |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           

                                                                                
|*  2 |   INDEX UNIQUE SCAN                                          | TPHC_PK  
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|   3 |  SORT GROUP BY                                               |          
                           |      1 |      1 |      1 |00:00:00.01 |       0 |  
    0 |      0 |  1024 |  1024 |          |         |                           
                                                                                
|   4 |   TABLE ACCESS BY INDEX ROWID BATCHED                        | CTR_PHASE
_ASGN                      |      1 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                

|*  5 |    INDEX RANGE SCAN                                          | CTPA_FK_I
_CTST_ID                   |      1 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|   6 |  TABLE ACCESS BY INDEX ROWID                                 | CTL_CT_PH
ASE                        |      4 |      1 |      4 |00:00:00.01 |       6 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|*  7 |   INDEX UNIQUE SCAN                                          | TPHC_PK  
                           |      4 |      1 |      4 |00:00:00.01 |       2 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|*  8 |  INDEX RANGE SCAN                                            | CTR_OBJEC

T_IVD_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|*  9 |   INDEX RANGE SCAN                                           | CTR_OBJEC
T_IVD_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 10 |  INDEX RANGE SCAN                                            | CTR_OBJEC
T_IVD_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 11 |   INDEX RANGE SCAN                                           | CTR_OBJEC
T_IVD_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |  

    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  12 |  SORT AGGREGATE                                              |          
                           |      1 |      1 |      1 |00:00:00.01 |       5 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  13 |   NESTED LOOPS                                               |          
                           |      1 |      5 |      0 |00:00:00.01 |       5 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  14 |    NESTED LOOPS                                              |          
                           |      1 |    140 |      0 |00:00:00.01 |       5 |  
    0 |      0 |       |       |          |         |                           

                                                                                
|* 15 |     HASH JOIN                                                |          
                           |      1 |      7 |      0 |00:00:00.01 |       5 |  
    0 |      0 |  2533K|  2533K| 2682K (0)|         |                           
                                                                                
|  16 |      MERGE JOIN CARTESIAN                                    |          
                           |      1 |     12 |     12 |00:00:00.01 |       5 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  17 |       INLIST ITERATOR                                        |          
                           |      1 |        |      3 |00:00:00.01 |       2 |  
    0 |      0 |       |       |          |         |                           
                                                                                

|* 18 |        INDEX RANGE SCAN                                      | CCSC_IDX_
M01                        |      3 |      3 |      3 |00:00:00.01 |       2 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  19 |       BUFFER SORT                                            |          
                           |      3 |      4 |     12 |00:00:00.01 |       3 |  
    0 |      0 |  2048 |  2048 | 2048  (0)|         |                           
                                                                                
|* 20 |        TABLE ACCESS STORAGE FULL                             | CTL_CT_SU
BJECT_GRP_TERM             |      1 |      4 |      4 |00:00:00.01 |       3 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 21 |      INDEX RANGE SCAN                                        | CTR_SUBJ_

GROUP_ASGN_IDX$$_37C930007 |      1 |      2 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 22 |     INDEX RANGE SCAN                                         | TSGC_FK_I
_CCSC_ID                   |      0 |     20 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 23 |    TABLE ACCESS BY INDEX ROWID                               | CTL_CT_SU
BJECT_GRP                  |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  24 |  TABLE ACCESS BY INDEX ROWID BATCHED                         | CTR_AMEND
MENT                       |      1 |      1 |      0 |00:00:00.01 |       0 |  

    0 |      0 |       |       |          |         |                           
                                                                                
|* 25 |   INDEX RANGE SCAN                                           | CTAM_FK_I
_CTAM_CTST_ID              |      1 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  26 |  NESTED LOOPS                                                |          
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  27 |   NESTED LOOPS                                               |          
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           

                                                                                
|* 28 |    TABLE ACCESS BY INDEX ROWID                               | CAT_CT_MD
_RISK_CLASS                |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 29 |     INDEX UNIQUE SCAN                                        | CTMC_PK  
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 30 |    TABLE ACCESS BY INDEX ROWID                               | CAT_CTL_C
AT_STATE                   |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                

|* 31 |     INDEX UNIQUE SCAN                                        | CCSC_PK  
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 32 |   TABLE ACCESS BY INDEX ROWID                                | CAT_CT_MD
_RISK_CLASS_TERM           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 33 |    INDEX UNIQUE SCAN                                         | CTMTC_PK 
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  34 |    NESTED LOOPS                                              |          

                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  35 |     NESTED LOOPS                                             |          
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 36 |      TABLE ACCESS BY INDEX ROWID                             | CAT_CT_IV
D_CLASS                    |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 37 |       INDEX UNIQUE SCAN                                      | CTIC_PK  
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  

    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 38 |      TABLE ACCESS BY INDEX ROWID                             | CAT_CTL_C
AT_STATE                   |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 39 |       INDEX UNIQUE SCAN                                      | CCSC_PK  
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 40 |     TABLE ACCESS BY INDEX ROWID                              | CAT_CT_IV
D_CLASS_TERM               |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           

                                                                                
|* 41 |      INDEX UNIQUE SCAN                                       | CTITC_PK 
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  42 |      NESTED LOOPS                                            |          
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  43 |       NESTED LOOPS                                           |          
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                

|* 44 |        TABLE ACCESS BY INDEX ROWID                           | CAT_CLASS
IFICATION_ACC              |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 45 |         INDEX UNIQUE SCAN                                    | CCAC_PK  
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 46 |        TABLE ACCESS BY INDEX ROWID                           | CAT_CTL_C
AT_STATE                   |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 47 |         INDEX UNIQUE SCAN                                    | CCSC_PK  

                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 48 |       TABLE ACCESS BY INDEX ROWID                            | CAT_CLASS
IFICATION_ACC_TERM         |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 49 |        INDEX UNIQUE SCAN                                     | CCATC_PK 
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|* 50 |  HASH JOIN OUTER                                             |          
                           |      1 |      2 |      2 |00:00:11.16 |    1510K|  

 1465K|  42642 |  1586K|  1586K|  745K (0)|         |                           
                                                                                
|  51 |   JOIN FILTER CREATE                                         | :BF0000  
                           |      1 |      2 |      2 |00:00:11.10 |    1478K|  
 1465K|  42642 |       |       |          |         |                           
                                                                                
|* 52 |    HASH JOIN OUTER                                           |          
                           |      1 |      2 |      2 |00:00:11.10 |    1478K|  
 1465K|  42642 |  1540K|  1540K| 1706K (0)|         |                           
                                                                                
|* 53 |     HASH JOIN OUTER                                          |          
                           |      1 |      2 |      2 |00:00:01.18 |    1422K|  
 1426K|   4410 |  1541K|  1541K|  726K (0)|         |                           

                                                                                
|  54 |      JOIN FILTER CREATE                                      | :BF0001  
                           |      1 |      2 |      2 |00:00:00.01 |     248 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  55 |       NESTED LOOPS OUTER                                     |          
                           |      1 |      2 |      2 |00:00:00.01 |     248 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  56 |        NESTED LOOPS OUTER                                    |          
                           |      1 |      2 |      2 |00:00:00.01 |     242 |  
    0 |      0 |       |       |          |         |                           
                                                                                

|  57 |         NESTED LOOPS OUTER                                   |          
                           |      1 |      2 |      2 |00:00:00.01 |     242 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  58 |          NESTED LOOPS OUTER                                  |          
                           |      1 |      2 |      2 |00:00:00.01 |     242 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  59 |           NESTED LOOPS OUTER                                 |          
                           |      1 |      2 |      2 |00:00:00.01 |     242 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  60 |            NESTED LOOPS OUTER                                |          

                           |      1 |      2 |      2 |00:00:00.01 |     242 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 61 |             HASH JOIN OUTER                                  |          
                           |      1 |      2 |      2 |00:00:00.01 |     238 |  
    0 |      0 |  1593K|  1593K| 1211K (0)|         |                           
                                                                                
|* 62 |              HASH JOIN OUTER                                 |          
                           |      1 |      2 |      2 |00:00:00.01 |     222 |  
    0 |      0 |  1597K|  1597K|  756K (0)|         |                           
                                                                                
|  63 |               JOIN FILTER CREATE                             | :BF0002  
                           |      1 |      2 |      2 |00:00:00.01 |     169 |  

    0 |      0 |       |       |          |         |                           
                                                                                
|* 64 |                HASH JOIN OUTER                               |          
                           |      1 |      2 |      2 |00:00:00.01 |     169 |  
    0 |      0 |  1603K|  1603K|  750K (0)|         |                           
                                                                                
|  65 |                 JOIN FILTER CREATE                           | :BF0003  
                           |      1 |      2 |      2 |00:00:00.01 |      55 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 66 |                  HASH JOIN OUTER                             |          
                           |      1 |      2 |      2 |00:00:00.01 |      55 |  
    0 |      0 |  1605K|  1605K| 1194K (0)|         |                           

                                                                                
|  67 |                   JOIN FILTER CREATE                         | :BF0004  
                           |      1 |      2 |      2 |00:00:00.01 |      24 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  68 |                    NESTED LOOPS OUTER                        |          
                           |      1 |      2 |      2 |00:00:00.01 |      24 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  69 |                     NESTED LOOPS                             |          
                           |      1 |      2 |      2 |00:00:00.01 |      24 |  
    0 |      0 |       |       |          |         |                           
                                                                                

|  70 |                      NESTED LOOPS OUTER                      |          
                           |      1 |      2 |      2 |00:00:00.01 |      16 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  71 |                       NESTED LOOPS                           |          
                           |      1 |      2 |      2 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  72 |                        COLLECTION ITERATOR CONSTRUCTOR FETCH |          
                           |      1 |      2 |      2 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  73 |                        TABLE ACCESS BY INDEX ROWID BATCHED   | PROCEDURE

                           |      2 |      1 |      2 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 74 |                         INDEX RANGE SCAN                     | PRCD_IX_R
EF_NR                      |      2 |      1 |      2 |00:00:00.01 |       6 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  75 |                       VIEW PUSHED PREDICATE                  |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  76 |                        NESTED LOOPS                          |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  

    0 |      0 |       |       |          |         |                           
                                                                                
|  77 |                         NESTED LOOPS                         |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 78 |                          HASH JOIN                           |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |  1657K|  1657K|  579K (0)|         |                           
                                                                                
|  79 |                           NESTED LOOPS                       |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           

                                                                                
|  80 |                            NESTED LOOPS                      |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  81 |                             NESTED LOOPS                     |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|  82 |                              NESTED LOOPS                    |          
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                

|* 83 | TCHED                         TABLE ACCESS BY INDEX ROWID BA | PTY_ROLE 
                           |      2 |      1 |      0 |00:00:00.01 |       8 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 84 |                                INDEX RANGE SCAN              | ROLE_FK_I
_PRCD_ID                   |      2 |      3 |      5 |00:00:00.01 |       6 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  85 |                               TABLE ACCESS BY INDEX ROWID    | PTY_PARTY
                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |       |       |          |         |                           
                                                                                
|* 86 |                                INDEX UNIQUE SCAN             | PRTY_PK  

                           |      0 |      1 |      0 |00:00:00.01 |       0 |  
    0 |      0 |  1028K|  1028K|          |         |                           
                                                                                
|  87 | CHED                         TABLE ACCESS BY INDEX ROWID BAT | PTY_CONTA
CT_DETAILS                 |      0 |      1 |      0 |00:00:00.01 |       0 | 

FAST (version with UNION) Execution Plan

A reader, May 31, 2024 - 7:37 pm UTC


SQL_ID  bbffwmvqghcy4, child number 0                                           
-------------------------------------                                           
with        t_ctis_error         AS             (  SELECT                       
ctxd.ctxd_ctrs_id ctrs_id, MAX (:"SYS_B_00") error                              
FROM ct_xml_data ctxd                       INNER JOIN                          
ct_staging_xml_data csxd                           ON     ctxd.ctxd_id          
= csxd.csxd_ctxd_id                              AND                            
csxd.csxd_logging_info IS NOT NULL                 WHERE                        
ctxd.ctxd_valid_to IS NULL              GROUP BY ctxd.ctxd_ctrs_id),            
     t_t_deatline         AS             (             SELECT DISTINCT          
                   FIRST_VALUE (tide.tide_ctis_due_date)                        
         OVER (PARTITION BY proc.tita_prcd_id                                   
    ORDER BY tide.tide_day)    AS ctis_due_date,                                

proc.tita_prcd_id                    prcd_id                FROM (              
          SELECT FIRST_VALUE (tide_day)                                         
OVER (PARTITION BY prcd_id                                       ORDER          
BY tide_day NULLS LAST)                                 AS min_day              
                                                                                
Plan hash value: 3158229646                                                     
                                                                                
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------------                                                           
                                                                                
| Id  | Operation                                                | Name         
                       | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem

 |  1Mem | Used-Mem |                                                           
                                                                                
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
---------------------                                                           
                                                                                
|   0 | SELECT STATEMENT                                         |              
                       |      1 |        |      2 |00:00:00.01 |     267 |      
 |       |          |                                                           
                                                                                
|   1 |  TABLE ACCESS BY INDEX ROWID                             | CTL_CT_PHASE 
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           

                                                                                
|*  2 |   INDEX UNIQUE SCAN                                      | TPHC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|   3 |  SORT GROUP BY                                           |              
                       |      1 |      1 |      1 |00:00:00.01 |       0 |  1024
 |  1024 |          |                                                           
                                                                                
|   4 |   TABLE ACCESS BY INDEX ROWID BATCHED                    | CTR_PHASE_ASG
N                      |      1 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                

|*  5 |    INDEX RANGE SCAN                                      | CTPA_FK_I_CTS
T_ID                   |      1 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|   6 |  TABLE ACCESS BY INDEX ROWID                             | CTL_CT_PHASE 
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|*  7 |   INDEX UNIQUE SCAN                                      | TPHC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|*  8 |  INDEX RANGE SCAN                                        | CTR_OBJECT_IV

D_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|*  9 |   INDEX RANGE SCAN                                       | CTR_OBJECT_IV
D_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|* 10 |  INDEX RANGE SCAN                                        | CTR_OBJECT_IV
D_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|* 11 |   INDEX RANGE SCAN                                       | CTR_OBJECT_IV
D_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |  1028

K|  1028K|          |                                                           
                                                                                
|  12 |  SORT AGGREGATE                                          |              
                       |      1 |      1 |      1 |00:00:00.01 |       8 |      
 |       |          |                                                           
                                                                                
|* 13 |   HASH JOIN                                              |              
                       |      1 |      1 |      0 |00:00:00.01 |       8 |  3289
K|  3289K| 2712K (0)|                                                           
                                                                                
|* 14 |    HASH JOIN                                             |              
                       |      1 |      1 |      8 |00:00:00.01 |       8 |  3157
K|  3157K| 4310K (0)|                                                           

                                                                                
|  15 |     NESTED LOOPS                                         |              
                       |      1 |      1 |     20 |00:00:00.01 |       5 |      
 |       |          |                                                           
                                                                                
|  16 |      INLIST ITERATOR                                     |              
                       |      1 |        |      3 |00:00:00.01 |       2 |      
 |       |          |                                                           
                                                                                
|* 17 |       INDEX RANGE SCAN                                   | CCSC_IDX_M01 
                       |      3 |      3 |      3 |00:00:00.01 |       2 |  1028
K|  1028K|          |                                                           
                                                                                

|* 18 |      TABLE ACCESS BY INDEX ROWID BATCHED                 | CTL_CT_SUBJEC
T_GRP                  |      3 |      1 |     20 |00:00:00.01 |       3 |      
 |       |          |                                                           
                                                                                
|* 19 |       INDEX RANGE SCAN                                   | TSGC_FK_I_CCS
C_ID                   |      3 |     20 |     20 |00:00:00.01 |       2 |  1028
K|  1028K|          |                                                           
                                                                                
|* 20 |     TABLE ACCESS STORAGE FULL                            | CTL_CT_SUBJEC
T_GRP_TERM             |      1 |      1 |      4 |00:00:00.01 |       3 |  1028
K|  1028K|          |                                                           
                                                                                
|* 21 |    INDEX RANGE SCAN                                      | CTR_SUBJ_GROU

P_ASGN_IDX$$_37C930007 |      1 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|  22 |  TABLE ACCESS BY INDEX ROWID BATCHED                     | CTR_AMENDMENT
                       |      1 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 23 |   INDEX RANGE SCAN                                       | CTAM_FK_I_CTA
M_CTST_ID              |      1 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|  24 |  NESTED LOOPS                                            |              
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      

 |       |          |                                                           
                                                                                
|  25 |   NESTED LOOPS                                           |              
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 26 |    TABLE ACCESS BY INDEX ROWID                           | CAT_CT_MD_RIS
K_CLASS                |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 27 |     INDEX UNIQUE SCAN                                    | CTMC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           

                                                                                
|* 28 |    TABLE ACCESS BY INDEX ROWID                           | CAT_CTL_CAT_S
TATE                   |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 29 |     INDEX UNIQUE SCAN                                    | CCSC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|* 30 |   TABLE ACCESS BY INDEX ROWID                            | CAT_CT_MD_RIS
K_CLASS_TERM           |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                

|* 31 |    INDEX UNIQUE SCAN                                     | CTMTC_PK     
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|  32 |    NESTED LOOPS                                          |              
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|  33 |     NESTED LOOPS                                         |              
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 34 |      TABLE ACCESS BY INDEX ROWID                         | CAT_CT_IVD_CL

ASS                    |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 35 |       INDEX UNIQUE SCAN                                  | CTIC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|* 36 |      TABLE ACCESS BY INDEX ROWID                         | CAT_CTL_CAT_S
TATE                   |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 37 |       INDEX UNIQUE SCAN                                  | CCSC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028

K|  1028K|          |                                                           
                                                                                
|* 38 |     TABLE ACCESS BY INDEX ROWID                          | CAT_CT_IVD_CL
ASS_TERM               |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 39 |      INDEX UNIQUE SCAN                                   | CTITC_PK     
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|  40 |      NESTED LOOPS                                        |              
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           

                                                                                
|  41 |       NESTED LOOPS                                       |              
                       |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 42 |        TABLE ACCESS BY INDEX ROWID                       | CAT_CLASSIFIC
ATION_ACC              |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 43 |         INDEX UNIQUE SCAN                                | CCAC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                

|* 44 |        TABLE ACCESS BY INDEX ROWID                       | CAT_CTL_CAT_S
TATE                   |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 45 |         INDEX UNIQUE SCAN                                | CCSC_PK      
                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|* 46 |       TABLE ACCESS BY INDEX ROWID                        | CAT_CLASSIFIC
ATION_ACC_TERM         |      0 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 47 |        INDEX UNIQUE SCAN                                 | CCATC_PK     

                       |      0 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|  48 |  NESTED LOOPS OUTER                                      |              
                       |      1 |      2 |      2 |00:00:00.01 |     267 |      
 |       |          |                                                           
                                                                                
|  49 |   NESTED LOOPS OUTER                                     |              
                       |      1 |      2 |      2 |00:00:00.01 |     267 |      
 |       |          |                                                           
                                                                                
|  50 |    NESTED LOOPS OUTER                                    |              
                       |      1 |      2 |      2 |00:00:00.01 |     259 |      

 |       |          |                                                           
                                                                                
|* 51 |     HASH JOIN OUTER                                      |              
                       |      1 |      2 |      2 |00:00:00.01 |     259 |  1581
K|  1581K| 1216K (0)|                                                           
                                                                                
|  52 |      NESTED LOOPS OUTER                                  |              
                       |      1 |      2 |      2 |00:00:00.01 |     243 |      
 |       |          |                                                           
                                                                                
|* 53 |       HASH JOIN OUTER                                    |              
                       |      1 |      2 |      2 |00:00:00.01 |     224 |  1532
K|  1532K|  749K (0)|                                                           

                                                                                
|  54 |        JOIN FILTER CREATE                                | :BF0000      
                       |      1 |      2 |      2 |00:00:00.01 |     171 |      
 |       |          |                                                           
                                                                                
|* 55 |         HASH JOIN OUTER                                  |              
                       |      1 |      2 |      2 |00:00:00.01 |     171 |  1534
K|  1534K|  749K (0)|                                                           
                                                                                
|  56 |          JOIN FILTER CREATE                              | :BF0001      
                       |      1 |      2 |      2 |00:00:00.01 |      57 |      
 |       |          |                                                           
                                                                                

|  57 |           NESTED LOOPS OUTER                             |              
                       |      1 |      2 |      2 |00:00:00.01 |      57 |      
 |       |          |                                                           
                                                                                
|  58 |            NESTED LOOPS OUTER                            |              
                       |      1 |      2 |      2 |00:00:00.01 |      57 |      
 |       |          |                                                           
                                                                                
|  59 |             NESTED LOOPS OUTER                           |              
                       |      1 |      2 |      2 |00:00:00.01 |      57 |      
 |       |          |                                                           
                                                                                
|  60 |              NESTED LOOPS OUTER                          |              

                       |      1 |      2 |      2 |00:00:00.01 |      57 |      
 |       |          |                                                           
                                                                                
|  61 |               NESTED LOOPS OUTER                         |              
                       |      1 |      2 |      2 |00:00:00.01 |      57 |      
 |       |          |                                                           
                                                                                
|  62 |                NESTED LOOPS OUTER                        |              
                       |      1 |      2 |      2 |00:00:00.01 |      57 |      
 |       |          |                                                           
                                                                                
|  63 |                 NESTED LOOPS OUTER                       |              
                       |      1 |      2 |      2 |00:00:00.01 |      51 |      

 |       |          |                                                           
                                                                                
|* 64 |                  HASH JOIN OUTER                         |              
                       |      1 |      2 |      2 |00:00:00.01 |      47 |  1604
K|  1604K| 1194K (0)|                                                           
                                                                                
|  65 |                   JOIN FILTER CREATE                     | :BF0002      
                       |      1 |      2 |      2 |00:00:00.01 |      16 |      
 |       |          |                                                           
                                                                                
|  66 |                    NESTED LOOPS                          |              
                       |      1 |      2 |      2 |00:00:00.01 |      16 |      
 |       |          |                                                           

                                                                                
|  67 |                     NESTED LOOPS                         |              
                       |      1 |      4 |      3 |00:00:00.01 |      14 |      
 |       |          |                                                           
                                                                                
|  68 |                      NESTED LOOPS                        |              
                       |      1 |      2 |      2 |00:00:00.01 |       8 |      
 |       |          |                                                           
                                                                                
|  69 |                       VIEW                               |              
                       |      1 |      2 |      2 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                

|  70 |                        SORT UNIQUE                       |              
                       |      1 |      2 |      2 |00:00:00.01 |       0 |  2048
 |  2048 | 2048  (0)|                                                           
                                                                                
|  71 |                         UNION-ALL                        |              
                       |      1 |        |      2 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|  72 |                          FAST DUAL                       |              
                       |      1 |      1 |      1 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|  73 |                          FAST DUAL                       |              

                       |      1 |      1 |      1 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|  74 |                       TABLE ACCESS BY INDEX ROWID BATCHED| PROCEDURE    
                       |      2 |      1 |      2 |00:00:00.01 |       8 |      
 |       |          |                                                           
                                                                                
|* 75 |                        INDEX RANGE SCAN                  | PRCD_IX_REF_N
R                      |      2 |      1 |      2 |00:00:00.01 |       6 |  1028
K|  1028K|          |                                                           
                                                                                
|* 76 |                      INDEX RANGE SCAN                    | PRFA_FK_I_PRC
D_ID                   |      2 |      2 |      3 |00:00:00.01 |       6 |  1028

K|  1028K|          |                                                           
                                                                                
|* 77 |                     TABLE ACCESS BY INDEX ROWID          | PROC_FOLDER_A
SGN                    |      3 |      1 |      2 |00:00:00.01 |       2 |      
 |       |          |                                                           
                                                                                
|  78 |                   JOIN FILTER USE                        | :BF0002      
                       |      1 |   1630 |      0 |00:00:00.01 |      31 |      
 |       |          |                                                           
                                                                                
|* 79 |                    TABLE ACCESS STORAGE FULL             | CT_PROCEDURE_
PROC_FOLDER            |      1 |   1630 |      0 |00:00:00.01 |      31 |  1028
K|  1028K|          |                                                           

                                                                                
|  80 |                  TABLE ACCESS BY INDEX ROWID BATCHED     | CTR_PROC_FOLD
ER                     |      2 |      1 |      0 |00:00:00.01 |       4 |      
 |       |          |                                                           
                                                                                
|* 81 |                   INDEX RANGE SCAN                       | CTPF_FK_I_PRO
F_ID                   |      2 |      1 |      0 |00:00:00.01 |       4 |  1028
K|  1028K|          |                                                           
                                                                                
|  82 |                 TABLE ACCESS BY INDEX ROWID BATCHED      | GENERAL_ENQUI
RY_PROC_FOLDER         |      2 |      1 |      2 |00:00:00.01 |       6 |      
 |       |          |                                                           
                                                                                

|* 83 |                  INDEX RANGE SCAN                        | EQPF_FK_I_PRO
F_ID                   |      2 |      1 |      2 |00:00:00.01 |       4 |  1028
K|  1028K|          |                                                           
                                                                                
|* 84 |                TABLE ACCESS BY INDEX ROWID               | MASTER_FOLDER
                       |      2 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 85 |                 INDEX UNIQUE SCAN                        | MAFO_REF_NUM_
FOLDER_UK              |      2 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1028K|          |                                                           
                                                                                
|  86 |               TABLE ACCESS BY INDEX ROWID                | CTR_STUDY    

                       |      2 |      1 |      0 |00:00:00.01 |       0 |      
 |       |          |                                                           
                                                                                
|* 87 |                INDEX UNIQUE SCAN                         | CTST_PK      
                       |      2 |      1 |      0 |00:00:00.01 |       0 |  1028
K|  1

Chris Saxon
June 03, 2024 - 4:03 pm UTC

The query is estimating 2 rows from the nested table. But as you've found this disables adaptive plans.

Rather than asking "what can I do to get an adaptive plan", it may be better to understand why it's using a hash join for the slow query.

I'm guessing there's a misestimation somewhere in the plan - The bottom of the plan is missing, which likely contains the key info to understand this.

PS - please set the linesize to a large enough value so that each operation fits on one line!

BAD Plan nice formatted

Alessandra, June 03, 2024 - 6:18 pm UTC

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| Id  | Operation                                                    | Name                                | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  | Writes |  OMem |  1Mem | Used-Mem | Used-Tmp|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|   0 | SELECT STATEMENT                                             |                                     |      1 |        |      2 |00:00:07.57 |    1511K|   1497K|  44204 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|   1 |  TABLE ACCESS BY INDEX ROWID                                 | CTL_CT_PHASE                        |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*  2 |   INDEX UNIQUE SCAN                                          | TPHC_PK                             |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

|   3 |  SORT GROUP BY                                               |                                     |      1 |      1 |      1 |00:00:00.01 |       0 |      0 |      0 |  1024 |  1024 |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|   4 |   TABLE ACCESS BY INDEX ROWID BATCHED                        | CTR_PHASE_ASGN                      |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*  5 |    INDEX RANGE SCAN                                          | CTPA_FK_I_CTST_ID                   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|   6 |  TABLE ACCESS BY INDEX ROWID                                 | CTL_CT_PHASE                        |      4 |      1 |      4 |00:00:00.01 |       6 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*  7 |   INDEX UNIQUE SCAN                                          | TPHC_PK                             |      4 |      1 |      4 |00:00:00.01 |       2 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*  8 |  INDEX RANGE SCAN                                            | CTR_OBJECT_IVD_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*  9 |   INDEX RANGE SCAN                                           | CTR_OBJECT_IVD_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 10 |  INDEX RANGE SCAN                                            | CTR_OBJECT_IVD_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 11 |   INDEX RANGE SCAN                                           | CTR_OBJECT_IVD_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|  12 |  SORT AGGREGATE                                              |                                     |      1 |      1 |      1 |00:00:00.01 |      10 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|  13 |   NESTED LOOPS                                               |                                     |      1 |      1 |      0 |00:00:00.01 |      10 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|  14 |    NESTED LOOPS                                              |                                     |      1 |      1 |      8 |00:00:00.01 |      10 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|  15 |     NESTED LOOPS                                             |                                     |      1 |      1 |     20 |00:00:00.01 |       5 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

|  16 |      INLIST ITERATOR                                         |                                     |      1 |        |      3 |00:00:00.01 |       2 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 17 |       INDEX RANGE SCAN                                       | CCSC_IDX_M01                        |      3 |      3 |      3 |00:00:00.01 |       2 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 18 |      TABLE ACCESS BY INDEX ROWID BATCHED                     | CTL_CT_SUBJECT_GRP                  |      3 |      1 |     20 |00:00:00.01 |       3 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 19 |       INDEX RANGE SCAN                                       | TSGC_FK_I_CCSC_ID                   |      3 |     20 |     20 |00:00:00.01 |       2 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 20 |     TABLE ACCESS BY INDEX ROWID                              | CTL_CT_SUBJECT_GRP_TERM             |     20 |      1 |      8 |00:00:00.01 |       5 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 21 |      INDEX UNIQUE SCAN                                       | TSGTC_PK                            |     20 |      1 |     20 |00:00:00.01 |       4 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 22 |    INDEX RANGE SCAN                                          | CTR_SUBJ_GROUP_ASGN_IDX$$_37C930007 |      8 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|  23 |  TABLE ACCESS BY INDEX ROWID BATCHED                         | CTR_AMENDMENT                       |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 24 |   INDEX RANGE SCAN                                           | CTAM_FK_I_CTAM_CTST_ID              |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|  25 |  NESTED LOOPS                                                |                                     |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|  26 |   NESTED LOOPS                                               |                                     |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|* 27 |    TABLE ACCESS BY INDEX ROWID                               | CAT_CT_MD_RISK_CLASS                |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

GOOD PLAN (OF THE VERSION WITH UNION) NICE FORMATTED

Alessandra, June 03, 2024 - 6:21 pm UTC

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| Id  | Operation                                                | Name                                | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|   0 | SELECT STATEMENT                                         |                                     |      1 |        |      2 |00:00:00.01 |     263 |      2 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|   1 |  TABLE ACCESS BY INDEX ROWID                             | CTL_CT_PHASE                        |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*  2 |   INDEX UNIQUE SCAN                                      | TPHC_PK                             |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

|   3 |  SORT GROUP BY                                           |                                     |      1 |      1 |      1 |00:00:00.01 |       0 |      0 |  1024 |  1024 |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|   4 |   TABLE ACCESS BY INDEX ROWID BATCHED                    | CTR_PHASE_ASGN                      |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*  5 |    INDEX RANGE SCAN                                      | CTPA_FK_I_CTST_ID                   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|   6 |  TABLE ACCESS BY INDEX ROWID                             | CTL_CT_PHASE                        |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*  7 |   INDEX UNIQUE SCAN                                      | TPHC_PK                             |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*  8 |  INDEX RANGE SCAN                                        | CTR_OBJECT_IVD_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*  9 |   INDEX RANGE SCAN                                       | CTR_OBJECT_IVD_MD_IDX$$_37C930005   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 10 |  INDEX RANGE SCAN                                        | CTR_OBJECT_IVD_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 11 |   INDEX RANGE SCAN                                       | CTR_OBJECT_IVD_MD_IDX$$_37C930006   |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|  12 |  SORT AGGREGATE                                          |                                     |      1 |      1 |      1 |00:00:00.01 |       8 |      1 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 13 |   HASH JOIN                                              |                                     |      1 |      1 |      0 |00:00:00.01 |       8 |      1 |  3289K|  3289K| 2722K (0)|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 14 |    HASH JOIN                                             |                                     |      1 |      1 |      8 |00:00:00.01 |       8 |      1 |  3157K|  3157K| 4315K (0)|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|  15 |     NESTED LOOPS                                         |                                     |      1 |      1 |     20 |00:00:00.01 |       5 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

|  16 |      INLIST ITERATOR                                     |                                     |      1 |        |      3 |00:00:00.01 |       2 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 17 |       INDEX RANGE SCAN                                   | CCSC_IDX_M01                        |      3 |      3 |      3 |00:00:00.01 |       2 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 18 |      TABLE ACCESS BY INDEX ROWID BATCHED                 | CTL_CT_SUBJECT_GRP                  |      3 |      1 |     20 |00:00:00.01 |       3 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 19 |       INDEX RANGE SCAN                                   | TSGC_FK_I_CCSC_ID                   |      3 |     20 |     20 |00:00:00.01 |       2 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 20 |     TABLE ACCESS STORAGE FULL                            | CTL_CT_SUBJECT_GRP_TERM             |      1 |      1 |      4 |00:00:00.01 |       3 |      1 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 21 |    INDEX RANGE SCAN                                      | CTR_SUBJ_GROUP_ASGN_IDX$$_37C930007 |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|  22 |  TABLE ACCESS BY INDEX ROWID BATCHED                     | CTR_AMENDMENT                       |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 23 |   INDEX RANGE SCAN                                       | CTAM_FK_I_CTAM_CTST_ID              |      1 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|  24 |  NESTED LOOPS                                            |                                     |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|  25 |   NESTED LOOPS                                           |                                     |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 26 |    TABLE ACCESS BY INDEX ROWID                           | CAT_CT_MD_RISK_CLASS                |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|* 27 |     INDEX UNIQUE SCAN                                    | CTMC_PK                             |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              

BAD bottom part of execution plan

Alessandra, June 03, 2024 - 6:22 pm UTC

| 107 |                NESTED LOOPS                                  |                                     |      1 |      1 |      3 |00:00:00.01 |      13 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 108 |                 NESTED LOOPS                                 |                                     |      1 |      1 |      3 |00:00:00.01 |      12 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 109 |                  NESTED LOOPS                                |                                     |      1 |      1 |      3 |00:00:00.01 |      10 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*110 |                   TABLE ACCESS STORAGE FULL                  | CAT_CT_RISK_CATEGORY                |      1 |      1 |      3 |00:00:00.01 |       7 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*111 |                   TABLE ACCESS BY INDEX ROWID                | CAT_CTL_CAT_STATE                   |      3 |      1 |      3 |00:00:00.01 |       3 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*112 |                    INDEX UNIQUE SCAN                         | CCSC_PK                             |      3 |      1 |      3 |00:00:00.01 |       2 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*113 |                  INDEX UNIQUE SCAN                           | CRCTC_PK                            |      3 |      1 |      3 |00:00:00.01 |       2 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*114 |                 TABLE ACCESS BY INDEX ROWID                  | CAT_CT_RISK_CATEGORY_TERM           |      3 |      1 |      3 |00:00:00.01 |       1 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 115 |              TABLE ACCESS BY INDEX ROWID BATCHED             | CTR_PROC_FOLDER                     |      2 |      1 |      0 |00:00:00.01 |       4 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*116 |               INDEX RANGE SCAN                               | CTPF_FK_I_PROF_ID                   |      2 |      1 |      0 |00:00:00.01 |       4 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 117 |             TABLE ACCESS BY INDEX ROWID                      | CTR_STUDY                           |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*118 |              INDEX UNIQUE SCAN                               | CTST_PK                             |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 119 |            TABLE ACCESS BY INDEX ROWID                       | CTR_STUDY_IMP                       |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

|*120 |             INDEX UNIQUE SCAN                                | CTIM_PK                             |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 121 |           TABLE ACCESS BY INDEX ROWID                        | CTR_OBJECT_IVD_MD                   |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*122 |            INDEX UNIQUE SCAN                                 | CTOB_PK                             |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 123 |          TABLE ACCESS BY INDEX ROWID                         | CTL_CT_SPONS_STAT                   |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*124 |           INDEX UNIQUE SCAN                                  | CSSC_PK                             |      2 |      1 |      0 |00:00:00.01 |       0 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 125 |         TABLE ACCESS BY INDEX ROWID BATCHED                  | GENERAL_ENQUIRY_PROC_FOLDER         |      2 |      1 |      2 |00:00:00.01 |       6 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*126 |          INDEX RANGE SCAN                                    | EQPF_FK_I_PROF_ID                   |      2 |      1 |      2 |00:00:00.01 |       4 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 127 |       VIEW                                                   |                                     |      1 |   1966 |      0 |00:00:01.04 |    1453K|   1459K|   5715 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 128 |        HASH GROUP BY                                         |                                     |      1 |   1966 |      0 |00:00:01.04 |    1453K|   1459K|   5715 |  1850K|  1850K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 129 |         JOIN FILTER USE                                      | :BF0002                             |      1 |  70098 |      0 |00:00:01.04 |    1453K|   1459K|   5715 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*130 |          HASH JOIN                                           |                                     |      1 |  70098 |   2360 |00:00:01.04 |    1453K|   1459K|   5715 |    90M|  8268K|   93M (1)|      48M|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 131 |           JOIN FILTER CREATE                                 | :BF0006                             |      1 |    138K|    184K|00:00:00.47 |    1190K|   1190K|      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*132 |            TABLE ACCESS STORAGE FULL                         | CT_STAGING_XML_DATA                 |      1 |    138K|    184K|00:00:00.42 |    1190K|   1190K|      0 |  1028K|  1028K| 3096K (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

| 133 |           JOIN FILTER USE                                    | :BF0006                             |      1 |    381K|  18665 |00:00:00.05 |     263K|    263K|      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*134 |            TABLE ACCESS STORAGE FULL                         | CT_XML_DATA                         |      1 |    381K|  18665 |00:00:00.05 |     263K|    263K|      0 |  1028K|  1028K| 3096K (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 135 |     VIEW                                                     |                                     |      1 |  70250 |      4 |00:00:06.52 |   56010 |  38489 |  38489 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 136 |      HASH UNIQUE                                             |                                     |      1 |  70250 |      4 |00:00:06.52 |   56010 |  38489 |  38489 |    19M|  7803K| 6351K (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 137 |       JOIN FILTER USE                                        | :BF0001                             |      1 |  70250 |    228 |00:00:06.52 |   56010 |  38489 |  38489 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

BAD one

Alessandra, June 03, 2024 - 7:07 pm UTC

| 137 |       JOIN FILTER USE                                        | :BF0001                             |      1 |  70250 |    228 |00:00:06.52 |   56010 |  38489 |  38489 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 138 |        WINDOW SORT                                           |                                     |      1 |  70250 |   1046K|00:00:06.46 |   56010 |  38489 |  38489 |   101M|  5185K|   31M (1)|      98M|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*139 |         HASH JOIN                                            |                                     |      1 |  70250 |   1046K|00:00:03.83 |   56001 |  15419 |  15419 |    28M|  8259K|   36M (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 140 |          VIEW                                                |                                     |      1 |    874K|    394K|00:00:02.95 |   28004 |  15419 |  15419 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 141 |           WINDOW SORT                                        |                                     |      1 |    874K|    394K|00:00:02.92 |   28004 |  15419 |  15419 |    22M|  2709K|   20M (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*142 |            VIEW                                              |                                     |      1 |    874K|    394K|00:00:02.55 |   28004 |  15419 |  15419 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 143 |             WINDOW SORT                                      |                                     |      1 |    874K|    875K|00:00:02.43 |   28004 |  15419 |  15419 |    67M|  4327K|   31M (1)|      66M|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*144 |              HASH JOIN                                       |                                     |      1 |    874K|    875K|00:00:00.54 |   27997 |      0 |      0 |    36M|  6754K|   38M (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 145 |               TABLE ACCESS STORAGE FULL                      | PROC_TIMETABLE                      |      1 |    447K|    447K|00:00:00.05 |    7688 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

| 146 |               TABLE ACCESS STORAGE FULL                      | TIMETABLE_DEADLINE                  |      1 |    874K|    875K|00:00:00.15 |   20309 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*147 |          HASH JOIN                                           |                                     |      1 |    640K|    640K|00:00:00.49 |   27997 |      0 |      0 |    36M|  6754K|   38M (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 148 |           TABLE ACCESS STORAGE FULL                          | PROC_TIMETABLE                      |      1 |    447K|    447K|00:00:00.04 |    7688 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*149 |           TABLE ACCESS STORAGE FULL                          | TIMETABLE_DEADLINE                  |      1 |    640K|    640K|00:00:00.18 |   20309 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 150 |   VIEW                                                       | VW_SSQ_1                            |      1 |  71160 |      4 |00:00:00.01 |    1389 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 151 |    HASH GROUP BY                                             |                                     |      1 |  71160 |      4 |00:00:00.01 |    1389 |      0 |      0 |  1453K|  1453K| 3336K (0)|         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
| 152 |     JOIN FILTER USE                                          | :BF0000                             |      1 |  75243 |      4 |00:00:00.01 |    1383 |      0 |      0 |       |       |          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
|*153 |      TABLE ACCESS STORAGE FULL                               | CTR_PHASE_ASGN                      |      1 |  75243 |      4 |00:00:00.01 |    1383 |      0 |      0 |  1028K|  1028K|          |         |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Predicate Information (identified by operation id):                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
---------------------------------------------------         

GOOD ONE BOTTOM PART (version with UNION)

Alessandra, June 03, 2024 - 7:10 pm UTC

| 107 |       VIEW PUSHED PREDICATE                              |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 108 |        NESTED LOOPS                                      |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 109 |         NESTED LOOPS                                     |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*110 |          HASH JOIN                                       |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |  1678K|  1678K|  562K (0)|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 111 |           NESTED LOOPS                                   |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 112 |            NESTED LOOPS                                  |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 113 |             NESTED LOOPS                                 |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 114 |              NESTED LOOPS                                |                                     |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*115 |               TABLE ACCESS BY INDEX ROWID BATCHED        | PTY_ROLE                            |      2 |      1 |      0 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*116 |                INDEX RANGE SCAN                          | ROLE_FK_I_PRCD_ID                   |      2 |      3 |      5 |00:00:00.01 |       6 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 117 |               TABLE ACCESS BY INDEX ROWID                | PTY_PARTY                           |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*118 |                INDEX UNIQUE SCAN                         | PRTY_PK                             |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 119 |              TABLE ACCESS BY INDEX ROWID BATCHED         | PTY_CONTACT_DETAILS                 |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

|*120 |               INDEX RANGE SCAN                           | CODT_FK_I_PRTY_ID                   |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*121 |             INDEX RANGE SCAN                             | ADDR_FK_I_CODT_ID                   |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 122 |            TABLE ACCESS BY INDEX ROWID                   | PTY_ADDRESS                         |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 123 |           TABLE ACCESS STORAGE FULL                      | CTL_COUNTRY                         |      0 |    430 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*124 |          INDEX RANGE SCAN                                | LNGC_IX_ISO_639_1                   |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*125 |         TABLE ACCESS BY INDEX ROWID                      | CTL_LANGUAGE                        |      0 |      1 |      0 |00:00:00.01 |       0 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 126 |      VIEW PUSHED PREDICATE                               |                                     |      2 |      1 |      1 |00:00:00.01 |      19 |      2 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 127 |       SORT UNIQUE                                        |                                     |      2 |      1 |      1 |00:00:00.01 |      19 |      2 |  2048 |  2048 | 2048  (0)|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 128 |        WINDOW SORT                                       |                                     |      2 |      1 |    225 |00:00:00.01 |      19 |      2 | 43008 | 43008 |38912  (0)|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*129 |         HASH JOIN                                        |                                     |      2 |      1 |    225 |00:00:00.01 |      19 |      2 |  1988K|  1988K| 1243K (0)|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 130 |          NESTED LOOPS                                    |                                     |      2 |      2 |     15 |00:00:00.01 |      11 |      2 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 131 |           NESTED LOOPS                                   |                                     |      2 |      3 |     15 |00:00:00.01 |      10 |      2 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 132 |            TABLE ACCESS BY INDEX ROWID BATCHED           | PROC_TIMETABLE                      |      2 |      1 |      1 |00:00:00.01 |       7 |      1 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

|*133 |             INDEX RANGE SCAN                             | TITA_FK_I_PRCD_ID                   |      2 |      1 |      1 |00:00:00.01 |       6 |      1 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*134 |            INDEX RANGE SCAN                              | TIDE_FK_I_TITA_ID                   |      1 |      3 |     15 |00:00:00.01 |       3 |      1 |  1028K|  1028K|          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
|*135 |           TABLE ACCESS BY INDEX ROWID                    | TIMETABLE_DEADLINE                  |     15 |      2 |     15 |00:00:00.01 |       1 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 136 |          VIEW                                            |                                     |      1 |      3 |     15 |00:00:00.01 |       8 |      0 |       |       |          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
| 137 |           WINDOW SORT                                    |                                     |      1 |      3 |     15 |00:00:00.01 |       8 |      0 |  2048 |  2048 | 2048  (0)|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              

Chris Saxon
June 04, 2024 - 1:21 pm UTC

Right, the bad plan is processing way more data than needed. The estimates for the tablescans are reasonably accurate, except for this one:

|*134 |            TABLE ACCESS STORAGE FULL                         | CT_XML_DATA                         |      1 |    381K|  18665


That comes from a join bloom filter though so the table stats for CT_XML_DATA may be accurate - it's worth checking though.

A good chunk of the time is processing steps 135 - 149, which is the t_t_deatline CTE. It may be worth seeing if you can move any of the joins inside this - particularly the filtering to the IDs from the NUMBER_TBL.

Other things you could try:

- Increase the level of dynamic statistics (dynamic_sampling) for the whole query - this may help the optimizer spot you're only getting a few rows from t_t_deatline
- Materializing the CTEs
- Disabling bloom filters may lead to higher row estimates for the subqueries; which may lead the optimizer to prefer nested loops

Query should be changed, correct?

Alessandra, June 05, 2024 - 8:08 am UTC

Hi Chris,
thanks for you advice.
Dynamic sampling do not help even with alter session set.
Statistics refrsh do not help either.
Did I understand correctly that you mean changing the query in order to let the optmizer understand that he has to select only the 2 ID specified in the number of table would transform the execution plan?
So you do not see any other possibility that do not need query code change?
I'm asking as a lot of other queries of the application use table of number.
Chris Saxon
June 05, 2024 - 1:23 pm UTC

I'm asking as a lot of other queries of the application use table of number.

Are the other queries fast enough? If so, focus on this one.

The optimizer correctly estimates two rows from the table of number in your query. The problem lies in:

- It's massively overestimating the number of rows for operations later in the plan - this is unrelated to the table of number and leads it to prefer hash joins
- The optimizer is unable to use adaptive joins for table of number, so it can't correct and use nested loops instead

If the other proposed solutions don't help, rewriting is your best bet.

hash join going on to be preferred more usually towards nested loop

A reader, November 24, 2024 - 7:32 pm UTC

Hi Chris,
after cheking what's going on with these queries involving pl/sql collection I noticed that the Optimizer only sometimes decided the best plan and choose Nested Loop.
I'm trying a lot of hints without be able to fix the good plan one for ever.
Do you see other solution different from using "Sql Plan Management" ?

Thanks
Chris Saxon
November 26, 2024 - 1:52 pm UTC

SQL Plan Management is the preferred approach to lock in specific execution plans.

There may be better options in your specific case; hard to say without seeing your query, it's plan, & what you've tried though.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library