mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING
Part#1: Frame_n_rows::next_partition() should not assume that the current table->record[0] points to the first row in the partition. Since cursor supports move_to() operation, we dont need this.
This commit is contained in:
@ -658,3 +658,29 @@ part_id pk val CNT
|
||||
5678 207 3 9
|
||||
5678 208 3 9
|
||||
drop table t4;
|
||||
#
|
||||
# MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING
|
||||
#
|
||||
create table t1 (pk int, a int, b int);
|
||||
insert into t1 values
|
||||
( 1 , 0, 1),
|
||||
( 2 , 0, 2),
|
||||
( 3 , 1, 4),
|
||||
( 4 , 1, 8),
|
||||
( 5 , 2, 32),
|
||||
( 6 , 2, 64),
|
||||
( 7 , 2, 128),
|
||||
( 8 , 2, 16);
|
||||
select pk, a, b,
|
||||
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or
|
||||
from t1;
|
||||
pk a b bit_or
|
||||
1 0 1 3
|
||||
2 0 2 3
|
||||
3 1 4 12
|
||||
4 1 8 12
|
||||
5 2 32 96
|
||||
6 2 64 224
|
||||
7 2 128 208
|
||||
8 2 16 144
|
||||
drop table t1;
|
||||
|
@ -422,3 +422,22 @@ from t4;
|
||||
|
||||
drop table t4;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING
|
||||
--echo #
|
||||
create table t1 (pk int, a int, b int);
|
||||
insert into t1 values
|
||||
( 1 , 0, 1),
|
||||
( 2 , 0, 2),
|
||||
( 3 , 1, 4),
|
||||
( 4 , 1, 8),
|
||||
( 5 , 2, 32),
|
||||
( 6 , 2, 64),
|
||||
( 7 , 2, 128),
|
||||
( 8 , 2, 16);
|
||||
|
||||
select pk, a, b,
|
||||
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or
|
||||
from t1;
|
||||
|
||||
drop table t1;
|
||||
|
@ -650,16 +650,8 @@ public:
|
||||
{
|
||||
if (rownum != 0)
|
||||
{
|
||||
/*
|
||||
The cursor in "ROWS n PRECEDING" lags behind by n_rows rows.
|
||||
Catch up.
|
||||
TODO: change this to be a jump forward.
|
||||
*/
|
||||
while (!(cursor_eof= (0 != cursor.get_next())))
|
||||
{
|
||||
if (bound_tracker.check_if_next_group())
|
||||
break;
|
||||
}
|
||||
/* The cursor in "ROWS n PRECEDING" lags behind by n_rows rows. */
|
||||
cursor.move_to(rownum);
|
||||
}
|
||||
n_rows_to_skip= n_rows - (is_top_bound? 0:1);
|
||||
}
|
||||
@ -717,7 +709,7 @@ private:
|
||||
{
|
||||
if (!(cursor_eof= (0 != cursor.get_next())))
|
||||
{
|
||||
bool new_group= bound_tracker.check_if_next_group();
|
||||
bool new_group= is_preceding? false: bound_tracker.check_if_next_group();
|
||||
if (at_partition_start || !new_group)
|
||||
{
|
||||
if (is_top_bound) // this is frame start endpoint
|
||||
|
Reference in New Issue
Block a user