Skip to content

Commit 7c80937

Browse files
author
bell@sanja.is.com.ua
committed
Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-5.0
into sanja.is.com.ua:/home/bell/mysql/bk/work-update-5.0
2 parents 3d59f12 + 9d0bb74 commit 7c80937

18 files changed

+342
-155
lines changed

mysql-test/r/lock_multi.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ lock table t1 read;
2626
update t1,t2 set c=a where b=d;
2727
select c from t2;
2828
c
29-
1
29+
2
3030
drop table t1;
3131
drop table t2;
3232
create table t1 (a int);

mysql-test/r/multi_update.result

+22-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
155155
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
156156
ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
157157
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
158-
ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
159158
unlock tables;
160159
LOCK TABLES t1 write, t2 write;
161160
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
@@ -461,6 +460,7 @@ drop table t1, t2, t3;
461460
create table t1 (col1 int);
462461
create table t2 (col1 int);
463462
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
463+
ERROR HY000: You can't specify target table 't1' for update in FROM clause
464464
delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1;
465465
ERROR HY000: You can't specify target table 't1' for update in FROM clause
466466
drop table t1,t2;
@@ -490,3 +490,24 @@ insert into t2 select * from t1;
490490
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
491491
set @@storage_engine=@ttype_save;
492492
drop table t1,t2;
493+
create table t1 (a int, b int);
494+
insert into t1 values (1, 2), (2, 3), (3, 4);
495+
create table t2 (a int);
496+
insert into t2 values (10), (20), (30);
497+
create view v1 as select a as b, a/10 as a from t2;
498+
lock table t1 write;
499+
alter table t1 add column c int default 100 after a;
500+
update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a;
501+
unlock tables;
502+
select * from t1;
503+
a c b
504+
1 100 13
505+
2 100 25
506+
3 100 37
507+
select * from t2;
508+
a
509+
10
510+
20
511+
30
512+
drop view v1;
513+
drop table t1, t2;

mysql-test/r/view.result

+2-4
Original file line numberDiff line numberDiff line change
@@ -1339,16 +1339,14 @@ c
13391339
prepare stmt1 from "update v1,t1 set v1.s1=? where t1.s1=v1.s1";
13401340
set @arg='d';
13411341
execute stmt1 using @arg;
1342-
ERROR HY000: Table 't1' is read only
13431342
select * from v1;
13441343
s1
1345-
c
1344+
d
13461345
set @arg='e';
13471346
execute stmt1 using @arg;
1348-
ERROR HY000: Table 't1' is read only
13491347
select * from v1;
13501348
s1
1351-
c
1349+
e
13521350
deallocate prepare stmt1;
13531351
drop view v1;
13541352
drop table t1;

mysql-test/t/multi_update.test

+33-3
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ LOCK TABLES t1 write, t2 read;
159159
DELETE t1.*, t2.* FROM t1,t2 where t1.n=t2.n;
160160
--error 1099
161161
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
162-
--QQ This should not generate an error
163-
--error 1099
164162
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
165163
unlock tables;
166164
LOCK TABLES t1 write, t2 write;
@@ -428,7 +426,7 @@ drop table t1, t2, t3;
428426
#
429427
create table t1 (col1 int);
430428
create table t2 (col1 int);
431-
-- QQ The following should give error 1093
429+
-- error 1093
432430
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
433431
-- error 1093
434432
delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1;
@@ -479,3 +477,35 @@ delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
479477

480478
set @@storage_engine=@ttype_save;
481479
drop table t1,t2;
480+
481+
create table t1 (a int, b int);
482+
insert into t1 values (1, 2), (2, 3), (3, 4);
483+
create table t2 (a int);
484+
insert into t2 values (10), (20), (30);
485+
create view v1 as select a as b, a/10 as a from t2;
486+
487+
connect (locker,localhost,root,,test);
488+
connection locker;
489+
lock table t1 write;
490+
491+
connect (changer,localhost,root,,test);
492+
connection changer;
493+
send alter table t1 add column c int default 100 after a;
494+
495+
connect (updater,localhost,root,,test);
496+
connection updater;
497+
send update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a;
498+
499+
connection locker;
500+
sleep 2;
501+
unlock tables;
502+
503+
connection changer;
504+
reap;
505+
506+
connection updater;
507+
reap;
508+
select * from t1;
509+
select * from t2;
510+
drop view v1;
511+
drop table t1, t2;

mysql-test/t/view.test

-4
Original file line numberDiff line numberDiff line change
@@ -1300,13 +1300,9 @@ update v1,t1 set v1.s1='c' where t1.s1=v1.s1;
13001300
select * from v1;
13011301
prepare stmt1 from "update v1,t1 set v1.s1=? where t1.s1=v1.s1";
13021302
set @arg='d';
1303-
-- QQ This should not generate an error
1304-
--error 1036
13051303
execute stmt1 using @arg;
13061304
select * from v1;
13071305
set @arg='e';
1308-
-- QQ This should not generate an error
1309-
--error 1036
13101306
execute stmt1 using @arg;
13111307
select * from v1;
13121308
deallocate prepare stmt1;

