Disallow colocating tables when collations don't match
DESCRIPTION: Disallows creating a distributed table or altering it to be colocated with another table if distribution key collations don't match.
Fixes #7683.
-
(Fixed by this PR)
These UDFs were not explicitly checking whether collation of the distribution keys of two distributed tables match, however, we were catching this via EnsurePartitionMetadataIsSane() when syncing metadata. And this incorrectly caused allowing to colocate two such distributed tables in a single-node setup as we don't have any nodes to sync metadata there. In such cases, we would only become aware of the situation when adding a new node to the cluster etc..
Otherwise, i.e., if we already had more than one nodes in the cluster, we were seeing this error while Citus is syncing metadata for the new / altered distributed table, which wasn't too bad but not ideal too:
ERROR: cannot colocate tables test_a_tbl_2 and test_a_tbl_1 DETAIL: Distribution column collations don't match for test_a_tbl_2 and test_a_tbl_1. CONTEXT: while executing command on localhost:9701-
create_distributed_table()
To fix that, now EnsureTableCanBeColocatedWith() calls EnsureColumnTypeEquality() to perform necessary checks, which already ensures collation match.
And to do that, now EnsureTableCanBeColocatedWith() has to accept distributionColumn Var as an argument (to be passed into EnsureColumnTypeEquality()), so now it doesn't have to accept distributionColumnType separately, so refactor accordingly.
And to provide distributionColumn Var to EnsureTableCanBeColocatedWith(), similarly the call sites of the function also need to have distributionColumn Var, like FindColocateWithColocationId(). And now that FindColocateWithColocationId() accepts distributionColumn Var, it doesn't have to accept distributionColumnType and distributionColumnCollation separately, so refactor accordingly.
-
alter_distributed_table()
Make sure to check column collations.
-
-
(Good)
-
update_distributed_table_colocation()/create_distributed_table_concurrently()
These are already checking whether collations of distribution keys match.
-
ALTER TABLE .. ALTER COLUMN .. TYPE .. COLLATE ..
We already don't allow changing the collation of a distribution column.
-
Codecov Report
:x: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 88.79%. Comparing base (b7a5f69) to head (544f452).
Additional details and impacted files
@@ Coverage Diff @@
## main #8257 +/- ##
==========================================
- Coverage 88.79% 88.79% -0.01%
==========================================
Files 287 287
Lines 63236 63242 +6
Branches 7928 7927 -1
==========================================
+ Hits 56150 56153 +3
- Misses 4754 4759 +5
+ Partials 2332 2330 -2
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.