Wrong Window frame for cost history query
The query use the window function LAST_VALUE
but does not setup a frame. So this means that it is the default which is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
. So it is always the value of the current row that is used instead of the last one from the partition.