Skip to content

Commit c458006

Browse files
committed
update
1 parent c05378c commit c458006

File tree

2 files changed

+116
-199
lines changed

2 files changed

+116
-199
lines changed

src/test/regress/expected/pg17.out

Lines changed: 70 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,68 @@ DROP TABLE pt_3;
955955
DROP TABLE pt_4;
956956
DROP TABLE alt_test;
957957
-- End of partition with identity columns testing
958+
-- Correlated sublinks are now supported as of PostgreSQL 17, resolving issue #4470.
959+
-- Enable DEBUG-level logging to capture detailed execution plans
960+
-- Create the tables
961+
CREATE TABLE postgres_table (key int, value text, value_2 jsonb);
962+
CREATE TABLE reference_table (key int, value text, value_2 jsonb);
963+
SELECT create_reference_table('reference_table');
964+
create_reference_table
965+
---------------------------------------------------------------------
966+
967+
(1 row)
968+
969+
CREATE TABLE distributed_table (key int, value text, value_2 jsonb);
970+
SELECT create_distributed_table('distributed_table', 'key');
971+
create_distributed_table
972+
---------------------------------------------------------------------
973+
974+
(1 row)
975+
976+
-- Insert test data
977+
INSERT INTO postgres_table SELECT i, i::varchar(256), '{}'::jsonb FROM generate_series(1, 10) i;
978+
INSERT INTO reference_table SELECT i, i::varchar(256), '{}'::jsonb FROM generate_series(1, 10) i;
979+
INSERT INTO distributed_table SELECT i, i::varchar(256), '{}'::jsonb FROM generate_series(1, 10) i;
980+
-- Set local table join policy to auto before running the tests
981+
SET citus.local_table_join_policy TO 'auto';
982+
SET client_min_messages TO DEBUG1;
983+
-- Correlated sublinks are supported in PostgreSQL 17
984+
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table USING (key)
985+
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key AND key = 5);
986+
DEBUG: Wrapping relation "postgres_table" to a subquery
987+
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM pg17.postgres_table WHERE (key OPERATOR(pg_catalog.=) 5)
988+
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (pg17.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 pg17.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
989+
count
990+
---------------------------------------------------------------------
991+
1
992+
(1 row)
993+
994+
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table USING (key)
995+
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key AND key = 5);
996+
DEBUG: Wrapping relation "postgres_table" to a subquery
997+
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM pg17.postgres_table WHERE (key OPERATOR(pg_catalog.=) 5)
998+
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (pg17.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 pg17.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
999+
count
1000+
---------------------------------------------------------------------
1001+
1
1002+
(1 row)
1003+
1004+
SET citus.local_table_join_policy TO 'prefer-distributed';
1005+
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table USING (key)
1006+
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key AND key = 5);
1007+
DEBUG: Wrapping relation "distributed_table" "d1" to a subquery
1008+
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM pg17.distributed_table d1 WHERE (key OPERATOR(pg_catalog.=) 5)
1009+
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 pg17.postgres_table USING (key)) WHERE (d1.key OPERATOR(pg_catalog.=) ANY (SELECT distributed_table.key FROM pg17.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
1010+
ERROR: direct joins between distributed and local tables are not supported
1011+
HINT: Use CTE's or subqueries to select from local tables and use them in joins
1012+
RESET citus.local_table_join_policy;
1013+
RESET client_min_messages;
1014+
DROP TABLE reference_table;
1015+
-- End for Correlated sublinks are now supported as of PostgreSQL 17, resolving issue #4470.
9581016
-- Test for exclusion constraints on partitioned and distributed partitioned tables in Citus environment
9591017
-- Step 1: Create a distributed partitioned table
9601018
\c - - :master_host :master_port
1019+
SET search_path TO pg17;
9611020
CREATE TABLE distributed_partitioned_table (
9621021
id serial NOT NULL,
9631022
partition_col int NOT NULL,
@@ -975,57 +1034,6 @@ SELECT create_distributed_table('distributed_partitioned_table', 'id');
9751034

9761035
(1 row)
9771036

978-
-- Additional test for long names and sequential execution mode
979-
-- Create schema if it doesn't already exist
980-
CREATE SCHEMA IF NOT EXISTS AT_AddConstNoName;
981-
CREATE TABLE AT_AddConstNoName.dist_partitioned_table (
982-
dist_col int,
983-
another_col int,
984-
partition_col timestamp
985-
) PARTITION BY RANGE (partition_col);
986-
CREATE TABLE AT_AddConstNoName.p1 PARTITION OF AT_AddConstNoName.dist_partitioned_table
987-
FOR VALUES FROM ('2021-01-01') TO ('2022-01-01');
988-
CREATE TABLE AT_AddConstNoName.longlonglonglonglonglonglonglonglonglonglonglonglonglonglongabc PARTITION OF AT_AddConstNoName.dist_partitioned_table
989-
FOR VALUES FROM ('2020-01-01') TO ('2021-01-01');
990-
SELECT create_distributed_table('AT_AddConstNoName.dist_partitioned_table', 'partition_col');
991-
create_distributed_table
992-
---------------------------------------------------------------------
993-
994-
(1 row)
995-
996-
-- Step 1.1: Insert and query data from long name partition
997-
INSERT INTO AT_AddConstNoName.dist_partitioned_table (dist_col, another_col, partition_col)
998-
VALUES (1, 10, '2020-06-01'), (2, 20, '2020-09-01');
999-
SELECT * FROM AT_AddConstNoName.longlonglonglonglonglonglonglonglonglonglonglonglonglonglongabc;
1000-
dist_col | another_col | partition_col
1001-
---------------------------------------------------------------------
1002-
1 | 10 | Mon Jun 01 00:00:00 2020
1003-
2 | 20 | Tue Sep 01 00:00:00 2020
1004-
(2 rows)
1005-
1006-
-- Step 1.2: Verify sequential execution mode
1007-
EXPLAIN SELECT * FROM AT_AddConstNoName.dist_partitioned_table WHERE partition_col = '2020-06-01';
1008-
QUERY PLAN
1009-
---------------------------------------------------------------------
1010-
Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=0 width=0)
1011-
Task Count: 1
1012-
Tasks Shown: All
1013-
-> Task
1014-
Node: host=localhost port=xxxxx dbname=regression
1015-
-> Seq Scan on longlonglonglonglonglonglonglonglonglonglonglon_537570f5_361817 dist_partitioned_table (cost=0.00..33.12 rows=9 width=16)
1016-
Filter: (partition_col = '2020-06-01 00:00:00'::timestamp without time zone)
1017-
(7 rows)
1018-
1019-
-- Step 1.3: Add exclusion constraints on parent table
1020-
ALTER TABLE AT_AddConstNoName.dist_partitioned_table
1021-
ADD CONSTRAINT long_name_exclude EXCLUDE USING btree (dist_col WITH =, partition_col WITH =);
1022-
-- Verify the constraint was added
1023-
SELECT conname FROM pg_constraint WHERE conrelid = 'AT_AddConstNoName.dist_partitioned_table'::regclass AND conname = 'long_name_exclude';
1024-
conname
1025-
---------------------------------------------------------------------
1026-
long_name_exclude
1027-
(1 row)
1028-
10291037
-- Step 2: Create a partitioned Citus local table
10301038
CREATE TABLE local_partitioned_table (
10311039
id serial NOT NULL,
@@ -1044,27 +1052,23 @@ SELECT citus_add_local_table_to_metadata('local_partitioned_table');
10441052
(1 row)
10451053

10461054
-- Verify the Citus tables
1047-
SELECT table_name, citus_table_type FROM citus_tables
1048-
WHERE table_name::regclass::text like '%_partitioned_table' ORDER BY 1;
1049-
table_name | citus_table_type
1050-
---------------------------------------------------------------------
1051-
distributed_partitioned_table | distributed
1052-
at_addconstnoname.dist_partitioned_table | distributed
1053-
local_partitioned_table | local
1054-
(3 rows)
1055-
1055+
SELECT table_name, citus_table_type FROM pg_catalog.citus_tables
1056+
WHERE table_name::regclass::text LIKE '%_partitioned_table' ORDER BY 1;
1057+
ERROR: relation "pg_catalog.citus_tables" does not exist
10561058
-- Step 3: Add an exclusion constraint with a name to the distributed partitioned table
10571059
ALTER TABLE distributed_partitioned_table ADD CONSTRAINT dist_exclude_named EXCLUDE USING btree (id WITH =, partition_col WITH =);
10581060
-- Step 4: Verify propagation of exclusion constraint to worker nodes
10591061
\c - - :public_worker_1_host :worker_1_port
1060-
SELECT conname FROM pg_constraint WHERE conrelid = 'distributed_partitioned_table'::regclass AND conname = 'dist_exclude_named';
1062+
SET search_path TO pg17;
1063+
SELECT conname FROM pg_constraint WHERE conrelid = 'pg17.distributed_partitioned_table'::regclass AND conname = 'dist_exclude_named';
10611064
conname
10621065
---------------------------------------------------------------------
10631066
dist_exclude_named
10641067
(1 row)
10651068

10661069
-- Step 5: Add an exclusion constraint with a name to the Citus local partitioned table
10671070
\c - - :master_host :master_port
1071+
SET search_path TO pg17;
10681072
ALTER TABLE local_partitioned_table ADD CONSTRAINT local_exclude_named EXCLUDE USING btree (partition_col WITH =);
10691073
-- Step 6: Verify the exclusion constraint on the local partitioned table
10701074
SELECT conname, contype FROM pg_constraint WHERE conname = 'local_exclude_named' AND contype = 'x';
@@ -1085,7 +1089,8 @@ SELECT conname, contype FROM pg_constraint WHERE conrelid = 'local_partitioned_t
10851089
(2 rows)
10861090

10871091
\c - - :public_worker_1_host :worker_1_port
1088-
SELECT conname, contype FROM pg_constraint WHERE conrelid = 'distributed_partitioned_table'::regclass AND contype = 'x';
1092+
SET search_path TO pg17;
1093+
SELECT conname, contype FROM pg_constraint WHERE conrelid = 'pg17.distributed_partitioned_table'::regclass AND contype = 'x';
10891094
conname | contype
10901095
---------------------------------------------------------------------
10911096
dist_exclude_named | x
@@ -1094,6 +1099,7 @@ SELECT conname, contype FROM pg_constraint WHERE conrelid = 'distributed_partiti
10941099

10951100
-- Step 9: Drop the exclusion constraints from both tables
10961101
\c - - :master_host :master_port
1102+
SET search_path TO pg17;
10971103
ALTER TABLE distributed_partitioned_table DROP CONSTRAINT dist_exclude_named;
10981104
ALTER TABLE local_partitioned_table DROP CONSTRAINT local_exclude_named;
10991105
-- Step 10: Verify the constraints were dropped
@@ -1108,70 +1114,9 @@ SELECT * FROM pg_constraint WHERE conname = 'local_exclude_named' AND contype =
11081114
(0 rows)
11091115

11101116
-- Step 11: Clean up - Drop the tables
1111-
DROP TABLE distributed_partitioned_table, local_partitioned_table;
1112-
DROP TABLE AT_AddConstNoName.p1,
1113-
AT_AddConstNoName.longlonglonglonglonglonglonglonglonglonglonglonglonglonglongabc,
1114-
AT_AddConstNoName.dist_partitioned_table;
1115-
DROP SCHEMA AT_AddConstNoName CASCADE;
1117+
DROP TABLE distributed_partitioned_table CASCADE;
1118+
DROP TABLE local_partitioned_table CASCADE;
11161119
-- End of Test for exclusion constraints on partitioned and distributed partitioned tables in Citus environment
1117-
-- Correlated sublinks are now supported as of PostgreSQL 17, resolving issue #4470.
1118-
-- Enable DEBUG-level logging to capture detailed execution plans
1119-
-- Create the tables
1120-
CREATE TABLE postgres_table (key int, value text, value_2 jsonb);
1121-
CREATE TABLE reference_table (key int, value text, value_2 jsonb);
1122-
SELECT create_reference_table('reference_table');
1123-
create_reference_table
1124-
---------------------------------------------------------------------
1125-
1126-
(1 row)
1127-
1128-
CREATE TABLE distributed_table (key int, value text, value_2 jsonb);
1129-
SELECT create_distributed_table('distributed_table', 'key');
1130-
create_distributed_table
1131-
---------------------------------------------------------------------
1132-
1133-
(1 row)
1134-
1135-
-- Insert test data
1136-
INSERT INTO postgres_table SELECT i, i::varchar(256), '{}'::jsonb FROM generate_series(1, 10) i;
1137-
INSERT INTO reference_table SELECT i, i::varchar(256), '{}'::jsonb FROM generate_series(1, 10) i;
1138-
INSERT INTO distributed_table SELECT i, i::varchar(256), '{}'::jsonb FROM generate_series(1, 10) i;
1139-
-- Set local table join policy to auto before running the tests
1140-
SET citus.local_table_join_policy TO 'auto';
1141-
SET client_min_messages TO DEBUG1;
1142-
-- Correlated sublinks are supported in PostgreSQL 17
1143-
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table USING (key)
1144-
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key AND key = 5);
1145-
DEBUG: Wrapping relation "postgres_table" to a subquery
1146-
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM pg17.postgres_table WHERE (key OPERATOR(pg_catalog.=) 5)
1147-
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (pg17.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 pg17.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
1148-
count
1149-
---------------------------------------------------------------------
1150-
1
1151-
(1 row)
1152-
1153-
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table USING (key)
1154-
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key AND key = 5);
1155-
DEBUG: Wrapping relation "postgres_table" to a subquery
1156-
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM pg17.postgres_table WHERE (key OPERATOR(pg_catalog.=) 5)
1157-
DEBUG: Plan XXX query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (pg17.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 pg17.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
1158-
count
1159-
---------------------------------------------------------------------
1160-
1
1161-
(1 row)
1162-
1163-
SET citus.local_table_join_policy TO 'prefer-distributed';
1164-
SELECT COUNT(*) FROM distributed_table d1 JOIN postgres_table USING (key)
1165-
WHERE d1.key IN (SELECT key FROM distributed_table WHERE d1.key = key AND key = 5);
1166-
DEBUG: Wrapping relation "distributed_table" "d1" to a subquery
1167-
DEBUG: generating subplan XXX_1 for subquery SELECT key FROM pg17.distributed_table d1 WHERE (key OPERATOR(pg_catalog.=) 5)
1168-
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 pg17.postgres_table USING (key)) WHERE (d1.key OPERATOR(pg_catalog.=) ANY (SELECT distributed_table.key FROM pg17.distributed_table WHERE ((d1.key OPERATOR(pg_catalog.=) distributed_table.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 5))))
1169-
ERROR: direct joins between distributed and local tables are not supported
1170-
HINT: Use CTE's or subqueries to select from local tables and use them in joins
1171-
RESET citus.local_table_join_policy;
1172-
RESET client_min_messages;
1173-
DROP TABLE reference_table;
1174-
-- End for Correlated sublinks are now supported as of PostgreSQL 17, resolving issue #4470.
11751120
DROP SCHEMA pg17 CASCADE;
11761121
NOTICE: drop cascades to 5 other objects
11771122
DETAIL: drop cascades to function fake_am_handler(internal)

0 commit comments

Comments
 (0)