From a966451e2c3983e3fc82f6f4102701f46455f86b Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Tue, 25 Sep 2018 00:36:08 +0100 Subject: [PATCH 1/3] Added cardinality to SQL on xmltable to avoid excessive estimates. Resolves #752 --- .../data_values/ut_compound_data_helper.pkb | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index ee01819d6..19a534ebc 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -95,37 +95,39 @@ create or replace package body ut_compound_data_helper is with expected_cols as ( select :a_expected as item_data from dual ), actual_cols as ( select :a_actual as item_data from dual ), - expected_cols_info as ( - select e.*, + expected_cols_info as ( + select /*+ cardinality(e 100) */ + e.*, replace(expected_type,'VARCHAR2','CHAR') expected_type_compare from ( - SELECT rownum expected_pos, - xt.name expected_name, - xt.type expected_type - FROM (select ]'||l_column_filter||q'[ from expected_cols ucd) x, - XMLTABLE('/ROW/*' - PASSING x.item_data - COLUMNS - name VARCHAR2(4000) PATH '@xml_valid_name', - type VARCHAR2(4000) PATH '/' - ) xt - ) e + select rownum expected_pos, + xt.name expected_name, + xt.type expected_type + from (select ]'||l_column_filter||q'[ from expected_cols ucd) x, + xmltable( + '/ROW/*' + passing x.item_data + columns + name varchar2(4000) PATH '@xml_valid_name', + type varchar2(4000) PATH '/' + ) xt + ) e ), actual_cols_info as ( - select a.*, + select /*+ cardinality(a 100) */ + a.*, replace(actual_type,'VARCHAR2','CHAR') actual_type_compare - from ( - SELECT rownum actual_pos, - xt.name actual_name, - xt.type actual_type - FROM (select ]'||l_column_filter||q'[ from actual_cols ucd) x, - XMLTABLE('/ROW/*' - PASSING x.item_data - COLUMNS - name VARCHAR2(4000) PATH '@xml_valid_name', - type VARCHAR2(4000) PATH '/' - ) xt - ) a + from (select rownum actual_pos, + xt.name actual_name, + xt.type actual_type + from (select ]'||l_column_filter||q'[ from actual_cols ucd) x, + xmltable('/ROW/*' + passing x.item_data + columns + name varchar2(4000) path '@xml_valid_name', + type varchar2(4000) path '/' + ) xt + ) a ), joined_cols as ( select e.*, a.*, @@ -134,7 +136,8 @@ create or replace package body ut_compound_data_helper is from expected_cols_info e full outer join actual_cols_info a on e.expected_name = a.actual_name ) - select case + select /*+ cardinality(joined_cols 100)*/ + case when expected_pos is null and actual_pos is not null then '+' when expected_pos is not null and actual_pos is null then '-' when expected_type_compare != actual_type_compare then 't' From eb0dab742764d52731a9eb932ee00d29e736aad2 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Tue, 25 Sep 2018 12:07:27 +0100 Subject: [PATCH 2/3] Additional cardinality hint. --- .../expectations/data_values/ut_compound_data_helper.pkb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index 19a534ebc..92d9fb399 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -91,6 +91,7 @@ create or replace package body ut_compound_data_helper is l_results tt_column_diffs; begin l_column_filter := get_columns_row_filter(a_exclude_xpath, a_include_xpath); + --CARDINALITY hints added to address issue: https://github.com/utPLSQL/utPLSQL/issues/752 l_sql := q'[ with expected_cols as ( select :a_expected as item_data from dual ), @@ -100,7 +101,8 @@ create or replace package body ut_compound_data_helper is e.*, replace(expected_type,'VARCHAR2','CHAR') expected_type_compare from ( - select rownum expected_pos, + select /*+ cardinality(xt 100) */ + rownum expected_pos, xt.name expected_name, xt.type expected_type from (select ]'||l_column_filter||q'[ from expected_cols ucd) x, @@ -117,7 +119,8 @@ create or replace package body ut_compound_data_helper is select /*+ cardinality(a 100) */ a.*, replace(actual_type,'VARCHAR2','CHAR') actual_type_compare - from (select rownum actual_pos, + from (select /*+ cardinality(xt 100) */ + rownum actual_pos, xt.name actual_name, xt.type actual_type from (select ]'||l_column_filter||q'[ from actual_cols ucd) x, From 0f592e6572e31da1be19435b88752eedd78f6ff4 Mon Sep 17 00:00:00 2001 From: Jacek Gebal Date: Tue, 25 Sep 2018 23:44:54 +0100 Subject: [PATCH 3/3] Cleanup of cardinality hints. --- .../data_values/ut_compound_data_helper.pkb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/source/expectations/data_values/ut_compound_data_helper.pkb b/source/expectations/data_values/ut_compound_data_helper.pkb index 92d9fb399..e6665bd10 100644 --- a/source/expectations/data_values/ut_compound_data_helper.pkb +++ b/source/expectations/data_values/ut_compound_data_helper.pkb @@ -97,11 +97,10 @@ create or replace package body ut_compound_data_helper is expected_cols as ( select :a_expected as item_data from dual ), actual_cols as ( select :a_actual as item_data from dual ), expected_cols_info as ( - select /*+ cardinality(e 100) */ - e.*, + select e.*, replace(expected_type,'VARCHAR2','CHAR') expected_type_compare from ( - select /*+ cardinality(xt 100) */ + select /*+ CARDINALITY(xt 100) */ rownum expected_pos, xt.name expected_name, xt.type expected_type @@ -116,10 +115,9 @@ create or replace package body ut_compound_data_helper is ) e ), actual_cols_info as ( - select /*+ cardinality(a 100) */ - a.*, + select a.*, replace(actual_type,'VARCHAR2','CHAR') actual_type_compare - from (select /*+ cardinality(xt 100) */ + from (select /*+ CARDINALITY(xt 100) */ rownum actual_pos, xt.name actual_name, xt.type actual_type @@ -139,8 +137,7 @@ create or replace package body ut_compound_data_helper is from expected_cols_info e full outer join actual_cols_info a on e.expected_name = a.actual_name ) - select /*+ cardinality(joined_cols 100)*/ - case + select case when expected_pos is null and actual_pos is not null then '+' when expected_pos is not null and actual_pos is null then '-' when expected_type_compare != actual_type_compare then 't'