From: Date: July 14 2005 12:39am Subject: bk commit into 5.0 tree (bell:1.1923) BUG#9597 List-Archive: http://lists.mysql.com/internals/27035 X-Bug: 9597 Message-Id: <20050713223945.1A325455F1E@sanja.is.com.ua> Below is the list of changes that have just been committed into a local 5.0 repository of bell. When bell does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.1923 05/07/14 01:39:38 bell@stripped +3 -0 take into account table lock mode when opening table: try to find most suitable table, to avouid pickup table with too low locking mode or occupy table with write mode for select when it will be need for update later (BUG#9597) sql/sql_base.cc 1.268 05/07/14 01:39:34 bell@stripped +35 -3 take into account table lock mode when opening table: try to find most suitable table, to avouid pickup table with too low locking mode or occupy table with write mode for select when it will be need for update later mysql-test/t/view.test 1.85 05/07/14 01:39:34 bell@stripped +18 -1 opening table in correct locking mode test mysql-test/r/view.result 1.90 05/07/14 01:39:34 bell@stripped +14 -0 opening table in correct locking mode test # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: bell # Host: sanja.is.com.ua # Root: /home/bell/mysql/bk/work-bug4-5.0 --- 1.267/sql/sql_base.cc 2005-07-13 12:57:01 +03:00 +++ 1.268/sql/sql_base.cc 2005-07-14 01:39:34 +03:00 @@ -1041,6 +1041,7 @@ if (thd->locked_tables || thd->prelocked_mode) { // Using table locks + TABLE *suitable_table= 0; for (table=thd->open_tables; table ; table=table->next) { if (table->s->key_length == key_length && @@ -1049,10 +1050,41 @@ table->query_id != thd->query_id && /* skip tables already used by this query */ !(thd->prelocked_mode && table->query_id)) { - table->query_id= thd->query_id; - DBUG_PRINT("info",("Using locked table")); - goto reset; + if (table->reginfo.lock_type > table_list->lock_type) + { + /* + this table have higher lock type then table we looking for, + so remember it if we do not find better we will use this one. + (if we do not find yet some other suitable table with lower + lock_type, but still suitable for using) + */ + if (!suitable_table || + suitable_table->reginfo.lock_type > table->reginfo.lock_type) + suitable_table= table; + continue; + } + if (table->reginfo.lock_type < table_list->lock_type) + { + /* + this table have not lock_type we require, but if we do not + find something better we will use it just to issue error about + bad lock mode + */ + if (!suitable_table) + suitable_table= table; + continue; + } + /* exact match, we can stop finding process */ + suitable_table= table; + break; } + } + if (suitable_table) + { + table= suitable_table; + table->query_id= thd->query_id; + DBUG_PRINT("info",("Using locked table")); + goto reset; } /* is it view? --- 1.89/mysql-test/r/view.result 2005-07-13 01:58:11 +03:00 +++ 1.90/mysql-test/r/view.result 2005-07-14 01:39:34 +03:00 @@ -1977,3 +1977,17 @@ B DROP VIEW v1; DROP TABLE t1; +CREATE TABLE t1 ( bug_table_seq INTEGER NOT NULL); +CREATE OR REPLACE VIEW v1 AS SELECT * from t1; +DROP PROCEDURE IF EXISTS p1; +Warnings: +Note 1305 PROCEDURE p1 does not exist +CREATE PROCEDURE p1 ( ) +BEGIN +DO (SELECT @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1); +INSERT INTO t1 VALUES (1); +END // +CALL p1(); +DROP PROCEDURE p1; +DROP VIEW v1; +DROP TABLE t1; --- 1.84/mysql-test/t/view.test 2005-07-13 01:58:11 +03:00 +++ 1.85/mysql-test/t/view.test 2005-07-14 01:39:34 +03:00 @@ -1804,7 +1804,6 @@ # # Test for bug #11771: wrong query_id in SELECT * FROM # - CREATE TABLE t1 (f1 char) ENGINE = innodb; INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; @@ -1813,5 +1812,23 @@ SELECT * FROM v1; SELECT * FROM t1; +DROP VIEW v1; +DROP TABLE t1; + +# +# opening table in correct locking mode (BUG#9597) +# +CREATE TABLE t1 ( bug_table_seq INTEGER NOT NULL); +CREATE OR REPLACE VIEW v1 AS SELECT * from t1; +DROP PROCEDURE IF EXISTS p1; +delimiter //; +CREATE PROCEDURE p1 ( ) +BEGIN + DO (SELECT @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1); + INSERT INTO t1 VALUES (1); +END // +delimiter ;// +CALL p1(); +DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1;