[Commits] 92d2a8a3d7b: MDEV-15837: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM'
revision-id: 92d2a8a3d7b2b1530b53fe2a2d1d5ac3e6506d34 (mariadb-10.2.5-613-g92d2a8a3d7b) parent(s): f033fbd9f2366619c52186a1a902066495539141 author: Varun Gupta committer: Varun Gupta timestamp: 2018-04-25 19:43:25 +0530 message: MDEV-15837: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM' failed in compare_order_elements function The issue here is the function compare_order_lists() is called for the order by list of the window functions so that those window function that can be computed together are adjacent. So in the function compare_order_list we iterate over all the elements in the order list of the two functions and compare the items in their order by clause. The function compare_order_elements() is called for each item in the order by clause. This function assumes that all the items that are in the order by list would be of the type Item::FIELD_ITEM. The case we have is that we have constants in the order by clause. We should ignore the constant and only compare items of the type Item::FIELD_ITEM in compare_order_elements() --- mysql-test/r/win.result | 12 ++++++++++++ mysql-test/t/win.test | 9 +++++++++ sql/sql_window.cc | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index e3cb40e8343..8c6e3d79e80 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3299,3 +3299,15 @@ ROW_NUMBER() OVER() i SELECT ROW_NUMBER() OVER(), i FROM t1 WHERE 0; ROW_NUMBER() OVER() i 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 2 +1 1 +1 3 +drop table t1; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 95ffb6d9909..6422ebc5d4b 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2067,3 +2067,12 @@ SELECT DISTINCT ROW_NUMBER() OVER(), i FROM t1 WHERE 0; SELECT ROW_NUMBER() OVER(), i FROM t1 WHERE 0; 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; diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 4e1e64365ae..e556d75442f 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; }
participants (1)
-
varunraiko1803@gmail.com