[Commits] 93cb373fc9d: MDEV-19398: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM' failed in compare_order_elements
revision-id: 93cb373fc9dd849ce5b850a929c41d2a8e5dde5e (mariadb-10.2.26-14-g93cb373fc9d) parent(s): 3b234104ae227556f06c2c3d227e5fc51692c8fa author: Varun Gupta committer: Varun Gupta timestamp: 2019-08-12 17:36:44 +0530 message: MDEV-19398: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM' failed in compare_order_elements For Blob type fields, we change the Item_field to Item_copy_string, so use get_tmp_table_field to get the field of the temp table that belongs to the item. --- mysql-test/r/win.result | 35 +++++++++++++++++++++++++++++++++++ mysql-test/t/win.test | 35 +++++++++++++++++++++++++++++++++++ sql/item.h | 4 ++++ sql/sql_window.cc | 9 ++++++--- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 13d452f3ef2..65523f9071d 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3634,5 +3634,40 @@ rank() over (partition by 'abc' order by 'xyz') 1 drop table t1; # +# MDEV-19398: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM' +# failed in compare_order_elements +# +CREATE TABLE t1 ( a char(25), b text); +INSERT INTO t1 VALUES ('foo','bar'); +SELECT SUM(b) OVER (PARTITION BY a), ROW_NUMBER() OVER (PARTITION BY b) +FROM t1 +GROUP BY LEFT((SYSDATE()), 2) WITH ROLLUP; +SUM(b) OVER (PARTITION BY a) ROW_NUMBER() OVER (PARTITION BY b) +NULL 1 +NULL 1 +drop table t1; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1),(2),(3); +set @x:=2; +SELECT PERCENT_RANK() OVER (ORDER BY (@x:=a)), SUM(a) OVER (ORDER BY a) FROM t1 GROUP BY a ; +PERCENT_RANK() OVER (ORDER BY (@x:=a)) SUM(a) OVER (ORDER BY a) +0.0000000000 1 +0.5000000000 3 +1.0000000000 6 +drop table t1; +CREATE TABLE t1 ( a char(25), b text, c int, d int); +INSERT INTO t1 VALUES ('foo','bar', 1, 1), ('fsf','bar', 2, 2); +CREATE TABLE t2 (col1 char(25), col2 text, col3 int, col4 int); +INSERT INTO t2 VALUES ('foo','bar', 1, 1), ('fsf','bar', 2, 2); +SELECT sum(distinct c) as x, SUM(c) OVER (PARTITION BY a) as y, ROW_NUMBER() OVER (PARTITION BY b) as z +FROM t1,t2 +GROUP BY d,col4; +x y z +1 NULL 3 +1 NULL 2 +2 NULL 4 +2 NULL 4 +drop table t1, t2; +# # End of 10.2 tests # diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index a4d42ce2b91..0f5de45e1dc 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2341,6 +2341,41 @@ select rank() over (partition by 'abc' order by 'xyz') from t1; select rank() over (partition by 'abc' order by 'xyz') from t1; drop table t1; +--echo # +--echo # MDEV-19398: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM' +--echo # failed in compare_order_elements +--echo # + +CREATE TABLE t1 ( a char(25), b text); +INSERT INTO t1 VALUES ('foo','bar'); + +SELECT SUM(b) OVER (PARTITION BY a), ROW_NUMBER() OVER (PARTITION BY b) +FROM t1 +GROUP BY LEFT((SYSDATE()), 2) WITH ROLLUP; + +drop table t1; + +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1),(2),(3); + +set @x:=2; +SELECT PERCENT_RANK() OVER (ORDER BY (@x:=a)), SUM(a) OVER (ORDER BY a) FROM t1 GROUP BY a ; + +drop table t1; + +CREATE TABLE t1 ( a char(25), b text, c int, d int); +INSERT INTO t1 VALUES ('foo','bar', 1, 1), ('fsf','bar', 2, 2); + +CREATE TABLE t2 (col1 char(25), col2 text, col3 int, col4 int); +INSERT INTO t2 VALUES ('foo','bar', 1, 1), ('fsf','bar', 2, 2); + +SELECT sum(distinct c) as x, SUM(c) OVER (PARTITION BY a) as y, ROW_NUMBER() OVER (PARTITION BY b) as z +FROM t1,t2 +GROUP BY d,col4; + +drop table t1, t2; + --echo # --echo # End of 10.2 tests --echo # + diff --git a/sql/item.h b/sql/item.h index 49762d3326f..6c38993b3c4 100644 --- a/sql/item.h +++ b/sql/item.h @@ -5168,6 +5168,10 @@ class Item_copy :public Item, return (item->walk(processor, walk_subquery, args)) || (this->*processor)(args); } + Field *get_tmp_table_field() + { + return item->get_tmp_table_field(); + } }; /** diff --git a/sql/sql_window.cc b/sql/sql_window.cc index b258b8f56c9..5fe978f498f 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -318,9 +318,12 @@ int compare_order_elements(ORDER *ord1, ORDER *ord2) return CMP_EQ; Item *item1= (*ord1->item)->real_item(); Item *item2= (*ord2->item)->real_item(); - DBUG_ASSERT(item1->type() == Item::FIELD_ITEM && - item2->type() == Item::FIELD_ITEM); - ptrdiff_t cmp= ((Item_field *) item1)->field - ((Item_field *) item2)->field; + + Field *fld1= item1->get_tmp_table_field(); + Field *fld2= item2->get_tmp_table_field(); + + DBUG_ASSERT(fld1 && fld2); + ptrdiff_t cmp= fld1 - fld2; if (cmp == 0) { if (ord1->direction == ord2->direction)
participants (1)
-
Varun