diff options
-rw-r--r-- | mysql-test/r/win.result | 12 | ||||
-rw-r--r-- | mysql-test/t/win.test | 10 | ||||
-rw-r--r-- | sql/sql_window.cc | 16 |
3 files changed, 38 insertions, 0 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 083b5dfd16d..0ddffc551dc 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3506,5 +3506,17 @@ id a b sum_a_b 2 2 2 4 drop table t1; # +# MDEV-15837: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM' +# failed in compare_order_elements function +# +CREATE TABLE t1 (a1 int); +insert into t1 values (1),(2),(3); +SELECT rank() OVER (ORDER BY 1), ROW_NUMBER() OVER (ORDER BY (EXPORT_SET(5,'Y','N',',',4))) FROM t1; +rank() OVER (ORDER BY 1) ROW_NUMBER() OVER (ORDER BY (EXPORT_SET(5,'Y','N',',',4))) +1 1 +1 2 +1 3 +drop table t1; +# # End of 10.2 tests # diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 0f02b1414a0..fd31e9d4bd9 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2256,5 +2256,15 @@ from t1 e; drop table t1; --echo # +--echo # MDEV-15837: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM' +--echo # failed in compare_order_elements function +--echo # + +CREATE TABLE t1 (a1 int); +insert into t1 values (1),(2),(3); +SELECT rank() OVER (ORDER BY 1), ROW_NUMBER() OVER (ORDER BY (EXPORT_SET(5,'Y','N',',',4))) FROM t1; +drop table t1; + +--echo # --echo # End of 10.2 tests --echo # diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 465c6ae032c..310cf5bfd91 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -342,6 +342,22 @@ int compare_order_lists(SQL_I_List<ORDER> *part_list1, for ( ; elem1 && elem2; elem1= elem1->next, elem2= elem2->next) { int cmp; + // remove all constants as we don't need them for comparision + while(elem1 && ((*elem1->item)->real_item())->const_item()) + { + elem1= elem1->next; + continue; + } + + while(elem2 && ((*elem2->item)->real_item())->const_item()) + { + elem2= elem2->next; + continue; + } + + if (!elem1 || !elem2) + break; + if ((cmp= compare_order_elements(elem1, elem2))) return cmp; } |