-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
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.
a2b1894
to
487a3ab
Compare
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 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
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+ |
Build succeeded: |
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. |
yep, the situation is improved. thanks! |
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 powerfulRunTests
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 powersSHOW RANGES
command among other things). The bug was introduced in 22.2.0 and is now fixed.