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

opt: fix distinct count estimation for outer joins #38229

Merged
merged 1 commit into from
Jun 17, 2019

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Jun 17, 2019

Prior to this commit, it was possible for the distinct count of a
column in an outer join to be zero when the row count was non-zero.
Since we require that the distinct count is always non-zero when the
row count is non-zero, this caused an error. This commit fixes the
issue by ensuring that there is always at least one distinct value
for each column in an outer join when the row count is non-zero.

Fixes #38091

Release note: None

Prior to this commit, it was possible for the distinct count of a
column in an outer join to be zero when the row count was non-zero.
Since we require that the distinct count is always non-zero when the
row count is non-zero, this caused an error. This commit fixes the
issue by ensuring that there is always at least one distinct value
for each column in an outer join when the row count is non-zero.

Fixes cockroachdb#38091

Release note: None
@rytaft rytaft requested a review from a team as a code owner June 17, 2019 19:15
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@justinj justinj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @justinj, @RaduBerinde, and @rytaft)


pkg/sql/opt/memo/testdata/stats/join, line 1125 at r1 (raw file):

 │    │         ├── left-join
 │    │         │    ├── outer: (2)
 │    │         │    ├── stats: [rows=1000, distinct(2)=1, null(2)=0]

Did this distinct count just happen to get computed during optimization? Is that why it's the only one that is showing up?

@rytaft
Copy link
Collaborator Author

rytaft commented Jun 17, 2019


pkg/sql/opt/memo/testdata/stats/join, line 1125 at r1 (raw file):

Previously, justinj (Justin Jaffray) wrote…

Did this distinct count just happen to get computed during optimization? Is that why it's the only one that is showing up?

Yea - it gets computed because column 2 is part of the join filter condition, and we need to know the distinct count to estimate selectivity.

@rytaft
Copy link
Collaborator Author

rytaft commented Jun 17, 2019

TFTR!

bors r+

craig bot pushed a commit that referenced this pull request Jun 17, 2019
38229: opt: fix distinct count estimation for outer joins r=rytaft a=rytaft

Prior to this commit, it was possible for the distinct count of a
column in an outer join to be zero when the row count was non-zero.
Since we require that the distinct count is always non-zero when the
row count is non-zero, this caused an error. This commit fixes the
issue by ensuring that there is always at least one distinct value
for each column in an outer join when the row count is non-zero.

Fixes #38091

Release note: None

Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Jun 17, 2019

Build succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: internal error: estimated distinct and/or null count must be non-zero
3 participants