-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PG17 compatibility: Fix Test Failure in multi_alter_table_add_const #7733
base: m3hm3t/pg17_support
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## m3hm3t/pg17_support #7733 +/- ##
======================================================
Coverage ? 89.56%
======================================================
Files ? 274
Lines ? 59689
Branches ? 7446
======================================================
Hits ? 53458
Misses ? 4087
Partials ? 2144 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we lack in documentation right now, let me introduce this concept here as it's a good PR for it.
For new things that PG allows, like an exclusion constraint on partitioned tables, first we make sure that it works as it is supposed to in Citus.
If it does, our general practice is to create a new file to test it, namely pg17.sql
where we add all such things. We will populate this file with other things as we go on with the support. (For this reason we have pg16.sql
pg15.sql
tests etc.) I will include this in the documentation for new PG support.
With that in mind, could you adjust this PR accordingly? I don't think we need to add a new output file for multi_alter_table_add_constraints
. Instead, we can create pg17.sql
file which will have pg17.out
and pg17_0.out
, and include this particular test case there. In this case, the pg17_0.out
file will have the error exclusion constraints are not supported on partitioned tables
.
fa4854a
to
765d397
Compare
@naisila Can you review the solution? If it is acceptable, I will update the PR to prepare it for merging into the release branch. |
b29c332
to
1cf690f
Compare
@@ -785,38 +785,6 @@ SELECT con.conname | |||
\c - - :master_host :master_port | |||
ALTER TABLE AT_AddConstNoName.citus_local_partitioned_table DROP CONSTRAINT citus_local_partitioned_table_partition_col_key; | |||
|
|||
-- Check "ADD EXCLUDE" errors out for partitioned table since the postgres does not allow it | |||
ALTER TABLE AT_AddConstNoName.citus_local_partitioned_table ADD EXCLUDE(partition_col WITH =); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that in this test, we only need to remove the line that adds the exclusion constraint, not the rest.
src/test/regress/sql/pg17.sql
Outdated
|
||
\c - - :master_host :master_port | ||
-- Check "ADD EXCLUDE" errors out for partitioned table since the postgres does not allow it before PG 17 | ||
ALTER TABLE AT_AddConstNoName.citus_local_partitioned_table ADD EXCLUDE(partition_col WITH =); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is now something new that Citus supports, we don't necessarily need to add the exact same test that was in multi_alter_table_add_constraints_without_name.sql
. We should include that particular test case for sure, i.e. ALTER TABLE ADD EXCLUDE CONSTRAINT
, but we can (should) do more to test this feature.
If we consider this as a new feature in Citus (even though it doesnt need extra code work, apparently), we can create a "simpler/more readable" test, e.g. with the following steps:
Create distributed partitioned table dist_blabla
create partitioned citus local table citus_local_blabla
add exclude constraint with name in dist_blabla
check that its propagated to the workers properly
add exclude constraint with name in citus_local_blabla
check that it was added correctly
add exclusin constraints without name in both tables
verify previous command worked
alter the constraints (if meaningful?)
verify previous command worked
drop constraints
verify previous command worked
something else you can think of?
A test like the above is actually what we run when we want to make sure that something works as it should in Citus. (i.e. something is distributed properly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve prepared a draft of the test based on this plan. Could you review it, please?
Should this test be in the pg17.sql file?
-- Test for exclusion constraints on partitioned and distributed partitioned tables in Citus environment
-- Step 1: Create a distributed partitioned table
CREATE TABLE distributed_partitioned_table (
id serial PRIMARY KEY,
partition_col int NOT NULL
) DISTRIBUTED BY (id)
PARTITION BY RANGE (partition_col);
-- Step 2: Create a partitioned Citus local table
CREATE TABLE local_partitioned_table (
id serial PRIMARY KEY,
partition_col int NOT NULL
) PARTITION BY RANGE (partition_col);
-- Step 3: Add an exclusion constraint with a name to the distributed partitioned table
ALTER TABLE distributed_partitioned_table ADD CONSTRAINT dist_exclude_named EXCLUDE USING gist (partition_col WITH =);
-- Step 4: Verify propagation of exclusion constraint to worker nodes
\c - - :public_worker_1_host :worker_1_port
SELECT * FROM pg_dist_shard_exclude WHERE constraint_name = dist_exclude_named;
-- Step 5: Add an exclusion constraint with a name to the Citus local partitioned table
\c - - :master_host :master_port
ALTER TABLE local_partitioned_table ADD CONSTRAINT local_exclude_named EXCLUDE USING gist (partition_col WITH =);
-- Step 6: Verify the exclusion constraint on the local partitioned table
SELECT conname FROM pg_constraint WHERE conname = 'local_exclude_named';
-- Step 7: Add exclusion constraints without names to both tables
ALTER TABLE distributed_partitioned_table ADD EXCLUDE USING gist (partition_col WITH =);
ALTER TABLE local_partitioned_table ADD EXCLUDE USING gist (partition_col WITH =);
-- Step 8: Verify the unnamed exclusion constraints were added
SELECT * FROM pg_constraint WHERE conrelid = 'local_partitioned_table'::regclass;
\c - - :public_worker_1_host :worker_1_port
SELECT * FROM pg_constraint WHERE conrelid = 'distributed_partitioned_table'::regclass;
-- Step 9: Drop the exclusion constraints from both tables
\c - - :master_host :master_port
ALTER TABLE distributed_partitioned_table DROP CONSTRAINT dist_exclude_named;
ALTER TABLE local_partitioned_table DROP CONSTRAINT local_exclude_named;
-- Step 10: Verify the constraints were dropped
SELECT * FROM pg_constraint WHERE conname = 'dist_exclude_named';
SELECT * FROM pg_constraint WHERE conname = 'local_exclude_named';
-- Step 11: Clean up - Drop the tables
DROP TABLE IF EXISTS distributed_partitioned_table;
DROP TABLE IF EXISTS local_partitioned_table;
e108bb8
to
c396ce6
Compare
update update . move the tests update update update style
765d397
to
bb75e64
Compare
In earlier versions of PostgreSQL, exclusion constraints were not allowed on partitioned tables. This is why the error in your regression test (ERROR: exclusion constraints are not supported on partitioned tables) was raised in PostgreSQL 16. In PostgreSQL 17, exclusion constraints are now allowed on partitioned tables, which is why the error no longer appears when you attempt to add an exclusion constraint.
The constraint exclusion mechanism, described in the documentation, relies on CHECK constraints to decide which partitions or child tables need to be queried.
CHECK constraints