Commit b22dc24c authored by unknown's avatar unknown

Fixed some bugs from last multi-table-update push.

More tests for multi-table-update & timestamp handling


mysql-test/r/innodb.result:
  New multi-table-update tests
mysql-test/r/multi_update.result:
  New multi-table-update tests
mysql-test/r/type_timestamp.result:
  New timestamp tests
mysql-test/t/innodb.test:
  New multi-table-update tests
mysql-test/t/multi_update.test:
  New multi-table-update tests
mysql-test/t/type_timestamp.test:
  New timestamp tests
sql/sql_select.cc:
  Fixed bug in safe mode checking
sql/sql_update.cc:
  Fixed bug in autocommit in multi-table-update
parent fdc094f5
...@@ -1021,3 +1021,18 @@ id code name ...@@ -1021,3 +1021,18 @@ id code name
7 4 Matt 7 4 Matt
COMMIT; COMMIT;
DROP TABLE t1; DROP TABLE t1;
drop table if exists t1,t2;
create table t1 (n int(10), d int(10)) type=innodb;
create table t2 (n int(10), d int(10)) type=innodb;
insert into t1 values(1,1),(1,2);
insert into t2 values(1,10),(2,20);
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
select * from t1;
n d
1 10
1 10
select * from t2;
n d
1 30
2 20
drop table t1,t2;
...@@ -166,3 +166,73 @@ n d ...@@ -166,3 +166,73 @@ n d
2 20 2 20
unlock tables; unlock tables;
drop table t1,t2; drop table t1,t2;
set sql_safe_updates=1;
create table t1 (n int(10), d int(10));
create table t2 (n int(10), d int(10));
insert into t1 values(1,1);
insert into t2 values(1,10),(2,20);
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
set sql_safe_updates=0;
drop table t1,t2;
set timestamp=1038401397;
create table t1 (n int(10) not null primary key, d int(10), t timestamp);
create table t2 (n int(10) not null primary key, d int(10), t timestamp);
insert into t1 values(1,1,NULL);
insert into t2 values(1,10,NULL),(2,20,NULL);
set timestamp=1038000000;
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
select * from t1;
n d t
1 10 20021123002000
select * from t2;
n d t
1 10 20021127154957
2 20 20021127154957
UPDATE t1,t2 SET 1=2 WHERE t1.n=t2.n;
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 '1=2 WHERE t1.n=t2.n' at line 1
drop table t1,t2;
set timestamp=0;
set sql_safe_updates=0;
create table t1 (n int(10) not null primary key, d int(10));
create table t2 (n int(10) not null primary key, d int(10));
insert into t1 values(1,1), (3,3);
insert into t2 values(1,10),(2,20);
UPDATE t2 left outer join t1 on t1.n=t2.n SET t1.d=t2.d;
select * from t1;
n d
1 10
3 3
select * from t2;
n d
1 10
2 20
drop table t1,t2;
create table t1 (n int(10), d int(10));
create table t2 (n int(10), d int(10));
insert into t1 values(1,1),(1,2);
insert into t2 values(1,10),(2,20);
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
select * from t1;
n d
1 10
1 10
select * from t2;
n d
1 30
2 20
drop table t1,t2;
create table t1 (n int(10), d int(10));
create table t2 (n int(10), d int(10));
insert into t1 values(1,1),(3,2);
insert into t2 values(1,10),(1,20);
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
select * from t1;
n d
1 10
3 2
select * from t2;
n d
1 30
1 30
drop table t1,t2;
drop table if exists t1; drop table if exists t1,t2;
CREATE TABLE t1 ( t timestamp); CREATE TABLE t1 (a int, t timestamp);
CREATE TABLE t2 (a int, t datetime);
SET TIMESTAMP=1234; SET TIMESTAMP=1234;
insert into t1 values(NULL); insert into t1 values(1,NULL);
insert into t1 values(2,"2002-03-03");
SET TIMESTAMP=1235;
insert into t1 values(3,NULL);
SET TIMESTAMP=1236;
insert into t1 (a) values(4);
insert into t2 values(5,"2002-03-04"),(6,NULL),(7,"2002-03-05"),(8,"00-00-00");
SET TIMESTAMP=1237;
insert into t1 select * from t2;
SET TIMESTAMP=1238;
insert into t1 (a) select a+1 from t2 where a=8;
select * from t1; select * from t1;
t a t
19700101032034 1 19700101032034
drop table t1; 2 20020303000000
3 19700101032035
4 19700101032036
5 20020304000000
6 19700101032037
7 20020305000000
8 00000000000000
9 19700101032038
drop table t1,t2;
SET TIMESTAMP=1234;
CREATE TABLE t1 (value TEXT NOT NULL, id VARCHAR(32) NOT NULL, stamp timestamp, PRIMARY KEY (id)); CREATE TABLE t1 (value TEXT NOT NULL, id VARCHAR(32) NOT NULL, stamp timestamp, PRIMARY KEY (id));
INSERT INTO t1 VALUES ("my value", "myKey","1999-04-02 00:00:00"); INSERT INTO t1 VALUES ("my value", "myKey","1999-04-02 00:00:00");
SELECT stamp FROM t1 WHERE id="myKey"; SELECT stamp FROM t1 WHERE id="myKey";
......
...@@ -660,3 +660,16 @@ insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt'); ...@@ -660,3 +660,16 @@ insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
select id, code, name from t1 order by id; select id, code, name from t1 order by id;
COMMIT; COMMIT;
DROP TABLE t1; DROP TABLE t1;
#
# Test of multi-table-update
#
drop table if exists t1,t2;
create table t1 (n int(10), d int(10)) type=innodb;
create table t2 (n int(10), d int(10)) type=innodb;
insert into t1 values(1,1),(1,2);
insert into t2 values(1,10),(2,20);
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
select * from t1;
select * from t2;
drop table t1,t2;
# #
# Only run the test if we are using --big-test, because this test takes a # Test of update statement that uses many tables.
# long time
# #
#-- require r/big_test.require
#eval select $BIG_TEST as using_big_test;
drop table if exists t1,t2,t3; drop table if exists t1,t2,t3;
create table t1(id1 int not null auto_increment primary key, t char(12)); create table t1(id1 int not null auto_increment primary key, t char(12));
...@@ -166,3 +163,54 @@ select * from t1; ...@@ -166,3 +163,54 @@ select * from t1;
select * from t2; select * from t2;
unlock tables; unlock tables;
drop table t1,t2; drop table t1,t2;
#
# Test safe updates and timestamps
#
set sql_safe_updates=1;
create table t1 (n int(10), d int(10));
create table t2 (n int(10), d int(10));
insert into t1 values(1,1);
insert into t2 values(1,10),(2,20);
--error 1175
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
set sql_safe_updates=0;
drop table t1,t2;
set timestamp=1038401397;
create table t1 (n int(10) not null primary key, d int(10), t timestamp);
create table t2 (n int(10) not null primary key, d int(10), t timestamp);
insert into t1 values(1,1,NULL);
insert into t2 values(1,10,NULL),(2,20,NULL);
set timestamp=1038000000;
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
select * from t1;
select * from t2;
--error 1064
UPDATE t1,t2 SET 1=2 WHERE t1.n=t2.n;
drop table t1,t2;
set timestamp=0;
set sql_safe_updates=0;
create table t1 (n int(10) not null primary key, d int(10));
create table t2 (n int(10) not null primary key, d int(10));
insert into t1 values(1,1), (3,3);
insert into t2 values(1,10),(2,20);
UPDATE t2 left outer join t1 on t1.n=t2.n SET t1.d=t2.d;
select * from t1;
select * from t2;
drop table t1,t2;
create table t1 (n int(10), d int(10));
create table t2 (n int(10), d int(10));
insert into t1 values(1,1),(1,2);
insert into t2 values(1,10),(2,20);
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
select * from t1;
select * from t2;
drop table t1,t2;
create table t1 (n int(10), d int(10));
create table t2 (n int(10), d int(10));
insert into t1 values(1,1),(3,2);
insert into t2 values(1,10),(1,20);
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
select * from t1;
select * from t2;
drop table t1,t2;
...@@ -2,14 +2,25 @@ ...@@ -2,14 +2,25 @@
# Test timestamp # Test timestamp
# #
drop table if exists t1; drop table if exists t1,t2;
CREATE TABLE t1 ( t timestamp); CREATE TABLE t1 (a int, t timestamp);
CREATE TABLE t2 (a int, t datetime);
SET TIMESTAMP=1234; SET TIMESTAMP=1234;
insert into t1 values(NULL); insert into t1 values(1,NULL);
insert into t1 values(2,"2002-03-03");
SET TIMESTAMP=1235;
insert into t1 values(3,NULL);
SET TIMESTAMP=1236;
insert into t1 (a) values(4);
insert into t2 values(5,"2002-03-04"),(6,NULL),(7,"2002-03-05"),(8,"00-00-00");
SET TIMESTAMP=1237;
insert into t1 select * from t2;
SET TIMESTAMP=1238;
insert into t1 (a) select a+1 from t2 where a=8;
select * from t1; select * from t1;
drop table t1; drop table t1,t2;
SET TIMESTAMP=1234;
CREATE TABLE t1 (value TEXT NOT NULL, id VARCHAR(32) NOT NULL, stamp timestamp, PRIMARY KEY (id)); CREATE TABLE t1 (value TEXT NOT NULL, id VARCHAR(32) NOT NULL, stamp timestamp, PRIMARY KEY (id));
INSERT INTO t1 VALUES ("my value", "myKey","1999-04-02 00:00:00"); INSERT INTO t1 VALUES ("my value", "myKey","1999-04-02 00:00:00");
SELECT stamp FROM t1 WHERE id="myKey"; SELECT stamp FROM t1 WHERE id="myKey";
......
...@@ -2744,7 +2744,7 @@ bool error_if_full_join(JOIN *join) ...@@ -2744,7 +2744,7 @@ bool error_if_full_join(JOIN *join)
tab < end; tab < end;
tab++) tab++)
{ {
if (tab->type == JT_ALL && !tab->select->quick) if (tab->type == JT_ALL && (!tab->select || !tab->select->quick))
{ {
my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,MYF(0)); my_error(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,MYF(0));
return(1); return(1);
......
...@@ -832,7 +832,7 @@ bool multi_update::send_eof() ...@@ -832,7 +832,7 @@ bool multi_update::send_eof()
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query, thd->query_length,
log_delayed); log_delayed);
if (mysql_bin_log.write(&qinfo) && trans_safe) if (mysql_bin_log.write(&qinfo) && trans_safe)
local_error=1; // Rollback update local_error= 1; // Rollback update
} }
if (!log_delayed) if (!log_delayed)
thd->options|=OPTION_STATUS_NO_TRANS_UPDATE; thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
...@@ -840,7 +840,7 @@ bool multi_update::send_eof() ...@@ -840,7 +840,7 @@ bool multi_update::send_eof()
if (transactional_tables) if (transactional_tables)
{ {
if (ha_autocommit_or_rollback(thd, local_error >= 0)) if (ha_autocommit_or_rollback(thd, local_error != 0))
local_error=1; local_error=1;
} }
......
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