diff options
Diffstat (limited to 'sql/item.cc')
-rw-r--r-- | sql/item.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sql/item.cc b/sql/item.cc index 6d5855cd0ca..a091552aa34 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5260,7 +5260,7 @@ Item_result item_cmp_type(Item_result a,Item_result b) void resolve_const_item(THD *thd, Item **ref, Item *comp_item) { Item *item= *ref; - Item *new_item; + Item *new_item= NULL; if (item->basic_const_item()) return; // Can't be better Item_result res_type=item_cmp_type(comp_item->result_type(), @@ -5293,7 +5293,16 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item) break; } case ROW_RESULT: + if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM) { + /* + Substitute constants only in Item_rows. Don't affect other Items + with ROW_RESULT (eg Item_singlerow_subselect). + + For such Items more optimal is to detect if it is constant and replace + it with Item_row. This would optimize queries like this: + SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1); + */ Item_row *item_row= (Item_row*) item; Item_row *comp_item_row= (Item_row*) comp_item; uint col; @@ -5311,6 +5320,7 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item) resolve_const_item(thd, item_row->addr(col), comp_item_row->el(col)); break; } + /* Fallthrough */ case REAL_RESULT: { // It must REAL_RESULT double result= item->val_real(); |