Skip to content

Commit

Permalink
sql/logictest: disable column family mutations in some cases
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mgartner committed Jan 14, 2025
1 parent 2857e2b commit f7a3d5d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f7a3d5d

Please sign in to comment.