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

release-19.2: sql: only include the number of non-null rows when building histograms #48645

Merged
merged 1 commit into from May 10, 2020

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented May 9, 2020

Backport 1/3 commits from #48528.

/cc @cockroachdb/release


Histograms used by the optimizer are built by sampling at most 10,000
rows, splitting those rows into 200 buckets, and then scaling up the
counts of each bucket based on the total number of rows in the table.

Prior to this commit, null values in the sampled column were excluded
from the sampled values but included in the row count used to scale
up the bucket counts. This could result in inaccurate histograms when
there were many nulls.

This commit fixes the problem by excluding nulls from the row count used
to scale up the histogram bucket counts.

Release note (performance improvement): Histograms used by the optimizer
for query planning now have more accurate row counts per histogram bucket,
particularly for columns that have many null values. This results in
better plans in some cases.

Histograms used by the optimizer are built by sampling at most 10,000
rows, splitting those rows into 200 buckets, and then scaling up the
counts of each bucket based on the total number of rows in the table.

Prior to this commit, null values in the sampled column were excluded
from the sampled values but included in the row count used to scale
up the bucket counts. This could result in inaccurate histograms when
there were many nulls.

This commit fixes the problem by excluding nulls from the row count used
to scale up the histogram bucket counts.

Release note (performance improvement): Histograms used by the optimizer
for query planning now have more accurate row counts per histogram bucket,
particularly for columns that have many null values. This results in
better plans in some cases.
@rytaft rytaft requested review from RaduBerinde and a team May 9, 2020 18:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rytaft
Copy link
Collaborator Author

rytaft commented May 10, 2020

bors r+

@rytaft
Copy link
Collaborator Author

rytaft commented May 10, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented May 10, 2020

Build failed

@rytaft
Copy link
Collaborator Author

rytaft commented May 10, 2020

Flaked on #47377

bors r+

@craig
Copy link
Contributor

craig bot commented May 10, 2020

Build succeeded

@craig craig bot merged commit 6b36035 into cockroachdb:release-19.2 May 10, 2020
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.

None yet

3 participants