From f7a3d5d57eb5c4350ec7045df8c7b1e22f64fc0c Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Tue, 14 Jan 2025 10:27:26 -0500 Subject: [PATCH] sql/logictest: disable column family mutations in some cases Random column family mutations are now disabled for `CREATE TABLE` statements with unique, hash-sharded indexes. This prevents the AST from being reserialized with a `UNIQUE` constraint with invalid options, instead of the original `UNIQUE INDEX`. See #65929 and #107398. Release note: None --- pkg/sql/logictest/logic.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/sql/logictest/logic.go b/pkg/sql/logictest/logic.go index 787f984b4b1d..89ca74238dee 100644 --- a/pkg/sql/logictest/logic.go +++ b/pkg/sql/logictest/logic.go @@ -3495,17 +3495,28 @@ func (t *logicTest) unexpectedError(sql string, pos string, err error) (bool, er return false, fmt.Errorf("%s: %s\nexpected success, but found\n%s", pos, sql, formatErr(err)) } +var uniqueHashPattern = regexp.MustCompile(`UNIQUE.*USING\s+HASH`) + func (t *logicTest) execStatement(stmt logicStatement) (bool, error) { db := t.db t.noticeBuffer = nil if *showSQL { t.outf("%s;", stmt.sql) } - execSQL, changed := randgen.ApplyString(t.rng, stmt.sql, randgen.ColumnFamilyMutator) - if changed { - log.Infof(context.Background(), "Rewrote test statement:\n%s", execSQL) - if *showSQL { - t.outf("rewrote:\n%s\n", execSQL) + execSQL := stmt.sql + // TODO(#65929, #107398): Don't mutate column families for CREATE TABLE + // statements with unique, hash-sharded indexes. The altered AST will be + // reserialized with a UNIQUE constraint, not a UNIQUE INDEX, which may not + // be parsable because constraints do not support all the options that + // indexes do. + if !uniqueHashPattern.MatchString(stmt.sql) { + var changed bool + execSQL, changed = randgen.ApplyString(t.rng, execSQL, randgen.ColumnFamilyMutator) + if changed { + log.Infof(context.Background(), "Rewrote test statement:\n%s", execSQL) + if *showSQL { + t.outf("rewrote:\n%s\n", execSQL) + } } } @@ -3535,8 +3546,6 @@ func (t *logicTest) execStatement(stmt logicStatement) (bool, error) { return t.finishExecStatement(stmt, execSQL, res, err) } -var uniqueHashPattern = regexp.MustCompile(`UNIQUE.*USING\s+HASH`) - func (t *logicTest) finishExecStatement( stmt logicStatement, execSQL string, res gosql.Result, err error, ) (bool, error) {