Skip to content

colbuilder: don't use direct scans in an invalid case #145255

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

Merged
merged 1 commit into from
Apr 26, 2025

Conversation

yuzefovich
Copy link
Member

We have an experimental feature to build coldata.Batches directly on the KV server side when handling Scan and ReverseScan requests. It assumes that each request corresponds to any number of full SQL rows, but previously we didn't disable usage of this feature when a single SQL row is populated via multiple requests. This is the case when we have multiple column families, and since we don't support Gets in the direct scans machinery right now, we need at least 5 column families - so that we get Scan for 0-1 and 3-4 CFs. This commit fixes this oversight to ensure that if we have two consecutive key spans that come from the same SQL row, we don't use the direct scans even if they are enabled.

There is no release note since this feature is disabled by default.

Fixes: #145232.

Release note: None

@yuzefovich yuzefovich requested a review from DrewKimball April 25, 2025 18:30
@yuzefovich yuzefovich requested a review from a team as a code owner April 25, 2025 18:30
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich force-pushed the fix-direct-scans branch 2 times, most recently from afa391b to 48830f0 Compare April 25, 2025 23:12
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:

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


pkg/sql/colexec/colbuilder/execplan.go line 896 at r1 (raw file):

							return false
						}
						if l, err := keys.GetRowPrefixLength(core.TableReader.Spans[i].Key); err == nil {

nit: it seems fine to just return false if we fail to get the length of a key - is there a useful case where we expect an error?

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.

TFTR!

bors r+

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


pkg/sql/colexec/colbuilder/execplan.go line 896 at r1 (raw file):

Previously, DrewKimball (Drew Kimball) wrote…

nit: it seems fine to just return false if we fail to get the length of a key - is there a useful case where we expect an error?

Good point, done.

craig bot pushed a commit that referenced this pull request Apr 26, 2025
145255: colbuilder: don't use direct scans in an invalid case r=yuzefovich a=yuzefovich

We have an experimental feature to build `coldata.Batch`es directly on the KV server side when handling Scan and ReverseScan requests. It assumes that each request corresponds to any number of full SQL rows, but previously we didn't disable usage of this feature when a single SQL row is populated via multiple requests. This is the case when we have multiple column families, and since we don't support Gets in the direct scans machinery right now, we need at least 5 column families - so that we get Scan for 0-1 and 3-4 CFs. This commit fixes this oversight to ensure that if we have two consecutive key spans that come from the same SQL row, we don't use the direct scans even if they are enabled.

There is no release note since this feature is disabled by default.

Fixes: #145232.

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
@craig
Copy link
Contributor

craig bot commented Apr 26, 2025

Build failed:

We have an experimental feature to build `coldata.Batch`es directly on
the KV server side when handling Scan and ReverseScan requests.
It assumes that each request corresponds to any number of full SQL rows,
but previously we didn't disable usage of this feature when a single SQL
row is populated via multiple requests. This is the case when we have
multiple column families, and since we don't support Gets in the direct
scans machinery right now, we need at least 5 column families - so that
we get Scan for 0-1 and 3-4 CFs. This commit fixes this oversight to
ensure that if we have two consecutive key spans that come from the same
SQL row, we don't use the direct scans even if they are enabled.

There is no release note since this feature is disabled by default.

Release note: None
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.

bors r+

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


pkg/sql/colexec/colbuilder/execplan.go line 896 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

Good point, done.

Turns out that we can return an error if we manually added a split point to the range, which is why I had to adjust one test. It still seems fine to just disable direct scans.

@craig
Copy link
Contributor

craig bot commented Apr 26, 2025

@craig craig bot merged commit 35fbea7 into cockroachdb:master Apr 26, 2025
22 checks passed
@yuzefovich yuzefovich deleted the fix-direct-scans branch April 27, 2025 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: direct columnar scans can produce NULL values for non-nullable columns with multiple column families
3 participants