dynamobi/dynamobi — Issue #695: [FRG-177] Optimize 'LAST_VALUE(x)' to 'x' when window ends at current row
Author: dynamobi-build
Created: 2011-12-30 03:43:42+00:00
State: open
Labels: FRG

[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.