LucidDB / luciddb

DEFUNCT: See README
https://github.com/LucidDB/luciddb
Apache License 2.0
53 stars 24 forks source link

[FRG-177] Optimize 'LAST_VALUE(x)' to 'x' when window ends at current row #695

Open dynamobi-build opened 12 years ago

dynamobi-build commented 12 years ago

[reporter="jhyde", created="Sat, 29 Jul 2006 18:08:51 -0500 (GMT-05:00)"] In a windowed aggregate query, when the upper bound of the window is the current row (as is common), LAST_VALUE(x) is the same as x. We should apply this as an optimization.

An example of a query where this can be done is
 
select
  first_value(x) over last3,
  x,
  last_value(x) over last3
from t
window last3 as (rows 3 preceding)

We can also optimize FIRST_VALUE(x) if the window happens to start at the current row.

Until //open/dt/dev/farrago/src/com/disruptivetech/farrago/calc/CalcRexImplementorTableImpl.java#35, there was an implementor which did this automatically. However, it was broken if the window did not end at the current row.