Repository navigation
Conversation
|
Workflow [PR], commit [c2e2504] Summary: ✅ AI ReviewSummaryThis PR fixes a real correctness issue in Missing context
ClickHouse Rules
Final Verdict
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness issue where ColumnReplicated could wrap a nested column containing rows that were never referenced by the JOIN/replication offsets, which can cause functions to evaluate on “should-have-been-dropped” values (e.g., division by zero).
Changes:
- Extend
convertOffsetsToIndexesto also compute a “referenced rows” filter, enabling removal of unreferenced rows before creatingColumnReplicated. - Apply this filtering in JOIN result materialization and ARRAY JOIN / expression replication paths when lazy replication is enabled.
- Add a stateless regression test demonstrating the previous failure and the corrected output.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Columns/ColumnReplicated.h |
Introduces OffsetsToIndexesResult (indexes + filter) returned from convertOffsetsToIndexes. |
src/Columns/ColumnReplicated.cpp |
Updates offsets→indexes conversion to support filtering out unreferenced source rows. |
src/Interpreters/HashJoin/HashJoinResult.cpp |
Filters right-side columns before wrapping them in ColumnReplicated for lazy replication. |
src/Interpreters/ExpressionActions.cpp |
Filters columns/inputs before lazy replication during ARRAY JOIN execution. |
src/Interpreters/ArrayJoinAction.cpp |
Filters non-array columns before creating ColumnReplicated when lazy replication is used. |
tests/queries/0_stateless/04036_columns_replicated_with_unreferenced_rows.sql |
Adds regression test for functions operating on lazily replicated JOIN output. |
tests/queries/0_stateless/04036_columns_replicated_with_unreferenced_rows.reference |
Expected output for the new regression test. |
|
I believe we are going to allow unused rows in |
That makes sense, I updated the change to handle in |
| /// Filter out unreferenced rows from nested columns. | ||
| ColumnIndex column_index(IColumn::mutate(common_replicated_indexes)); | ||
| auto filtered_nested_columns = column_index.removeUnusedRowsInIndexedData(nested_columns); | ||
| common_replicated_indexes = column_index.getIndexes(); | ||
| size_t nested_column_size = filtered_nested_columns.empty() ? 0 : filtered_nested_columns[0]->size(); |
There was a problem hiding this comment.
Let's try to avoid IColumn::mutate(common_replicated_indexes) when there is no unused rows, to avoid unnecessary indexes copy. Maybe we can first call ColumnIndex::buildUsedRowsFilter here to create a filter for used rows and filter nested columns and compact indexes only if the filter is not nullopt?
There was a problem hiding this comment.
I moved it all into ColumnIndex to avoid splitting it into 2 steps
| if (indexed_columns[i]->size() != indexed_data_size) | ||
| chassert(indexed_columns[i]->size() == indexed_data_size); |
There was a problem hiding this comment.
| if (indexed_columns[i]->size() != indexed_data_size) | |
| chassert(indexed_columns[i]->size() == indexed_data_size); | |
| chassert(indexed_columns[i]->size() == indexed_data_size); |
|
|
||
| /// Filter out unreferenced rows from nested columns. | ||
| ColumnIndex column_index(common_replicated_indexes); | ||
| auto [compact_common_replicated_indexes, filtered_nested_columns] = column_index.buildCompactIndexedColumns(nested_columns); |
There was a problem hiding this comment.
I have an idea - filter unused rows only when isSuitableForShortCircuitArgumentsExecution returns true. This method is used in short-circuit functions execution when we have similar problem and can't execute function on some rows because they should be filtered. For some functions it's 100% safe to execute on any garbage so we can avoid filtering here for such functions. WDYT?
There was a problem hiding this comment.
That makes sense, I'm also working on adding a similar canThrow() interface in functions that returns true if the function throws (should be a subset of isSuitableForShortCircuitArgumentsExecution). It's still WIP here #100127. Maybe we can use that instead to allow more functions to skip the filter?
There was a problem hiding this comment.
Yes, in this case canThrow interface will be even better.
Avogar
left a comment
There was a problem hiding this comment.
I think we can merge it and add logic with canThrow later. WDYT?
@Avogar Yes that makes sense, |
LLVM Coverage Report
Changed lines: 91.07% (102/112) | lost baseline coverage: 4 line(s) · Uncovered code |
efc307d
ColumnReplicated can have unreferenced rows in the nested column that did not fulfill the join condition. Functions in
IFunction.cppare executed on the nested column directly which can cause failures on values that should not have been in the result (based on discussion in #98883).This change makes sure to filter out unused rows in the default implementation of functions for
ColumnReplicatedinIFunction.cpp.04036_columns_replicated_with_unreferenced_rows.sql before the change:
04036_columns_replicated_with_unreferenced_rows.sql after the change:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix exception in functions operating on ColumnReplicated with unreferenced rows produced by JOIN.
Documentation entry for user-facing changes