-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: adding version gates for changes related to JSON forward indexes
Previously, #99275 and #97928 were responsible for laying the foundations of a JSON lexicographical order as well as enabling JSON forward indexes in CRDB. However, these commits did not account for version gates. In a given cluster, all of its nodes are required to be at a certain version number for creating JSON forward indexes as well as for ordering JSON columns. Thus, this PR aims to enable version gates for ensuring all nodes in a given cluster meet this requirement. Epic: CRDB-24501 Fixes: #35706 Release note (sql change): This PR adds version gates which requires all nodes in a given cluster to have a minimum binary version number which in turn is required for creating forward indexes on JSON columns and for ordering JSON columns.
- Loading branch information
1 parent
58fbcfb
commit 33a903e
Showing
9 changed files
with
202 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# LogicTest: default-configs !local-mixed-22.2-23.1 | ||
|
||
statement ok | ||
CREATE TABLE t ( | ||
k INT PRIMARY KEY, | ||
|
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
14 changes: 0 additions & 14 deletions
14
pkg/sql/logictest/tests/local-mixed-22.2-23.1/generated_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,147 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package upgrades_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/clusterversion" | ||
"github.com/cockroachdb/cockroach/pkg/server" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/skip" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestJSONForwardingIndexes(t *testing.T) { | ||
var err error | ||
skip.UnderStressRace(t) | ||
defer leaktest.AfterTest(t)() | ||
ctx := context.Background() | ||
|
||
settings := cluster.MakeTestingClusterSettingsWithVersions( | ||
clusterversion.TestingBinaryVersion, | ||
clusterversion.TestingBinaryMinSupportedVersion, | ||
false, | ||
) | ||
|
||
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ | ||
ServerArgs: base.TestServerArgs{ | ||
Settings: settings, | ||
Knobs: base.TestingKnobs{ | ||
Server: &server.TestingKnobs{ | ||
DisableAutomaticVersionUpgrade: make(chan struct{}), | ||
BinaryVersionOverride: clusterversion.TestingBinaryMinSupportedVersion, | ||
}, | ||
}, | ||
}, | ||
}) | ||
defer tc.Stopper().Stop(ctx) | ||
|
||
db := tc.ServerConn(0) | ||
defer db.Close() | ||
|
||
// Set the cluster version to 22.2 to test that with the legacy schema changer | ||
// we cannot create forward indexes on JSON columns. | ||
_, err = tc.Conns[0].ExecContext(ctx, `SET CLUSTER SETTING version = $1`, | ||
clusterversion.ByKey(clusterversion.V22_2).String()) | ||
require.NoError(t, err) | ||
|
||
_, err = db.Exec(`CREATE DATABASE test`) | ||
require.NoError(t, err) | ||
|
||
_, err = db.Exec(`CREATE TABLE test.hello ( | ||
key INT PRIMARY KEY, | ||
j JSONB | ||
)`) | ||
require.NoError(t, err) | ||
|
||
_, err = db.Exec(`INSERT INTO test.hello VALUES (1, '[{"a":"b"}]'::JSONB)`) | ||
require.NoError(t, err) | ||
|
||
// Creating an index on the JSON column should result in an error. | ||
_, err = db.Exec(`CREATE INDEX testidx_col on test.hello (j)`) | ||
require.Error(t, err) | ||
|
||
// Creating an JSON expression index should result in an error. | ||
_, err = db.Exec(`CREATE INDEX testidx_expr on test.hello ((j->'a'))`) | ||
require.Error(t, err) | ||
|
||
// Creating a table with an index on the JSON column should result in an error. | ||
_, err = db.Exec(`CREATE TABLE test.tbl_json_secondary( | ||
j JSONB, | ||
INDEX tbl_json_secondary_idx (j) | ||
)`) | ||
require.Error(t, err) | ||
|
||
// Creating a primary key on a JSON column should result in an error. | ||
_, err = db.Exec(`CREATE TABLE test.tbl_json_primary ( | ||
key JSONB PRIMARY KEY | ||
)`) | ||
require.Error(t, err) | ||
|
||
// Set the cluster version to 23.1 to test that with the declarative schema | ||
// changer we cannot create forward indexes on JSON columns. | ||
_, err = tc.Conns[0].ExecContext(ctx, `SET CLUSTER SETTING version = $1`, | ||
clusterversion.ByKey(clusterversion.V23_1).String()) | ||
require.NoError(t, err) | ||
|
||
// Creating an index on the JSON column should result in an error. | ||
_, err = db.Exec(`CREATE INDEX on test.hello (j)`) | ||
require.Error(t, err) | ||
|
||
// Creating an JSON expression index should result in an error. | ||
_, err = db.Exec(`CREATE INDEX on test.hello ((j->'a'))`) | ||
require.Error(t, err) | ||
|
||
// Creating a table with an index on the JSON column should result in an error. | ||
_, err = db.Exec(`CREATE TABLE test.tbl_json_secondary( | ||
j JSONB, | ||
INDEX tbl_json_secondary_idx (j) | ||
)`) | ||
require.Error(t, err) | ||
|
||
// Creating a primary key on a JSON column should result in an error. | ||
_, err = db.Exec(`CREATE TABLE test.tbl_json_primary ( | ||
key JSONB PRIMARY KEY | ||
)`) | ||
require.Error(t, err) | ||
|
||
// Setting a cluster version that supports forward indexes on JSON | ||
// columns and expecting success when creating forward indexes. | ||
_, err = tc.Conns[0].ExecContext(ctx, `SET CLUSTER SETTING version = $1`, | ||
clusterversion.ByKey(clusterversion.V23_2).String()) | ||
require.NoError(t, err) | ||
|
||
// Creating an index on the JSON column should not result in an error. | ||
_, err = db.Exec(`CREATE INDEX on test.hello (j)`) | ||
require.NoError(t, err) | ||
|
||
// Creating an JSON expression index should not result in an error. | ||
_, err = db.Exec(`CREATE INDEX on test.hello ((j->'a'))`) | ||
require.NoError(t, err) | ||
|
||
// Creating a table with an index on the JSON column should result in an error. | ||
_, err = db.Exec(`CREATE TABLE test.tbl_json_secondary( | ||
j JSONB, | ||
INDEX tbl_json_secondary_idx (j) | ||
)`) | ||
require.NoError(t, err) | ||
|
||
// Creating a primary key on a JSON column should result in an error. | ||
_, err = db.Exec(`CREATE TABLE test.tbl_json_primary ( | ||
key JSONB PRIMARY KEY | ||
)`) | ||
require.NoError(t, err) | ||
} |