[Commits] 10aa3936a794184229229ae43eee51ae3b3f5681 Fixed bug mdev-10842. In some cases the function compare_order_elements() erroneously returned CMP_EQ for not equal elements.

Igor Babaev igor at askmonty.org
Wed Sep 21 05:56:05 EEST 2016


commit 10aa3936a794184229229ae43eee51ae3b3f5681
Author: Igor Babaev <igor at askmonty.org>
Commit: Igor Babaev <igor at askmonty.org>

    Fixed bug mdev-10842.
    In some cases the function compare_order_elements() erroneously
    returned CMP_EQ for not equal elements.
---
 mysql-test/r/win.result |   39 +++++++++++++++++++++++++++++++++++++++
 mysql-test/t/win.test   |   32 ++++++++++++++++++++++++++++++++
 sql/sql_window.cc       |    2 +-
 3 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result
index d23e865..27824a3 100644
--- a/mysql-test/r/win.result
+++ b/mysql-test/r/win.result
@@ -2015,3 +2015,42 @@ AND 15 FOLLOWING)
 242	NULL
 238	NULL
 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;
diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test
index 2ede130..de03dd1 100644
--- a/mysql-test/t/win.test
+++ b/mysql-test/t/win.test
@@ -1230,3 +1230,35 @@ SELECT o_custkey, avg(o_custkey) OVER (PARTITION BY abs(o_custkey)
                                        RANGE BETWEEN 15 FOLLOWING
                                                  AND 15 FOLLOWING) from 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;
diff --git a/sql/sql_window.cc b/sql/sql_window.cc
index e720c39..4705fdc 100644
--- a/sql/sql_window.cc
+++ b/sql/sql_window.cc
@@ -238,7 +238,7 @@
 static
 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;
   Item *item1= (*ord1->item)->real_item();
   Item *item2= (*ord2->item)->real_item();


More information about the commits mailing list