risinglight icon indicating copy to clipboard operation
risinglight copied to clipboard

Optimizer: eliminate common sub-expressions

Open lokax opened this issue 3 years ago • 1 comments

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

lokax avatar Jun 02 '22 02:06 lokax

That's cool! We can see if we can do this optimization with optimizer rule 🤣

skyzh avatar Jun 02 '22 07:06 skyzh