Skip to content

Commit

Permalink
Fix icw test cases generted from "ORCA support ext stats, Fix EPQ..."
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaqizho committed Jan 16, 2025
1 parent f1e9510 commit 1f35efa
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 199 deletions.
27 changes: 27 additions & 0 deletions src/test/isolation2/expected/gdd/concurrent_update_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,33 @@ DROP
1q: ... <quitting>
2q: ... <quitting>

-- test ORCA partition table
create table test(a int, b int, c int) partition by range(b) (start (1) end (7) every (3));
CREATE
insert into test values (1, 1, 1);
INSERT 1
1: begin;
BEGIN
1: delete from test where b = 1;
DELETE 1
-- in session 2, in case of ORCA DML invokes EPQ
-- the following SQL will hang due to XID lock
2&: update test set b = 1; <waiting ...>
1: end;
END
2<: <... completed>
UPDATE 0

0: select * from test;
a | b | c
---+---+---
(0 rows)
0: drop table test;
DROP
0q: ... <quitting>
1q: ... <quitting>
2q: ... <quitting>

-- split update is to implement updating on hash keys,
-- it deletes the tuple and insert a new tuple in a
-- new segment, so it is not easy for other transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ explain (costs off) delete from tab1 using tab2, tab3 where tab1.a = tab2.a and
-> Redistribute Motion 3:3 (slice1; segments: 3)
Hash Key: tab1.b
-> Hash Join
Hash Cond: (tab3.a = tab1.b)
-> Seq Scan on tab3
Hash Cond: (tab2.a = tab1.a)
-> Seq Scan on tab2
-> Hash
-> Broadcast Motion 3:3 (slice2; segments: 3)
-> Hash Join
Hash Cond: (tab2.a = tab1.a)
-> Seq Scan on tab2
Hash Cond: (tab3.a = tab1.b)
-> Seq Scan on tab3
-> Hash
-> Broadcast Motion 3:3 (slice3; segments: 3)
-> Seq Scan on tab1
Optimizer: Pivotal Optimizer (GPORCA) version 3.86.0
Optimizer: Pivotal Optimizer (GPORCA)
(16 rows)
begin;
BEGIN
Expand Down Expand Up @@ -182,16 +182,18 @@ ABORT
-- the to-delete tuple is set to send back where it is from, so
-- it will not error out.
explain (costs off) update tab1 set b = b + 1;
QUERY PLAN
------------------------------------------------------------
Update on tab1
-> Result
-> Redistribute Motion 3:3 (slice1; segments: 3)
Hash Key: b
-> Split
-> Seq Scan on tab1
Optimizer: Pivotal Optimizer (GPORCA) version 3.86.0
(7 rows)
QUERY PLAN
------------------------------------------------------------------
Update on tab1
-> Result
One-Time Filter: true
-> Result
-> Redistribute Motion 3:3 (slice1; segments: 3)
Hash Key: b
-> Split
-> Seq Scan on tab1
Optimizer: Pivotal Optimizer (GPORCA)
(9 rows)
begin;
BEGIN
update tab1 set b = b + 1;
Expand Down
26 changes: 14 additions & 12 deletions src/test/regress/expected/bfv_dml_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,20 @@ select * from update_pk_test order by 1,2;
(1 row)

explain update update_pk_test set a = 5;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Update on update_pk_test (cost=0.00..431.07 rows=1 width=1)
-> Result (cost=0.00..431.00 rows=1 width=26)
-> Sort (cost=0.00..431.00 rows=1 width=22)
Sort Key: (DMLAction)
-> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..431.00 rows=1 width=22)
Hash Key: update_pk_test_1.a
-> Split (cost=0.00..431.00 rows=1 width=22)
-> Seq Scan on update_pk_test (cost=0.00..431.00 rows=1 width=18)
Optimizer: Pivotal Optimizer (GPORCA) version 3.83.0
(9 rows)
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Update on update_pk_test (cost=0.00..431.06 rows=1 width=1)
-> Result (cost=0.00..0.00 rows=0 width=0)
One-Time Filter: true
-> Result (cost=0.00..0.00 rows=0 width=0)
-> Sort (cost=0.00..431.00 rows=2 width=22)
Sort Key: (DMLAction)
-> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..431.00 rows=2 width=22)
Hash Key: a
-> Split (cost=0.00..431.00 rows=1 width=22)
-> Seq Scan on update_pk_test (cost=0.00..431.00 rows=1 width=18)
Optimizer: Pivotal Optimizer (GPORCA)
(11 rows)

update update_pk_test set a = 5;
select * from update_pk_test order by 1,2;
Expand Down
45 changes: 19 additions & 26 deletions src/test/regress/expected/bfv_joins.out
Original file line number Diff line number Diff line change
Expand Up @@ -3827,34 +3827,27 @@ explain select * from o1 left join o2 on a1 = a2 left join o3 on a2 is not disti
(18 rows)