sql/item.cc

+17
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ void Item::cleanup()
117117
DBUG_VOID_RETURN;
118118
}
119119

120+
121+
/*
122+
cleanup() item if it is 'fixed'
123+
124+
SYNOPSIS
125+
cleanup_processor()
126+
arg - a dummy parameter, is not used here
127+
*/
128+
129+
bool Item::cleanup_processor(byte *arg)
130+
{
131+
if (fixed)
132+
cleanup();
133+
return FALSE;
134+
}
135+
136+
120137
Item_ident::Item_ident(const char *db_name_par,const char *table_name_par,
121138
const char *field_name_par)
122139
:orig_db_name(db_name_par), orig_table_name(table_name_par),

sql/item.h

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ class Item {
283283

284284
virtual bool remove_dependence_processor(byte * arg) { return 0; }
285285
virtual bool remove_fixed(byte * arg) { fixed= 0; return 0; }
286+
virtual bool cleanup_processor(byte *arg);
286287
virtual bool collect_item_field_processor(byte * arg) { return 0; }
287288
virtual Item *equal_fields_propagator(byte * arg) { return this; }
288289
virtual Item *set_no_const_sub(byte *arg) { return this; }

sql/mysql_priv.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,11 @@ int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
565565
select_result *result);
566566
int mysql_union(THD *thd, LEX *lex, select_result *result,
567567
SELECT_LEX_UNIT *unit);
568-
int mysql_handle_derived(LEX *lex);
568+
int mysql_handle_derived(LEX *lex, int (*processor)(THD *thd,
569+
st_lex *lex,
570+
st_table_list *table));
571+
int mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
572+
int mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
569573
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
570574
Item ***copy_func, Field **from_field,
571575
bool group, bool modify_item, uint convert_blob_length);
@@ -792,7 +796,6 @@ void wait_for_refresh(THD *thd);
792796
int open_tables(THD *thd, TABLE_LIST *tables, uint *counter);
793797
int simple_open_n_lock_tables(THD *thd,TABLE_LIST *tables);
794798
int open_and_lock_tables(THD *thd,TABLE_LIST *tables);
795-
void relink_tables_for_derived(THD *thd);
796799
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter);
797800
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
798801
const char *table_name, bool link_in_list);

sql/sql_base.cc

+8-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static my_bool open_new_frm(const char *path, const char *alias,
4444
uint db_stat, uint prgflag,
4545
uint ha_open_flags, TABLE *outparam,
4646
TABLE_LIST *table_desc, MEM_ROOT *mem_root);
47+
static void relink_tables_for_multidelete(THD *thd);
4748

4849
extern "C" byte *table_cache_key(const byte *record,uint *length,
4950
my_bool not_used __attribute__((unused)))
@@ -1857,21 +1858,23 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
18571858
{
18581859
DBUG_ENTER("open_and_lock_tables");
18591860
uint counter;
1860-
if (open_tables(thd, tables, &counter) ||
1861+
if (open_tables(thd, tables, &counter) ||
18611862
lock_tables(thd, tables, counter) ||
1862-
mysql_handle_derived(thd->lex))
1863+
mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
1864+
(thd->fill_derived_tables() &&
1865+
mysql_handle_derived(thd->lex, &mysql_derived_filling)))
18631866
DBUG_RETURN(thd->net.report_error ? -1 : 1); /* purecov: inspected */
1864-
relink_tables_for_derived(thd);
1867+
relink_tables_for_multidelete(thd);
18651868
DBUG_RETURN(0);
18661869
}
18671870

18681871

18691872
/*
18701873
Let us propagate pointers to open tables from global table list
1871-
to table lists in particular selects if needed.
1874+
to table lists for multi-delete
18721875
*/
18731876

1874-
void relink_tables_for_derived(THD *thd)
1877+
static void relink_tables_for_multidelete(THD *thd)
18751878
{
18761879
if (thd->lex->all_selects_list->next_select_in_list() ||
18771880
thd->lex->time_zone_tables_used)

sql/sql_class.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,12 @@ class THD :public ilink,
11311131
{
11321132
return command == COM_PREPARE;
11331133
}
1134-
inline gptr trans_alloc(unsigned int size)
1135-
{
1134+
inline bool fill_derived_tables()
1135+
{
1136+
return !only_prepare() && !lex->only_view_structure();
1137+
}
1138+
inline gptr trans_alloc(unsigned int size)
1139+
{
11361140
return alloc_root(&transaction.mem_root,size);
11371141
}
11381142

0 commit comments

Comments
 (0)