From c583de95f8cf7d685e893ae4298c032cb1077078 Mon Sep 17 00:00:00 2001 From: "ramil@mysql.com" <> Date: Thu, 18 May 2006 17:10:58 +0500 Subject: [PATCH 1/3] Fix for bug #15558: truncate doesn't clear table on archive storage engine tables. --- mysql-test/r/archive.result | 2 ++ mysql-test/t/archive.test | 2 ++ sql/examples/ha_archive.cc | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result index 246e96bf993..2626b439059 100644 --- a/mysql-test/r/archive.result +++ b/mysql-test/r/archive.result @@ -2616,6 +2616,7 @@ select count(*) from t4; count(*) 1203 DELETE FROM t2; +ERROR HY000: Table storage engine for 't2' doesn't have this option SELECT * FROM t2; auto fld1 companynr fld3 fld4 fld5 fld6 1 000001 00 Omaha teethe neat @@ -5033,6 +5034,7 @@ auto fld1 companynr fld3 fld4 fld5 fld6 3 011402 37 Romans scholastics jarring 4 011403 37 intercepted audiology tinily TRUNCATE TABLE t2; +ERROR HY000: Table storage engine for 't2' doesn't have this option SELECT * FROM t2; auto fld1 companynr fld3 fld4 fld5 fld6 1 000001 00 Omaha teethe neat diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test index f10ff0f648e..7b3ee45de5f 100644 --- a/mysql-test/t/archive.test +++ b/mysql-test/t/archive.test @@ -1316,12 +1316,14 @@ select count(*) from t4; # # For bug #12836 # Delete was allowing all rows to be removed +--error 1031 DELETE FROM t2; SELECT * FROM t2; INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W'); INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring',''); INSERT INTO t2 VALUES (4,011403,37,'intercepted','audiology','tinily',''); SELECT * FROM t2; +--error 1031 TRUNCATE TABLE t2; SELECT * FROM t2; diff --git a/sql/examples/ha_archive.cc b/sql/examples/ha_archive.cc index ee4cad25460..55fc359348f 100644 --- a/sql/examples/ha_archive.cc +++ b/sql/examples/ha_archive.cc @@ -1010,6 +1010,6 @@ ha_rows ha_archive::records_in_range(uint inx, key_range *min_key, int ha_archive::delete_all_rows() { DBUG_ENTER("ha_archive::delete_all_rows"); - DBUG_RETURN(0); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); } #endif /* HAVE_ARCHIVE_DB */ From 0bdae38efbf4696739e116c8fcc1f876b3ecc7fc Mon Sep 17 00:00:00 2001 From: "ramil@mysql.com" <> Date: Wed, 7 Jun 2006 14:01:10 +0500 Subject: [PATCH 2/3] Fix for bug #6880: LAST_INSERT_ID() within a statement --- mysql-test/r/auto_increment.result | 22 ++++++++++++++++++++++ mysql-test/r/rpl_log.result | 17 +++++++++++++++++ mysql-test/t/auto_increment.test | 17 +++++++++++++++++ mysql-test/t/rpl_log.test | 14 ++++++++++++++ sql/item_func.cc | 7 ++++--- 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result index 426f20212c3..c1b7b753bd4 100644 --- a/mysql-test/r/auto_increment.result +++ b/mysql-test/r/auto_increment.result @@ -378,4 +378,26 @@ t1 CREATE TABLE `t1` ( KEY `t1_name` (`t1_name`) ) ENGINE=MyISAM AUTO_INCREMENT=1003 DEFAULT CHARSET=latin1 DROP TABLE `t1`; +create table t1(a int not null auto_increment primary key); +create table t2(a int not null auto_increment primary key, t1a int); +insert into t1 values(NULL); +insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()); +insert into t1 values (NULL); +insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()), +(NULL, LAST_INSERT_ID()); +insert into t1 values (NULL); +insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()), +(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()); +select * from t2; +a t1a +1 1 +2 1 +3 2 +4 2 +5 2 +6 3 +7 3 +8 3 +9 3 +drop table t1, t2; End of 4.1 tests diff --git a/mysql-test/r/rpl_log.result b/mysql-test/r/rpl_log.result index 9fcab2a7cbe..3833800bfeb 100644 --- a/mysql-test/r/rpl_log.result +++ b/mysql-test/r/rpl_log.result @@ -99,3 +99,20 @@ Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File # 127.0.0.1 root MASTER_PORT 1 master-bin.000002 276 slave-relay-bin.000003 214 master-bin.000002 Yes Yes 0 0 276 214 None 0 No # show binlog events in 'slave-bin.000005' from 4; ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Could not find target log +create table t1(a int auto_increment primary key, b int); +insert into t1 values (NULL, 1); +reset master; +set insert_id=5; +insert into t1 values (NULL, last_insert_id()), (NULL, last_insert_id()); +show binlog events; +Log_name Pos Event_type Server_id Orig_log_pos Info +slave-bin.000001 4 Start 2 4 Server ver: VERSION, Binlog ver: 3 +slave-bin.000001 79 Intvar 2 79 LAST_INSERT_ID=1 +slave-bin.000001 107 Intvar 2 107 INSERT_ID=5 +slave-bin.000001 135 Query 2 135 use `test`; insert into t1 values (NULL, last_insert_id()), (NULL, last_insert_id()) +select * from t1; +a b +1 1 +5 1 +6 1 +drop table t1; diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index eed2ea44d05..37b92b32bfb 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -238,4 +238,21 @@ SHOW CREATE TABLE `t1`; DROP TABLE `t1`; +# +# Bug #6880: LAST_INSERT_ID() within a statement +# + +create table t1(a int not null auto_increment primary key); +create table t2(a int not null auto_increment primary key, t1a int); +insert into t1 values(NULL); +insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()); +insert into t1 values (NULL); +insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()), +(NULL, LAST_INSERT_ID()); +insert into t1 values (NULL); +insert into t2 values (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()), +(NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID()); +select * from t2; +drop table t1, t2; + --echo End of 4.1 tests diff --git a/mysql-test/t/rpl_log.test b/mysql-test/t/rpl_log.test index 7a67ab2311a..08aa3b28850 100644 --- a/mysql-test/t/rpl_log.test +++ b/mysql-test/t/rpl_log.test @@ -108,4 +108,18 @@ show slave status; --error 1220 show binlog events in 'slave-bin.000005' from 4; +# +# Bug #6880: LAST_INSERT_ID() within a statement +# + +create table t1(a int auto_increment primary key, b int); +insert into t1 values (NULL, 1); +reset master; +set insert_id=5; +insert into t1 values (NULL, last_insert_id()), (NULL, last_insert_id()); +--replace_result $VERSION VERSION +show binlog events; +select * from t1; +drop table t1; + # End of 4.1 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index 66300d129d4..91ccef6511f 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2233,15 +2233,16 @@ longlong Item_func_release_lock::val_int() longlong Item_func_last_insert_id::val_int() { DBUG_ASSERT(fixed == 1); + THD* thd= current_thd; if (arg_count) { longlong value=args[0]->val_int(); - current_thd->insert_id(value); + thd->insert_id(value); null_value=args[0]->null_value; } else - current_thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT); - return current_thd->insert_id(); + thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT); + return thd->last_insert_id_used ? thd->current_insert_id : thd->insert_id(); } /* This function is just used to test speed of different functions */ From 47bb56997910d9c580e5b49c8db92489380fd4bf Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Mon, 12 Jun 2006 15:35:47 +0200 Subject: [PATCH 3/3] Added order by --- mysql-test/r/ndb_lock.result | 8 ++++---- mysql-test/t/ndb_lock.test | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/ndb_lock.result b/mysql-test/r/ndb_lock.result index 281b02b8228..875dcd775e6 100644 --- a/mysql-test/r/ndb_lock.result +++ b/mysql-test/r/ndb_lock.result @@ -78,10 +78,10 @@ ERROR HY000: Lock wait timeout exceeded; try restarting transaction rollback; commit; begin; -select * from t1 where y = 'one' or y = 'three' for update; +select * from t1 where y = 'one' or y = 'three' order by x for update; x y z -3 three 3 1 one 1 +3 three 3 begin; select * from t1 where x = 2 for update; x y z @@ -118,10 +118,10 @@ ERROR HY000: Lock wait timeout exceeded; try restarting transaction rollback; commit; begin; -select * from t1 where y = 'one' or y = 'three' lock in share mode; +select * from t1 where y = 'one' or y = 'three' order by x lock in share mode; x y z -3 three 3 1 one 1 +3 three 3 begin; select * from t1 where y = 'one' lock in share mode; x y z diff --git a/mysql-test/t/ndb_lock.test b/mysql-test/t/ndb_lock.test index db42b7ec2dd..e8f7c57ac96 100644 --- a/mysql-test/t/ndb_lock.test +++ b/mysql-test/t/ndb_lock.test @@ -93,7 +93,7 @@ commit; # table scan connection con1; begin; -select * from t1 where y = 'one' or y = 'three' for update; +select * from t1 where y = 'one' or y = 'three' order by x for update; connection con2; begin; @@ -145,7 +145,7 @@ commit; # table scan connection con1; begin; -select * from t1 where y = 'one' or y = 'three' lock in share mode; +select * from t1 where y = 'one' or y = 'three' order by x lock in share mode; connection con2; begin;