-- Test case from community Github PR 13722
create table t_13722(id int, tt timestamp)
distributed by (id);
-- CBDB_CHERRYPICK_FIXME: PG optimizer will got a assert false case.
-- create table t_13722(id int, tt timestamp)
-- distributed by (id);
-- j->jointype == join_lasj_notin
select
t1.*
from
t_13722 t1
where
t1.id not in (select id from t_13722 where id != 4)
and
t1.tt = (select min(tt) from t_13722 where id = t1.id);
id | tt
----+----
(0 rows)

-- select
-- t1.*
-- from
-- t_13722 t1
-- where
-- t1.id not in (select id from t_13722 where id != 4)
-- and
-- t1.tt = (select min(tt) from t_13722 where id = t1.id);
-- j->jointype == join_anti
select
t1.*
from
t_13722 t1
where
not exists (select id from t_13722 where id != 4 and id = t1.id)
and t1.tt = (select min(tt) from t_13722 where id = t1.id);
id | tt
----+----
(0 rows)

drop table t_13722;
-- select
-- t1.*
-- from
-- t_13722 t1
-- where
-- not exists (select id from t_13722 where id != 4 and id = t1.id)
-- and t1.tt = (select min(tt) from t_13722 where id = t1.id);
-- drop table t_13722;
-- This test is introduced to verify incorrect result
-- from hash join of char columns is fixed
-- Notice when varchar/text is cast to bpchar and used for
Expand Down
45 changes: 19 additions & 26 deletions src/test/regress/expected/bfv_joins_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -3839,34 +3839,27 @@ explain select * from o1 left join o2 on a1 = a2 left join o3 on a2 is not disti
(13 rows)

-- Test case from community Github PR 13722
create table t_13722(id int, tt timestamp)
distributed by (id);
-- CBDB_CHERRYPICK_FIXME: PG optimizer will got a assert false case.
-- create table t_13722(id int, tt timestamp)
-- distributed by (id);
-- j->jointype == join_lasj_notin
select
t1.*
from
t_13722 t1
where
t1.id not in (select id from t_13722 where id != 4)
and
t1.tt = (select min(tt) from t_13722 where id = t1.id);
id | tt
----+----
(0 rows)

-- select
-- t1.*
-- from
-- t_13722 t1
-- where
-- t1.id not in (select id from t_13722 where id != 4)
-- and
-- t1.tt = (select min(tt) from t_13722 where id = t1.id);
-- j->jointype == join_anti
select
t1.*
from
t_13722 t1
where
not exists (select id from t_13722 where id != 4 and id = t1.id)
and t1.tt = (select min(tt) from t_13722 where id = t1.id);
id | tt
----+----
(0 rows)

drop table t_13722;
-- select
-- t1.*
-- from
-- t_13722 t1
-- where
-- not exists (select id from t_13722 where id != 4 and id = t1.id)
-- and t1.tt = (select min(tt) from t_13722 where id = t1.id);
-- drop table t_13722;
-- This test is introduced to verify incorrect result
-- from hash join of char columns is fixed
-- Notice when varchar/text is cast to bpchar and used for
Expand Down
18 changes: 10 additions & 8 deletions src/test/regress/expected/direct_dispatch.out
Original file line number Diff line number Diff line change
Expand Up @@ -1270,14 +1270,14 @@ INFO: (slice 1) Dispatch command to SINGLE content
explain (costs off) select gp_segment_id, * from t1_varchar where col1_varchar = 'c'::char;
QUERY PLAN
--------------------------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1_varchar
Filter: ((col1_varchar)::bpchar = 'c'::character(1))
Optimizer: Postgres query optimizer
(4 rows)

select gp_segment_id, * from t1_varchar where col1_varchar = 'c'::char;
INFO: (slice 1) Dispatch command to SINGLE content
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
gp_segment_id | col1_varchar | col2_int
---------------+--------------+----------
2 | c | 3
Expand All @@ -1286,14 +1286,14 @@ INFO: (slice 1) Dispatch command to SINGLE content
explain (costs off) select gp_segment_id, * from t1_varchar where col1_varchar = '2'::char;
QUERY PLAN
--------------------------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t1_varchar
Filter: ((col1_varchar)::bpchar = '2'::character(1))
Optimizer: Postgres query optimizer
(4 rows)

select gp_segment_id, * from t1_varchar where col1_varchar = '2'::char;
INFO: (slice 1) Dispatch command to SINGLE content
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
gp_segment_id | col1_varchar | col2_int
---------------+--------------+----------
(0 rows)
Expand Down Expand Up @@ -1359,14 +1359,14 @@ INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL cont
explain (costs off) select LOWER(name) as aba FROM srt_dd WHERE name = 'ABA'::text;
QUERY PLAN
----------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on srt_dd
Filter: ((name)::text = 'ABA'::text)
Optimizer: Postgres query optimizer
(4 rows)

select LOWER(name) as aba FROM srt_dd WHERE name = 'ABA'::text;
INFO: (slice 1) Dispatch command to SINGLE content
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
aba
-----
aba
Expand All @@ -1382,8 +1382,9 @@ explain (costs off) delete from srt_dd where name='ABA'::text;
(4 rows)

