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

colexec: fix range stats operator with the selection vector #93868

Merged
merged 1 commit into from
Dec 18, 2022

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Dec 18, 2022

Previously, if the input batch had a selection vector set, we could get an index out of bounds internal error because we would iterate up to the length of the selection vector which can exceed the length of the batch.

Note that in practice this should be very rare to hit - generally speaking, the selection vector has the same length as all of the vectors in the batch. I couldn't reproduce the problem when using demo, so there is no regression test. Introduction of unit tests that use powerful RunTests test harness (that might have caught this bug) is left as a TODO.

Fixes: #93806.
Epic: CRDB-22701

Release note (bug fix): CockroachDB could previously, in rare cases, encounter an internal error when evaluating crdb_internal.range_stats builtin (which powers SHOW RANGES command among other things). The bug was introduced in 22.2.0 and is now fixed.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Previously, if the input batch had a selection vector set, we could get
an index out of bounds internal error because we would iterate up to the
length of the selection vector which can exceed the length of the batch.

Note that in practice this should be very rare to hit - generally
speaking, the selection vector has the same length as all of the vectors
in the batch. I couldn't reproduce the problem when using `demo`, so
there is no regression test. Introduction of unit tests that use
powerful `RunTests` test harness (that might have caught this bug) is
left as a TODO.

Release note (bug fix): CockroachDB could previously, in rare cases,
encounter an internal error when evaluating `crdb_internal.range_stats`
builtin (which powers `SHOW RANGES` command among other things). The
bug was introduced in 22.2.0 and is now fixed.
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

I don't understand the contracts, and find the need to do this surprising, but I'll happily stamp it.

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: Huh, I never really thought about this, but I guess we explicitly set the selection vector length everywhere else.

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

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.

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


pkg/col/coldata/batch.go line 51 at r1 (raw file):

	// not been filtered out by a previous step.
	// TODO(yuzefovich): consider ensuring that the length of the returned slice
	// equals the length of the batch.

+1

@yuzefovich
Copy link
Member Author

The contract hasn't really been properly defined. I think in many other places we do set the length on the selection vector mostly in order to get bounds-checks elimination, but IIRC there was a similar bug in another operator at some point, so it's definitely worth being explicit about the contract.

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 18, 2022

Build succeeded:

@craig craig bot merged commit 94e03c0 into cockroachdb:master Dec 18, 2022
@yuzefovich yuzefovich deleted the fix-range-stats branch December 19, 2022 02:04
@knz
Copy link
Contributor

knz commented Dec 19, 2022

I couldn't reproduce the problem when using demo, so there is no regression test.

There was always 5-10 tests failing in CI for #93644 due to this bug so it was quite easy to reproduce actually. I'll rebase and report if the situation improves.

@knz
Copy link
Contributor

knz commented Dec 19, 2022

yep, the situation is improved. thanks!

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: internal error caused by crdb_internal.range_stats
5 participants