From 1f1a61cfc41a01ffa65d568eebdc037a54b5c463 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Wed, 24 Apr 2019 00:16:56 +0530 Subject: 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() --- sql/sql_window.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'sql/sql_window.cc') 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 *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; } -- cgit v1.2.1