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

release-25.1: workload/schemachange: improve diagnostics for unique constraint failures #143193

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
24 changes: 18 additions & 6 deletions pkg/workload/schemachange/error_screening.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,23 +856,35 @@ func (og *operationGenerator) canApplyUniqueConstraint(
}
}

return og.scanBool(ctx, tx,
// We will compare counts of distinct rows with all rows. We pull out each
// component separately, even though we only care about the (distinct == all)
// boolean result so that it gets logged in the test output.
type countComp struct {
DistinctCount int
AllCount int
DistinctEqualsAll bool
}
res, err := CollectOne(ctx, og, tx, pgx.RowToStructByPos[countComp],
fmt.Sprintf(`
SELECT (
WITH distinct_count AS (
SELECT count(*)
FROM (
SELECT DISTINCT %s
FROM %s
WHERE %s
)
)
= (
), all_count AS (
SELECT count(*)
FROM %s
WHERE %s
);
)
SELECT dc.count, ac.count, dc.count = ac.count
FROM distinct_count dc, all_count ac;
`, columnNames, tableName.String(), whereNotNullClause.String(), tableName.String(), whereNotNullClause.String()))

if err != nil {
return false, errors.Wrapf(err, "count query failure: %q", err)
}
return res.DistinctEqualsAll, err
}

func (og *operationGenerator) columnContainsNull(
Expand Down