summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2004-05-07 23:06:11 +0300
committerunknown <bell@sanja.is.com.ua>2004-05-07 23:06:11 +0300
commite54ca13b666b48226b7a54d6847d6437ac32ae74 (patch)
tree52e47dc7ee99268a0b704b1402fdd7b965199c80 /sql/item_subselect.cc
parentc207325aaf0cbb3781d72891c9ae95e18c6ea355 (diff)
downloadmariadb-git-e54ca13b666b48226b7a54d6847d6437ac32ae74.tar.gz
keep old engine & JOIN if we changed subquery Item (Bug #3646)
mysql-test/r/subselect.result: ALL/ANY test mysql-test/t/subselect.test: ALL/ANY test sql/item_subselect.cc: keep old engine & JOIN if we changed subquery Item, which allow avoid second all SELECT items fix_fields call with pervios clean up (because of second setup_tables which remove table->key_use and maybe something else) keep list when we change Item in SELECT list processing inserted max/min function (now JOIN::prepare will be called only once) methods of changing item for subselect engines sql/item_subselect.h: change item & results procedure sql/item_sum.cc: Item_sum_hybrid::clear moved to .cc file (to keep .h clean and to make inserving/removing debug info easy) sql/item_sum.h: Item_sum_hybrid::clear moved to .cc file (to keep .h clean and to make inserving/removing debug info easy) sql/sql_lex.cc: note about new method sql/sql_lex.h: method for changing result of UNION JOINs sql/sql_select.cc: method for changing result in JOIN sql/sql_select.h: method for changing result in JOIN sql/sql_union.cc: method for changing result in JOIN
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc107
1 files changed, 98 insertions, 9 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 2d10be62d53..4503c1b63a9 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -56,10 +56,24 @@ void Item_subselect::init(st_select_lex *select_lex,
DBUG_PRINT("subs", ("select_lex 0x%xl", (ulong) select_lex));
unit= select_lex->master_unit();
- if (select_lex->next_select())
- engine= new subselect_union_engine(unit, result, this);
+ if (unit->item)
+ {
+ /*
+ Item can be changed in JOIN::prepare while engine in JOIN::optimize
+ => we do not copy old_engine here
+ */
+ engine= unit->item->engine;
+ unit->item->engine= 0;
+ unit->item= this;
+ engine->change_item(this, result);
+ }
else
- engine= new subselect_single_select_engine(select_lex, result, this);
+ {
+ if (select_lex->next_select())
+ engine= new subselect_union_engine(unit, result, this);
+ else
+ engine= new subselect_single_select_engine(select_lex, result, this);
+ }
DBUG_VOID_RETURN;
}
@@ -69,11 +83,13 @@ void Item_subselect::cleanup()
Item_result_field::cleanup();
if (old_engine)
{
- engine->cleanup();
+ if (engine)
+ engine->cleanup();
engine= old_engine;
old_engine= 0;
}
- engine->cleanup();
+ if (engine)
+ engine->cleanup();
reset();
value_assigned= 0;
DBUG_VOID_RETURN;
@@ -127,7 +143,6 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
if (have_to_be_excluded)
engine->exclude();
substitution= 0;
- fixed= 1;
thd->where= "checking transformed subquery";
if (!(*ref)->fixed)
ret= (*ref)->fix_fields(thd, tables, ref);
@@ -660,10 +675,20 @@ Item_in_subselect::single_value_transformer(JOIN *join,
item= new Item_sum_min(*select_lex->ref_pointer_array);
}
*select_lex->ref_pointer_array= item;
- select_lex->item_list.empty();
- select_lex->item_list.push_back(item);
+ {
+ List_iterator<Item> it(select_lex->item_list);
+ it++;
+ it.replace(item);
+ }
- // fix_fields call for 'item' will be made during new subquery fix_fields
+ /*
+ Item_sum_(max|min) can't substitute other item => we can use 0 as
+ reference
+ */
+ if (item->fix_fields(thd, join->tables_list, 0))
+ goto err;
+ /* we added aggregate function => we have to change statistic */
+ count_field_types(&join->tmp_table_param, join->all_fields, 0);
subs= new Item_singlerow_subselect(select_lex);
}
@@ -1428,3 +1453,67 @@ void subselect_indexsubquery_engine::print(String *str)
}
str->append(')');
}
+
+/*
+ change select_result object of engine
+
+ SINOPSYS
+ subselect_single_select_engine::change_result()
+ si new subselect Item
+ res new select_result object
+
+ RETURN
+ 0 OK
+ -1 error
+*/
+
+int subselect_single_select_engine::change_item(Item_subselect *si,
+ select_subselect *res)
+{
+ item= si;
+ result= res;
+ return select_lex->join->change_result(result);
+}
+
+
+/*
+ change select_result object of engine
+
+ SINOPSYS
+ subselect_single_select_engine::change_result()
+ si new subselect Item
+ res new select_result object
+
+ RETURN
+ 0 OK
+ -1 error
+*/
+
+int subselect_union_engine::change_item(Item_subselect *si,
+ select_subselect *res)
+{
+ item= si;
+ int rc= unit->change_result(res, result);
+ result= res;
+ return rc;
+}
+
+
+/*
+ change select_result emulation, never should be called
+
+ SINOPSYS
+ subselect_single_select_engine::change_result()
+ si new subselect Item
+ res new select_result object
+
+ RETURN
+ -1 error
+*/
+
+int subselect_uniquesubquery_engine::change_item(Item_subselect *si,
+ select_subselect *res)
+{
+ DBUG_ASSERT(0);
+ return -1;
+}