Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-24.2: schemachange/mixed-versions: handle possible syntax error for BIT(0) column usage #134503

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,18 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
}
return false
}()
mixedVersion, err := isMixedVersionState(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(), mixedVersion) {
return true
}
}
return false
}()

tableExists, err := og.tableExists(ctx, tx, tableName)
if err != nil {
Expand All @@ -1249,6 +1261,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 @@ -3763,11 +3776,17 @@ func (og *operationGenerator) randType(
if err != nil {
return nil, nil, err
}
mixedVersion, err := isMixedVersionState(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 @@ -3955,6 +3974,10 @@ FROM
if err != nil {
return nil, err
}
mixedVersion, err := isMixedVersionState(ctx, tx)
if err != nil {
return nil, err
}

// Generate random parameters / values for builtin types.
for i, typeVal := range randgen.SeedTypes {
Expand All @@ -3968,7 +3991,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 @@ -4609,6 +4633,22 @@ func isClusterVersionLessThan(
return clusterVersion.Less(targetVersion), nil
}

// isMixedVersionState 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 isMixedVersionState(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 testing, 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.1.7 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