Repository navigation
Cherry pick #106802 to 26.5: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing - #106875
Merged
robot-clickhouse-ci-1 merged 3 commits intoJun 9, 2026
Conversation
…ring parsing Composite columns grow several nested structures in sequence inside `insertDefault` with no rollback. If one of them throws (for example on a memory limit [1]) the already-grown structures are left ahead of the rest, so the column's nested structures end up with different sizes. [1]: https://pastila.nl/?0005eb6b/e1cd0ca11139b61c65264e368f8e6150#BjWwSA/197t3/SuuGCsqdg==GCM This is reachable during deserialization default-filling: a missing named-tuple element (`input_format_json_defaults_for_missing_elements_in_named_tuple`) or a null with `input_format_null_as_default` calls `insertDefault` on a nested column. When an allocation throws in the middle, the column is left desynchronized; the exception then unwinds into a serialization-level restore (`SerializationTuple::addElementSafe` and friends) which calls `popBack` to undo the partial row, and `popBack` over-pops the shorter nested structure: Cannot pop 1 rows from String: there are only 0 rows Per type: - `Tuple`: `size` is `columns[0]->size` and `columns[0]` grows first, so any later element that throws leaves `size` ahead - roll back the grown elements. - `Nullable`: the nested column grows before the null map - roll back the nested column if appending to the null map throws. - `Variant`: `local_discriminators` grows before `offsets` - roll it back if appending to `offsets` throws. - `Object`: typed/dynamic paths and `shared_data` grow in sequence - roll each back to the previous size. This should be sufficient (i.e. we do not need to fix IColumn::insert() and others) because usually if some method of IColumn throws, we discard the column, there are only few exceptions: - checkpoint-based rollback (`getCheckpoint`/`rollback`) - should be safe already - manual handling of parsing errors and reverting the state via popBack() - usually safe, but not safe when filling defaults via insertDefault() -- this patch Note `insertManyDefaults` is not on this path (parsing fills defaults one row at a time via `insertDefault`), but the `Variant`/`Object` overrides were made exception-safe too, since they do a bulk fill and may be reused elsewhere. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing
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.
Original pull-request #106802
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job