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

workload/schemachange: add select support for workload #84399

Merged
merged 5 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pkg/workload/schemachange/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"operation_generator.go",
"schemachange.go",
"type_resolver.go",
"watch_dog.go",
":gen-optype-stringer", # keep
],
importpath = "github.com/cockroachdb/cockroach/pkg/workload/schemachange",
Expand All @@ -36,6 +37,7 @@ go_library(
"@com_github_cockroachdb_errors//:errors",
"@com_github_jackc_pgconn//:pgconn",
"@com_github_jackc_pgx_v4//:pgx",
"@com_github_jackc_pgx_v4//pgxpool",
"@com_github_lib_pq//oid",
"@com_github_spf13_pflag//:pflag",
],
Expand Down
31 changes: 30 additions & 1 deletion pkg/workload/schemachange/error_screening.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ GROUP BY name;
for range constraints {
constraintTuples = append(constraintTuples, make(map[string]struct{}))
}

for _, row := range rows {
hasGenerationError := false
// Put values to be inserted into a column name to value map to simplify lookups.
columnsToValues := map[string]string{}
for i := 0; i < len(columns); i++ {
Expand All @@ -339,14 +339,43 @@ GROUP BY name;
if !colInfo.generated {
continue
}
evalTxn, err := tx.Begin(ctx)
if err != nil {
return false, nil, err
}
newCols[colInfo.name], err = og.generateColumn(ctx, tx, colInfo, columnsToValues)
if err != nil {
if rbkErr := evalTxn.Rollback(ctx); rbkErr != nil {
return false, nil, errors.WithSecondaryError(err, rbkErr)
}
var pgErr *pgconn.PgError
if !errors.As(err, &pgErr) {
return false, nil, err
}
// Only accept know error types for generated expressions.
if !isValidGenerationError(pgErr.Code) {
return false, nil, err
}
generatedCodes = append(generatedCodes,
codesWithConditions{
{code: pgcode.MakeCode(pgErr.Code), condition: true},
}...,
)
hasGenerationError = true
continue
}
err = evalTxn.Commit(ctx)
if err != nil {
return false, nil, err
}
}
for k, v := range newCols {
columnsToValues[k] = v
}
// Skip over constraint validation, since we know an expression is bad here.
if hasGenerationError {
continue
}
// Next validate the uniqueness of both constraints and index expressions.
for constraintIdx, constraint := range constraints {
nonTupleConstraint := constraint[0]
Expand Down
Loading