Skip to content

Cherry pick #106802 to 26.3: Fix inconsistent columns on exception (i.e. MEMORY_LIMIT_EXCEEDED) during parsing - #106871

Merged
robot-clickhouse-ci-1 merged 3 commits into
backport/26.3/106802from
cherrypick/26.3/106802
Jun 9, 2026
Merged

robot-clickhouse-ci-1 merged 3 commits into
backport/26.3/106802from
cherrypick/26.3/106802

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

azat and others added 3 commits June 9, 2026 09:53
…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
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jun 9, 2026
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 merged commit be050c9 into backport/26.3/106802 Jun 9, 2026
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 deleted the cherrypick/26.3/106802 branch June 9, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants