Commit c3cf3d28 authored by unknown's avatar unknown

Merge


sql/sql_parse.cc:
  Auto merged
sql/sql_update.cc:
  Auto merged
sql/sql_yacc.yy:
  Auto merged
mysql-test/r/derived.result:
  SCCS merged
mysql-test/t/derived.test:
  e
  merge
parents fe21bfb6 7a1a5cd2
...@@ -303,4 +303,5 @@ ...@@ -303,4 +303,5 @@
#define ER_WARN_HOSTNAME_WONT_WORK 1284 #define ER_WARN_HOSTNAME_WONT_WORK 1284
#define ER_UNKNOWN_STORAGE_ENGINE 1285 #define ER_UNKNOWN_STORAGE_ENGINE 1285
#define ER_WARN_DEPRECATED_SYNTAX 1286 #define ER_WARN_DEPRECATED_SYNTAX 1286
#define ER_ERROR_MESSAGES 287 #define ER_NON_UPDATABLE_TABLE 1287
#define ER_ERROR_MESSAGES 288
...@@ -213,7 +213,7 @@ ERROR 42000: You have an error in your SQL syntax. Check the manual that corres ...@@ -213,7 +213,7 @@ ERROR 42000: You have an error in your SQL syntax. Check the manual that corres
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
update (select * from t1) as t1 set a = 5; update (select * from t1) as t1 set a = 5;
ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use ERROR HY000: The target table t1 of the UPDATE is not updatable.
delete from (select * from t1); delete from (select * from t1);
ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(select * from t1)' at line 1 ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(select * from t1)' at line 1
insert into (select * from t1) values (5); insert into (select * from t1) values (5);
...@@ -249,6 +249,31 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -249,6 +249,31 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DERIVED t1 ALL NULL NULL NULL NULL 2 2 DERIVED t1 ALL NULL NULL NULL NULL 2
3 UNION t1 ALL NULL NULL NULL NULL 2 3 UNION t1 ALL NULL NULL NULL NULL 2
drop table t1; drop table t1;
CREATE TABLE `t1` (
`N` int(11) unsigned NOT NULL default '0',
`M` tinyint(1) default '0',
) TYPE=MyISAM DEFAULT CHARSET=latin1;
Warnings:
Warning 1286 'TYPE=database_engine' is deprecated. Use 'ENGINE=database_engine' instead.
INSERT INTO `t1` (N, M) VALUES (1, 0),(1, 0),(1, 0),(2, 0),(2, 0),(3, 0);
UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2;
select * from t1;
N M
1 2
1 2
1 2
2 2
2 2
3 0
UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2, P2.N = 2;
ERROR HY000: The target table P2 of the UPDATE is not updatable.
delete P1.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
select * from t1;
N M
3 0
delete P1.*,P2.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
ERROR HY000: The target table P2 of the DELETE is not updatable.
drop table t1;
CREATE TABLE t1 ( CREATE TABLE t1 (
OBJECTID int(11) NOT NULL default '0', OBJECTID int(11) NOT NULL default '0',
SORTORDER int(11) NOT NULL auto_increment, SORTORDER int(11) NOT NULL auto_increment,
......
...@@ -244,7 +244,7 @@ select * from t2; ...@@ -244,7 +244,7 @@ select * from t2;
n d n d
1 30 1 30
1 30 1 30
DELETE t1, t2 FROM t1 a,t2 b where a.n=b.n; DELETE a, b FROM t1 a,t2 b where a.n=b.n;
select * from t1; select * from t1;
n d n d
3 2 3 2
......
...@@ -158,7 +158,7 @@ insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6), ...@@ -158,7 +158,7 @@ insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6),
('0','1','2',1,5), ('0','2','0',1,3), ('1','0','1',1,2), ('0','1','2',1,5), ('0','2','0',1,3), ('1','0','1',1,2),
('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4), ('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4),
('2','2','0',1,7); ('2','2','0',1,7);
delete from t1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3); delete from m1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3);
select * from t1; select * from t1;
F1 F2 F3 cnt groupid F1 F2 F3 cnt groupid
0 0 0 1 6 0 0 0 1 6
......
...@@ -116,7 +116,7 @@ select mail_id, if(folder.f_description!='', folder.f_description, folder.f_nam ...@@ -116,7 +116,7 @@ select mail_id, if(folder.f_description!='', folder.f_description, folder.f_nam
# #
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
-- error 1149 -- error 1287
update (select * from t1) as t1 set a = 5; update (select * from t1) as t1 set a = 5;
-- error 1064 -- error 1064
delete from (select * from t1); delete from (select * from t1);
...@@ -141,6 +141,24 @@ explain select * from ( select * from t1 union select * from t1) a,(select * fro ...@@ -141,6 +141,24 @@ explain select * from ( select * from t1 union select * from t1) a,(select * fro
drop table t1; drop table t1;
#
# multi-update & multi-delete with derived tables
#
CREATE TABLE `t1` (
`N` int(11) unsigned NOT NULL default '0',
`M` tinyint(1) default '0',
) TYPE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `t1` (N, M) VALUES (1, 0),(1, 0),(1, 0),(2, 0),(2, 0),(3, 0);
UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2;
select * from t1;
-- error 1287
UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2, P2.N = 2;
delete P1.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
select * from t1;
-- error 1287
delete P1.*,P2.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
drop table t1;
# #
# correct lex->current_select # correct lex->current_select
# #
......
...@@ -218,7 +218,7 @@ select * from t2; ...@@ -218,7 +218,7 @@ select * from t2;
UPDATE t1 a ,t2 b SET a.d=b.d,b.d=30 WHERE a.n=b.n; UPDATE t1 a ,t2 b SET a.d=b.d,b.d=30 WHERE a.n=b.n;
select * from t1; select * from t1;
select * from t2; select * from t2;
DELETE t1, t2 FROM t1 a,t2 b where a.n=b.n; DELETE a, b FROM t1 a,t2 b where a.n=b.n;
select * from t1; select * from t1;
select * from t2; select * from t2;
drop table t1,t2; drop table t1,t2;
......
...@@ -126,6 +126,6 @@ insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6), ...@@ -126,6 +126,6 @@ insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6),
('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4), ('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4),
('2','2','0',1,7); ('2','2','0',1,7);
delete from t1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3); delete from m1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3);
select * from t1; select * from t1;
drop table t1; drop table t1;
...@@ -299,3 +299,4 @@ character-set=latin2 ...@@ -299,3 +299,4 @@ character-set=latin2
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -293,3 +293,4 @@ character-set=latin1 ...@@ -293,3 +293,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -301,3 +301,4 @@ character-set=latin1 ...@@ -301,3 +301,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -290,3 +290,4 @@ character-set=latin1 ...@@ -290,3 +290,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -295,3 +295,4 @@ character-set=latin7 ...@@ -295,3 +295,4 @@ character-set=latin7
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -290,3 +290,4 @@ character-set=latin1 ...@@ -290,3 +290,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -302,3 +302,4 @@ character-set=latin1 ...@@ -302,3 +302,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -290,3 +290,4 @@ character-set=greek ...@@ -290,3 +290,4 @@ character-set=greek
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -292,3 +292,4 @@ character-set=latin2 ...@@ -292,3 +292,4 @@ character-set=latin2
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -290,3 +290,4 @@ character-set=latin1 ...@@ -290,3 +290,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -292,3 +292,4 @@ character-set=ujis ...@@ -292,3 +292,4 @@ character-set=ujis
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -290,3 +290,4 @@ character-set=euckr ...@@ -290,3 +290,4 @@ character-set=euckr
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -292,3 +292,4 @@ character-set=latin1 ...@@ -292,3 +292,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -292,3 +292,4 @@ character-set=latin1 ...@@ -292,3 +292,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -294,3 +294,4 @@ character-set=latin2 ...@@ -294,3 +294,4 @@ character-set=latin2
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -291,3 +291,4 @@ character-set=latin1 ...@@ -291,3 +291,4 @@ character-set=latin1
"MySQL foi inicializado em modo --skip-name-resolve. Você necesita reincializá-lo sem esta opção para este grant funcionar", "MySQL foi inicializado em modo --skip-name-resolve. Você necesita reincializá-lo sem esta opção para este grant funcionar",
"Motor de tabela desconhecido '%s'", "Motor de tabela desconhecido '%s'",
"'%s' é desatualizado. Use '%s' em seu lugar.", "'%s' é desatualizado. Use '%s' em seu lugar.",
"The target table %-.100s of the %s is not updatable.",
...@@ -294,3 +294,4 @@ character-set=latin2 ...@@ -294,3 +294,4 @@ character-set=latin2
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -292,3 +292,4 @@ character-set=koi8r ...@@ -292,3 +292,4 @@ character-set=koi8r
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
" %-.100s %s .",
...@@ -285,3 +285,4 @@ character-set=cp1250 ...@@ -285,3 +285,4 @@ character-set=cp1250
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -298,3 +298,4 @@ character-set=latin2 ...@@ -298,3 +298,4 @@ character-set=latin2
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -292,3 +292,4 @@ character-set=latin1 ...@@ -292,3 +292,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -290,3 +290,4 @@ character-set=latin1 ...@@ -290,3 +290,4 @@ character-set=latin1
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
"The target table %-.100s of the %s is not updatable.",
...@@ -295,3 +295,4 @@ character-set=koi8u ...@@ -295,3 +295,4 @@ character-set=koi8u
"MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work", "MySQL is started in --skip-name-resolve mode. You need to restart it without this switch for this grant to work",
"Unknown table engine '%s'", "Unknown table engine '%s'",
"'%s' is deprecated. Use '%s' instead.", "'%s' is deprecated. Use '%s' instead.",
" %-.100s %s .",
...@@ -2665,15 +2665,29 @@ mysql_execute_command(THD *thd) ...@@ -2665,15 +2665,29 @@ mysql_execute_command(THD *thd)
table_count++; table_count++;
/* All tables in aux_tables must be found in FROM PART */ /* All tables in aux_tables must be found in FROM PART */
TABLE_LIST *walk; TABLE_LIST *walk;
for (walk=(TABLE_LIST*) tables ; walk ; walk=walk->next) for (walk= (TABLE_LIST*) tables; walk; walk= walk->next)
{ {
if (!strcmp(auxi->real_name,walk->real_name) && if (!strcmp(auxi->real_name, walk->alias) &&
!strcmp(walk->db,auxi->db)) !strcmp(walk->db, auxi->db))
break; break;
} }
if (!walk) if (!walk)
{ {
net_printf(thd,ER_NONUNIQ_TABLE,auxi->real_name); if (lex->derived_tables)
{
// are we trying to delete derived table?
for (walk= (TABLE_LIST*) tables; walk; walk= walk->next)
{
if (!strcmp(auxi->real_name,walk->alias) &&
walk->derived)
{
net_printf(thd, ER_NON_UPDATABLE_TABLE,
auxi->real_name, "DELETE");
goto error;
}
}
}
net_printf(thd, ER_NONUNIQ_TABLE, auxi->real_name);
goto error; goto error;
} }
walk->lock_type= auxi->lock_type; walk->lock_type= auxi->lock_type;
......
...@@ -434,13 +434,36 @@ int mysql_multi_update(THD *thd, ...@@ -434,13 +434,36 @@ int mysql_multi_update(THD *thd,
fix_tables_pointers(thd->lex->all_selects_list); fix_tables_pointers(thd->lex->all_selects_list);
select_lex->select_limit= HA_POS_ERROR; select_lex->select_limit= HA_POS_ERROR;
table_map item_tables= 0, derived_tables= 0;
if (thd->lex->derived_tables)
{
// Assign table map values to check updatability of derived tables
uint tablenr=0;
for (TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
table_list;
table_list= table_list->next, tablenr++)
{
table_list->table->map= (table_map) 1 << tablenr;
}
}
if (setup_fields(thd, 0, table_list, *fields, 1, 0, 0)) if (setup_fields(thd, 0, table_list, *fields, 1, 0, 0))
DBUG_RETURN(-1); DBUG_RETURN(-1);
if (thd->lex->derived_tables)
{
// Find tables used in items
List_iterator_fast<Item> it(*fields);
Item *item;
while ((item= it++))
{
item_tables|= item->used_tables();
}
}
/* /*
Count tables and setup timestamp handling Count tables and setup timestamp handling
*/ */
for (tl= select_lex->get_table_list() ; tl ; tl=tl->next) for (tl= select_lex->get_table_list() ; tl ; tl= tl->next)
{ {
TABLE *table= tl->table; TABLE *table= tl->table;
if (table->timestamp_field) if (table->timestamp_field)
...@@ -450,6 +473,18 @@ int mysql_multi_update(THD *thd, ...@@ -450,6 +473,18 @@ int mysql_multi_update(THD *thd,
if (table->timestamp_field->query_id != thd->query_id) if (table->timestamp_field->query_id != thd->query_id)
table->time_stamp= table->timestamp_field->offset() +1; table->time_stamp= table->timestamp_field->offset() +1;
} }
if (tl->derived)
derived_tables|= table->map;
}
if (thd->lex->derived_tables && (item_tables & derived_tables))
{
// find derived table which cause error
for (tl= select_lex->get_table_list() ; tl ; tl= tl->next)
{
if (tl->derived && (item_tables & tl->table->map))
my_printf_error(ER_NON_UPDATABLE_TABLE, ER(ER_NON_UPDATABLE_TABLE),
MYF(0), tl->alias, "UPDATE");
}
} }
if (!(result=new multi_update(thd, table_list, fields, values, if (!(result=new multi_update(thd, table_list, fields, values,
......
...@@ -3155,13 +3155,6 @@ join_table: ...@@ -3155,13 +3155,6 @@ join_table:
| '(' SELECT_SYM select_derived ')' opt_table_alias | '(' SELECT_SYM select_derived ')' opt_table_alias
{ {
LEX *lex=Lex; LEX *lex=Lex;
if (lex->sql_command == SQLCOM_UPDATE &&
&lex->select_lex == lex->current_select->outer_select())
{
send_error(lex->thd, ER_SYNTAX_ERROR);
YYABORT;
}
SELECT_LEX_UNIT *unit= lex->current_select->master_unit(); SELECT_LEX_UNIT *unit= lex->current_select->master_unit();
lex->current_select= unit->outer_select(); lex->current_select= unit->outer_select();
if (!($$= lex->current_select-> if (!($$= lex->current_select->
...@@ -3838,6 +3831,13 @@ update: ...@@ -3838,6 +3831,13 @@ update:
Select->set_lock_for_tables($3); Select->set_lock_for_tables($3);
if (lex->select_lex.table_list.elements > 1) if (lex->select_lex.table_list.elements > 1)
lex->sql_command= SQLCOM_UPDATE_MULTI; lex->sql_command= SQLCOM_UPDATE_MULTI;
else if (lex->select_lex.get_table_list()->derived)
{
/* it is single table update and it is update of derived table */
net_printf(lex->thd, ER_NON_UPDATABLE_TABLE,
lex->select_lex.get_table_list()->alias, "UPDATE");
YYABORT;
}
} }
; ;
......
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