Skip to content

Commit cf22052

Browse files
jiaqizhomy-ship-it
authored andcommitted
Fix: cherry-pick "pushdown in union all, pruned partitions, plans with the ProjectSet node..."
1 parent f009bc8 commit cf22052

25 files changed

+469
-1720
lines changed

src/test/isolation2/expected/concurrent_partition_table_operations_should_not_deadlock_optimizer.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
CREATE EXTENSION IF NOT EXISTS gp_inject_fault;
2-
CREATE EXTENSION
2+
CREATE
33

44

55
-- Two concurrent transactions on partitioned table
66
-- 1) dynamic scan
77
-- 2) truncate
88
-- should not cause deadlock
99
CREATE TABLE pt(a int, b text) DISTRIBUTED BY (a) PARTITION BY range(a) (start (0) end(10) every(2));
10-
CREATE TABLE
10+
CREATE
1111
INSERT INTO pt SELECT i%10, 'text'||i FROM generate_series(1, 10)i;
12-
INSERT 0 10
12+
INSERT 10
1313
VACUUM ANALYZE pt;
1414
VACUUM
1515

@@ -73,17 +73,17 @@ BEGIN
7373
1 | text1
7474
(4 rows)
7575
1: END;
76-
COMMIT
76+
END
7777
2<: <... completed>
78-
TRUNCATE TABLE
78+
TRUNCATE
7979

8080

8181
-- Two concurrent transactions on partitioned table
8282
-- 1) dynamic index scan
8383
-- 2) truncate
8484
-- should not cause deadlock
8585
CREATE INDEX idx ON pt(a);
86-
CREATE INDEX
86+
CREATE
8787
VACUUM ANALYZE pt;
8888
VACUUM
8989

@@ -143,9 +143,9 @@ BEGIN
143143
3 | text3
144144
(2 rows)
145145
1: END;
146-
COMMIT
146+
END
147147
2<: <... completed>
148-
TRUNCATE TABLE
148+
TRUNCATE
149149

150150

151151
-- ORCA_FEATURE_NOT_SUPPORTED: dynamic index only scan
@@ -212,6 +212,6 @@ BEGIN
212212
3
213213
(2 rows)
214214
1: END;
215-
COMMIT
215+
END
216216
2<: <... completed>
217-
TRUNCATE TABLE
217+
TRUNCATE

src/test/regress/expected/bfv_aggregate.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,31 @@ select count(distinct(b)), gp_segment_id from t group by gp_segment_id;
20222022
10 | 1
20232023
(1 row)
20242024

2025+
-- The cost of multistage agg is higher than hash agg
2026+
set optimizer_force_multistage_agg to on;
2027+
explain (costs off) select count(distinct(b)), gp_segment_id from t group by gp_segment_id;
2028+
QUERY PLAN
2029+
------------------------------------------------------------------
2030+
Gather Motion 3:1 (slice1; segments: 3)
2031+
-> HashAggregate
2032+
Group Key: gp_segment_id
2033+
-> HashAggregate
2034+
Group Key: gp_segment_id, b
2035+
-> Redistribute Motion 3:3 (slice2; segments: 3)
2036+
Hash Key: gp_segment_id
2037+
-> Streaming HashAggregate
2038+
Group Key: gp_segment_id, b
2039+
-> Seq Scan on t
2040+
Optimizer: Postgres query optimizer
2041+
(11 rows)
2042+
2043+
select count(distinct(b)), gp_segment_id from t group by gp_segment_id;
2044+
count | gp_segment_id
2045+
-------+---------------
2046+
10 | 1
2047+
(1 row)
2048+
2049+
reset optimizer_force_multistage_agg;
20252050
drop table t;
20262051
-- CLEANUP
20272052
set client_min_messages='warning';

src/test/regress/expected/bfv_aggregate_optimizer.out

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,28 @@ insert into t select 1, i, i from generate_series(1, 10)i;
20232023
insert into t select 1, i, i from generate_series(1, 10)i;
20242024
insert into t select 1, i, i from generate_series(1, 10)i;
20252025
analyze t;
2026+
explain (costs off) select count(distinct(b)), gp_segment_id from t group by gp_segment_id;
2027+
QUERY PLAN
2028+
------------------------------------------------------------------
2029+
Gather Motion 3:1 (slice1; segments: 3)
2030+
-> GroupAggregate
2031+
Group Key: gp_segment_id
2032+
-> Sort
2033+
Sort Key: gp_segment_id
2034+
-> Redistribute Motion 3:3 (slice2; segments: 3)
2035+
Hash Key: gp_segment_id
2036+
-> Seq Scan on t
2037+
Optimizer: Pivotal Optimizer (GPORCA)
2038+
(9 rows)
2039+
2040+
select count(distinct(b)), gp_segment_id from t group by gp_segment_id;
2041+
count | gp_segment_id
2042+
-------+---------------
2043+
10 | 1
2044+
(1 row)
2045+
2046+
-- The cost of multistage agg is higher than hash agg
2047+
set optimizer_force_multistage_agg to on;
20262048
explain (costs off) select count(distinct(b)), gp_segment_id from t group by gp_segment_id;
20272049
QUERY PLAN
20282050
------------------------------------------------------------------------------------
@@ -2047,6 +2069,7 @@ select count(distinct(b)), gp_segment_id from t group by gp_segment_id;
20472069
10 | 1
20482070
(1 row)
20492071

