From c34b6a56013362dd501c713df048649733c97db0 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Fri, 17 Oct 2025 12:54:28 +0300 Subject: [PATCH] add tests --- src/test/regress/expected/single_node.out | 101 +++++++++++++++ .../regress/expected/update_colocation_mx.out | 119 ++++++++++++++++++ src/test/regress/sql/single_node.sql | 61 +++++++++ src/test/regress/sql/update_colocation_mx.sql | 78 ++++++++++++ 4 files changed, 359 insertions(+) diff --git a/src/test/regress/expected/single_node.out b/src/test/regress/expected/single_node.out index 2d1a26a44..cbeddb1a0 100644 --- a/src/test/regress/expected/single_node.out +++ b/src/test/regress/expected/single_node.out @@ -278,6 +278,107 @@ SELECT t (1 row) +create table test_a_tbl_1(text_col text collate "C" unique); +create table test_a_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_a_tbl_1', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +select create_distributed_table('test_a_tbl_2', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +-- make sure we assing them to different colocation groups +select count(*) = 2 as colocationids_different from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'single_node' + and pg_class.relname in ('test_a_tbl_1', 'test_a_tbl_2') +) q; + colocationids_different +------------------------- + t +(1 row) + +DROP TABLE test_a_tbl_1, test_a_tbl_2; +create table test_d_tbl_1(text_col text collate "C" unique); +create table test_d_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_d_tbl_1', 'text_col', shard_count=>4); + create_distributed_table +-------------------------- + +(1 row) + +select create_distributed_table('test_d_tbl_2', 'text_col', shard_count=>6); + create_distributed_table +-------------------------- + +(1 row) + +select alter_distributed_table('test_d_tbl_2', shard_count=>4); +NOTICE: creating a new table for single_node.test_d_tbl_2 +NOTICE: moving the data of single_node.test_d_tbl_2 +NOTICE: dropping the old single_node.test_d_tbl_2 +NOTICE: renaming the new table to single_node.test_d_tbl_2 + alter_distributed_table +------------------------- + +(1 row) + +-- make sure we assing them to different colocation groups +select count(*) = 2 as colocationids_different from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'single_node' + and pg_class.relname in ('test_d_tbl_1', 'test_d_tbl_2') +) q; + colocationids_different +------------------------- + t +(1 row) + +DROP TABLE test_d_tbl_1, test_d_tbl_2; +create table test_b_tbl_1(text_col text collate "C" unique); +create table test_b_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_b_tbl_1', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +-- errors +select create_distributed_table('test_b_tbl_2', 'text_col', colocate_with => 'test_b_tbl_1'); +ERROR: cannot colocate tables test_b_tbl_1 and test_b_tbl_2 +DETAIL: Distribution column collations don't match for test_b_tbl_1 and test_b_tbl_2. +DROP TABLE test_b_tbl_1, test_b_tbl_2; +create table test_c_tbl_1(text_col text collate "C" unique); +create table test_c_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_c_tbl_1', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +select create_distributed_table('test_c_tbl_2', 'text_col', colocate_with => 'none'); + create_distributed_table +-------------------------- + +(1 row) + +-- errors +select alter_distributed_table('test_c_tbl_2', colocate_with=>'test_c_tbl_1'); +ERROR: cannot colocate with test_c_tbl_1 because collation of its distribution column is different than test_c_tbl_2 +DROP TABLE test_c_tbl_1, test_c_tbl_2; SET client_min_messages TO WARNING; DROP TABLE failover_to_local, single_node_nullkey_c1, single_node_nullkey_c2, ref_table_conversion_test, single_shard_conversion_test_1, single_shard_conversion_test_2; DROP SCHEMA tenant_1 CASCADE; diff --git a/src/test/regress/expected/update_colocation_mx.out b/src/test/regress/expected/update_colocation_mx.out index 12b0a4a46..ea56a1ddd 100644 --- a/src/test/regress/expected/update_colocation_mx.out +++ b/src/test/regress/expected/update_colocation_mx.out @@ -95,6 +95,125 @@ SELECT count(DISTINCT colocationid) FROM pg_dist_partition WHERE logicalrelid IN 2 (1 row) +\c - - - :master_port +SET search_path TO "Update Colocation"; +create table test_a_tbl_1(text_col text collate "C" unique); +create table test_a_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_a_tbl_1', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +select create_distributed_table('test_a_tbl_2', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +-- make sure we assing them to different colocation groups +select result as colocationids_different from run_command_on_all_nodes($$ + select count(*) = 2 from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'Update Colocation' + and pg_class.relname in ('test_a_tbl_1', 'test_a_tbl_2') + ) q; +$$); + colocationids_different +------------------------- + t + t + t +(3 rows) + +DROP TABLE test_a_tbl_1, test_a_tbl_2; +create table test_d_tbl_1(text_col text collate "C" unique); +create table test_d_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_d_tbl_1', 'text_col', shard_count=>4); + create_distributed_table +-------------------------- + +(1 row) + +select create_distributed_table('test_d_tbl_2', 'text_col', shard_count=>6); + create_distributed_table +-------------------------- + +(1 row) + +select alter_distributed_table('test_d_tbl_2', shard_count=>4); +NOTICE: creating a new table for "Update Colocation".test_d_tbl_2 +NOTICE: moving the data of "Update Colocation".test_d_tbl_2 +NOTICE: dropping the old "Update Colocation".test_d_tbl_2 +NOTICE: renaming the new table to "Update Colocation".test_d_tbl_2 + alter_distributed_table +------------------------- + +(1 row) + +-- make sure we assing them to different colocation groups +select result as colocationids_different from run_command_on_all_nodes($$ + select count(*) = 2 from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'Update Colocation' + and pg_class.relname in ('test_d_tbl_1', 'test_d_tbl_2') + ) q; +$$); + colocationids_different +------------------------- + t + t + t +(3 rows) + +DROP TABLE test_d_tbl_1, test_d_tbl_2; +create table test_b_tbl_1(text_col text collate "C" unique); +create table test_b_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_b_tbl_1', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +-- errors +select create_distributed_table('test_b_tbl_2', 'text_col', colocate_with => 'test_b_tbl_1'); +ERROR: cannot colocate tables test_b_tbl_1 and test_b_tbl_2 +DETAIL: Distribution column collations don't match for test_b_tbl_1 and test_b_tbl_2. +DROP TABLE test_b_tbl_1, test_b_tbl_2; +create table test_c_tbl_1(text_col text collate "C" unique); +create table test_c_tbl_2(text_col text collate "en-x-icu" unique); +select create_distributed_table('test_c_tbl_1', 'text_col'); + create_distributed_table +-------------------------- + +(1 row) + +select create_distributed_table('test_c_tbl_2', 'text_col', colocate_with => 'none'); + create_distributed_table +-------------------------- + +(1 row) + +-- errors +select alter_distributed_table('test_c_tbl_2', colocate_with=>'test_c_tbl_1'); +ERROR: cannot colocate with test_c_tbl_1 because collation of its distribution column is different than test_c_tbl_2 +DROP TABLE test_c_tbl_1, test_c_tbl_2; \c - postgres - :master_port SET client_min_messages TO ERROR; DROP SCHEMA "Update Colocation" cascade; +SET citus.enable_ddl_propagation TO OFF; +DROP ROLE mx_update_colocation; +\c - postgres - :worker_1_port +SET citus.enable_ddl_propagation TO OFF; +DROP ROLE mx_update_colocation; +\c - postgres - :worker_2_port +SET citus.enable_ddl_propagation TO OFF; +DROP ROLE mx_update_colocation; diff --git a/src/test/regress/sql/single_node.sql b/src/test/regress/sql/single_node.sql index b8838ac66..4574899d0 100644 --- a/src/test/regress/sql/single_node.sql +++ b/src/test/regress/sql/single_node.sql @@ -168,6 +168,67 @@ SELECT WHERE logicalrelid = 'single_node.single_shard_conversion_test_2'::regclass ); +create table test_a_tbl_1(text_col text collate "C" unique); +create table test_a_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_a_tbl_1', 'text_col'); +select create_distributed_table('test_a_tbl_2', 'text_col'); + +-- make sure we assing them to different colocation groups +select count(*) = 2 as colocationids_different from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'single_node' + and pg_class.relname in ('test_a_tbl_1', 'test_a_tbl_2') +) q; + +DROP TABLE test_a_tbl_1, test_a_tbl_2; + +create table test_d_tbl_1(text_col text collate "C" unique); +create table test_d_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_d_tbl_1', 'text_col', shard_count=>4); +select create_distributed_table('test_d_tbl_2', 'text_col', shard_count=>6); +select alter_distributed_table('test_d_tbl_2', shard_count=>4); + +-- make sure we assing them to different colocation groups +select count(*) = 2 as colocationids_different from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'single_node' + and pg_class.relname in ('test_d_tbl_1', 'test_d_tbl_2') +) q; + + +DROP TABLE test_d_tbl_1, test_d_tbl_2; + +create table test_b_tbl_1(text_col text collate "C" unique); +create table test_b_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_b_tbl_1', 'text_col'); + +-- errors +select create_distributed_table('test_b_tbl_2', 'text_col', colocate_with => 'test_b_tbl_1'); + +DROP TABLE test_b_tbl_1, test_b_tbl_2; + +create table test_c_tbl_1(text_col text collate "C" unique); +create table test_c_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_c_tbl_1', 'text_col'); +select create_distributed_table('test_c_tbl_2', 'text_col', colocate_with => 'none'); + +-- errors +select alter_distributed_table('test_c_tbl_2', colocate_with=>'test_c_tbl_1'); + +DROP TABLE test_c_tbl_1, test_c_tbl_2; + SET client_min_messages TO WARNING; DROP TABLE failover_to_local, single_node_nullkey_c1, single_node_nullkey_c2, ref_table_conversion_test, single_shard_conversion_test_1, single_shard_conversion_test_2; DROP SCHEMA tenant_1 CASCADE; diff --git a/src/test/regress/sql/update_colocation_mx.sql b/src/test/regress/sql/update_colocation_mx.sql index c62dfa7b3..737f8cf59 100644 --- a/src/test/regress/sql/update_colocation_mx.sql +++ b/src/test/regress/sql/update_colocation_mx.sql @@ -53,6 +53,84 @@ SELECT count(DISTINCT colocationid) FROM pg_dist_partition WHERE logicalrelid IN SET search_path TO "Update Colocation"; SELECT count(DISTINCT colocationid) FROM pg_dist_partition WHERE logicalrelid IN ('t1'::regclass, 't2'::regclass); +\c - - - :master_port +SET search_path TO "Update Colocation"; + +create table test_a_tbl_1(text_col text collate "C" unique); +create table test_a_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_a_tbl_1', 'text_col'); +select create_distributed_table('test_a_tbl_2', 'text_col'); + +-- make sure we assing them to different colocation groups +select result as colocationids_different from run_command_on_all_nodes($$ + select count(*) = 2 from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'Update Colocation' + and pg_class.relname in ('test_a_tbl_1', 'test_a_tbl_2') + ) q; +$$); + +DROP TABLE test_a_tbl_1, test_a_tbl_2; + +create table test_d_tbl_1(text_col text collate "C" unique); +create table test_d_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_d_tbl_1', 'text_col', shard_count=>4); +select create_distributed_table('test_d_tbl_2', 'text_col', shard_count=>6); +select alter_distributed_table('test_d_tbl_2', shard_count=>4); + +-- make sure we assing them to different colocation groups +select result as colocationids_different from run_command_on_all_nodes($$ + select count(*) = 2 from ( + select distinct(colocationid) + from pg_dist_partition + join pg_class on (logicalrelid = pg_class.oid) + join pg_namespace on (relnamespace = pg_namespace.oid) + join pg_dist_colocation using (colocationid) + where pg_namespace.nspname = 'Update Colocation' + and pg_class.relname in ('test_d_tbl_1', 'test_d_tbl_2') + ) q; +$$); + +DROP TABLE test_d_tbl_1, test_d_tbl_2; + +create table test_b_tbl_1(text_col text collate "C" unique); +create table test_b_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_b_tbl_1', 'text_col'); + +-- errors +select create_distributed_table('test_b_tbl_2', 'text_col', colocate_with => 'test_b_tbl_1'); + +DROP TABLE test_b_tbl_1, test_b_tbl_2; + +create table test_c_tbl_1(text_col text collate "C" unique); +create table test_c_tbl_2(text_col text collate "en-x-icu" unique); + +select create_distributed_table('test_c_tbl_1', 'text_col'); +select create_distributed_table('test_c_tbl_2', 'text_col', colocate_with => 'none'); + +-- errors +select alter_distributed_table('test_c_tbl_2', colocate_with=>'test_c_tbl_1'); + +DROP TABLE test_c_tbl_1, test_c_tbl_2; + \c - postgres - :master_port SET client_min_messages TO ERROR; DROP SCHEMA "Update Colocation" cascade; + +SET citus.enable_ddl_propagation TO OFF; +DROP ROLE mx_update_colocation; + +\c - postgres - :worker_1_port +SET citus.enable_ddl_propagation TO OFF; +DROP ROLE mx_update_colocation; + +\c - postgres - :worker_2_port +SET citus.enable_ddl_propagation TO OFF; +DROP ROLE mx_update_colocation;