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.
101932: sql: adding version gates for changes related to JSON forward indexes r=fqazi a=Shivs11 Previously, cockroachdb#99275 and cockroachdb#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](https://cockroachlabs.atlassian.net/browse/CRDB-24501) Fixes: cockroachdb#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. Co-authored-by: Shivam Saraf <[email protected]>
- Loading branch information
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) | ||
} |