risinglight
risinglight copied to clipboard
Optimizer: eliminate common sub-expressions
In the present, the optimizer doesn't realize any information abount common expression.
This causes the Expression Evaluator to evaluate expressions repeatedly for every input tuple.
For Example:
> explain select x * 2 + y, x * 2 + y + 4 from test;
PhysicalProjection:
((InputRef #0 * 2) + InputRef #1)
(((InputRef #0 * 2) + InputRef #1) + 4)
PhysicalTableScan:
table #0,
columns [0, 1],
with_row_handler: false,
is_sorted: false,
expr: None
Maybe we should rewrite the plan to:
> explain select x * 2 + y, x * 2 + y + 4 from test;
PhysicalProjection:
(InputRef #0)
((InputRef #0) + 4)
PhysicalProjection:
((InputRef #0 * 2) + InputRef #1)
PhysicalTableScan:
table #0,
columns [0, 1],
with_row_handler: false,
is_sorted: false,
expr: None
That's cool! We can see if we can do this optimization with optimizer rule 🤣