Skip to content

Commit 3410251

Browse files
committed
workload/schemachange/mixed-version: avoid index visibility
Fixes: #87768 Previously, we were generating statements with invisible indexes in mixed version environments, which could lead to statements generated not supported on older versions. To address this, this patch will prevent the generation of create table/ create index statements with invisible indexes. Release note: None
1 parent 87bd307 commit 3410251

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

pkg/workload/schemachange/operation_generator.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,13 +934,22 @@ func (og *operationGenerator) createIndex(ctx context.Context, tx pgx.Tx) (*opSt
934934
return nil, err
935935
}
936936

937+
// Only generate invisible indexes when they are supported.
938+
invisibleIndexesIsNotSupported, err := isClusterVersionLessThan(
939+
ctx,
940+
tx,
941+
clusterversion.ByKey(clusterversion.Start22_2))
942+
if err != nil {
943+
return nil, err
944+
}
945+
937946
def := &tree.CreateIndex{
938947
Name: tree.Name(indexName),
939948
Table: *tableName,
940-
Unique: og.randIntn(4) == 0, // 25% UNIQUE
941-
Inverted: og.randIntn(10) == 0, // 10% INVERTED
942-
IfNotExists: og.randIntn(2) == 0, // 50% IF NOT EXISTS
943-
NotVisible: og.randIntn(20) == 0, // 5% NOT VISIBLE
949+
Unique: og.randIntn(4) == 0, // 25% UNIQUE
950+
Inverted: og.randIntn(10) == 0, // 10% INVERTED
951+
IfNotExists: og.randIntn(2) == 0, // 50% IF NOT EXISTS
952+
NotVisible: og.randIntn(20) == 0 && !invisibleIndexesIsNotSupported, // 5% NOT VISIBLE
944953
}
945954

946955
regionColumn := ""
@@ -1207,6 +1216,26 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
12071216
return false
12081217
}()
12091218

1219+
invisibleIndexesIsNotSupported, err := isClusterVersionLessThan(
1220+
ctx,
1221+
tx,
1222+
clusterversion.ByKey(clusterversion.Start22_2))
1223+
if err != nil {
1224+
return nil, err
1225+
}
1226+
hasInvisibleIndexesUnsupported := func() bool {
1227+
if !invisibleIndexesIsNotSupported {
1228+
return false
1229+
}
1230+
// Check if any of the indexes have trigrams involved.
1231+
for _, def := range stmt.Defs {
1232+
if idx, ok := def.(*tree.IndexTableDef); ok && idx.NotVisible {
1233+
return true
1234+
}
1235+
}
1236+
return false
1237+
}()
1238+
12101239
tableExists, err := og.tableExists(ctx, tx, tableName)
12111240
if err != nil {
12121241
return nil, err
@@ -1224,6 +1253,7 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
12241253
// fully transaction aware.
12251254
codesWithConditions{
12261255
{code: pgcode.FeatureNotSupported, condition: hasTrigramIdxUnsupported},
1256+
{code: pgcode.Syntax, condition: hasInvisibleIndexesUnsupported},
12271257
}.add(opStmt.potentialExecErrors)
12281258
opStmt.sql = tree.Serialize(stmt)
12291259
return opStmt, nil

0 commit comments

Comments
 (0)