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: adding version gates for changes related to JSON forward indexes
Previously, cockroachdb#99275 and cockroachdb#97298 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 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. Fixes: cockroachdb#35706
- Loading branch information
Showing
8 changed files
with
137 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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() | ||
|
||
// Setting an older cluster version and expecting an error when creating | ||
// forward indexes on JSON columns. | ||
_, err = tc.Conns[0].ExecContext(ctx, `SET CLUSTER SETTING version = $1`, | ||
clusterversion.ByKey(clusterversion.V23_1WebSessionsTableHasUserIDColumn).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) | ||
|
||
// 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 primary key on a JSON column should result in an error. | ||
_, err = db.Exec(`CREATE TABLE test.new ( | ||
key JSONB PRIMARY KEY | ||
)`) | ||
require.Error(t, err) | ||
|
||
} |