2072+
reset optimizer_force_multistage_agg;
20502073
drop table t;
20512074
-- CLEANUP
20522075
set client_min_messages='warning';

src/test/regress/expected/bfv_index.out

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,22 +1182,26 @@ insert into ao_tbl select 'abc' from generate_series(1,20) i;
11821182
analyze ao_tbl;
11831183
-- identical plans
11841184
explain select * from ao_tbl where path_hash = 'ABC';
1185-
QUERY PLAN
1186-
--------------------------------------------------------------------------------
1187-
Gather Motion 1:1 (slice1; segments: 1) (cost=0.14..4.17 rows=1 width=4)
1188-
-> Index Only Scan using ao_idx on ao_tbl (cost=0.14..4.16 rows=1 width=4)
1189-
Index Cond: (path_hash = 'ABC'::text)
1185+
QUERY PLAN
1186+
----------------------------------------------------------------------------
1187+
Gather Motion 1:1 (slice1; segments: 1) (cost=4.15..8.18 rows=1 width=4)
1188+
-> Bitmap Heap Scan on ao_tbl (cost=4.15..8.16 rows=1 width=4)
1189+
Recheck Cond: ((path_hash)::text = 'ABC'::text)
1190+
-> Bitmap Index Scan on ao_idx (cost=0.00..4.15 rows=1 width=0)
1191+
Index Cond: ((path_hash)::text = 'ABC'::text)
11901192
Optimizer: Postgres query optimizer
1191-
(4 rows)
1193+
(6 rows)
11921194

11931195
explain select * from ao_tbl where 'ABC' = path_hash;
1194-
QUERY PLAN
1195-
--------------------------------------------------------------------------------
1196-
Gather Motion 1:1 (slice1; segments: 1) (cost=0.14..4.17 rows=1 width=4)
1197-
-> Index Only Scan using ao_idx on ao_tbl (cost=0.14..4.16 rows=1 width=4)
1198-
Index Cond: (path_hash = 'ABC'::text)
1196+
QUERY PLAN
1197+
----------------------------------------------------------------------------
1198+
Gather Motion 1:1 (slice1; segments: 1) (cost=4.15..8.18 rows=1 width=4)
1199+
-> Bitmap Heap Scan on ao_tbl (cost=4.15..8.16 rows=1 width=4)
1200+
Recheck Cond: ('ABC'::text = (path_hash)::text)
1201+
-> Bitmap Index Scan on ao_idx (cost=0.00..4.15 rows=1 width=0)
1202+
Index Cond: ((path_hash)::text = 'ABC'::text)
11991203
Optimizer: Postgres query optimizer
1200-
(4 rows)
1204+
(6 rows)
12011205

12021206
-- Test AO partition table
12031207
-- Dynamic index scan is disabled in AO table, so dynamic bitmap
@@ -1212,22 +1216,26 @@ insert into part_tbl select 'abc' from generate_series(1,20) i;
12121216
analyze part_tbl;
12131217
-- identical plans
12141218
explain select * from part_tbl where path_hash = 'ABC';
1215-
QUERY PLAN
1216-
--------------------------------------------------------------------------------------------------------------------------
1217-
Gather Motion 1:1 (slice1; segments: 1) (cost=0.14..4.17 rows=1 width=4)
1218-
-> Index Only Scan using part_tbl_1_prt_other_path_hash_idx on part_tbl_1_prt_other (cost=0.14..4.16 rows=1 width=4)
1219-
Index Cond: (path_hash = 'ABC'::text)
1219+
QUERY PLAN
1220+
-------------------------------------------------------------------------------------------------------
1221+
Gather Motion 1:1 (slice1; segments: 1) (cost=4.15..8.18 rows=1 width=4)
1222+
-> Bitmap Heap Scan on part_tbl_1_prt_other part_tbl (cost=4.15..8.16 rows=1 width=4)
1223+
Recheck Cond: ((path_hash)::text = 'ABC'::text)
1224+
-> Bitmap Index Scan on part_tbl_1_prt_other_path_hash_idx (cost=0.00..4.15 rows=1 width=0)
1225+
Index Cond: ((path_hash)::text = 'ABC'::text)
12201226
Optimizer: Postgres query optimizer
1221-
(4 rows)
1227+
(6 rows)
12221228

