cockroachdb / cockroachdb/cockroach

opt: push a limit past operators that expand and then shrink row count

Open
#151,257 3 comments 0 reactions 1 assignee Claimed by @DrewKimball View on GitHub
A-sql-optimizer C-enhancement O-support P-3 T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

It is common for decorrelation rules to lead to a situation where a join increases a row count, and then a grouping operator shrinks it back to that of the join's input. Example:
```
-- Assume "x" is the PK of "xy", and "a" the PK for "ab".
(GroupBy (LeftJoin (Scan xy) (Scan ab) ON y = b) (GroupingCols x))
```
We can't push a Limit past a GroupBy in general, because otherwise we may end up with too few rows after grouping is applied. However, we can push the Limit past the GroupBy if we also push it past the Join, since then the growing effect of the Join cancels out the shrinking effect of the GroupBy. This is valid as long as the Join operator preserves rows from the input we push the limit to (e.g. for a LeftJoin, or a join on a foreign key relation).

Jira issue: CRDB-53146

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.