fix: TableScan should recurse into provider logical plan in map_children#19282
fix: TableScan should recurse into provider logical plan in map_children#19282shifluxxc wants to merge 3 commits intoapache:mainfrom
Conversation
leoyvens
left a comment
There was a problem hiding this comment.
Thanks for jumping onto this issue so quickly! I just have a concern about the fn replace_logical_plan, I'm hoping there is a simpler way.
datafusion/expr/src/table_source.rs
Outdated
| None | ||
| } | ||
|
|
||
| fn replace_logical_plan( |
There was a problem hiding this comment.
Would it be possible to avoid adding a method to the TableSource trait?
There was a problem hiding this comment.
Hey @leoyvens , can u please review . I removed any changes made to TableSource trait .
588864a to
e74ca7a
Compare
leoyvens
left a comment
There was a problem hiding this comment.
This addresses my issue
martin-g
left a comment
There was a problem hiding this comment.
I am not sure how problematic this is but now the visit method (apply_children) is not symmetrical with the rewrite method (map_children).
apply_children does not visit the inner plan of TableScan.
|
run benchmark sql_planner |
|
🤖 |
|
🤖: Benchmark completed Details
|
Should i rewrite the |
|
I'm not the best person to answer this question. |
Which issue does this PR close?
Rationale for this change
LogicalPlan::TableScan is currently treated as a leaf node in map_children, but some table providers (such as views) expose their own logical plan via TableSource::get_logical_plan().
Because of this incorrect leaf assumption, logical plan visitors and optimizer passes fail to recurse into the underlying logical plan. This leads to missed optimizations and incomplete rewrites when a scan represents a view or other provider-defined logical plan.
What changes are included in this PR?
TableSourcereturns a logical planTableSourceusingreplace_logical_planafter transformationtest_table_scan_with_inner_plan_is_visitedensures recursion occurs for providers with an inner plantest_table_scan_without_inner_plan_is_not_visitedensures behavior remains unchanged when no inner plan existsAre these changes tested?
Yes.
Two dedicated unit tests validate:
Are there any user-facing changes?
No