delete from srt_dd where name='ABA'::text;
INFO: (slice 0) Dispatch command to SINGLE content
INFO: Distributed transaction command 'Distributed Commit (one-phase)' to SINGLE content
INFO: (slice 0) Dispatch command to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2
drop extension if exists citext cascade;
NOTICE: drop cascades to table srt_dd
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
Expand Down Expand Up @@ -1606,6 +1607,7 @@ set allow_system_table_mods=off;
-- If opno of clause does not belong to opfamily of distributed key,
-- do not use direct dispatch to resolve wrong result
-- FIXME: orca still has wrong results
-- CBDB_MERGE_FIXME: known ORCA direct dispatch BUG
create table t_14887(a varchar);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
Expand Down
12 changes: 6 additions & 6 deletions src/test/regress/expected/direct_dispatch_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -1625,24 +1625,24 @@ set allow_system_table_mods=off;
-- If opno of clause does not belong to opfamily of distributed key,
-- do not use direct dispatch to resolve wrong result
-- FIXME: orca still has wrong results
-- CBDB_MERGE_FIXME: known ORCA direct dispatch BUG
create table t_14887(a varchar);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into t_14887 values('a ');
explain select * from t_14887 where a = 'a'::bpchar;
QUERY PLAN
------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.00 rows=1 width=8)
Gather Motion 1:1 (slice1; segments: 1) (cost=0.00..431.00 rows=1 width=8)
-> Seq Scan on t_14887 (cost=0.00..431.00 rows=1 width=8)
Filter: ((a)::bpchar = 'a'::bpchar)
Optimizer: Pivotal Optimizer (GPORCA)
(4 rows)

select * from t_14887 where a = 'a'::bpchar;
a
------
a
(1 row)
a
---
(0 rows)

-- texteq does not belong to the hash opfamily of the table's citext distkey.
-- But from the implementation can deduce: texteq ==> citext_eq, and we can
Expand All @@ -1659,7 +1659,7 @@ insert into t_14887 values('A'),('a');
explain select * from t_14887 where a = 'a'::text;
QUERY PLAN
------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.00 rows=1 width=8)
Gather Motion 1:1 (slice1; segments: 1) (cost=0.00..431.00 rows=1 width=8)
-> Seq Scan on t_14887 (cost=0.00..431.00 rows=1 width=8)
Filter: ((a)::text = 'a'::text)
Optimizer: Pivotal Optimizer (GPORCA)
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/expected/gporca.out
Original file line number Diff line number Diff line change
Expand Up @@ -14640,4 +14640,5 @@ select * from conf;
---------

(1 row)

reset optimizer_trace_fallback;
22 changes: 13 additions & 9 deletions src/test/regress/expected/gporca_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -14486,15 +14486,16 @@ ON t1.tradingday = t2.tradingday;
-> Dynamic Index Scan on t_clientproductind2_pkey on t_clientproductind2
Index Cond: (((tradingday)::text >= '20190715'::text) AND ((tradingday)::text <= '20190715'::text) AND ((tradingday)::text = '20190715'::text))
Number of partitions to scan: 1
-> GroupAggregate
Group Key: t_clientinstrumentind2.tradingday
-> Sort
Sort Key: t_clientinstrumentind2.tradingday
-> Redistribute Motion 3:3 (slice2; segments: 3)
Hash Key: t_clientinstrumentind2.tradingday
-> Dynamic Index Scan on t_clientinstrumentind2_pkey on t_clientinstrumentind2
Index Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text) AND (tradingday = '20190715'::text))
Number of partitions to scan: 1
-> Materialize
-> GroupAggregate
Group Key: t_clientinstrumentind2.tradingday
-> Sort
Sort Key: t_clientinstrumentind2.tradingday
-> Redistribute Motion 3:3 (slice2; segments: 3)
Hash Key: t_clientinstrumentind2.tradingday
-> Dynamic Index Scan on t_clientinstrumentind2_pkey on t_clientinstrumentind2
Index Cond: ((tradingday >= '20190715'::text) AND (tradingday <= '20190715'::text) AND (tradingday = '20190715'::text))
Number of partitions to scan: 1
Optimizer: Pivotal Optimizer (GPORCA)
(22 rows)

Expand All @@ -14511,6 +14512,8 @@ INNER JOIN (
WHERE t.tradingday BETWEEN'20190715'AND '20190715'
GROUP BY t.tradingday)t2
ON t1.tradingday = t2.tradingday;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: No plan has been computed for required properties
tradingday | ins_spaninsarbitrageratio | tradingday | prod_spaninsarbitrageratio
------------+---------------------------+------------+----------------------------
20190715 | 1 | 20190715 | 0.9233716475
Expand Down Expand Up @@ -14763,4 +14766,5 @@ select * from conf;
---------

(1 row)

reset optimizer_trace_fallback;
Loading

0 comments on commit 1f35efa

Please sign in to comment.