Repository navigation
Conversation
…tch-apply paths"
|
Workflow [PR], commit [422d9d1] AI ReviewSummaryThis PR reverts the recent Findings❌ Blockers
Final VerdictStatus: ❌ Block |
|
@Avogar, hold on. We have occasional bugs due to shared modification of columns that were shared with
The I need this change to be more confident in #96844 Also, I very much dislike the amount of |
|
If you see performance is worse in some cases, please add performance tests to prove that. |
| mutable_column->insertRangeFrom(*cached_column, cached_column->size() - num_read_rows, num_read_rows); | ||
| column = std::move(mutable_column); | ||
| } | ||
| column->assumeMutable()->insertRangeFrom(*cached_column, cached_column->size() - num_read_rows, num_read_rows); |
There was a problem hiding this comment.
This reopens the rows_offset > 0 aliasing bug from the reverted change. When the same size substream is read once with rows_offset == 0, line 63 stores column itself in the cache; a later cache hit in the same range comes back here with cached_column sharing that storage. Appending through assumeMutable and then compacting the offsets in place below mutates the buffer that the cache still owns, which is the same heap-use-after-free / double-free path the COW-safe version was closing.
The identical regression is still present in SerializationStringSize.cpp:221, so this needs a clone-if-shared step (IColumn::mutate or equivalent) before the append.
There was a problem hiding this comment.
That's true. This PR is not acceptable.
| mutable_discriminators->insertRangeFrom(*cached_column, cached_column->size() - num_read_rows, num_read_rows); | ||
| discriminators = std::move(mutable_discriminators); | ||
| } | ||
| col.getLocalDiscriminatorsPtr()->assumeMutable()->insertRangeFrom(*cached_column, cached_column->size() - num_read_rows, num_read_rows); |
There was a problem hiding this comment.
This has the same problem for Variant discriminators. On the fresh-read path below, rows_offset == 0 caches col.getLocalDiscriminatorsPtr() itself, not a cut() copy. A later partial-granule read of the same substream therefore hits this branch with cached_column aliasing the live discriminators, so the assumeMutable append plus the in-place rows_offset compaction later in this function mutate storage that is still referenced by the cache.
04504_variant_discriminators_cow_safe_rows_offset was added to pin exactly this case, so deleting that test together with the COW detachment reintroduces the same heap-use-after-free / double-free regression instead of just removing an extra copy.
There was a problem hiding this comment.
@Avogar, if this is not true, make the code more understandable, clearer, not only for genius experts but also for stupid creatures like AI agents or me.
alexey-milovidov
left a comment
There was a problem hiding this comment.
Not approved. And please don't revert bug fixes.
|
I don't mind if something about Variant/Dynamic/JSON will degrade a little. |
I will add it
But the test from the "bug fix" doesn't reproduce anything. So the PR didn't fix anything |
|
I'm preparing another PR, it will burn all incorrect usages of COWPtr furiously. Can't wait to see it merged. |
|
And another one: #110471 |
|
However, looking at the code, I start to understand why we use ColumnPtr here. Because MutableColumnPtr is non-copyable. So we won't be able to use substreams cache to share subcolumns between columns. |
|
So the idea of substreams cache is to avoid copying the data when you read the data from the same stream multiple times (for example, when you read Tuple and its subcolumns, or when different subcolumns share the same stream, like array offsets or variant discriminators). To avoid that we might share the same subcolumns in result columns. It should not lead to any problems because the result of MergeTree reader is a set of constant columns that must not be changed in-place. |
|
@CurtizJ you may also have a few words to say here |
|
Initially, the substreams cache was introduced to avoid deserializing the same substream twice when a complex column is read together with its subcolumns ( if (auto cached_column = getFromSubstreamsCache(cache, settings.path))
{
col.getNullMapColumnPtr() = cached_column;
}
else if (auto * stream = settings.getter(settings.path))
{
DataTypeUInt8().deserializeBinaryBulk(col.getNullMapColumn(), *stream, limit, 0);
addToSubstreamsCache(cache, settings.path, col.getNullMapColumnPtr());
}So the invariant was simple: a substream column is mutated by deserialization exactly once per read, and only by the first reader; all other owners share the pointer and never modify it. The sharing was intentional and safe — not elegant, but simple, and it never caused problems. Now I see that we can append data to the cached column: I think the first mode of substream cache is acceptable, and we should keep it. Can we somehow avoid appending to the shared columns, or keep |
That's exactly what I want to do here: #110714. |
|
Also, I want to make an experiment PR to change the code of substream cache so it doesn't reuse the same column, but stores the data of the currently deserialized range, so we can copy only this range when we have multiple columns/subcolumns sharing the same stream. It will me buch faster than doing IColumn::mutate, because mutate copies the whole column from the block if it's shared, it may be up to With this approach, we can complitely remove usage of |
Reverts #109105