Skip to content

sql, opt: validating the unique constraint must be efficient for partitioned unique indexes #56201

@rytaft

Description

@rytaft

As discussed offline with @RaduBerinde:

When we create a partitioned unique index, we need to validate that we don't have duplicates on the unique column(s). If we write down a validation query for that today, it would likely end up being a hash aggregation on the full table, which is not acceptable. Instead, we would want to separate the scans between the regions so that each scan is ordered, and union them (keeping order) into a streaming aggregation.

To achieve this, we may be able to extend SplitScanIntoUnionScans (as described in #55156). Additionally, we currently only apply the rule when there's a limit, but we could add a corresponding rule for aggregations.

Epic CRDB-2528

Metadata

Metadata

Assignees

Labels

A-multiregionRelated to multi-regionA-sql-optimizerSQL logical planning and optimizations.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)C-performancePerf of queries or internals. Solution not expected to change functional behavior.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions