Skip to content

Commit af16502

Browse files
committed
fixup! Disallow colocating tables when collations don't match
1 parent bede3d1 commit af16502

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/backend/distributed/sql/udfs/fix_pre_citus14_colocation_group_collation_mismatches/14.0-1.sql

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backend/distributed/sql/udfs/fix_pre_citus14_colocation_group_collation_mismatches/latest.sql

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ BEGIN
2020
JOIN pg_attribute pa
2121
ON pa.attrelid = pdp.logicalrelid
2222
AND pa.attname = column_to_column_name(pdp.logicalrelid, pdp.partkey)
23-
-- ignore the table if its distribution column collation matches the collation saved for the colocation group
24-
WHERE pdc.distributioncolumncollation != pa.attcollation
23+
-- column_to_column_name() returns NULL if partkey is NULL, so we're already
24+
-- implicitly ignoring the tables that don't have a distribution column, such
25+
-- as reference tables, but let's still explicitly discard such tables below.
26+
WHERE pdp.partkey IS NOT NULL
27+
-- ignore the table if its distribution column collation matches the collation saved for the colocation group
28+
AND pdc.distributioncolumncollation != pa.attcollation
2529
)
2630
SELECT
2731
colocationid,
@@ -58,15 +62,15 @@ BEGIN
5862
-- but this won't be super easy. Plus, even if we had such a colocation group, the user
5963
-- was anyways okay with having this in a different colocation group in the first place.
6064

61-
RAISE DEBUG 'Moving out table with id % to a new colocation group', v_table_to_move_out;
65+
RAISE DEBUG 'Moving out table with oid % to a new colocation group', v_table_to_move_out;
6266
PERFORM update_distributed_table_colocation(v_table_to_move_out, colocate_with => 'none');
6367

6468
-- save the first table to colocate the rest of the tables with it
6569
v_first_table := v_table_to_move_out;
6670
ELSE
6771
-- Move the rest of the tables to colocate with the first table.
6872

69-
RAISE DEBUG 'Moving out table with id % to colocate with table with id %', v_table_to_move_out, v_first_table;
73+
RAISE DEBUG 'Moving out table with oid % to colocate with table with oid %', v_table_to_move_out, v_first_table;
7074
PERFORM update_distributed_table_colocation(v_table_to_move_out, colocate_with => v_first_table::regclass::text);
7175
END IF;
7276
END LOOP;

src/test/regress/sql/single_node.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ select count(*) = 2 as colocationids_different from (
205205
and pg_class.relname in ('test_d_tbl_1', 'test_d_tbl_2')
206206
) q;
207207

208-
209208
DROP TABLE test_d_tbl_1, test_d_tbl_2;
210209

211210
create table test_b_tbl_1(text_col text collate "C" unique);

0 commit comments

Comments
 (0)