From 5750fb9519100a8f651d43629ed0bab0adf82c35 Mon Sep 17 00:00:00 2001 From: Matt Spilchen Date: Wed, 6 Nov 2024 16:41:45 -0400 Subject: [PATCH] schemachange/mixed-versions: handle possible syntax error for BIT(0) column usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A recent fix enabled support for BIT(0) columns (see issue #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 #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: #133339, #133790, #131162 --- .../schemachange/operation_generator.go | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/pkg/workload/schemachange/operation_generator.go b/pkg/workload/schemachange/operation_generator.go index b38003d0572f..214a58e793da 100644 --- a/pkg/workload/schemachange/operation_generator.go +++ b/pkg/workload/schemachange/operation_generator.go @@ -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 { @@ -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 @@ -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 } @@ -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 { @@ -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 } @@ -4808,6 +4832,22 @@ 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