fix(encoding): filter out NULLs in encodeContainingArrayInvertedIndexSpans (#173046) - #173089
Closed
waterWang wants to merge 1 commit into
Closed
fix(encoding): filter out NULLs in encodeContainingArrayInvertedIndexSpans (#173046)#173089waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
…Spans (cockroachdb#173046) When encodeContainingArrayInvertedIndexSpans encounters an array with NULL elements, it previously returned an empty SpanExpression with no spans. This caused the optimizer to generate an inverted index scan with no constraint, which the execution engine rejected with: 'expected inverted index scan to have a constraint'. Fix: filter out NULL elements using excludeNulls=true, and generate spans for the remaining non-NULL elements. If all elements are NULL, return nil to let the optimizer fall back to a full table scan. Fixes cockroachdb#173046
|
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? Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
|
Collaborator
|
Thanks for working on this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #173046
Problem: When
encodeContainingArrayInvertedIndexSpansencounters an array with NULL elements (e.g.,ARRAY[NULL::TIMETZ]), it previously returned an emptySpanExpressionwith no spans. This caused the optimizer to generate an inverted index scan with no constraint, which the execution engine rejected with:Root cause: The
HasNulls()check inencodeContainingArrayInvertedIndexSpanswas too aggressive: it returned an empty SpanExpression for ALL arrays with NULLs, even those that also contain non-NULL elements. The empty SpanExpression caused the optimizer to generate an unconstrained inverted scan.Fix: When the array has NULLs, filter them out using
excludeNulls=truewhen callingencodeArrayInvertedIndexTableKeys, and generate spans for the remaining non-NULL elements. If all elements are NULL, returnnilto let the optimizer fall back to a full table scan (which correctly returns no rows since NULL comparisons in SQL are unknown).Reproduction:
This previously errored with "expected inverted index scan to have a constraint". After the fix, it returns an empty result set without error.
The
<@(contained by) variant already worked correctly by usingexcludeNulls=true.