mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Fixed bug mdev-10842.
In some cases the function compare_order_elements() erroneously returned CMP_EQ for not equal elements.
This commit is contained in:
@@ -2015,3 +2015,42 @@ AND 15 FOLLOWING)
|
|||||||
242 NULL
|
242 NULL
|
||||||
238 NULL
|
238 NULL
|
||||||
DROP table orders;
|
DROP table orders;
|
||||||
|
#
|
||||||
|
# MDEV-10842: window functions with the same order column
|
||||||
|
# but different directions
|
||||||
|
#
|
||||||
|
create table t1 (
|
||||||
|
pk int primary key,
|
||||||
|
a int,
|
||||||
|
b int,
|
||||||
|
c char(10)
|
||||||
|
);
|
||||||
|
insert into t1 values
|
||||||
|
( 1, 0, 1, 'one'),
|
||||||
|
( 2, 0, 2, 'two'),
|
||||||
|
( 3, 0, 3, 'three'),
|
||||||
|
( 4, 1, 1, 'one'),
|
||||||
|
( 5, 1, 1, 'two'),
|
||||||
|
( 6, 1, 2, 'three'),
|
||||||
|
( 7, 2, NULL, 'n_one'),
|
||||||
|
( 8, 2, 1, 'n_two'),
|
||||||
|
( 9, 2, 2, 'n_three'),
|
||||||
|
(10, 2, 0, 'n_four'),
|
||||||
|
(11, 2, 10, NULL);
|
||||||
|
select pk,
|
||||||
|
row_number() over (order by pk desc) as r_desc,
|
||||||
|
row_number() over (order by pk asc) as r_asc
|
||||||
|
from t1;
|
||||||
|
pk r_desc r_asc
|
||||||
|
1 11 1
|
||||||
|
2 10 2
|
||||||
|
3 9 3
|
||||||
|
4 8 4
|
||||||
|
5 7 5
|
||||||
|
6 6 6
|
||||||
|
7 5 7
|
||||||
|
8 4 8
|
||||||
|
9 3 9
|
||||||
|
10 2 10
|
||||||
|
11 1 11
|
||||||
|
drop table t1;
|
||||||
|
@@ -1230,3 +1230,35 @@ SELECT o_custkey, avg(o_custkey) OVER (PARTITION BY abs(o_custkey)
|
|||||||
RANGE BETWEEN 15 FOLLOWING
|
RANGE BETWEEN 15 FOLLOWING
|
||||||
AND 15 FOLLOWING) from orders;
|
AND 15 FOLLOWING) from orders;
|
||||||
DROP table orders;
|
DROP table orders;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-10842: window functions with the same order column
|
||||||
|
--echo # but different directions
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
create table t1 (
|
||||||
|
pk int primary key,
|
||||||
|
a int,
|
||||||
|
b int,
|
||||||
|
c char(10)
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into t1 values
|
||||||
|
( 1, 0, 1, 'one'),
|
||||||
|
( 2, 0, 2, 'two'),
|
||||||
|
( 3, 0, 3, 'three'),
|
||||||
|
( 4, 1, 1, 'one'),
|
||||||
|
( 5, 1, 1, 'two'),
|
||||||
|
( 6, 1, 2, 'three'),
|
||||||
|
( 7, 2, NULL, 'n_one'),
|
||||||
|
( 8, 2, 1, 'n_two'),
|
||||||
|
( 9, 2, 2, 'n_three'),
|
||||||
|
(10, 2, 0, 'n_four'),
|
||||||
|
(11, 2, 10, NULL);
|
||||||
|
|
||||||
|
select pk,
|
||||||
|
row_number() over (order by pk desc) as r_desc,
|
||||||
|
row_number() over (order by pk asc) as r_asc
|
||||||
|
from t1;
|
||||||
|
|
||||||
|
drop table t1;
|
||||||
|
@@ -238,7 +238,7 @@ setup_windows(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
|||||||
static
|
static
|
||||||
int compare_order_elements(ORDER *ord1, ORDER *ord2)
|
int compare_order_elements(ORDER *ord1, ORDER *ord2)
|
||||||
{
|
{
|
||||||
if (*ord1->item == *ord2->item)
|
if (*ord1->item == *ord2->item && ord1->direction == ord2->direction)
|
||||||
return CMP_EQ;
|
return CMP_EQ;
|
||||||
Item *item1= (*ord1->item)->real_item();
|
Item *item1= (*ord1->item)->real_item();
|
||||||
Item *item2= (*ord2->item)->real_item();
|
Item *item2= (*ord2->item)->real_item();
|
||||||
|
Reference in New Issue
Block a user