Repository navigation
Implement lazy columns replication in JOIN and ARRAY JOIN - #88752
Conversation
|
Workflow [PR], commit [57d94ce] Summary: ❌
|
| namespace DB | ||
| { | ||
|
|
||
| /// Wrapper around ColumnVector to store indexes. |
There was a problem hiding this comment.
I think this part was ejected from LowCardinality with no change, so I can skip reviewing it.
There was a problem hiding this comment.
Howewer, I added a few new simple methods that I needed in ColumnReplicated
There was a problem hiding this comment.
I found a bug in ColumnVariant::index implementation during testing. I will also create a separate bug-fix PR with this change to backport it
| ColumnReplicated::ColumnReplicated(MutableColumnPtr && nested_column_) | ||
| : nested_column(std::move(nested_column_)) | ||
| { | ||
| indexes.insertIndexesRange(0, nested_column->size()); |
There was a problem hiding this comment.
Can we deprecate this ctor? If ColumnReplicated can replace any column, then we can always use the initial one without indexes.
There was a problem hiding this comment.
Also, maybe we can check that no sparse/LC is possible inside. (not sure, but at least it does not make a lot of sense to me).
There was a problem hiding this comment.
Can we deprecate this ctor? If ColumnReplicated can replace any column, then we can always use the initial one without indexes.
We cannot use initial one if we will need to insert into it from ColumnReplicated. It's needed in MergingSortedTransform. Otherwise we will need to convert ColumnReplicated to full there and loose it's benefits.
There was a problem hiding this comment.
Also, maybe we can check that no sparse/LC is possible inside. (not sure, but at least it does not make a lot of sense to me).
Sparse inside Replicated 100% makes sense, Sparse column can contain big values inside that we want to avoid replicating.
LC inside Replicated doesn't make sense, let's avoid it
There was a problem hiding this comment.
Sparse inside Replicated 100% makes sense
Sparse is kind of included in replicated. At least you can reuse the same internal column when converting sparse->replicated, and only rebuild indexes
There was a problem hiding this comment.
If it's ok, I will add proper Sparse -> Replicated conversion later, maybe even in a separate PR.
…ion, add a test for an old client requesting replicated columns
…olumn-replication
Backport #88752 to 25.10: Implement lazy columns replication in JOIN and ARRAY JOIN
Tuple itself cannot be Sparse, but, some previous ClickHouse version may write this into the serialization.json, and such table will not be able to loaded. Follow-up for: ClickHouse#88752
ArrayJoinStep::deserialize read enable_lazy_columns_replication from the per-step QueryPlanSerializationSettings object, but ArrayJoinStep::serializeSettings writes only max_block_size, so nothing ever put that name into an ArrayJoinStep's settings block. QueryPlan::serialize builds a fresh QueryPlanSerializationSettings for every step and writeChangedBinary emits only the names that step assigned, while readBinary leaves absent names at their DECLARE default. A write done by one step therefore cannot supply a read done by another, and the only tree-wide writer of this name is JoinSettings::updatePlanSettings, reached only from JoinStepLogical. A deserialized ArrayJoinStep always got the plan DECLARE default false, while the core setting defaults to true, so with serialize_query_plan = 1 the node executing a remote fragment did eager column replication on an untouched configuration. Rows are identical either way, so the cost is lost memory and CPU savings, not a wrong result. Carry the value in the step's existing flags byte (bit 4) and drop the settings read, instead of adding the missing serializeSettings write. Adding the write would newly emit a setting name that 25.8 does not declare, and BaseSettings::readBinary throws UNKNOWN_SETTING on an unknown name; a bare ARRAY JOIN plan works against 25.8 today because max_block_size is the only name such a plan emits, so the settings channel would turn a working shape into a hard error. Version-gating that write is impossible, since serializeSettings receives no version and runs before the Serialization context exists. The flags byte degrades gracefully. Measured over master 26.7 26.6 26.5 26.4 26.3 26.2 26.1 25.8: no branch uses bit 4 and no branch validates the byte, so an older reader ignores the bit and keeps doing eager replication, exactly as today. No plan-version bump is needed. No byte in serialize is conditioned on a flag bit, so the stream cannot desynchronize. This also removes the read-without-write asymmetry rather than balancing it: the file now reads exactly the one plan setting it writes. The read was introduced by ClickHouse#88752. Related: ClickHouse#112079
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Implement lazy columns replication in JOIN and ARRAY JOIN. Avoid converting special columns representation like Sparse and Replicated to full columns in some output formats. This avoids unnecessary data copy in memory.
Closes #82669.
To use lazy replication enable settings
enable_lazy_columns_replicationandallow_special_serialization_kinds_in_output_formats(they are disabled by default for now).Documentation entry for user-facing changes