Repository navigation
Fix column not found error for lazy materialization and part_offset i… - #108287
Conversation
|
Workflow [PR], commit [cb4a75f] Summary: ✅
AI ReviewSummaryThis PR fixes the lazy-materialization path when Final Verdict✅ No blocking issues found in the current PR head. |
| if (!filter_actions) | ||
| continue; | ||
| auto & dag_outputs = filter_actions->getOutputs(); | ||
| for (const auto * input : filter_actions->getInputs()) |
There was a problem hiding this comment.
I think if the row policy has it as input but the prewhere not, than we will fail to expose this in the output. We have to add it to the prewhere actions if it is not present.
There was a problem hiding this comment.
Okay, after thinking more about it: this probably cannot happen, because we don't push thing into row policies. However I think this is inconcistent: we should either don't touch row level filter or handle the case when row level filter doesn't output it.
There was a problem hiding this comment.
If the row policy has _part_starting_offset as an input but PREWHERE does not, then that column will be bypassed.
The other way around also works as expected: if the row policy does not have _part_starting_offset, but PREWHERE does.
This is I assume how expression calculation works: if we merge DAGs where the second one has an unknown output from the previous one, it passes it further, and which is intentional.
That said, the only important thing is to add the column to the output if it is present in the inputs. Otherwise, in this case, it will be dropped.
Please check my example. I will add this to the test cases, but overall I think the current version of the code covers this. Let me know what you think.
Details
DROP ROW POLICY IF EXISTS repro_pol2 ON repro;
DROP ROW POLICY IF EXISTS repro_pol ON repro;
DROP TABLE IF EXISTS repro;
CREATE TABLE repro (Id UInt64, EventId UInt64, flag UInt8) ENGINE = MergeTree ORDER BY Id;
INSERT INTO repro SELECT number, number, number % 2 FROM numbers(1000);
SET query_plan_optimize_lazy_materialization = 1;
CREATE ROW POLICY repro_pol ON repro USING _part_starting_offset + _part_offset < 100 TO ALL;
SELECT repeat('-----', 10);
EXPLAIN PLAN actions = 1
SELECT EventId FROM repro WHERE Id < 10 ORDER BY Id DESC LIMIT 10;
SELECT repeat('-----', 10);
EXPLAIN PLAN actions = 1
SELECT EventId FROM repro WHERE Id < 10 AND _part_starting_offset + _part_offset < 50 ORDER BY Id DESC LIMIT 10;
DROP ROW POLICY repro_pol ON repro;
CREATE ROW POLICY repro_pol2 ON repro USING Id < 10 TO ALL;
SELECT repeat('-----', 10);
EXPLAIN PLAN actions = 1
SELECT EventId FROM repro WHERE _part_starting_offset + _part_offset < 50 ORDER BY Id DESC LIMIT 10;
EXPLAIN results:
...
Prewhere filter
Prewhere filter column: less(__table1.Id, 10_UInt8) (removed)
Actions: INPUT : 0 -> Id UInt64 : 0
COLUMN Const(UInt8) -> 10_UInt8 UInt8 : 1
FUNCTION less(Id : 0, 10_UInt8 :: 1) -> less(__table1.Id, 10_UInt8) UInt8 : 2
Positions: 0 2
Row level filter
Row level filter column: less(plus(_part_starting_offset, _part_offset), 100_UInt8) (removed)
Actions: INPUT : 0 -> _part_starting_offset UInt64 : 0
INPUT : 1 -> _part_offset UInt64 : 1
COLUMN Const(UInt8) -> 100_UInt8 UInt8 : 2
FUNCTION plus(_part_starting_offset : 0, _part_offset : 1) -> plus(_part_starting_offset, _part_offset) UInt64 : 3
FUNCTION less(plus(_part_starting_offset, _part_offset) :: 3, 100_UInt8 :: 2) -> less(plus(_part_starting_offset, _part_offset), 100_UInt8) UInt8 : 4
Positions: 4 0 1
...
There was a problem hiding this comment.
If the row policy has _part_starting_offset as an input but PREWHERE does not, then that column will be bypassed.
The other way around also works as expected: if the row policy does not have _part_starting_offset, but PREWHERE does.
Yes, you are right. I forgot about bypassed columns.
|
@groeneai please check CI failures have inflight fixes |
|
@vdimir checked all failing checks on 2b3ba0e. None are caused by this PR (your diff is the
|
@groeneai try to reproduce this issue on this branch or determine whether this comment is valid. |
|
@vdimir Confirmed valid, reproduced on this branch head (b985d63, debug). Two shapes throw CREATE TABLE repro (Id UInt64, EventId UInt64, flag UInt8) ENGINE = MergeTree ORDER BY Id;
INSERT INTO repro SELECT number, number, number % 2 FROM numbers(1000);
-- (1) explicit PREWHERE on the bare virtual column
SELECT EventId FROM repro PREWHERE _part_offset ORDER BY Id DESC LIMIT 10
SETTINGS query_plan_optimize_lazy_materialization=1, query_plan_max_limit_for_lazy_materialization=100;
-- Code: 10. Not found column _part_offset: in block _part_starting_offset ..., Id ...
-- (2) row policy USING the bare virtual column
CREATE ROW POLICY p ON repro USING _part_offset TO ALL;
SELECT EventId FROM repro ORDER BY Id DESC LIMIT 10
SETTINGS query_plan_optimize_lazy_materialization=1, query_plan_max_limit_for_lazy_materialization=100;
-- same Code: 10Server stack: One correction to the review's literal example: If you want, I can send a suggestion that treats the filter-output-preserved column as re-exposed (clear |
b985d63 to
cb4a75f
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 35/35 (100.00%) · Uncovered code |
@groeneai is it known failure? |
Yes, and it is unrelated to this PR.
Tracked in #110518 (comp-parallel-replicas; sibling STID 5217-5b3d, same message). A prior fix attempt (#109202) was closed unmerged and there is no open fix PR at the moment. |
Cherry pick #108287 to 25.8: Fix column not found error for lazy materialization and part_offset i…
…lization and part_offset i…
Backport #108287 to 26.6: Fix column not found error for lazy materialization and part_offset i…
Backport #108287 to 26.7: Fix column not found error for lazy materialization and part_offset i…
Backport #108287 to 26.3: Fix column not found error for lazy materialization and part_offset i…
Backport #108287 to 26.4: Fix column not found error for lazy materialization and part_offset i…
Backport #108287 to 26.5: Fix column not found error for lazy materialization and part_offset i…
…zy materialization and part_offset i…
…zy materialization and part_offset i…
…zy materialization and part_offset i…
…zy materialization and part_offset i…
…rialization_part_offset_prewhere Fix column not found error for lazy materialization and part_offset i…
…n prewhere
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
NOT_FOUND_COLUMN_IN_BLOCKerror for queries that use the_part_starting_offset/_part_offsetvirtual columns in WHERE together with lazy materializationClose #108126
Version info
26.7.1.1382(included in26.7and later)26.7.2.10,26.6.2.106,26.5.6.68,26.4.5.155,26.3.17.72