Skip to content

Revert "Lazily apply selector and replication indexes in join" - #106277

Merged
Algunenano merged 4 commits into
masterfrom
revert-98883-revisit-lazy-column-replication-usage
Jun 2, 2026
Merged

Algunenano merged 4 commits into
masterfrom
revert-98883-revisit-lazy-column-replication-usage

Conversation

@Algunenano

@Algunenano Algunenano commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Reverts #98883

Multiple crashes -> #106095

Version info

  • Merged into: 26.6.1.332

@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5e42887]

Summary: ✅


AI Review

Summary

This PR reverts Lazily apply selector and replication indexes in join and removes the associated planner pass, settings, and tests while preserving the unrelated query_plan_max_set_size_for_projection_match compatibility entry. The revert addresses the risky join lazy-indexing feature, but the current PR head still leaves correctness issues around ColumnReplicated compaction/rollback and does not cover the linked ARRAY JOIN ... ORDER BY bad-cast exception path, so it is not ready as-is.

Missing context / blind spots
  • ⚠️ Full PR-head CI was still pending during review; completed checks I fetched had no failures, but pending stateless/unit/integration/fuzzer jobs would close the runtime coverage gap.
Findings

❌ Blockers

  • [src/Processors/Transforms/FinishSortingTransform.cpp:70] The PR links Logical error: Bad cast from type A to B (STID: 3336-2f87) #106095, but the ARRAY JOIN ... ORDER BY repro in that issue can still reach FinishSortingTransform::consume with a ColumnReplicated sort key. ArrayJoinAction still lazily wraps non-joined useful columns under enable_lazy_columns_replication, and this path only removes const columns before less compares saved and incoming chunks; a mixed full/replicated representation can still throw the same bad-cast exception. Materialize the sort-prefix columns here, or disable lazy replication for this path, and add the linked regression test.
  • [src/Columns/ColumnReplicated.cpp:300] popBack compacts nested_column but leaves insertion_cache entries pointing at the pre-compaction nested layout. A later insertFrom, insertRangeFrom, or insertManyFrom from the same source can reuse a stale inserted index, producing a wrong value or an index past nested_column->size. Clear insertion_cache after compaction, as filter already does, and add a focused test that inserts from the same replicated source after a compacting popBack.
  • [src/Columns/ColumnReplicated.cpp:603] [dismissed by author -- https://github.com/Revert "Lazily apply selector and replication indexes in join" #106277#discussion_r3339923937] rollback still resizes indexes from the nested checkpoint size rather than the outer ColumnCheckpointWithNested::size; with 9 logical rows over 3 nested values, rollback restores the nested data to 3 rows and then truncates the logical indexes to 3, losing six logical rows. The author chose to keep the revert, but the invariant remains broken.
Tests
  • ⚠️ Add a smallest possible ARRAY JOIN ... ORDER BY regression test for the linked issue so the bad-cast exception path is proven fixed.
  • ⚠️ Add a ColumnReplicated unit test for stale insertion_cache after a compacting popBack.
  • ⚠️ If the rollback behavior is not intentionally tracked as known debt, add a checkpoint/rollback test where the logical size differs from the nested column size.
Final Verdict

Status: ❌ Block

Minimum required actions: fix the non-dismissed FinishSortingTransform and popBack findings with focused regression coverage. The dismissed rollback issue remains recorded as a real correctness risk.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 2, 2026
Comment thread src/Columns/ColumnReplicated.cpp Resolved
void ColumnReplicated::popBack(size_t n)
{
indexes.popBack(n);
nested_column = indexes.removeUnusedRowsInIndexedData(std::move(nested_column));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

popBack now compacts nested_column, but it leaves insertion_cache populated with positions from the pre-compaction layout. Concrete trace: insert from a ColumnReplicated source so insertion_cache[src_id][src_index] = old_nested_pos, then popBack rows that make removeUnusedRowsInIndexedData drop or remap nested rows. A later insertFrom / insertRangeFrom from the same source will hit the stale cache and append the old index without inserting the value; that index can now point past nested_column->size or at a different value. Please clear insertion_cache after compacting here, as filter does, and add a focused test that inserts from the same replicated source, pops enough rows to compact, then inserts from that source again.

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@@ -68,7 +68,6 @@ void FinishSortingTransform::consume(Chunk chunk)
}

removeConstColumns(chunk);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ARRAY JOIN repro linked from #106095 can still reach this prefix comparison with a ColumnReplicated sort key. ArrayJoinAction still lazily wraps non-joined useful columns when enable_lazy_columns_replication is true, and the failing query orders by key; after this revert FinishSortingTransform::consume only removes const columns before less compares last_chunk and chunk. If one side is already materialized and the other is still ColumnReplicated, ColumnString::compareAt / ColumnVector::compareAt sees the wrapper and throws the same bad-cast exception reported in the issue. Please materialize the sort-prefix columns here, or disable lazy replication for this path, and add the issue's ARRAY JOIN ... ORDER BY regression test so the linked bug-fix contract is actually covered.

@Algunenano
Algunenano enabled auto-merge June 2, 2026 13:12
@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 148/169 (87.57%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@Algunenano
Algunenano added this pull request to the merge queue Jun 2, 2026
Merged via the queue into master with commit d10a56f Jun 2, 2026
166 of 167 checks passed
@Algunenano
Algunenano deleted the revert-98883-revisit-lazy-column-replication-usage branch June 2, 2026 16:55
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants