Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
m3hm3t committed Nov 15, 2024
1 parent f69de66 commit 12b095e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1,676 deletions.
6 changes: 6 additions & 0 deletions src/test/regress/bin/normalize.sed
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,9 @@ s/permission denied to terminate process/must be a superuser to terminate superu
s/permission denied to cancel query/must be a superuser to cancel superuser query/g

#endif /* PG_VERSION_NUM < PG_VERSION_16 */

# Adjusted subplan generation in local_table_join test due to PostgreSQL 17 changes, ensuring consistency in the subquery condition format
# Normalize subplan for postgres_table_key5_filtering to keep key condition "(key OPERATOR(pg_catalog.=) 5)"
s/subquery SELECT key FROM local_table_join\.postgres_table_key5_filtering WHERE.*/subquery SELECT key FROM local_table_join.postgres_table_key5_filtering WHERE (key OPERATOR(pg_catalog.=) 5)/
# Normalize subplan for distributed_table d1 to keep key condition "(key OPERATOR(pg_catalog.=) 5)"
s/subquery SELECT key FROM local_table_join\.distributed_table d1 WHERE.*/subquery SELECT key FROM local_table_join.distributed_table d1 WHERE (key OPERATOR(pg_catalog.=) 5)/
19 changes: 8 additions & 11 deletions src/test/regress/expected/local_table_join.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
-- Two alternative test outputs:
-- local_table_join_0.out for PG16 and before
-- local_table_join.out for PG17
-- PostgreSQL 17 optimizes correlated subqueries by pushing down filter conditions into subplans for more efficient query execution.
CREATE SCHEMA local_table_join;
SET search_path TO local_table_join;
CREATE TABLE postgres_table (key int, value text, value_2 jsonb);
Expand Down Expand Up @@ -1427,23 +1423,24 @@ DEBUG: Wrapping relation "custom_pg_type" to a subquery
DEBUG: generating subplan XXX_1 for subquery SELECT typdefault FROM local_table_join.custom_pg_type WHERE true
ERROR: direct joins between distributed and local tables are not supported
HINT: Use CTE's or subqueries to select from local tables and use them in joins
CREATE TABLE postgres_table_key5_filtering AS TABLE postgres_table;
-- correlated sublinks are not yet supported because of #4470, unless we convert not-correlated table
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table using(key)
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table_key5_filtering using(key)
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key and key = 5);
DEBUG: Wrapping relation "postgres_table" to a subquery
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM local_table_join.postgres_table WHERE (key OPERATOR(pg_catalog.=) 5)
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (local_table_join.distributed_table d1 JOIN (SELECT postgres_table_1.key, NULL::text AS value, NULL::jsonb AS value_2 FROM (SELECT intermediate_result.key FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer)) postgres_table_1) postgres_table USING (key)) WHERE (d1.key OPERATOR(pg_catalog.=) ANY (SELECT distributed_table.key FROM local_table_join.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
DEBUG: Wrapping relation "postgres_table_key5_filtering" to a subquery
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM local_table_join.postgres_table_key5_filtering WHERE (key OPERATOR(pg_catalog.=) 5)
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (local_table_join.distributed_table d1 JOIN (SELECT postgres_table_key5_filtering_1.key, NULL::text AS value, NULL::jsonb AS value_2 FROM (SELECT intermediate_result.key FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer)) postgres_table_key5_filtering_1) postgres_table_key5_filtering USING (key)) WHERE (d1.key OPERATOR(pg_catalog.=) ANY (SELECT distributed_table.key FROM local_table_join.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
count
---------------------------------------------------------------------
100
(1 row)

set citus.local_table_join_policy to 'prefer-distributed';
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table using(key)
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table_key5_filtering using(key)
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key and key = 5);
DEBUG: Wrapping relation "distributed_table" "d1" to a subquery
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM local_table_join.distributed_table d1 WHERE (key OPERATOR(pg_catalog.=) 5)
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM ((SELECT d1_1.key, NULL::text AS value, NULL::jsonb AS value_2 FROM (SELECT intermediate_result.key FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer)) d1_1) d1 JOIN local_table_join.postgres_table USING (key)) WHERE (d1.key OPERATOR(pg_catalog.=) ANY (SELECT distributed_table.key FROM local_table_join.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM ((SELECT d1_1.key, NULL::text AS value, NULL::jsonb AS value_2 FROM (SELECT intermediate_result.key FROM read_intermediate_result('XXX_1'::text, 'binary'::citus_copy_format) intermediate_result(key integer)) d1_1) d1 JOIN local_table_join.postgres_table_key5_filtering USING (key)) WHERE (d1.key OPERATOR(pg_catalog.=) ANY (SELECT distributed_table.key FROM local_table_join.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
ERROR: direct joins between distributed and local tables are not supported
HINT: Use CTE's or subqueries to select from local tables and use them in joins
set citus.local_table_join_policy to 'auto';
Expand Down Expand Up @@ -1656,4 +1653,4 @@ SELECT citus_set_coordinator_host('localhost'); -- https://github.com/citusdata/
RESET client_min_messages;
\set VERBOSITY terse
DROP SCHEMA local_table_join CASCADE;
NOTICE: drop cascades to 23 other objects
NOTICE: drop cascades to 24 other objects
Loading

0 comments on commit 12b095e

Please sign in to comment.