forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: set zone configs before backfill on ALTER TABLE LOCALITY/PRIMARY…
… KEY Ensure that the zone configurations are correctly set before the backfill runs, so data is backfilled to the correct location upfront for REGIONAL BY ROW tables. Note this bug also exists on existing ALTER PRIMARY KEY statements. Release justification: bug fixes and low-risk updates to new functionality Release note (bug fix): Fix bug where zone configurations on indexes were not copied before the backfill of an ALTER PRIMARY KEY. They used to be copied afterwards instead.
- Loading branch information
Showing
8 changed files
with
444 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package partitionccl | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
) | ||
|
||
func TestAlterPrimaryKeyCorrectZoneConfigBeforeBackfill(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
testCases := []testutilsccl.AlterPrimaryKeyCorrectZoneConfigTestCase{ | ||
{ | ||
Desc: "ALTER PRIMARY KEY", | ||
SetupQuery: `CREATE TABLE t.test (k INT NOT NULL, v INT NOT NULL, INDEX v_idx (v)); | ||
ALTER INDEX t.test@v_idx CONFIGURE ZONE USING gc.ttlseconds = 888 | ||
`, | ||
AlterQuery: `ALTER TABLE t.test ALTER PRIMARY KEY USING COLUMNS (v)`, | ||
ExpectedIntermediateZoneConfigs: []testutilsccl.AlterPrimaryKeyCorrectZoneConfigIntermediateZoneConfig{ | ||
{ | ||
ShowConfigStatement: `SHOW ZONE CONFIGURATION FOR INDEX t.test@v_idx_rewrite_for_primary_key_change`, | ||
ExpectedTarget: `INDEX t.public.test@v_idx_rewrite_for_primary_key_change`, | ||
ExpectedSQL: `ALTER INDEX t.public.test@v_idx_rewrite_for_primary_key_change CONFIGURE ZONE USING | ||
range_min_bytes = 134217728, | ||
range_max_bytes = 536870912, | ||
gc.ttlseconds = 888, | ||
num_replicas = 1, | ||
constraints = '[]', | ||
lease_preferences = '[]'`, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testutilsccl.AlterPrimaryKeyCorrectZoneConfigTest( | ||
t, | ||
`CREATE DATABASE t`, | ||
testCases, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "testutilsccl", | ||
srcs = ["alter_primary_key.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/base", | ||
"//pkg/roachpb", | ||
"//pkg/sql", | ||
"//pkg/sql/execinfra", | ||
"//pkg/sql/sqltestutils", | ||
"//pkg/sql/tests", | ||
"//pkg/testutils/serverutils", | ||
"//pkg/util", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
Oops, something went wrong.