Skip to content

Commit

Permalink
workload/schemachanger: disable trigram operations in a mixed version…
Browse files Browse the repository at this point in the history
… state

Previously, the schema changer workload in a mixed version state
attempted to use trigram indexes against 22.1, which is unsupported.
This patch adds code to detect a mixed version state and expects
the appropriate error when this occurs.

Release justification: no risk improves test coverage
Release note: None
  • Loading branch information
fqazi committed Sep 14, 2022
1 parent bc9c8f6 commit eb07fe3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,29 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
stmt := randgen.RandCreateTableWithColumnIndexNumberGenerator(og.params.rng, "table", tableIdx, databaseHasMultiRegion, og.newUniqueSeqNum)
stmt.Table = *tableName
stmt.IfNotExists = og.randIntn(2) == 0
trigramIsNotSupported, err := isClusterVersionLessThan(
ctx,
tx,
clusterversion.ByKey(clusterversion.TrigramInvertedIndexes))
if err != nil {
return nil, err
}
hasTrigramIdxUnsupported := func() bool {
if !trigramIsNotSupported {
return false
}
// Check if any of the indexes have trigrams involved.
for _, def := range stmt.Defs {
if idx, ok := def.(*tree.IndexTableDef); ok && idx.Inverted {
lastColumn := idx.Columns[len(idx.Columns)-1]
switch lastColumn.OpClass {
case "gin_trgm_ops", "gist_trgm_ops":
return true
}
}
}
return false
}()

tableExists, err := og.tableExists(ctx, tx, tableName)
if err != nil {
Expand All @@ -1197,6 +1220,11 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
{code: pgcode.DuplicateRelation, condition: tableExists && !stmt.IfNotExists},
{code: pgcode.UndefinedSchema, condition: !schemaExists},
}.add(opStmt.expectedExecErrors)
// Compatibility errors aren't guaranteed since the cluster version update is not
// fully transaction aware.
codesWithConditions{
{code: pgcode.FeatureNotSupported, condition: hasTrigramIdxUnsupported},
}.add(opStmt.potentialExecErrors)
opStmt.sql = tree.Serialize(stmt)
return opStmt, nil
}
Expand Down

0 comments on commit eb07fe3

Please sign in to comment.