Repository navigation
Cherry pick #121385 to 26.8: Fix logical error in ASOF JOIN when the right ASOF key is lazily replicated - #130500
Conversation
HashJoin deliberately supports the lazy column replication wrapper on the right side. materializeColumnsFromRightBlock peels it, promotes the nested column to Nullable when the sample column is Nullable, and re-wraps it, and isLazyReplicationUseful is true for every Nullable column because ColumnNullable::isFixedAndContiguous() returns false. So addBlockToJoin legitimately receives an ASOF key of type Nullable(T) whose column is a ColumnReplicated(ColumnNullable(...)). The ASOF-key NULL filter guarded on asof_column.type->isNullable(), which says nothing about the wrapper, peeled exactly one representation (ColumnConst), and then asserted the column was a ColumnNullable in order to hoist its null map. The branch that cannot handle the wrapper was therefore the only branch that ran for the column class that is always wrapped. The filter predates ColumnReplicated and was never revisited for it. Read nullness through IColumn::isNullAt instead. ColumnReplicated::isNullAt resolves the logical row through its indexes, so no peel and no materialization is needed, and the same call three lines above already reads a const key's nullness this way. Indexing the nested column with the logical row would not have been equivalent: ColumnReplicated::size() is the indexes size, so under replication the nested column is smaller and that read is out of bounds rather than merely wrong. Deleting the assertion loses no coverage. The "type says Nullable, column is not a ColumnNullable" invariant is still enforced in the same call by assertBlocksHaveEqualStructureAllowReplicated, which compares the concrete column class after peeling one replication level on both sides, and which runs before the block is stored. The regression test asserts row equality between the enable_lazy_columns_replication = 0 and = 1 arms rather than the absence of an error, because a fix that peeled the wrapper but indexed the nested null map would not fail, it would silently keep or drop the wrong rows. It covers the hash and parallel_hash entry points; grace_hash cannot reach the site, since it materializes the block at its entry point and rejects ASOF. Co-Authored-By: Claude Opus 5 <[email protected]>
One stress worker in three runs with join_use_nulls=1 (ci/jobs/scripts/stress/stress.py:383). Under that setting an unmatched ASOF LEFT JOIN row returns NULL for the right-side columns instead of the type default, so the k = 2 and k = 4 rows disagreed with the reference and the test would have failed in Stress test and Upgrade check. A query-local SETTINGS clause overrides a client option only for the settings it names, so pinning it in the query is what makes the oracle stable. Local runs could not have caught this: join_use_nulls is not in SettingsRandomizer, only stress.py injects it. Co-Authored-By: Claude Opus 5 <[email protected]>
Collapse the added ASOF-key comment to the one non-obvious property: the wrapper resolves the logical row.
Requested in review: read the null map directly when the ASOF key column really is a ColumnNullable, and only fall back to IColumn::isNullAt for the representations that the direct read cannot serve. checkAndGetColumn<ColumnNullable> replaces the assert_cast that aborted, so the wrapped ColumnReplicated(ColumnNullable(...)) case takes the fallback instead of being asserted away, while the common unwrapped case keeps the original per-row null map indexing and no longer pays a virtual call. Measured with a mutation binary built from this tree, both join algorithms of the regression test: with the fast path replaced by a throw, the enable_lazy_columns_replication = 0 arm raises it (size=12) and the = 1 arm does not, so the fast path is taken exactly for the unwrapped column; with the fallback replaced by the old assert_cast, the = 1 arm aborts with the reported 'Bad cast from type DB::ColumnReplicated to DB::ColumnNullable' at the same two addBlockToJoin frames. Unmutated, all four arms return output byte-identical to the committed reference. Co-Authored-By: Claude Opus 5 <[email protected]>
Build the prepared key columns before the ASOF NULL filter and read the null map from the prepared ASOF key, so the filter keeps the original assert_cast and no longer sees the lazy replication wrapper. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…azy-replication Fix logical error in ASOF JOIN when the right ASOF key is lazily replicated
Resolve the only conflict, in HashJoin::addBlockToJoin: 26.8 still increments data->rows_to_join right after computing the row count (master moved it later in #116991, which is not backported). Keep that line and take #121385's move of the key-column loop above the ASOF NULL filter unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The only conflict is in 26.8 is affected: the official 26.8.35.29 returns a wrong row for I cannot push to |
Original pull-request #121385
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.
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:
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