Skip to content

Commit

Permalink
schemachange/mixed-versions: handle possible syntax error for BIT(0) …
Browse files Browse the repository at this point in the history
…column usage

A recent fix enabled support for BIT(0) columns (see issue cockroachdb#132944),
which has since been backported. However, since this backport hasn’t
been released yet, running against an older down-level client may still
trigger a syntax error. This change adds a temporary check to handle
such errors until the backports for cockroachdb#132944 are publicly released.

This adjustment will be backported to older branches, with slight
variations per release:
- release-24.3: Reuse the same fix as in master.
- release-24.2: Use isClusterVersionLessThan with clusterversion.V24.2.
- release-24.1: Use isClusterVersionLessThan with clusterversion.V24.1.
- release-23.2: Use isClusterVersionLessThan with clusterversion.V23.2.

Epic: None
Release note: None
Closes: cockroachdb#133339, cockroachdb#133790, cockroachdb#131162
  • Loading branch information
spilchen committed Nov 6, 2024
1 parent f5fde85 commit e66b80d
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,18 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
}
return false
}()
mixedVersionTest, err := isMixedVersionTest(ctx, tx)
if err != nil {
return nil, err
}
hasUnsupportedBit0Type := func() bool {
for _, def := range stmt.Defs {
if col, ok := def.(*tree.ColumnTableDef); ok && isUnsupportedBit0Type(col.Type.SQLString(), mixedVersionTest) {
return true
}
}
return false
}()

tableExists, err := og.tableExists(ctx, tx, tableName)
if err != nil {
Expand All @@ -1297,6 +1309,7 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
opStmt.potentialExecErrors.addAll(codesWithConditions{
{code: pgcode.Syntax, condition: hasVectorType},
{code: pgcode.FeatureNotSupported, condition: hasVectorType},
{code: pgcode.InvalidParameterValue, condition: hasUnsupportedBit0Type},
})
opStmt.sql = tree.Serialize(stmt)
return opStmt, nil
Expand Down Expand Up @@ -3941,11 +3954,17 @@ func (og *operationGenerator) randType(
if err != nil {
return nil, nil, err
}
mixedVersion, err := isMixedVersionTest(ctx, tx)
if err != nil {
return nil, nil, err
}

typ := randgen.RandSortingType(og.params.rng)
for pgVectorNotSupported && typ.Family() == types.PGVectorFamily {
for (pgVectorNotSupported && typ.Family() == types.PGVectorFamily) ||
isUnsupportedBit0Type(typ.SQLString(), mixedVersion) {
typ = randgen.RandSortingType(og.params.rng)
}

typeName := tree.MakeUnqualifiedTypeName(typ.SQLString())
return &typeName, typ, nil
}
Expand Down Expand Up @@ -4139,6 +4158,10 @@ FROM
if err != nil {
return nil, err
}
mixedVersion, err := isMixedVersionTest(ctx, tx)
if err != nil {
return nil, err
}

// Generate random parameters / values for builtin types.
for i, typeVal := range randgen.SeedTypes {
Expand All @@ -4152,7 +4175,8 @@ FROM
typeVal.Family() == types.VoidFamily {
continue
}
if pgVectorNotSupported && typeVal.Family() == types.PGVectorFamily {
if pgVectorNotSupported && typeVal.Family() == types.PGVectorFamily ||
isUnsupportedBit0Type(typeVal.SQLString(), mixedVersion) {
continue
}

Expand Down Expand Up @@ -4808,6 +4832,26 @@ func isClusterVersionLessThan(
return clusterVersion.Less(targetVersion), nil
}

// isMixedVersionTest works similarly to isClusterVersionLessThan, but without
// specifying a version. It returns true if the cluster version is not the
// latest, indicating a mixed-version test.
func isMixedVersionTest(
ctx context.Context, tx pgx.Tx,
) (bool, error) {
return isClusterVersionLessThan(ctx, tx, clusterversion.Latest.Version())
}

func isUnsupportedBit0Type(
typName string, mixedVersion bool,
) bool {
// TODO(spilchen): In mixed-version tests, declaring a BIT(0) column can cause a
// syntax error. Support for this type was recently added and backported, but the
// backport release is still pending. We need to regenerate the type until
// something other than BIT(0) is generated. This can be removed once 24.2.5 is
// publicly released.
return mixedVersion && strings.HasPrefix(typName, "BIT(0)")
}

func (og *operationGenerator) setSeedInDB(ctx context.Context, tx pgx.Tx) error {
if notSupported, err := isClusterVersionLessThan(ctx, tx, clusterversion.V24_1.Version()); err != nil {
return err
Expand Down

0 comments on commit e66b80d

Please sign in to comment.