12231229
explain select * from part_tbl where 'ABC' = path_hash;
1224-
QUERY PLAN
1225-
--------------------------------------------------------------------------------------------------------------------------
1226-
Gather Motion 1:1 (slice1; segments: 1) (cost=0.14..4.17 rows=1 width=4)
1227-
-> Index Only Scan using part_tbl_1_prt_other_path_hash_idx on part_tbl_1_prt_other (cost=0.14..4.16 rows=1 width=4)
1228-
Index Cond: (path_hash = 'ABC'::text)
1230+
QUERY PLAN
1231+
-------------------------------------------------------------------------------------------------------
1232+
Gather Motion 1:1 (slice1; segments: 1) (cost=4.15..8.18 rows=1 width=4)
1233+
-> Bitmap Heap Scan on part_tbl_1_prt_other part_tbl (cost=4.15..8.16 rows=1 width=4)
1234+
Recheck Cond: ('ABC'::text = (path_hash)::text)
1235+
-> Bitmap Index Scan on part_tbl_1_prt_other_path_hash_idx (cost=0.00..4.15 rows=1 width=0)
1236+
Index Cond: ((path_hash)::text = 'ABC'::text)
12291237
Optimizer: Postgres query optimizer
1230-
(4 rows)
1238+
(6 rows)
12311239

12321240
-- Test table indexed on two columns
12331241
-- Two indices allow ORCA to generate the bitmap scan alternative

src/test/regress/expected/direct_dispatch.out

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -899,30 +899,9 @@ INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
899899
2 | 0 | 6 | 2
900900
(3 rows)
901901

902-
explain (costs off) select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
903-
QUERY PLAN
904-
------------------------------------------------------------
905-
Gather Motion 3:1 (slice1; segments: 3)
906-
-> Finalize HashAggregate
907-
Group Key: gp_segment_id
908-
-> Redistribute Motion 3:3 (slice2; segments: 3)
909-
Hash Key: gp_segment_id
910-
-> Partial HashAggregate
911-
Group Key: gp_segment_id
912-
-> Seq Scan on t_test_dd_via_segid
913-
Optimizer: Postgres query optimizer
914-
(10 rows)
915-
916-
select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
917-
INFO: (slice 2) Dispatch command to ALL contents: 0 1 2
918-
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
919-
gp_segment_id | count
920-
---------------+-------
921-
0 | 3
922-
1 | 1
923-
2 | 2
924-
(3 rows)
925-
902+
-- flaky tests
903+
-- explain (costs off) select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
904+
-- select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
926905
-- test direct dispatch via gp_segment_id qual with conjunction
927906
create table t_test_dd_via_segid_conj(a int, b int);
928907
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.

src/test/regress/expected/direct_dispatch_optimizer.out

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -915,34 +915,9 @@ INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
915915
2 | 0 | 6 | 2
916916
(3 rows)
917917

918-
explain (costs off) select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
919-
QUERY PLAN
920-
---------------------------------------------------
921-
Gather Motion 3:1 (slice1; segments: 3)
922-
-> Finalize GroupAggregate
923-
Group Key: gp_segment_id
924-
-> Sort
925-
Sort Key: gp_segment_id
926-
-> Redistribute Motion 3:3 (slice2; segments: 3)
927-
Hash Key: gp_segment_id
928-
-> Partial GroupAggregate
929-
Group Key: gp_segment_id
930-
-> Sort
931-
Sort Key: gp_segment_id
932-
-> Seq Scan on t_test_dd_via_segid
933-
Optimizer: Pivotal Optimizer (GPORCA)
934-
(9 rows)
935-
936-
select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
937-
INFO: (slice 2) Dispatch command to ALL contents: 0 1 2
938-
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
939-
gp_segment_id | count
940-
---------------+-------
941-
2 | 2
942-
0 | 3
943-
1 | 1
944-
(3 rows)
945-
918+
-- flaky tests
919+
-- explain (costs off) select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
920+
-- select gp_segment_id, count(*) from t_test_dd_via_segid group by gp_segment_id;
946921
-- test direct dispatch via gp_segment_id qual with conjunction
947922
create table t_test_dd_via_segid_conj(a int, b int);
948923
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.

0 commit comments

Comments
 (0)