diff options
author | unknown <bell@sanja.is.com.ua> | 2004-01-17 13:13:48 +0200 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2004-01-17 13:13:48 +0200 |
commit | fb006367e5052402b57721fde082ae05e3c9db9d (patch) | |
tree | bd13fb064a3a0fcc08e582e6ffba928760cc73ed | |
parent | 2de832dbf99a8796b081419a29cacbeb07cd3871 (diff) | |
parent | 19fe657f4edf5e7f08a91e2c8e20a194ca4f204b (diff) | |
download | mariadb-git-fb006367e5052402b57721fde082ae05e3c9db9d.tar.gz |
merge
sql/mysql_priv.h:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_help.cc:
Auto merged
sql/sql_select.cc:
Auto merged
-rw-r--r-- | mysql-test/r/subselect_innodb.result | 17 | ||||
-rw-r--r-- | mysql-test/t/subselect_innodb.test | 11 | ||||
-rw-r--r-- | sql/mysql_priv.h | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 27 | ||||
-rw-r--r-- | sql/sql_class.cc | 2 | ||||
-rw-r--r-- | sql/sql_help.cc | 2 | ||||
-rw-r--r-- | sql/sql_insert.cc | 4 | ||||
-rw-r--r-- | sql/sql_lex.cc | 5 | ||||
-rw-r--r-- | sql/sql_load.cc | 2 | ||||
-rw-r--r-- | sql/sql_olap.cc | 2 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 4 | ||||
-rw-r--r-- | sql/sql_update.cc | 2 |
13 files changed, 57 insertions, 25 deletions
diff --git a/mysql-test/r/subselect_innodb.result b/mysql-test/r/subselect_innodb.result index e3528e06546..b2a055fa72c 100644 --- a/mysql-test/r/subselect_innodb.result +++ b/mysql-test/r/subselect_innodb.result @@ -60,8 +60,8 @@ 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; 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 -2 1 -3 1 +2 2 +3 3 drop table t1,t2,t3; CREATE TABLE t1 ( id int(11) NOT NULL default '0', @@ -83,3 +83,16 @@ select (select max(id) from t2 where b=1 group by b) as x,b from t1 where b=1; x b 2 1 drop table t1,t2; +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; diff --git a/mysql-test/t/subselect_innodb.test b/mysql-test/t/subselect_innodb.test index affa6301db4..8e8d41f7653 100644 --- a/mysql-test/t/subselect_innodb.test +++ b/mysql-test/t/subselect_innodb.test @@ -90,3 +90,14 @@ CREATE TABLE t2 ( INSERT INTO t2 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL'); select (select max(id) from t2 where b=1 group by b) as x,b from t1 where b=1; drop table t1,t2; + +# +# reiniting innodb tables +# +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; +select t2.id,t2.value,(select t1.value from t1 where t1.id=t2.id) from t2; +drop table t1,t2; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index a277e06301b..4da5381abf1 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -665,7 +665,7 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table, bool insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, const char *table_name, 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, List<Item> *sum_func_list, uint wild_num); int setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables, diff --git a/sql/sql_base.cc b/sql/sql_base.cc index d7984213fd6..3125c392751 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2039,15 +2039,28 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, /* - Remap table numbers if INSERT ... SELECT - Check also that the 'used keys' and 'ignored keys' exists and set up the - table structure accordingly + prepare tables - This has to be called for all tables that are used by items, as otherwise - table->map is not set and all Item_field will be regarded as const items. + 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 + Check also that the 'used keys' and 'ignored keys' exists and set up the + table structure accordingly + + This has to be called for all tables that are used by items, as otherwise + 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"); uint tablenr=0; @@ -2074,7 +2087,7 @@ bool setup_tables(TABLE_LIST *tables) table->keys_in_use_for_query.subtract(map); } 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; /* Clear query_id that may have been set by previous select */ diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 696744953dc..ce30c6f3d09 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1026,7 +1026,7 @@ bool select_singlerow_subselect::send_data(List<Item> &items) Item_singlerow_subselect *it= (Item_singlerow_subselect *)item; if (it->assigned()) { - my_message(ER_SUBQUERY_NO_1_ROW, ER(ER_SUBQUERY_NO_1_ROW), MYF(0)); + my_message(ER_SUBQUERY_NO_1_ROW, ER(ER_SUBQUERY_NO_1_ROW), MYF(0)); DBUG_RETURN(1); } if (unit->offset_limit_cnt) diff --git a/sql/sql_help.cc b/sql/sql_help.cc index d5516fe3337..3c98b7b0bb4 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -686,7 +686,7 @@ int mysqld_help(THD *thd, const char *mask) goto end; } /* 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)); if (init_fields(thd, tables, used_fields, array_elements(used_fields))) { diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index e23e62fb714..c2f3e737daf 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -84,7 +84,7 @@ check_insert_fields(THD *thd,TABLE *table,List<Item> &fields, table_list.grant=table->grant; 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)) return -1; if (thd->dupp_field) @@ -204,7 +204,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list, } 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) || (duplic == DUP_UPDATE && (setup_fields(thd, 0, insert_table_list, update_fields, 0, 0, 0) || diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index de0d6ade618..efb0ce92ad0 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1222,11 +1222,6 @@ void st_select_lex::mark_as_dependent(SELECT_LEX *last) s->uncacheable|= UNCACHEABLE_DEPENDENT; SELECT_LEX_UNIT *munit= s->master_unit(); 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; } } diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 0c35e99ed08..175791ef31e 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -123,7 +123,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, else { // Part field list 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)) DBUG_RETURN(-1); if (thd->dupp_field) diff --git a/sql/sql_olap.cc b/sql/sql_olap.cc index ef7bf013be8..1d16771c1a4 100644 --- a/sql/sql_olap.cc +++ b/sql/sql_olap.cc @@ -164,7 +164,7 @@ int handle_olaps(LEX *lex, SELECT_LEX *select_lex) 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, select_lex->item_list, 1, &all_fields,1) || setup_fields(lex->thd, 0, (TABLE_LIST *)select_lex->table_list.first, diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 5d6ab165641..0a565c00ba7 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -679,7 +679,7 @@ static bool mysql_test_upd_fields(Prepared_statement *stmt, #endif if (open_and_lock_tables(thd, table_list)) 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_conds(thd, table_list, &conds) || thd->net.report_error) DBUG_RETURN(1); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3f9492f1d72..5c632e686db 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -301,7 +301,7 @@ JOIN::prepare(Item ***rref_pointer_array, /* 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) || select_lex->setup_ref_array(thd, og_num) || setup_fields(thd, (*rref_pointer_array), tables_list, fields_list, 1, @@ -1015,7 +1015,7 @@ JOIN::reinit() if (unit->select_limit_cnt == HA_POS_ERROR) select_lex->options&= ~OPTION_FOUND_ROWS; - if (setup_tables(tables_list)) + if (setup_tables(tables_list, 1)) DBUG_RETURN(1); /* Reset of sum functions */ diff --git a/sql/sql_update.cc b/sql/sql_update.cc index cdea32ad3f6..9fc8d482bfa 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -95,7 +95,7 @@ int mysql_update(THD *thd, tables.table= table; 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) || thd->lex->select_lex.setup_ref_array(thd, order_num) || setup_order(thd, thd->lex->select_lex.ref_pointer_array, |