`MoveTowardsLeafNodes` placement implies speculative evaluation, but the docs don't say so
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust
- Lĩnh vực
- backend-api-design, documentation
Hướng nghiên cứu
Bắt đầu với tài liệu về ExpressionPlacement::MoveTowardsLeafNodes và ScalarUDFImpl::placement được liên kết trong issue. Đọc về cách trích xuất và pushdown biểu thức lá có thể đánh giá biểu thức trên các hàng bị loại trừ bởi nhánh CASE hoặc bộ lọc, rồi ghi lại yêu cầu an toàn trên cả hai API. Hoàn tất khi cả hai tài liệu đều nêu rõ rằng biểu thức có cách đặt này không được thất bại hoặc gây tác dụng phụ trên bất kỳ hàng đầu vào nào.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
ExpressionPlacement::MoveTowardsLeafNodes is documented as a performance hint: the expression is cheap and can be pushed down towards the leaves of the plan. When the optimizer acts on that hint, it also runs the expression on rows that the original plan never evaluated it on:
ExtractLeafExpressionsextractsMoveTowardsLeafNodessub-expressions from anywhere inside an expression tree, including the branches ofCASE. In the extraction projection, they are evaluated for every input row, not just the rows the branch selects.PushDownLeafProjectionsthen pushes the extraction projections belowFilternodes, so the expressions also run on rows the filter removes.
So an expression with this placement must be safe to evaluate on rows that a filter or a conditional would exclude: it must not fail on them or have side effects. Neither ExpressionPlacement::MoveTowardsLeafNodes nor ScalarUDFImpl::placement states this. The built-in functions with this placement (get_field, input_file_name, file_row_index) meet the requirement as far as I can tell. A user-defined function that returns MoveTowardsLeafNodes because it is cheap, but fails on some inputs, can make a query fail even though SQL CASE and WHERE semantics say that input is never evaluated.
To Reproduce
The plan below shows how get_field is moved with the default configuration (datafusion.optimizer.enable_leaf_expression_pushdown = true):
CREATE TABLE t AS SELECT * FROM (VALUES
(1, named_struct('a', 1, 'b', 2)),
(-1, named_struct('a', 3, 'b', 4))
) AS v(x, s);
EXPLAIN SELECT CASE WHEN x > 0 THEN s['a'] WHEN x < -100 THEN 0 END FROM t WHERE x <> 5;
logical_plan
01)Projection: CASE WHEN t.x > Int64(0) THEN __datafusion_extracted_1 WHEN t.x < Int64(-100) THEN Int64(0) END AS ...
02)--Filter: t.x != Int64(5)
03)----Projection: get_field(t.s, Utf8("a")) AS __datafusion_extracted_1, t.x
04)------TableScan: t projection=[x, s]
get_field(t.s, 'a') came from the first THEN branch, and it is now evaluated below the filter for every row of t.
Replace s['a'] with a UDF that returns MoveTowardsLeafNodes and fails on some values, for example a checked conversion that fails when its argument is 0. The query then fails on rows where x <= 0 or x = 5, even though the result would never include the UDF's value for those rows.
Expected behavior
Either of these would resolve it:
- Document the requirement (preferred). State on
ExpressionPlacement::MoveTowardsLeafNodesandScalarUDFImpl::placementthat an expression with this placement may be evaluated on rows that enclosing filters or conditional expressions would exclude, so it must not fail or have side effects on any input row. This matches what the optimizer already relies on. - Stop speculative evaluation: don't extract leaf expressions from conditional sub-expressions (
CASEbranches, the right side of short-circuitingAND/OR), and don't push extraction projections below filters when the extracted expression could fail. That would give up much of the benefit of the leaf pushdown optimization, which is mainly about evaluatingget_fieldclose to the scan.
Additional context
The question came up while reviewing #26589, which precomputes MoveTowardsLeafNodes expressions over the whole batch before evaluating CASE branches (https://github.com/apache/datafusion/pull/26589#discussion_r4581490634). That PR relies on the same assumption at the physical level, so documenting the requirement would cover both.
- Ngôn ngữ chính
- Rust
- Star
- 9.6k
- Fork
- 2.6k
- Merge trung bình
- 3 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 352
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/datafusion
-
`verify-release-candidate.sh` version check doesn't catch `-dev` versions and is skipped on macOSCó thể đã có người làm @vinycalves đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/datafusion#27563 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`lpad` and `rpad` with a literal length above `i32::MAX` error on a NULL string or fillCó thể đã có người làm @TechWizard9999 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
apache/datafusion#27482 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Window constructors panic when the expression list is emptyCó thể đã có người làm @abp002 đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/datafusion#27315 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/datafusion#27094 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Substrait consumer doesn't recognise `shift_left` / `shift_right` from functions_arithmetic.yamlCó thể đã có người làm @jonasHanhan đã nhận 15 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/datafusion#27059 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/datafusion
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tinystream-dev/tinystream#132 ·
-
contract good first issue testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Emmyt24/nova-launch#2436 ·
Maintainer thường phản hồi trong vòng 1 ngày