fix: reset vector class to FLAT in ResetWithSameType to fix prepared stmt null json panic#23864
Merged
mergify[bot] merged 6 commits intomatrixorigin:mainfrom Mar 17, 2026
Merged
Conversation
…stmt null json panic (matrixorigin#23859) When a prepared statement inserts NULL into a JSON column multiple times, the second execution panics with 'index out of range [0] with length 0' in ByteJson.Unmarshal during SELECT. Root cause: FunctionExpressionExecutor.doFold() calls ToConst() on the result vector after constant folding. On the second execution, PreExtendAndReset() calls ResetWithSameType() which clears nsp but preserves the CONSTANT class. When FunctionResult.AppendBytes(nil, true) is called on a CONSTANT vector, it skips setting the null marker, resulting in a non-null empty byte slice being stored instead of NULL. Fix: Reset vector class to FLAT in ResetWithSameType(), so the vector is in a clean state for re-population. doFold() will call ToConst() again after evaluation if needed.
Contributor
Merge Queue Status
This pull request spent 7 hours 11 minutes 12 seconds in the queue, including 5 hours 43 minutes 10 seconds running CI. Required conditions to merge
|
7 tasks
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.
What type of PR is this?
Which issue(s) this PR fixes:
issue #23859
What this PR does / why we need it:
When a prepared statement inserts NULL into a JSON column multiple times, the second execution causes a panic during SELECT:
Reproduce:
Root cause:
FunctionExpressionExecutor.doFold()callsToConst()on the result vector after constant folding. On the second execution,PreExtendAndReset()callsResetWithSameType()which clears nsp (null bitmap) but preserves the CONSTANT class. WhenFunctionResult.AppendBytes(nil, true)is called on a CONSTANT vector, it skips setting the null marker entirely, resulting in a non-null empty byte slice being stored instead of NULL.Fix: Reset vector class to FLAT in
ResetWithSameType(), so the vector is in a clean state for re-population.doFold()will callToConst()again after evaluation if needed.