Skip to content

Commit 92bb97d

Browse files
Merge d29f7f4 into blathers/backport-release-25.1-142983
2 parents 9903c4a + d29f7f4 commit 92bb97d

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

pkg/workload/schemachange/error_screening.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -856,23 +856,35 @@ func (og *operationGenerator) canApplyUniqueConstraint(
856856
}
857857
}
858858

859-
return og.scanBool(ctx, tx,
859+
// We will compare counts of distinct rows with all rows. We pull out each
860+
// component separately, even though we only care about the (distinct == all)
861+
// boolean result so that it gets logged in the test output.
862+
type countComp struct {
863+
DistinctCount int
864+
AllCount int
865+
DistinctEqualsAll bool
866+
}
867+
res, err := CollectOne(ctx, og, tx, pgx.RowToStructByPos[countComp],
860868
fmt.Sprintf(`
861-
SELECT (
869+
WITH distinct_count AS (
862870
SELECT count(*)
863871
FROM (
864872
SELECT DISTINCT %s
865873
FROM %s
866874
WHERE %s
867875
)
868-
)
869-
= (
876+
), all_count AS (
870877
SELECT count(*)
871878
FROM %s
872879
WHERE %s
873-
);
880+
)
881+
SELECT dc.count, ac.count, dc.count = ac.count
882+
FROM distinct_count dc, all_count ac;
874883
`, columnNames, tableName.String(), whereNotNullClause.String(), tableName.String(), whereNotNullClause.String()))
875-
884+
if err != nil {
885+
return false, errors.Wrapf(err, "count query failure: %q", err)
886+
}
887+
return res.DistinctEqualsAll, err
876888
}
877889

878890
func (og *operationGenerator) columnContainsNull(

0 commit comments

Comments
 (0)