From f486bfbbdb8eeaca11428c7822472150f11185cc Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Sat, 29 Nov 2008 15:36:17 +0200 Subject: Bug #37742: HA_EXTRA_KEYREAD flag is set when key contains only prefix of requested column When the storage engine uses secondary keys clustered with the primary key MySQL was adding the primary key parts to each secondary key. In doing so it was not checking whether the index was on full columns and this resulted in the secondary keys being added to the list of covering keys even if they have partial columns. Fixed by not adding a primary key part to the list of columns that can be used for index read of the secondary keys when the primary key part is a partial key part. --- mysql-test/r/innodb_mysql.result | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'mysql-test/r/innodb_mysql.result') diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index 2c14b1f2385..a348c63ec81 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1677,3 +1677,87 @@ select @@session.sql_log_bin, @@session.binlog_format, @@session.tx_isolation; CREATE TABLE t1 ( a INT ) ENGINE=InnoDB; INSERT INTO t1 VALUES(1); DROP TABLE t1; +CREATE TABLE foo (a int, b int, c char(10), +PRIMARY KEY (c(3)), +KEY b (b) +) engine=innodb; +CREATE TABLE foo2 (a int, b int, c char(10), +PRIMARY KEY (c), +KEY b (b) +) engine=innodb; +CREATE TABLE bar (a int, b int, c char(10), +PRIMARY KEY (c(3)), +KEY b (b) +) engine=myisam; +INSERT INTO foo VALUES +(1,2,'abcdefghij'), (2,3,''), (3,4,'klmnopqrst'), +(4,5,'uvwxyz'), (5,6,'meotnsyglt'), (4,5,'asfdewe'); +INSERT INTO bar SELECT * FROM foo; +INSERT INTO foo2 SELECT * FROM foo; +EXPLAIN SELECT c FROM bar WHERE b>2;; +id 1 +select_type SIMPLE +table bar +type ALL +possible_keys b +key NULL +key_len NULL +ref NULL +rows 6 +Extra Using where +EXPLAIN SELECT c FROM foo WHERE b>2;; +id 1 +select_type SIMPLE +table foo +type ALL +possible_keys b +key NULL +key_len NULL +ref NULL +rows 6 +Extra Using where +EXPLAIN SELECT c FROM foo2 WHERE b>2;; +id 1 +select_type SIMPLE +table foo2 +type range +possible_keys b +key b +key_len 5 +ref NULL +rows 3 +Extra Using where; Using index +EXPLAIN SELECT c FROM bar WHERE c>2;; +id 1 +select_type SIMPLE +table bar +type ALL +possible_keys PRIMARY +key NULL +key_len NULL +ref NULL +rows 6 +Extra Using where +EXPLAIN SELECT c FROM foo WHERE c>2;; +id 1 +select_type SIMPLE +table foo +type ALL +possible_keys PRIMARY +key NULL +key_len NULL +ref NULL +rows 6 +Extra Using where +EXPLAIN SELECT c FROM foo2 WHERE c>2;; +id 1 +select_type SIMPLE +table foo2 +type index +possible_keys PRIMARY +key b +key_len 5 +ref NULL +rows 6 +Extra Using where; Using index +DROP TABLE foo, bar, foo2; -- cgit v1.2.1 From dc5a0f4481e09fa7423231c154e1bb1a8f8c55d1 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Wed, 7 Jan 2009 10:11:37 -0200 Subject: Bug#41348: INSERT INTO tbl SELECT * FROM temp_tbl overwrites locking type of temp table The problem is that INSERT INTO .. SELECT FROM .. and CREATE TABLE .. SELECT FROM a temporary table could inadvertently overwrite the locking type of the temporary table. The lock type of temporary tables should be a write lock by default. The solution is to reset the lock type of temporary tables back to its default value after they are used in a statement. --- mysql-test/r/innodb_mysql.result | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'mysql-test/r/innodb_mysql.result') diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index 075b4f84f2d..a1116a78bda 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1767,4 +1767,25 @@ ref NULL rows 6 Extra Using where; Using index DROP TABLE foo, bar, foo2; +DROP TABLE IF EXISTS t1,t3,t2; +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1() RETURNS VARCHAR(250) +BEGIN +return 'hhhhhhh' ; +END| +CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20), c VARCHAR(20)) ENGINE=INNODB; +BEGIN WORK; +CREATE TEMPORARY TABLE t2 (a VARCHAR(20), b VARCHAR(20), c varchar(20)) ENGINE=INNODB; +CREATE TEMPORARY TABLE t3 LIKE t2; +INSERT INTO t1 VALUES ('a','b',NULL),('c','d',NULL),('e','f',NULL); +SET @stmt := CONCAT('INSERT INTO t2 SELECT tbl.a, tbl.b, f1()',' FROM t1 tbl'); +PREPARE stmt1 FROM @stmt; +SET @stmt := CONCAT('INSERT INTO t3', ' SELECT * FROM t2'); +PREPARE stmt3 FROM @stmt; +EXECUTE stmt1; +COMMIT; +DEALLOCATE PREPARE stmt1; +DEALLOCATE PREPARE stmt3; +DROP TABLE t1,t3,t2; +DROP FUNCTION f1; End of 5.1 tests -- cgit v1.2.1 From 577e390eceb06a6c35198d0026c11b47a3d33232 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 9 Jan 2009 08:20:32 -0200 Subject: Bug#37016: TRUNCATE TABLE removes some rows but not all The special TRUNCATE TABLE (DDL) transaction wasn't being properly rolled back if a error occurred during row by row deletion. The error can be caused by a foreign key restriction imposed by InnoDB SE and would cause the server to erroneously issue a implicit commit. The solution is to rollback the transaction if a truncation via row by row deletion fails, otherwise commit. All effects of a TRUNCATE ABLE operation are rolled back if a row by row deletion fails. --- mysql-test/r/innodb_mysql.result | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'mysql-test/r/innodb_mysql.result') diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index a1116a78bda..6fcc9415d12 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1788,4 +1788,62 @@ DEALLOCATE PREPARE stmt1; DEALLOCATE PREPARE stmt3; DROP TABLE t1,t3,t2; DROP FUNCTION f1; +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB; +CREATE TABLE t2 (id INT PRIMARY KEY, +t1_id INT, INDEX par_ind (t1_id), +FOREIGN KEY (t1_id) REFERENCES t1(id)) ENGINE=INNODB; +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (3,2); +SET AUTOCOMMIT = 0; +START TRANSACTION; +TRUNCATE TABLE t1; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`)) +SELECT * FROM t1; +id +1 +2 +COMMIT; +SELECT * FROM t1; +id +1 +2 +START TRANSACTION; +TRUNCATE TABLE t1; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`)) +SELECT * FROM t1; +id +1 +2 +ROLLBACK; +SELECT * FROM t1; +id +1 +2 +SET AUTOCOMMIT = 1; +START TRANSACTION; +SELECT * FROM t1; +id +1 +2 +COMMIT; +TRUNCATE TABLE t1; +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`)) +SELECT * FROM t1; +id +1 +2 +DELETE FROM t2 WHERE id = 3; +START TRANSACTION; +SELECT * FROM t1; +id +1 +2 +TRUNCATE TABLE t1; +ROLLBACK; +SELECT * FROM t1; +id +TRUNCATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; End of 5.1 tests -- cgit v1.2.1