Skip to content

Cherry pick #127859 to 26.10: Do not re-create nested Tuple elements when creating a column for deserialization - #132313

Merged
robot-clickhouse-ci-1 merged 6 commits into
backport/26.10/127859from
cherrypick/26.10/127859
Nov 17, 2026
Merged

robot-clickhouse-ci-1 merged 6 commits into
backport/26.10/127859from
cherrypick/26.10/127859

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Original pull-request #127859

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.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

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

groeneai and others added 5 commits October 26, 2026 16:30
…erialization

SerializationTuple::wrapColumnForDeserialization cloned every element with
cloneEmpty() and rebuilt the ColumnTuple at each nesting level, so a column
with k Tuple ancestors was created k + 1 times. IDataType::createColumn(serialization)
runs once per block in row input formats (Block::cloneEmptyColumns), so for
the depth-8 schema of #127427 (510 columns) every block paid 3076 extra
column creations. It came with #111427, which replaced
DataTypeTuple::createColumn(const ISerialization &).

Wrap the elements in place instead: the input is the freshly created base
column, whose elements are not shared, so each element is passed to its
serialization's wrap and the result is stored back in the same slot.

Release build, RowBinary, max_block_size = 1, 5000 rows, best of 5:
  depth 8: 1.558 s -> 0.478 s (26.7: 0.425 s)
  depth 4: 0.641 s -> 0.339 s (26.7: 0.308 s)
  flat:    0.333 s -> 0.332 s
Taking the element through IColumn::mutate instead of assumeMutable gives
0.679 s at depth 8, because mutate walks the whole subtree again at every
level.

Extend tests/performance/parse_engine_file.xml with a small-block read of
16-deep nested Tuples (perf.py locally: 2.03 s -> 0.62 s).

Closes #127427

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the wrapColumnForDeserialization comment to two lines and backtick SerializationNamed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wrapping them

Replace `ISerialization::wrapColumnForDeserialization(MutableColumnPtr)` with
`ISerialization::createColumnForDeserialization(const IDataType &)`, and route
`IDataType::createColumn(const ISerialization &)` through it.

The wrap took an already created column and rebuilt it into the layout the
serialization deserializes into. For a Tuple that meant `cloneEmpty()` of every
element (each clone materializing the element's whole subtree) and then a
recursive rebuild of each clone, so a node under k Tuple levels was created
k + 1 times per block. Row formats with small blocks (Kafka, async inserts)
create a column per block, so deeply nested Tuples got up to 3x slower in 26.9.

Now each serialization creates its own column from the type: the Tuple
serialization creates every element from the element type with the element
serialization, so every node is created exactly once and nothing is mutated
or rebuilt afterwards. Sparse, Replicated and Detached create the nested
column and wrap it; the wrapper forwards; the product quantization codebook
creates its placeholder `ColumnConst` as before; VariantElement and
DynamicElement peel the extraction-added `Nullable` off the type instead of
off the column.

This replaces the previous in-place wrap in this PR, which needed
`assumeMutable` on tuple elements.

The perf query moves from `parse_engine_file.xml` to its own file.

Closes #127427

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-127427

# Conflicts:
#	src/DataTypes/Serializations/ISerialization.cpp
Do not re-create nested Tuple elements when creating a column for deserialization
@robot-ch-test-poll robot-ch-test-poll 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 labels Nov 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The only conflict is one context line in SerializationWrapper.h: master caches supportsPooling() in nested_supports_pooling (#126554, which is not on 26.10). I kept the 26.10 line and took only this PR's createColumnForDeserialization line. The other 17 files merge cleanly, so the resolution's diff against backport/26.10/127859 adds and removes exactly the lines this PR does.

On a 26.10 debug build, the depth-8 case from #127427 (5000 rows, 254 nested Tuples, RowBinary, max_block_size = 1) takes 0.51 s instead of 1.72 s (best of 5). The same data read as 256 flat UInt8 columns takes 0.37 s on both builds. The 1199 stateless tests matching sparse|tuple|variant|dynamic|native|subcolumn|marshalling|quantize_codec|lazy_replication give the same result with and without the change (the same 16 tests fail in both runs, all for environment reasons such as no object storage on my machine).

I cannot push to cherrypick/26.10/127859. The branch on my fork has this PR's head 9fed72b4f0c2 as an ancestor, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git resolve-26.10-cherrypick-127859
git push origin FETCH_HEAD:cherrypick/26.10/127859

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

The 26.10 branch moved since this cherry-pick was created (now at a5c46eb). Re-tried the merge against it and it applies cleanly, so the bot is proceeding without manual resolution.

@robot-clickhouse-ci-1
robot-clickhouse-ci-1 merged commit 15da4a0 into backport/26.10/127859 Nov 17, 2026
2 checks passed
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 deleted the cherrypick/26.10/127859 branch November 17, 2026 15:15
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-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.

5 participants