From a17b3dcbe3d86eaaaabe627139ed09c35828d61c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 28 Sep 2005 00:58:12 +0400 Subject: [PATCH] Fix bug#13356 resolve_const_item() wasn't able to handle Item_row items. resolve_const_item() assumed to be not called for Item_row items. For ensuring that DBUG_ASSERT(0) was set there. This patch adds section for Item_row items. If it can it recursively calls resolve_const_item() for each item the Item_row contains. If any of the contained items is null then whole Item_row substitued by Item_null. Otherwise it just returns. sql/item.cc: Fix bug#13356 resolve_const_item() wasn't able to handle Item_row items. Added section to resolve_const_item() for Item_row items. If it can it recursively calls resolve_const_item() for each item the Item_row contains. If any of the contained items is null then Item_row is substituted by Item_null. Otherwise it just returns. Comment moved closer to function it belongs to. mysql-test/t/select.test: Test case for bug#13356 resolve_const_item() wasn't able to handle Item_row items. mysql-test/r/select.result: Test case for bug#13356 resolve_const_item() wasn't able to handle Item_row items. --- mysql-test/r/select.result | 9 +++++++++ mysql-test/t/select.test | 10 ++++++++++ sql/item.cc | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 993fe7d22f1..64cbaf4fa67 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2617,3 +2617,12 @@ select found_rows(); found_rows() 1 DROP TABLE t1; +create table t1(f1 int, f2 int); +create table t2(f3 int); +select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,1)); +f1 +select f1 from t1,t2 where f1=f2 and (f1,NULL) = ((1,1)); +f1 +select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,NULL)); +f1 +drop table t1,t2; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index b51ea89c7dd..bdadd5c536b 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2164,4 +2164,14 @@ select found_rows(); DROP TABLE t1; +# +# Bug #13356 assertion failed in resolve_const_item() +# +create table t1(f1 int, f2 int); +create table t2(f3 int); +select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,1)); +select f1 from t1,t2 where f1=f2 and (f1,NULL) = ((1,1)); +select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,NULL)); +drop table t1,t2; + # End of 4.1 tests diff --git a/sql/item.cc b/sql/item.cc index 010189c321c..03ab38fc970 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2870,6 +2870,35 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item) new_item= (null_value ? (Item*) new Item_null(name) : (Item*) new Item_int(name, result, length)); } + else if (res_type == ROW_RESULT) + { + new_item= 0; + /* + If item and comp_item are both Item_rows and have same number of cols + then process items in Item_row one by one. If Item_row contain nulls + substitute it by Item_null. Otherwise just return. + */ + if (item->result_type() == comp_item->result_type() && + ((Item_row*)item)->cols() == ((Item_row*)comp_item)->cols()) + { + Item_row *item_row= (Item_row*)item,*comp_item_row= (Item_row*)comp_item; + if (item_row->null_inside()) + new_item= (Item*) new Item_null(name); + else + { + int i= item_row->cols() - 1; + for (; i >= 0; i--) + { + if (item_row->maybe_null && item_row->el(i)->is_null()) + { + new_item= (Item*) new Item_null(name); + break; + } + resolve_const_item(thd, item_row->addr(i), comp_item_row->el(i)); + } + } + } + } else { // It must REAL_RESULT double result=item->val();