Skip to content

Commit 0a2141b

Browse files
committed
sql: prohibit CITEXT as column type in 25.2-25.3 mixed version state
This commit fixes an oversight from fd50f23 where we forgot to prohibit usage of (new in 25.3) CITEXT type as a column type. The impact should be minor since this type is simply implemented as collated string with fixed locale, yet it seems prudent to disable the type's usage until 25.3 version is finalized. Release note: None
1 parent 481329e commit 0a2141b

File tree

7 files changed

+88
-5
lines changed

7 files changed

+88
-5
lines changed

pkg/sql/catalog/colinfo/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ go_library(
1616
importpath = "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo",
1717
visibility = ["//visibility:public"],
1818
deps = [
19+
"//pkg/clusterversion",
1920
"//pkg/docs",
2021
"//pkg/settings/cluster",
2122
"//pkg/sql/catalog",
2223
"//pkg/sql/catalog/catpb",
2324
"//pkg/sql/catalog/descpb",
25+
"//pkg/sql/oidext",
2426
"//pkg/sql/pgwire/pgcode",
2527
"//pkg/sql/pgwire/pgerror",
2628
"//pkg/sql/sem/catconstants",

pkg/sql/catalog/colinfo/col_type_info.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"context"
1010
"fmt"
1111

12+
"github.com/cockroachdb/cockroach/pkg/clusterversion"
1213
"github.com/cockroachdb/cockroach/pkg/docs"
1314
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
1415
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
16+
"github.com/cockroachdb/cockroach/pkg/sql/oidext"
1517
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
1618
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
1719
"github.com/cockroachdb/cockroach/pkg/sql/sem/idxtype"
@@ -71,6 +73,14 @@ func (ti ColTypeInfo) Type(idx int) *types.T {
7173
func ValidateColumnDefType(ctx context.Context, st *cluster.Settings, t *types.T) error {
7274
switch t.Family() {
7375
case types.StringFamily, types.CollatedStringFamily:
76+
if t.Oid() == oidext.T_citext {
77+
if !st.Version.IsActive(ctx, clusterversion.V25_3) {
78+
return pgerror.Newf(
79+
pgcode.FeatureNotSupported,
80+
"citext not supported until version 25.3",
81+
)
82+
}
83+
}
7484
if t.Family() == types.CollatedStringFamily {
7585
if _, err := language.Parse(t.Locale()); err != nil {
7686
return pgerror.Newf(pgcode.Syntax, `invalid locale %s`, t.Locale())
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# LogicTest: cockroach-go-testserver-25.2
2+
3+
# Sanity check that CITEXT type is only allowed to be used once the cluster is
4+
# upgraded to 25.3.
5+
6+
statement error pgcode 42704 type \"citext\" does not exist
7+
CREATE TABLE c (c CITEXT);
8+
9+
statement error pgcode 42704 type \"citext\" does not exist
10+
CREATE TABLE ca (ca CITEXT[]);
11+
12+
statement error pgcode 42704 type \"citext\" does not exist
13+
SELECT 'A'::CITEXT
14+
15+
statement error pgcode 42704 type \"citext\" does not exist
16+
SELECT ARRAY['A', 'B']::CITEXT[]
17+
18+
upgrade 0
19+
20+
statement error pgcode 0A000 citext not supported until version 25.3
21+
CREATE TABLE c (c CITEXT);
22+
23+
statement error pgcode 0A000 citext not supported until version 25.3
24+
CREATE TABLE ca (ca CITEXT[]);
25+
26+
statement error pgcode 0A000 citext not supported until version 25.3
27+
SELECT 'A'::CITEXT
28+
29+
statement error pgcode 0A000 citext\[\] not supported until version 25.3
30+
SELECT ARRAY['A', 'B']::CITEXT[]
31+
32+
upgrade 1
33+
34+
upgrade 2
35+
36+
statement ok
37+
SET CLUSTER SETTING version = crdb_internal.node_executable_version()
38+
39+
statement ok
40+
CREATE TABLE c (c CITEXT);
41+
42+
statement ok
43+
CREATE TABLE ca (ca CITEXT[]);
44+
45+
statement ok
46+
SELECT 'A'::CITEXT
47+
48+
statement ok
49+
SELECT ARRAY['A', 'B']::CITEXT[]

pkg/sql/logictest/tests/cockroach-go-testserver-25.2/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ go_test(
1111
"//pkg/sql/logictest:testdata", # keep
1212
],
1313
exec_properties = {"test.Pool": "heavy"},
14-
shard_count = 8,
14+
shard_count = 9,
1515
tags = ["cpu:3"],
1616
deps = [
1717
"//pkg/base",

pkg/sql/logictest/tests/cockroach-go-testserver-25.2/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sql/ttl/ttljob/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ go_test(
100100
"//pkg/sql/execinfrapb",
101101
"//pkg/sql/isql",
102102
"//pkg/sql/lexbase",
103+
"//pkg/sql/oidext",
103104
"//pkg/sql/parser",
104105
"//pkg/sql/physicalplan",
105106
"//pkg/sql/randgen",

pkg/sql/ttl/ttljob/ttljob_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
2929
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
3030
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
31+
"github.com/cockroachdb/cockroach/pkg/sql/oidext"
3132
"github.com/cockroachdb/cockroach/pkg/sql/parser"
3233
"github.com/cockroachdb/cockroach/pkg/sql/randgen"
3334
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
@@ -605,11 +606,24 @@ func TestRowLevelTTLJobRandomEntries(t *testing.T) {
605606
collatedStringType := types.MakeCollatedString(types.String, "en" /* locale */)
606607
var indexableTyps []*types.T
607608
for _, typ := range append(types.Scalar, collatedStringType) {
609+
if !colinfo.ColumnTypeIsIndexable(typ) {
610+
continue
611+
}
612+
switch typ.Family() {
613+
case types.DateFamily:
608614
// TODO(#76419): DateFamily has a broken `-infinity` case.
609-
// TODO(#99432): JsonFamily has broken cases. This is because the test is wrapping JSON
610-
// objects in multiple single quotes which causes parsing errors.
611-
if colinfo.ColumnTypeIsIndexable(typ) && typ.Family() != types.DateFamily &&
612-
typ.Family() != types.JsonFamily {
615+
case types.JsonFamily:
616+
// TODO(#99432): JsonFamily has broken cases. This is because the
617+
// test is wrapping JSON objects in multiple single quotes which
618+
// causes parsing errors.
619+
case types.CollatedStringFamily:
620+
if typ.Oid() != oidext.T_citext && typ.Oid() != oidext.T__citext {
621+
// TODO(foundations): CITEXT should only be prohibited when
622+
// running with mixed 25.2 version where the type is not
623+
// supported.
624+
indexableTyps = append(indexableTyps, typ)
625+
}
626+
default:
613627
indexableTyps = append(indexableTyps, typ)
614628
}
615629
}

0 commit comments

Comments
 (0)