summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2002-11-23 19:20:04 +0200
committerunknown <bell@sanja.is.com.ua>2002-11-23 19:20:04 +0200
commit96b338f7dfd123e93d0c3bc31dca1e7c10db5c77 (patch)
tree9fe88aa9a632d93ab216559d9912707472f72580
parentf94e6e7d8e0b9310a4590f87888b1cfb6d5641ff (diff)
parentc81300691327066b954fb34116f6d1f88e0d49d6 (diff)
downloadmariadb-git-96b338f7dfd123e93d0c3bc31dca1e7c10db5c77.tar.gz
merging
sql/mysql_priv.h: Auto merged sql/sql_select.cc: Auto merged sql/sql_yacc.yy: Auto merged
-rw-r--r--mysql-test/r/subselect.result16
-rw-r--r--mysql-test/t/subselect.test13
-rw-r--r--sql/mysql_priv.h3
-rw-r--r--sql/sql_base.cc16
-rw-r--r--sql/sql_lex.cc3
-rw-r--r--sql/sql_select.cc3
-rw-r--r--sql/sql_update.cc19
-rw-r--r--sql/sql_yacc.yy5
8 files changed, 63 insertions, 15 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index c7862440bf1..8e8e404638e 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -289,3 +289,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY threadhardwarefr7 const PRIMARY,numreponse PRIMARY 7 const,const 1
2 SUBSELECT Select tables optimized away
drop table if exists threadhardwarefrtest7;
+create table t1 (a int NOT NULL, b int, primary key (a));
+create table t2 (a int NOT NULL, b int, primary key (a));
+insert into t1 values (0, 10),(1, 11),(2, 12);
+insert into t2 values (1, 21),(2, 22),(3, 23);
+select * from t1;
+a b
+0 10
+1 11
+2 12
+update t1 set b= (select b from t2 where t1.a = t2.a);
+select * from t1;
+a b
+0 NULL
+1 21
+2 22
+drop table t1, t2;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 7a507be4ed2..75ae1a74125 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -114,7 +114,6 @@ EXPLAIN SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
EXPLAIN SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
-SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
-- error 1240
SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
EXPLAIN SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1);
@@ -182,3 +181,15 @@ EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numrep
EXPLAIN SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1';
EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1');
drop table if exists threadhardwarefrtest7;
+drop table searchconthardwarefr3;
+
+#update with subselects
+create table t1 (a int NOT NULL, b int, primary key (a));
+create table t2 (a int NOT NULL, b int, primary key (a));
+insert into t1 values (0, 10),(1, 11),(2, 12);
+insert into t2 values (1, 21),(2, 22),(3, 23);
+select * from t1;
+update t1 set b= (select b from t2 where t1.a = t2.a);
+select * from t1;
+drop table t1, t2;
+
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 3ba88d493bd..a92893ca142 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -448,7 +448,8 @@ void kill_delayed_threads(void);
int mysql_delete(THD *thd, TABLE_LIST *table, COND *conds, ORDER *order,
ha_rows rows, ulong options);
int mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok=0);
-TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update);
+TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
+ bool multiopen= 0);
TABLE *open_table(THD *thd,const char *db,const char *table,const char *alias,
bool *refresh);
TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 59310fb00de..4c6192bc694 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1615,16 +1615,24 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table,
table_list->table table
*/
-TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type)
+TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type,
+ bool multiopen)
{
TABLE *table;
bool refresh;
DBUG_ENTER("open_ltable");
thd->proc_info="Opening table";
- while (!(table=open_table(thd,table_list->db,
- table_list->real_name,table_list->alias,
- &refresh)) && refresh) ;
+ if (table_list->next && multiopen)
+ {
+ while (open_tables(thd,table_list) && refresh) ;
+ table= table_list->table;
+ }
+ else
+ while (!(table= open_table(thd,table_list->db,
+ table_list->real_name,table_list->alias,
+ &refresh)) && refresh) ;
+
if (table)
{
#if defined( __WIN__) || defined(OS2)
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 286cec87424..5adc1bec539 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -149,6 +149,7 @@ LEX *lex_start(THD *thd, uchar *buf,uint length)
lex->select_lex.expr_list.empty();
lex->select_lex.ftfunc_list_alloc.empty();
lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
+ lex->select= &lex->select_lex;
lex->convert_set= (lex->thd= thd)->variables.convert_set;
lex->yacc_yyss=lex->yacc_yyvs=0;
lex->ignore_space=test(thd->sql_mode & MODE_IGNORE_SPACE);
@@ -959,6 +960,7 @@ void st_select_lex::init_query()
item_list.empty();
join= 0;
olap= UNSPECIFIED_OLAP_TYPE;
+ having_fix_field= 0;
}
void st_select_lex::init_select()
@@ -976,7 +978,6 @@ void st_select_lex::init_select()
ftfunc_list_alloc.empty();
ftfunc_list= &ftfunc_list_alloc;
linkage= UNSPECIFIED_TYPE;
- having_fix_field= 0;
}
/*
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 20b000392df..34f8108f6de 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -5698,6 +5698,9 @@ make_cond_for_table(COND *cond,table_map tables,table_map used_table)
static Item *
part_of_refkey(TABLE *table,Field *field)
{
+ if (!table->reginfo.join_tab)
+ return (Item*) 0; // field from outer non-select (UPDATE,...)
+
uint ref_parts=table->reginfo.join_tab->ref.key_parts;
if (ref_parts)
{
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index e3e0bca9856..ece2ed3df41 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -62,12 +62,18 @@ int mysql_update(THD *thd,
TABLE *table;
SQL_SELECT *select;
READ_RECORD info;
+ TABLE_LIST *update_table_list= (TABLE_LIST*)
+ thd->lex.select_lex.table_list.first;
DBUG_ENTER("mysql_update");
LINT_INIT(used_index);
LINT_INIT(timestamp_query_id);
- if (!(table = open_ltable(thd,table_list,table_list->lock_type)))
- DBUG_RETURN(-1); /* purecov: inspected */
+ table_list->lock_type= lock_type;
+ if ((open_and_lock_tables(thd, table_list)))
+ DBUG_RETURN(-1);
+ fix_tables_pointers(&thd->lex.select_lex);
+ table= table_list->table;
+
save_time_stamp=table->time_stamp;
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
thd->proc_info="init";
@@ -77,8 +83,9 @@ int mysql_update(THD *thd,
table->quick_keys=0;
want_privilege=table->grant.want_privilege;
table->grant.want_privilege=(SELECT_ACL & ~table->grant.privilege);
- if (setup_tables(table_list) || setup_conds(thd,table_list,&conds)
- || setup_ftfuncs(&thd->lex.select_lex))
+ if (setup_tables(update_table_list) ||
+ setup_conds(thd,update_table_list,&conds)
+ || setup_ftfuncs(&thd->lex.select_lex))
DBUG_RETURN(-1); /* purecov: inspected */
old_used_keys=table->used_keys; // Keys used in WHERE
@@ -94,7 +101,7 @@ int mysql_update(THD *thd,
/* Check the fields we are going to modify */
table->grant.want_privilege=want_privilege;
- if (setup_fields(thd,table_list,fields,1,0,0))
+ if (setup_fields(thd,update_table_list,fields,1,0,0))
DBUG_RETURN(-1); /* purecov: inspected */
if (table->timestamp_field)
{
@@ -107,7 +114,7 @@ int mysql_update(THD *thd,
/* Check values */
table->grant.want_privilege=(SELECT_ACL & ~table->grant.privilege);
- if (setup_fields(thd,table_list,values,0,0,0))
+ if (setup_fields(thd,update_table_list,values,0,0,0))
{
table->time_stamp=save_time_stamp; // Restore timestamp pointer
DBUG_RETURN(-1); /* purecov: inspected */
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index f2c8869b1af..e5ec86e6658 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1631,8 +1631,9 @@ select_init:
select_part2:
{
LEX *lex=Lex;
- lex->lock_option=TL_READ;
- mysql_init_select(lex);
+ if (lex->select == &lex->select_lex)
+ lex->lock_option= TL_READ; /* Only for global SELECT */
+ mysql_init_select(lex);
}
select_options select_item_list select_into select_lock_type;