Skip to content

Commit

Permalink
PG17 compatibility: add helper function for EXPLAIN diffs in scalar s…
Browse files Browse the repository at this point in the history
…ubquery output (#7757)

PG17 changed how scalar subquery outputs appear in EXPLAIN output (*).
This commit changes impacted regress goldfiles to the PG17 format, and
adds a helper function to covert pre-PG17 plans to the PG17 format. The
conversion is required when testing Citus on pgversions prior to 17. The
helper function can and should be removed when 17 becomes the minimum
supported version.

(*)
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=fd0398fcb
  • Loading branch information
colm-mchugh authored Nov 21, 2024
1 parent 680c23f commit 7e701be
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 63 deletions.
42 changes: 26 additions & 16 deletions src/test/regress/expected/ch_bench_having.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ SELECT create_distributed_table('stock','s_w_id');

(1 row)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false, summary false, timing false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock
where s_order_cnt > (select sum(s_order_cnt) * .005 as where_query from stock)
group by s_i_id
having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from stock)
order by s_i_id;
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
Sort
Sort Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> HashAggregate
Group Key: remote_scan.s_i_id
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > $0)
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > (InitPlan 1).col1)
-> Custom Scan (Citus Adaptive)
-> Distributed Subplan XXX_1
-> Aggregate
Expand All @@ -53,27 +55,29 @@ order by s_i_id;
Node: host=localhost port=xxxxx dbname=regression
-> HashAggregate
Group Key: stock.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> Seq Scan on stock_1640000 stock
Filter: ((s_order_cnt)::numeric > $0)
Filter: ((s_order_cnt)::numeric > (InitPlan 1).col1)
(36 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false, summary false, timing false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock
group by s_i_id
having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from stock)
order by s_i_id;
QUERY PLAN
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
Sort
Sort Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> HashAggregate
Group Key: remote_scan.s_i_id
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > $0)
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > (InitPlan 1).col1)
-> Custom Scan (Citus Adaptive)
-> Distributed Subplan XXX_1
-> Aggregate
Expand All @@ -93,17 +97,19 @@ order by s_i_id;
-> Seq Scan on stock_1640000 stock
(24 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false, summary false, timing false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock
group by s_i_id
having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from stock);
QUERY PLAN
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
HashAggregate
Group Key: remote_scan.s_i_id
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > $0)
InitPlan 1 (returns $0)
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > (InitPlan 1).col1)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> Custom Scan (Citus Adaptive)
-> Distributed Subplan XXX_1
Expand All @@ -124,24 +130,26 @@ having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from st
-> Seq Scan on stock_1640000 stock
(22 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock s
group by s_i_id
having (select true)
order by s_i_id;
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
Sort
Sort Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Result
-> HashAggregate
Group Key: remote_scan.s_i_id
-> Result
One-Time Filter: $0
One-Time Filter: (InitPlan 1).col1
-> Custom Scan (Citus Adaptive)
Filter: $0
Filter: (InitPlan 1).col1
Task Count: 4
Tasks Shown: One of 4
-> Task
Expand All @@ -151,21 +159,23 @@ order by s_i_id;
-> Seq Scan on stock_1640000 s
(17 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock s
group by s_i_id
having (select true);
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
HashAggregate
Group Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Result
-> Result
One-Time Filter: $0
One-Time Filter: (InitPlan 1).col1
-> Custom Scan (Citus Adaptive)
Filter: $0
Filter: (InitPlan 1).col1
Task Count: 4
Tasks Shown: One of 4
-> Task
Expand Down
44 changes: 27 additions & 17 deletions src/test/regress/expected/ch_bench_having_mx.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ SELECT create_distributed_table('stock','s_w_id');

\c - - - :worker_1_port
SET search_path = ch_bench_having;
SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false, summary false, timing false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock
where s_order_cnt > (select sum(s_order_cnt) * .005 as where_query from stock)
group by s_i_id
having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from stock)
order by s_i_id;
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
Sort
Sort Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> HashAggregate
Group Key: remote_scan.s_i_id
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > $0)
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > (InitPlan 1).col1)
-> Custom Scan (Citus Adaptive)
-> Distributed Subplan XXX_1
-> Aggregate
Expand All @@ -57,27 +59,29 @@ order by s_i_id;
Node: host=localhost port=xxxxx dbname=regression
-> HashAggregate
Group Key: stock.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> Seq Scan on stock_1640000 stock
Filter: ((s_order_cnt)::numeric > $0)
Filter: ((s_order_cnt)::numeric > (InitPlan 1).col1)
(36 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false, summary false, timing false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock
group by s_i_id
having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from stock)
order by s_i_id;
QUERY PLAN
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
Sort
Sort Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> HashAggregate
Group Key: remote_scan.s_i_id
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > $0)
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > (InitPlan 1).col1)
-> Custom Scan (Citus Adaptive)
-> Distributed Subplan XXX_1
-> Aggregate
Expand All @@ -97,17 +101,19 @@ order by s_i_id;
-> Seq Scan on stock_1640000 stock
(24 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false, summary false, timing false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock
group by s_i_id
having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from stock);
QUERY PLAN
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
HashAggregate
Group Key: remote_scan.s_i_id
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > $0)
InitPlan 1 (returns $0)
Filter: ((pg_catalog.sum(remote_scan.worker_column_3))::bigint > (InitPlan 1).col1)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> Custom Scan (Citus Adaptive)
-> Distributed Subplan XXX_1
Expand All @@ -128,24 +134,26 @@ having sum(s_order_cnt) > (select max(s_order_cnt) - 3 as having_query from st
-> Seq Scan on stock_1640000 stock
(22 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain (costs false)
select s_i_id, sum(s_order_cnt) as ordercount
from stock s
group by s_i_id
having (select true)
order by s_i_id;
QUERY PLAN
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
Sort
Sort Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Result
-> HashAggregate
Group Key: remote_scan.s_i_id
-> Result
One-Time Filter: $0
One-Time Filter: (InitPlan 1).col1
-> Custom Scan (Citus Adaptive)
Filter: $0
Filter: (InitPlan 1).col1
Task Count: 4
Tasks Shown: One of 4
-> Task
Expand All @@ -155,20 +163,22 @@ order by s_i_id;
-> Seq Scan on stock_1640000 s
(17 rows)

SELECT public.explain_with_pg17_initplan_format($Q$
explain select s_i_id, sum(s_order_cnt) as ordercount
from stock s
group by s_i_id
having (select true);
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
HashAggregate (cost=500.01..503.01 rows=200 width=12)
Group Key: remote_scan.s_i_id
InitPlan 1 (returns $0)
InitPlan 1
-> Result (cost=0.00..0.01 rows=1 width=1)
-> Result (cost=0.00..0.00 rows=100000 width=12)
One-Time Filter: $0
One-Time Filter: (InitPlan 1).col1
-> Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=100000 width=12)
Filter: $0
Filter: (InitPlan 1).col1
Task Count: 4
Tasks Shown: One of 4
-> Task
Expand Down
8 changes: 5 additions & 3 deletions src/test/regress/expected/having_subquery.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ HAVING (
(3 rows)

-- lets pin the plan in the test as well
SELECT public.explain_with_pg17_initplan_format($Q$
EXPLAIN (COSTS OFF)
SELECT count(*),
o_orderstatus
Expand All @@ -31,16 +32,17 @@ HAVING (
SELECT count(*)
FROM customer
) > 0;
$Q$) as "QUERY PLAN";
QUERY PLAN
---------------------------------------------------------------------
HashAggregate
Group Key: remote_scan.o_orderstatus
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result
-> Result
One-Time Filter: ($0 > 0)
One-Time Filter: ((InitPlan 1).col1 > 0)
-> Custom Scan (Citus Adaptive)
Filter: ($0 > 0)
Filter: ((InitPlan 1).col1 > 0)
-> Distributed Subplan XXX_1
-> Custom Scan (Citus Adaptive)
Task Count: 1
Expand Down
18 changes: 11 additions & 7 deletions src/test/regress/expected/multi_explain.out
Original file line number Diff line number Diff line change
Expand Up @@ -1456,25 +1456,27 @@ Custom Scan (Citus INSERT ... SELECT)
INSERT/SELECT method: pull to coordinator
-> Function Scan on generate_series s
-- WHERE EXISTS forces pg12 to materialize cte
SELECT public.explain_with_pg17_initplan_format($Q$
EXPLAIN (COSTS OFF)
WITH cte1 AS (SELECT s FROM generate_series(1,10) s)
INSERT INTO lineitem_hash_part
WITH cte1 AS (SELECT * FROM cte1 WHERE EXISTS (SELECT * FROM cte1) LIMIT 5)
SELECT s FROM cte1 WHERE EXISTS (SELECT * FROM cte1);
$Q$);
Custom Scan (Citus INSERT ... SELECT)
INSERT/SELECT method: pull to coordinator
-> Result
One-Time Filter: $3
One-Time Filter: (InitPlan 4).col1
CTE cte1
-> Function Scan on generate_series s
CTE cte1
-> Limit
InitPlan 2 (returns $1)
InitPlan 2
-> CTE Scan on cte1 cte1_1
-> Result
One-Time Filter: $1
One-Time Filter: (InitPlan 2).col1
-> CTE Scan on cte1 cte1_2
InitPlan 4 (returns $3)
InitPlan 4
-> CTE Scan on cte1 cte1_3
-> CTE Scan on cte1
EXPLAIN (COSTS OFF)
Expand Down Expand Up @@ -2425,9 +2427,11 @@ Aggregate (actual rows=1 loops=1)
Sort Key: ref_table.a
Sort Method: quicksort Memory: 25kB
-> Seq Scan on ref_table_570021 ref_table (actual rows=10 loops=1)
EXPLAIN :default_analyze_flags
SELECT public.explain_with_pg17_initplan_format($Q$
EXPLAIN (ANALYZE on, COSTS off, TIMING off, SUMMARY off)
SELECT count(distinct a) FROM dist_table
WHERE EXISTS(SELECT random() < 2 FROM dist_table NATURAL JOIN ref_table);
$Q$);
Aggregate (actual rows=1 loops=1)
-> Custom Scan (Citus Adaptive) (actual rows=4 loops=1)
-> Distributed Subplan XXX_1
Expand Down Expand Up @@ -2457,13 +2461,13 @@ Aggregate (actual rows=1 loops=1)
Tuple data received from node: 8 bytes
Node: host=localhost port=xxxxx dbname=regression
-> Aggregate (actual rows=1 loops=1)
InitPlan 1 (returns $0)
InitPlan 1
-> Function Scan on read_intermediate_result intermediate_result (actual rows=1 loops=1)
-> Sort (actual rows=4 loops=1)
Sort Key: dist_table.a
Sort Method: quicksort Memory: 25kB
-> Result (actual rows=4 loops=1)
One-Time Filter: $0
One-Time Filter: (InitPlan 1).col1
-> Seq Scan on dist_table_570017 dist_table (actual rows=4 loops=1)
BEGIN;
EXPLAIN :default_analyze_flags
Expand Down
Loading

0 comments on commit 7e701be

Please sign in to comment.