From 121375a532c787e4047f319a80b716e0d88a305d Mon Sep 17 00:00:00 2001 From: Steven Danna Date: Fri, 29 Jan 2021 14:20:25 +0000 Subject: [PATCH] sql: deterministic zone config output for SHOW CREATE Previously, tests that depended on the order of the ALTER PARTITION statements generated as part of SHOW CREATE would occasionally fail. This change sorts the zone_configs CTE by the partition_name and index_name, leading to more deterministic output. With this in place, I was able to run the previously flaky test, 500 times without failure, whereas it previously would fail after 10 or so runs. Fixes #59511 Release note (sql change): The SHOW CREATE statement now lists ALTER PARTITION statements sorted by the partition name and index_name. --- .../testdata/logic_test/regional_by_row | 40 +++++++++---------- pkg/sql/delegate/show_table.go | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row index 1d4cf18af740..7f703756550f 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row +++ b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row @@ -300,6 +300,10 @@ CREATE TABLE public.regional_by_row_table ( UNIQUE INDEX unique_b_a (b ASC, a ASC), FAMILY fam_0_pk_pk2_a_b_crdb_region (pk, pk2, a, b, crdb_region) ) LOCALITY REGIONAL BY ROW; +ALTER PARTITION "ap-southeast-2" OF INDEX multi_region_test_db.public.regional_by_row_table@new_idx CONFIGURE ZONE USING + num_replicas = 3, + constraints = '{+region=ap-southeast-2: 1}', + lease_preferences = '[[+region=ap-southeast-2]]'; ALTER PARTITION "ap-southeast-2" OF INDEX multi_region_test_db.public.regional_by_row_table@primary CONFIGURE ZONE USING num_replicas = 3, constraints = '{+region=ap-southeast-2: 1}', @@ -312,6 +316,14 @@ ALTER PARTITION "ap-southeast-2" OF INDEX multi_region_test_db.public.regional_b num_replicas = 3, constraints = '{+region=ap-southeast-2: 1}', lease_preferences = '[[+region=ap-southeast-2]]'; +ALTER PARTITION "ap-southeast-2" OF INDEX multi_region_test_db.public.regional_by_row_table@unique_b_a CONFIGURE ZONE USING + num_replicas = 3, + constraints = '{+region=ap-southeast-2: 1}', + lease_preferences = '[[+region=ap-southeast-2]]'; +ALTER PARTITION "ca-central-1" OF INDEX multi_region_test_db.public.regional_by_row_table@new_idx CONFIGURE ZONE USING + num_replicas = 3, + constraints = '{+region=ca-central-1: 1}', + lease_preferences = '[[+region=ca-central-1]]'; ALTER PARTITION "ca-central-1" OF INDEX multi_region_test_db.public.regional_by_row_table@primary CONFIGURE ZONE USING num_replicas = 3, constraints = '{+region=ca-central-1: 1}', @@ -324,38 +336,26 @@ ALTER PARTITION "ca-central-1" OF INDEX multi_region_test_db.public.regional_by_ num_replicas = 3, constraints = '{+region=ca-central-1: 1}', lease_preferences = '[[+region=ca-central-1]]'; -ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@primary CONFIGURE ZONE USING +ALTER PARTITION "ca-central-1" OF INDEX multi_region_test_db.public.regional_by_row_table@unique_b_a CONFIGURE ZONE USING + num_replicas = 3, + constraints = '{+region=ca-central-1: 1}', + lease_preferences = '[[+region=ca-central-1]]'; +ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@new_idx CONFIGURE ZONE USING num_replicas = 3, constraints = '{+region=us-east-1: 1}', lease_preferences = '[[+region=us-east-1]]'; -ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@regional_by_row_table_a_idx CONFIGURE ZONE USING +ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@primary CONFIGURE ZONE USING num_replicas = 3, constraints = '{+region=us-east-1: 1}', lease_preferences = '[[+region=us-east-1]]'; -ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@regional_by_row_table_b_key CONFIGURE ZONE USING +ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@regional_by_row_table_a_idx CONFIGURE ZONE USING num_replicas = 3, constraints = '{+region=us-east-1: 1}', lease_preferences = '[[+region=us-east-1]]'; -ALTER PARTITION "ap-southeast-2" OF INDEX multi_region_test_db.public.regional_by_row_table@new_idx CONFIGURE ZONE USING - num_replicas = 3, - constraints = '{+region=ap-southeast-2: 1}', - lease_preferences = '[[+region=ap-southeast-2]]'; -ALTER PARTITION "ca-central-1" OF INDEX multi_region_test_db.public.regional_by_row_table@new_idx CONFIGURE ZONE USING - num_replicas = 3, - constraints = '{+region=ca-central-1: 1}', - lease_preferences = '[[+region=ca-central-1]]'; -ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@new_idx CONFIGURE ZONE USING +ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@regional_by_row_table_b_key CONFIGURE ZONE USING num_replicas = 3, constraints = '{+region=us-east-1: 1}', lease_preferences = '[[+region=us-east-1]]'; -ALTER PARTITION "ap-southeast-2" OF INDEX multi_region_test_db.public.regional_by_row_table@unique_b_a CONFIGURE ZONE USING - num_replicas = 3, - constraints = '{+region=ap-southeast-2: 1}', - lease_preferences = '[[+region=ap-southeast-2]]'; -ALTER PARTITION "ca-central-1" OF INDEX multi_region_test_db.public.regional_by_row_table@unique_b_a CONFIGURE ZONE USING - num_replicas = 3, - constraints = '{+region=ca-central-1: 1}', - lease_preferences = '[[+region=ca-central-1]]'; ALTER PARTITION "us-east-1" OF INDEX multi_region_test_db.public.regional_by_row_table@unique_b_a CONFIGURE ZONE USING num_replicas = 3, constraints = '{+region=us-east-1: 1}', diff --git a/pkg/sql/delegate/show_table.go b/pkg/sql/delegate/show_table.go index 7369dd9b15f7..40f7ef2ab63a 100644 --- a/pkg/sql/delegate/show_table.go +++ b/pkg/sql/delegate/show_table.go @@ -24,7 +24,7 @@ func (d *delegator) delegateShowCreate(n *tree.ShowCreate) (tree.Statement, erro const showCreateQuery = ` WITH zone_configs AS ( - SELECT string_agg(raw_config_sql, e';\n') FROM crdb_internal.zones + SELECT string_agg(raw_config_sql, e';\n' ORDER BY partition_name, index_name) FROM crdb_internal.zones WHERE database_name = %[1]s AND table_name = %[2]s AND raw_config_yaml IS NOT NULL