Commit e5fa5585 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

removed droping field->query_id for reinitialization tables for subquery.

(BUG#2089)
parent 1c74cd9b
...@@ -60,6 +60,19 @@ INSERT INTO t2 VALUES (1,1),(2,2),(3,3); ...@@ -60,6 +60,19 @@ INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
SELECT distinct p1.processor_id, (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id) FROM t1 p1; SELECT distinct p1.processor_id, (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id) FROM t1 p1;
processor_id (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id) processor_id (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id)
1 1 1 1
2 1 2 2
3 1 3 3
drop table t1,t2,t3; drop table t1,t2,t3;
create table t1 (id int not null, value char(255), primary key(id)) engine=innodb;
create table t2 (id int not null, value char(255)) engine=innodb;
insert into t1 values (1,'a'),(2,'b');
insert into t2 values (1,'z'),(2,'x');
select t2.id,t2.value,(select t1.value from t1 where t1.id=t2.id) from t2;
id value (select t1.value from t1 where t1.id=t2.id)
1 z a
2 x b
select t2.id,t2.value,(select t1.value from t1 where t1.id=t2.id) from t2;
id value (select t1.value from t1 where t1.id=t2.id)
1 z a
2 x b
drop table t1,t2;
...@@ -664,7 +664,7 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table, ...@@ -664,7 +664,7 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
bool insert_fields(THD *thd,TABLE_LIST *tables, bool insert_fields(THD *thd,TABLE_LIST *tables,
const char *db_name, const char *table_name, const char *db_name, const char *table_name,
List_iterator<Item> *it); List_iterator<Item> *it);
bool setup_tables(TABLE_LIST *tables); bool setup_tables(TABLE_LIST *tables, my_bool reinit);
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
List<Item> *sum_func_list, uint wild_num); List<Item> *sum_func_list, uint wild_num);
int setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables, int setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables,
......
...@@ -2039,6 +2039,19 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, ...@@ -2039,6 +2039,19 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
/* /*
prepare tables
SYNOPSIS
setup_tables()
tables - tables list
reinit - true if called for table reinitialization before
subquery reexecuting
RETURN
0 ok; In this case *map will includes the choosed index
1 error
NOTE
Remap table numbers if INSERT ... SELECT Remap table numbers if INSERT ... SELECT
Check also that the 'used keys' and 'ignored keys' exists and set up the Check also that the 'used keys' and 'ignored keys' exists and set up the
table structure accordingly table structure accordingly
...@@ -2047,7 +2060,7 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, ...@@ -2047,7 +2060,7 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
table->map is not set and all Item_field will be regarded as const items. table->map is not set and all Item_field will be regarded as const items.
*/ */
bool setup_tables(TABLE_LIST *tables) bool setup_tables(TABLE_LIST *tables, my_bool reinit)
{ {
DBUG_ENTER("setup_tables"); DBUG_ENTER("setup_tables");
uint tablenr=0; uint tablenr=0;
...@@ -2074,7 +2087,7 @@ bool setup_tables(TABLE_LIST *tables) ...@@ -2074,7 +2087,7 @@ bool setup_tables(TABLE_LIST *tables)
table->keys_in_use_for_query.subtract(map); table->keys_in_use_for_query.subtract(map);
} }
table->used_keys.intersect(table->keys_in_use_for_query); table->used_keys.intersect(table->keys_in_use_for_query);
if (table_list->shared || table->clear_query_id) if ((table_list->shared || table->clear_query_id) && !reinit)
{ {
table->clear_query_id= 0; table->clear_query_id= 0;
/* Clear query_id that may have been set by previous select */ /* Clear query_id that may have been set by previous select */
......
...@@ -686,7 +686,7 @@ int mysqld_help(THD *thd, const char *mask) ...@@ -686,7 +686,7 @@ int mysqld_help(THD *thd, const char *mask)
goto end; goto end;
} }
/* Init tables and fields to be usable from items */ /* Init tables and fields to be usable from items */
setup_tables(tables); setup_tables(tables, 0);
memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields)); memcpy((char*) used_fields, (char*) init_used_fields, sizeof(used_fields));
if (init_fields(thd, tables, used_fields, array_elements(used_fields))) if (init_fields(thd, tables, used_fields, array_elements(used_fields)))
{ {
......
...@@ -84,7 +84,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields, ...@@ -84,7 +84,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
table_list.grant=table->grant; table_list.grant=table->grant;
thd->dupp_field=0; thd->dupp_field=0;
if (setup_tables(&table_list) || if (setup_tables(&table_list, 0) ||
setup_fields(thd, 0, &table_list,fields,1,0,0)) setup_fields(thd, 0, &table_list,fields,1,0,0))
return -1; return -1;
if (thd->dupp_field) if (thd->dupp_field)
...@@ -204,7 +204,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, ...@@ -204,7 +204,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
} }
if (check_insert_fields(thd,table,fields,*values,1) || if (check_insert_fields(thd,table,fields,*values,1) ||
setup_tables(insert_table_list) || setup_tables(insert_table_list, 0) ||
setup_fields(thd, 0, insert_table_list, *values, 0, 0, 0) || setup_fields(thd, 0, insert_table_list, *values, 0, 0, 0) ||
(duplic == DUP_UPDATE && (duplic == DUP_UPDATE &&
(setup_fields(thd, 0, insert_table_list, update_fields, 0, 0, 0) || (setup_fields(thd, 0, insert_table_list, update_fields, 0, 0, 0) ||
......
...@@ -1222,11 +1222,6 @@ void st_select_lex::mark_as_dependent(SELECT_LEX *last) ...@@ -1222,11 +1222,6 @@ void st_select_lex::mark_as_dependent(SELECT_LEX *last)
s->uncacheable|= UNCACHEABLE_DEPENDENT; s->uncacheable|= UNCACHEABLE_DEPENDENT;
SELECT_LEX_UNIT *munit= s->master_unit(); SELECT_LEX_UNIT *munit= s->master_unit();
munit->uncacheable|= UNCACHEABLE_DEPENDENT; munit->uncacheable|= UNCACHEABLE_DEPENDENT;
//Tables will be reopened many times
for (TABLE_LIST *tbl= s->get_table_list();
tbl;
tbl= tbl->next)
tbl->shared= 1;
} }
} }
......
...@@ -123,7 +123,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, ...@@ -123,7 +123,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
else else
{ // Part field list { // Part field list
thd->dupp_field=0; thd->dupp_field=0;
if (setup_tables(table_list) || if (setup_tables(table_list, 0) ||
setup_fields(thd, 0, table_list, fields, 1, 0, 0)) setup_fields(thd, 0, table_list, fields, 1, 0, 0))
DBUG_RETURN(-1); DBUG_RETURN(-1);
if (thd->dupp_field) if (thd->dupp_field)
......
...@@ -164,7 +164,7 @@ int handle_olaps(LEX *lex, SELECT_LEX *select_lex) ...@@ -164,7 +164,7 @@ int handle_olaps(LEX *lex, SELECT_LEX *select_lex)
List<Item> all_fields(select_lex->item_list); List<Item> all_fields(select_lex->item_list);
if (setup_tables((TABLE_LIST *)select_lex->table_list.first) || if (setup_tables((TABLE_LIST *)select_lex->table_list.first, 0) ||
setup_fields(lex->thd, 0, (TABLE_LIST *)select_lex->table_list.first, setup_fields(lex->thd, 0, (TABLE_LIST *)select_lex->table_list.first,
select_lex->item_list, 1, &all_fields,1) || select_lex->item_list, 1, &all_fields,1) ||
setup_fields(lex->thd, 0, (TABLE_LIST *)select_lex->table_list.first, setup_fields(lex->thd, 0, (TABLE_LIST *)select_lex->table_list.first,
......
...@@ -679,7 +679,7 @@ static bool mysql_test_upd_fields(Prepared_statement *stmt, ...@@ -679,7 +679,7 @@ static bool mysql_test_upd_fields(Prepared_statement *stmt,
#endif #endif
if (open_and_lock_tables(thd, table_list)) if (open_and_lock_tables(thd, table_list))
DBUG_RETURN(1); DBUG_RETURN(1);
if (setup_tables(table_list) || if (setup_tables(table_list, 0) ||
setup_fields(thd, 0, table_list, fields, 1, 0, 0) || setup_fields(thd, 0, table_list, fields, 1, 0, 0) ||
setup_conds(thd, table_list, &conds) || thd->net.report_error) setup_conds(thd, table_list, &conds) || thd->net.report_error)
DBUG_RETURN(1); DBUG_RETURN(1);
......
...@@ -301,7 +301,7 @@ JOIN::prepare(Item ***rref_pointer_array, ...@@ -301,7 +301,7 @@ JOIN::prepare(Item ***rref_pointer_array,
/* Check that all tables, fields, conds and order are ok */ /* Check that all tables, fields, conds and order are ok */
if (setup_tables(tables_list) || if (setup_tables(tables_list, 0) ||
setup_wild(thd, tables_list, fields_list, &all_fields, wild_num) || setup_wild(thd, tables_list, fields_list, &all_fields, wild_num) ||
select_lex->setup_ref_array(thd, og_num) || select_lex->setup_ref_array(thd, og_num) ||
setup_fields(thd, (*rref_pointer_array), tables_list, fields_list, 1, setup_fields(thd, (*rref_pointer_array), tables_list, fields_list, 1,
...@@ -1015,7 +1015,7 @@ JOIN::reinit() ...@@ -1015,7 +1015,7 @@ JOIN::reinit()
if (unit->select_limit_cnt == HA_POS_ERROR) if (unit->select_limit_cnt == HA_POS_ERROR)
select_lex->options&= ~OPTION_FOUND_ROWS; select_lex->options&= ~OPTION_FOUND_ROWS;
if (setup_tables(tables_list)) if (setup_tables(tables_list, 1))
DBUG_RETURN(1); DBUG_RETURN(1);
/* Reset of sum functions */ /* Reset of sum functions */
......
...@@ -95,7 +95,7 @@ int mysql_update(THD *thd, ...@@ -95,7 +95,7 @@ int mysql_update(THD *thd,
tables.table= table; tables.table= table;
tables.alias= table_list->alias; tables.alias= table_list->alias;
if (setup_tables(update_table_list) || if (setup_tables(update_table_list, 0) ||
setup_conds(thd,update_table_list,&conds) || setup_conds(thd,update_table_list,&conds) ||
thd->lex->select_lex.setup_ref_array(thd, order_num) || thd->lex->select_lex.setup_ref_array(thd, order_num) ||
setup_order(thd, thd->lex->select_lex.ref_pointer_array, setup_order(thd, thd->lex->select_lex.ref_pointer_array,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment