mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 02:05:57 +01:00
MDEV-11746: Wrong result upon using FIRST_VALUE with a window frame
The same approach is needed for LAST_VALUE, otherwise the LAST_VALUE sum functions are not cleared correctly. Now LAST_VALUE behaves as NTH_VALUE with 0 offset, only that the frame that it is examining is the bottom bound, not the top bound.
This commit is contained in:
parent
57341852b5
commit
5bf338435a
3 changed files with 33 additions and 18 deletions
|
@ -113,17 +113,19 @@ last_value(i) OVER (order by i rows between CURRENT ROW and 1 FOLLOWING) as last
|
|||
first_value(i) OVER (order by i rows between 1 PRECEDING AND 1 FOLLOWING) as fst_1p1f,
|
||||
last_value(i) OVER (order by i rows between 1 PRECEDING AND 1 FOLLOWING) as fst_1p1f,
|
||||
first_value(i) OVER (order by i rows between 2 PRECEDING AND 1 PRECEDING) as fst_2p1p,
|
||||
last_value(i) OVER (order by i rows between 2 PRECEDING AND 1 PRECEDING) as fst_2p1p
|
||||
last_value(i) OVER (order by i rows between 2 PRECEDING AND 1 PRECEDING) as fst_2p1p,
|
||||
first_value(i) OVER (order by i rows between 1 FOLLOWING AND 2 FOLLOWING) as fst_1f2f,
|
||||
last_value(i) OVER (order by i rows between 1 FOLLOWING AND 2 FOLLOWING) as fst_1f2f
|
||||
from t1;
|
||||
i fst_1f last_1f fst_1p1f fst_1p1f fst_2p1p fst_2p1p
|
||||
1 1 2 1 2 NULL NULL
|
||||
2 2 3 1 3 1 1
|
||||
3 3 4 2 4 1 2
|
||||
4 4 5 3 5 2 3
|
||||
5 5 6 4 6 3 4
|
||||
6 6 7 5 7 4 5
|
||||
7 7 8 6 8 5 6
|
||||
8 8 9 7 9 6 7
|
||||
9 9 10 8 10 7 8
|
||||
10 10 10 9 10 8 9
|
||||
i fst_1f last_1f fst_1p1f fst_1p1f fst_2p1p fst_2p1p fst_1f2f fst_1f2f
|
||||
1 1 2 1 2 NULL NULL 2 3
|
||||
2 2 3 1 3 1 1 3 4
|
||||
3 3 4 2 4 1 2 4 5
|
||||
4 4 5 3 5 2 3 5 6
|
||||
5 5 6 4 6 3 4 6 7
|
||||
6 6 7 5 7 4 5 7 8
|
||||
7 7 8 6 8 5 6 8 9
|
||||
8 8 9 7 9 6 7 9 10
|
||||
9 9 10 8 10 7 8 10 10
|
||||
10 10 10 9 10 8 9 NULL NULL
|
||||
drop table t1;
|
||||
|
|
|
@ -69,7 +69,9 @@ select i,
|
|||
first_value(i) OVER (order by i rows between 1 PRECEDING AND 1 FOLLOWING) as fst_1p1f,
|
||||
last_value(i) OVER (order by i rows between 1 PRECEDING AND 1 FOLLOWING) as fst_1p1f,
|
||||
first_value(i) OVER (order by i rows between 2 PRECEDING AND 1 PRECEDING) as fst_2p1p,
|
||||
last_value(i) OVER (order by i rows between 2 PRECEDING AND 1 PRECEDING) as fst_2p1p
|
||||
last_value(i) OVER (order by i rows between 2 PRECEDING AND 1 PRECEDING) as fst_2p1p,
|
||||
first_value(i) OVER (order by i rows between 1 FOLLOWING AND 2 FOLLOWING) as fst_1f2f,
|
||||
last_value(i) OVER (order by i rows between 1 FOLLOWING AND 2 FOLLOWING) as fst_1f2f
|
||||
from t1;
|
||||
|
||||
drop table t1;
|
||||
|
|
|
@ -2311,11 +2311,6 @@ void add_special_frame_cursors(THD *thd, Cursor_manager *cursor_manager,
|
|||
fc->add_sum_func(item_sum);
|
||||
cursor_manager->add_cursor(fc);
|
||||
break;
|
||||
case Item_sum::LAST_VALUE_FUNC:
|
||||
fc= get_frame_cursor(thd, spec, false);
|
||||
fc->add_sum_func(item_sum);
|
||||
cursor_manager->add_cursor(fc);
|
||||
break;
|
||||
case Item_sum::LEAD_FUNC:
|
||||
case Item_sum::LAG_FUNC:
|
||||
{
|
||||
|
@ -2355,6 +2350,22 @@ void add_special_frame_cursors(THD *thd, Cursor_manager *cursor_manager,
|
|||
cursor_manager->add_cursor(fc);
|
||||
break;
|
||||
}
|
||||
case Item_sum::LAST_VALUE_FUNC:
|
||||
{
|
||||
Frame_cursor *bottom_bound= get_frame_cursor(thd, spec, false);
|
||||
Frame_cursor *top_bound= get_frame_cursor(thd, spec, true);
|
||||
cursor_manager->add_cursor(bottom_bound);
|
||||
cursor_manager->add_cursor(top_bound);
|
||||
DBUG_ASSERT(item_sum->fixed);
|
||||
Item *offset_item= new (thd->mem_root) Item_int(thd, 0);
|
||||
offset_item->fix_fields(thd, &offset_item);
|
||||
fc= new Frame_positional_cursor(*bottom_bound,
|
||||
*top_bound, *bottom_bound,
|
||||
*offset_item, false);
|
||||
fc->add_sum_func(item_sum);
|
||||
cursor_manager->add_cursor(fc);
|
||||
break;
|
||||
}
|
||||
case Item_sum::NTH_VALUE_FUNC:
|
||||
{
|
||||
Frame_cursor *bottom_bound= get_frame_cursor(thd, spec, false);
|
||||
|
|
Loading…
Add table
Reference in a new issue