Skip to content

Commit f05cfb5

Browse files
committed
workload/schemachanger: add testing for schema_locked tables
Previously, the schema changer workload lacked randomized testing for schema_locked tables. This resulted in a lack of coverage for schema changes involving these tables. This patch adds support for creating and using schema_locked tables within the declarative schema changer tests. Fixes: #144591 Release note: None
1 parent d83b3da commit f05cfb5

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

pkg/workload/schemachange/operation_generator.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,14 @@ func (og *operationGenerator) createTable(ctx context.Context, tx pgx.Tx) (*opSt
13061306
return false
13071307
}()
13081308

1309+
// Randomly create as schema locked table.
1310+
if og.params.rng.Intn(2) == 0 {
1311+
stmt.StorageParams = append(stmt.StorageParams, tree.StorageParam{
1312+
Key: "schema_locked",
1313+
Value: tree.DBoolTrue,
1314+
})
1315+
}
1316+
13091317
tableExists, err := og.tableExists(ctx, tx, tableName)
13101318
if err != nil {
13111319
return nil, err
@@ -3821,6 +3829,14 @@ func (og *operationGenerator) randTypeName(
38213829
func (og *operationGenerator) randTable(
38223830
ctx context.Context, tx pgx.Tx, pctExisting int, desiredSchema string,
38233831
) (*tree.TableName, error) {
3832+
// Because the declarative schema change can automatically set / unset
3833+
// schema_locked on tables, we will allow random table selection include
3834+
// schema_locked tables. When working with the legacy schema changer, we
3835+
// will intentionally only select non-schema locked tables.
3836+
excludeSchemaLocked := " AND create_statement NOT LIKE '%schema_locked%' "
3837+
if og.useDeclarativeSchemaChanger {
3838+
excludeSchemaLocked = ""
3839+
}
38243840
if err := og.setSeedInDB(ctx, tx); err != nil {
38253841
return nil, err
38263842
}
@@ -3833,13 +3849,15 @@ func (og *operationGenerator) randTable(
38333849
return &treeTableName, nil
38343850
}
38353851
q := fmt.Sprintf(`
3836-
SELECT table_name
3837-
FROM [SHOW TABLES]
3838-
WHERE table_name SIMILAR TO 'table_w[0-9]_+%%'
3852+
SELECT descriptor_name
3853+
FROM crdb_internal.create_statements
3854+
WHERE descriptor_name SIMILAR TO 'table_w[0-9]_+%%'
38393855
AND schema_name = '%s'
3856+
AND descriptor_type='table'
3857+
%s
38403858
ORDER BY random()
38413859
LIMIT 1;
3842-
`, desiredSchema)
3860+
`, desiredSchema, excludeSchemaLocked)
38433861

38443862
var tableName string
38453863
if err := tx.QueryRow(ctx, q).Scan(&tableName); err != nil {
@@ -3870,13 +3888,17 @@ func (og *operationGenerator) randTable(
38703888
return &treeTableName, nil
38713889
}
38723890

3873-
const q = `
3874-
SELECT schema_name, table_name
3875-
FROM [SHOW TABLES]
3876-
WHERE table_name SIMILAR TO 'table_w[0-9]_+%'
3877-
ORDER BY random()
3878-
LIMIT 1;
3879-
`
3891+
q := fmt.Sprintf(`
3892+
SELECT schema_name, descriptor_name
3893+
FROM crdb_internal.create_statements
3894+
WHERE descriptor_name SIMILAR TO 'table_w[0-9]_+%%'
3895+
AND descriptor_type='table'
3896+
%s
3897+
ORDER BY random()
3898+
LIMIT 1;
3899+
`,
3900+
excludeSchemaLocked)
3901+
38803902
var schemaName string
38813903
var tableName string
38823904
if err := tx.QueryRow(ctx, q).Scan(&schemaName, &tableName); err != nil {

0 commit comments

Comments
 (0)