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

sql: minor improvements around estimated row count #118679

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Feb 2, 2024

This commit makes it so that we use the ceiling of the estimated row count in scans and aggregation. It also fixes recently-introduced bug that could cause integer overflow in the agg alloc code.

Fixes: #118724.

Epic: None

Release note: None

This commit makes it so that we use the ceiling of the estimated row
count in scans and aggregation. It also fixes recently-introduced bug
that could cause integer overflow in the agg alloc code.

Release note: None
@yuzefovich yuzefovich requested a review from a team as a code owner February 2, 2024 21:12
Copy link

blathers-crl bot commented Feb 2, 2024

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice find!

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball and @yuzefovich)


pkg/sql/colexec/hash_aggregator.go line 205 at r1 (raw file):

	if args.EstimatedRowCount != 0 {
		// Use uint64s for comparison to prevent overflow in case
		// args.EstimatedRowCount is larger than MaxInt64.

So the estimated row count from the optimizer is fine, just overflowing here? Good catch!

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball and @mgartner)


pkg/sql/colexec/hash_aggregator.go line 205 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

So the estimated row count from the optimizer is fine, just overflowing here? Good catch!

I think so - the problem occurred because we took the estimated row count (which is uint64 and could be very large), then down-casted it to int64 possibly producing negative numbers. This change prevents that from happening.

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

:lgtm: Thanks for the fix!

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @mgartner)

@yuzefovich
Copy link
Member Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 5, 2024

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 6, 2024

Build succeeded:

@craig craig bot merged commit aee73ac into cockroachdb:master Feb 6, 2024
9 of 10 checks passed
@yuzefovich yuzefovich deleted the agg-fixup branch February 6, 2024 01:10
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.

colexec: negative length supplied to makeslice
4 participants