Skip to content

Commit 53784d9

Browse files
committed
MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING
Part#2: Fix a couple more issues in rows-type frames. This also has a code cleanup: - introduce a separate Frame_rows_current_row_(top,bottom). This is is a special case which doesn't need its cursor or partition bound check - Split Frame_n_rows into = Frame_n_rows_preceding (this one is now much simpler) = Frame_n_rows_following (simpler and works but may need some work still)
1 parent 0e9fb98 commit 53784d9

File tree

3 files changed

+317
-90
lines changed

3 files changed

+317
-90
lines changed

mysql-test/r/win.result

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,4 +683,101 @@ pk a b bit_or
683683
6 2 64 224
684684
7 2 128 208
685685
8 2 16 144
686+
# Extra ROWS n PRECEDING tests
687+
select pk, a, b,
688+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) as bit_or
689+
from t1;
690+
pk a b bit_or
691+
1 0 1 0
692+
2 0 2 1
693+
3 1 4 0
694+
4 1 8 4
695+
5 2 32 0
696+
6 2 64 32
697+
7 2 128 64
698+
8 2 16 128
686699
drop table t1;
700+
create table t2 (
701+
pk int,
702+
a int,
703+
b int
704+
);
705+
insert into t2 values
706+
( 1, 0, 1),
707+
( 2, 0, 2),
708+
( 3, 0, 4),
709+
( 4, 0, 8),
710+
( 5, 1, 16),
711+
( 6, 1, 32),
712+
( 7, 1, 64),
713+
( 8, 1, 128),
714+
( 9, 2, 256),
715+
(10, 2, 512),
716+
(11, 2, 1024),
717+
(12, 2, 2048);
718+
select pk, a, b,
719+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) as bit_or
720+
from t2;
721+
pk a b bit_or
722+
1 0 1 0
723+
2 0 2 1
724+
3 0 4 2
725+
4 0 8 4
726+
5 1 16 0
727+
6 1 32 16
728+
7 1 64 32
729+
8 1 128 64
730+
9 2 256 0
731+
10 2 512 256
732+
11 2 1024 512
733+
12 2 2048 1024
734+
select pk, a, b,
735+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) as bit_or
736+
from t2;
737+
pk a b bit_or
738+
1 0 1 0
739+
2 0 2 0
740+
3 0 4 1
741+
4 0 8 2
742+
5 1 16 0
743+
6 1 32 0
744+
7 1 64 16
745+
8 1 128 32
746+
9 2 256 0
747+
10 2 512 0
748+
11 2 1024 256
749+
12 2 2048 512
750+
select pk, a, b,
751+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING) as bit_or
752+
from t2;
753+
pk a b bit_or
754+
1 0 1 0
755+
2 0 2 1
756+
3 0 4 3
757+
4 0 8 6
758+
5 1 16 0
759+
6 1 32 16
760+
7 1 64 48
761+
8 1 128 96
762+
9 2 256 0
763+
10 2 512 256
764+
11 2 1024 768
765+
12 2 2048 1536
766+
# Check CURRENT ROW
767+
select pk, a, b,
768+
bit_or(b) over (partition by a order by pk ROWS BETWEEN CURRENT ROW AND CURRENT ROW) as bit_or
769+
from t2;
770+
pk a b bit_or
771+
1 0 1 1
772+
2 0 2 2
773+
3 0 4 4
774+
4 0 8 8
775+
5 1 16 16
776+
6 1 32 32
777+
7 1 64 64
778+
8 1 128 128
779+
9 2 256 256
780+
10 2 512 512
781+
11 2 1024 1024
782+
12 2 2048 2048
783+
drop table t2;

mysql-test/t/win.test

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,50 @@ select pk, a, b,
440440
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or
441441
from t1;
442442

443+
--echo # Extra ROWS n PRECEDING tests
444+
select pk, a, b,
445+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) as bit_or
446+
from t1;
443447
drop table t1;
448+
449+
450+
create table t2 (
451+
pk int,
452+
a int,
453+
b int
454+
);
455+
456+
insert into t2 values
457+
( 1, 0, 1),
458+
( 2, 0, 2),
459+
( 3, 0, 4),
460+
( 4, 0, 8),
461+
( 5, 1, 16),
462+
( 6, 1, 32),
463+
( 7, 1, 64),
464+
( 8, 1, 128),
465+
( 9, 2, 256),
466+
(10, 2, 512),
467+
(11, 2, 1024),
468+
(12, 2, 2048);
469+
470+
select pk, a, b,
471+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) as bit_or
472+
from t2;
473+
474+
select pk, a, b,
475+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING) as bit_or
476+
from t2;
477+
478+
select pk, a, b,
479+
bit_or(b) over (partition by a order by pk ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING) as bit_or
480+
from t2;
481+
482+
--echo # Check CURRENT ROW
483+
484+
select pk, a, b,
485+
bit_or(b) over (partition by a order by pk ROWS BETWEEN CURRENT ROW AND CURRENT ROW) as bit_or
486+
from t2;
487+
488+
drop table t2;
489+

0 commit comments

Comments
 (0)