Skip to content

Commit f402c2a

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 a6a632c commit f402c2a

File tree

7 files changed

+86
-5
lines changed

7 files changed

+86
-5
lines changed

pkg/sql/catalog/colinfo/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ go_library(
2222
"//pkg/sql/catalog",
2323
"//pkg/sql/catalog/catpb",
2424
"//pkg/sql/catalog/descpb",
25+
"//pkg/sql/oidext",
2526
"//pkg/sql/pgwire/pgcode",
2627
"//pkg/sql/pgwire/pgerror",
2728
"//pkg/sql/sem/catconstants",

pkg/sql/catalog/colinfo/col_type_info.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cockroachdb/cockroach/pkg/docs"
1414
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
1515
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
16+
"github.com/cockroachdb/cockroach/pkg/sql/oidext"
1617
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
1718
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
1819
"github.com/cockroachdb/cockroach/pkg/sql/sem/idxtype"
@@ -72,6 +73,14 @@ func (ti ColTypeInfo) Type(idx int) *types.T {
7273
func ValidateColumnDefType(ctx context.Context, st *cluster.Settings, t *types.T) error {
7374
switch t.Family() {
7475
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+
}
7584
if t.Family() == types.CollatedStringFamily {
7685
if _, err := language.Parse(t.Locale()); err != nil {
7786
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 = 9,
14+
shard_count = 10,
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
@@ -105,6 +105,7 @@ go_test(
105105
"//pkg/sql/execinfrapb",
106106
"//pkg/sql/isql",
107107
"//pkg/sql/lexbase",
108+
"//pkg/sql/oidext",
108109
"//pkg/sql/parser",
109110
"//pkg/sql/physicalplan",
110111
"//pkg/sql/randgen",

pkg/sql/ttl/ttljob/ttljob_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
3333
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
3434
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
35+
"github.com/cockroachdb/cockroach/pkg/sql/oidext"
3536
"github.com/cockroachdb/cockroach/pkg/sql/parser"
3637
"github.com/cockroachdb/cockroach/pkg/sql/randgen"
3738
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
@@ -689,11 +690,24 @@ func TestRowLevelTTLJobRandomEntries(t *testing.T) {
689690
collatedStringType := types.MakeCollatedString(types.String, "en" /* locale */)
690691
var indexableTyps []*types.T
691692
for _, typ := range append(types.Scalar, collatedStringType) {
693+
if !colinfo.ColumnTypeIsIndexable(typ) {
694+
continue
695+
}
696+
switch typ.Family() {
697+
case types.DateFamily:
692698
// TODO(#76419): DateFamily has a broken `-infinity` case.
693-
// TODO(#99432): JsonFamily has broken cases. This is because the test is wrapping JSON
694-
// objects in multiple single quotes which causes parsing errors.
695-
if colinfo.ColumnTypeIsIndexable(typ) && typ.Family() != types.DateFamily &&
696-
typ.Family() != types.JsonFamily {
699+
case types.JsonFamily:
700+
// TODO(#99432): JsonFamily has broken cases. This is because the
701+
// test is wrapping JSON objects in multiple single quotes which
702+
// causes parsing errors.
703+
case types.CollatedStringFamily:
704+
if typ.Oid() != oidext.T_citext && typ.Oid() != oidext.T__citext {
705+
// TODO(foundations): CITEXT should only be prohibited when
706+
// running with mixed 25.2 version where the type is not
707+
// supported.
708+
indexableTyps = append(indexableTyps, typ)
709+
}
710+
default:
697711
indexableTyps = append(indexableTyps, typ)
698712
}
699713
}

0 commit comments

Comments
 (0)