diff --git a/src/backend/distributed/utils/colocation_utils.c b/src/backend/distributed/utils/colocation_utils.c index 076c29d54..02813db2e 100644 --- a/src/backend/distributed/utils/colocation_utils.c +++ b/src/backend/distributed/utils/colocation_utils.c @@ -112,6 +112,9 @@ get_colocated_shard_array(PG_FUNCTION_ARGS) Oid arrayTypeId = OIDOID; int colocatedShardIndex = 0; + /* sort to get consistent output */ + colocatedShardList = SortList(colocatedShardList, CompareShardIntervalsById); + foreach(colocatedShardCell, colocatedShardList) { ShardInterval *colocatedShardInterval = (ShardInterval *) lfirst( diff --git a/src/test/regress/expected/multi_colocation_utils.out b/src/test/regress/expected/multi_colocation_utils.out index 383554b86..3a1e8ed34 100644 --- a/src/test/regress/expected/multi_colocation_utils.out +++ b/src/test/regress/expected/multi_colocation_utils.out @@ -266,39 +266,39 @@ SELECT shards_colocated(1300000, 1300020); (1 row) -- check co-located table list -SELECT UNNEST(get_colocated_table_array('table1_group1'))::regclass; +SELECT UNNEST(get_colocated_table_array('table1_group1'))::regclass ORDER BY 1; unnest --------------- - table2_group1 table1_group1 + table2_group1 (2 rows) -SELECT UNNEST(get_colocated_table_array('table5_groupX'))::regclass; +SELECT UNNEST(get_colocated_table_array('table5_groupX'))::regclass ORDER BY 1; unnest --------------- table5_groupx (1 row) -SELECT UNNEST(get_colocated_table_array('table6_append'))::regclass; +SELECT UNNEST(get_colocated_table_array('table6_append'))::regclass ORDER BY 1; unnest --------------- table6_append (1 row) -- check co-located shard list -SELECT get_colocated_shard_array(1300000); +SELECT get_colocated_shard_array(1300000) ORDER BY 1; get_colocated_shard_array --------------------------- - {1300004,1300000} + {1300000,1300004} (1 row) -SELECT get_colocated_shard_array(1300016); +SELECT get_colocated_shard_array(1300016) ORDER BY 1; get_colocated_shard_array --------------------------- {1300016} (1 row) -SELECT get_colocated_shard_array(1300020); +SELECT get_colocated_shard_array(1300020) ORDER BY 1; get_colocated_shard_array --------------------------- {1300020} diff --git a/src/test/regress/sql/multi_colocation_utils.sql b/src/test/regress/sql/multi_colocation_utils.sql index c4ed46479..19bc09876 100644 --- a/src/test/regress/sql/multi_colocation_utils.sql +++ b/src/test/regress/sql/multi_colocation_utils.sql @@ -134,14 +134,14 @@ SELECT shards_colocated(1300000, 1300016); SELECT shards_colocated(1300000, 1300020); -- check co-located table list -SELECT UNNEST(get_colocated_table_array('table1_group1'))::regclass; -SELECT UNNEST(get_colocated_table_array('table5_groupX'))::regclass; -SELECT UNNEST(get_colocated_table_array('table6_append'))::regclass; +SELECT UNNEST(get_colocated_table_array('table1_group1'))::regclass ORDER BY 1; +SELECT UNNEST(get_colocated_table_array('table5_groupX'))::regclass ORDER BY 1; +SELECT UNNEST(get_colocated_table_array('table6_append'))::regclass ORDER BY 1; -- check co-located shard list -SELECT get_colocated_shard_array(1300000); -SELECT get_colocated_shard_array(1300016); -SELECT get_colocated_shard_array(1300020); +SELECT get_colocated_shard_array(1300000) ORDER BY 1; +SELECT get_colocated_shard_array(1300016) ORDER BY 1; +SELECT get_colocated_shard_array(1300020) ORDER BY 1; -- check FindShardIntervalIndex function SELECT find_shard_interval_index(1300000);