cockroachdb / cockroachdb/cockroach
sql: distributed UniqueKey operator
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Sometimes when decorrelating, we call `EnsureKey` to add a unique key to an input. Currently this wraps the input in the same `Ordinality` operator as used by `WITH ORDINALITY`. This works, but `WITH ORDINALITY` has stricter requirements than decorrelation: `WITH ORDINALITY` requires the output to be the natural numbers in increasing order, without gaps, whereas decorrelation only needs the rows to be unique.
@msirek relaxed one requirement for decorrelation by [pushing selects](https://github.com/cockroachdb/cockroach/pull/110593) into `Ordinality` when they are not from `WITH ORDINALITY`. But we still only have single-node execution of `Ordinality`.
It would be nice if we could distribute this unique key operation, maybe by using the nodeid of the local node. @msirek has already prototyped the optimizer changes [here](https://github.com/cockroachdb/cockroach/pull/109903), but we have not yet implemented it in DistSQL.
Jira issue: CRDB-31645
Contributor guide
Assessment
This issue has not been assessed yet.