From 33f3a11e2db38fad3c43ce3c1a30dc8d72bd53bd Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sun, 16 Dec 2012 16:13:17 +0200 Subject: Implemented MDEV-3941: CREATE TABLE xxx IF NOT EXISTS should not block if table exists. - Added option to check_if_table_exists() to quickly check if table exists (either SHARE or .FRM) - Extended lock_table_names() to not wait for meta data locks if CREATE IF NOT EXISTS is used. mysql-test/r/create.result: New test case mysql-test/t/create.test: New test case sql/sql_base.cc: Added option to check_if_table_exists() to quickly check if table exists (either SHARE or .FRM) Extended lock_table_names() to not wait for meta data locks if CREATE IF NOT EXISTS is used. sql/sql_base.h: Updated prototype sql/sql_db.cc: Added extra argument to call to check_if_table_exists() --- mysql-test/t/create.test | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'mysql-test/t/create.test') diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index d80127df860..c472c9f0a05 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -1996,4 +1996,25 @@ create table if not exists t1 (a int unique, b int) ignore select 1 as a, 1 as b union select 1 as a, 2 as b; select * from t1; drop table t1; + +--echo # +--echo # Checking that CREATE IF NOT EXISTS is not blocked by running SELECT --echo # + +create table t1 (a int, b int) engine=myisam; +create table t2 (a int, b int) engine=myisam; +insert into t1 values (1,1); +lock tables t1 read; +connect (user1,localhost,root,,test); +set @@lock_wait_timeout=5; +--error ER_TABLE_EXISTS_ERROR +create table if not exists t1 (a int, b int); +--error ER_TABLE_EXISTS_ERROR +create table if not exists t1 (a int, b int) select 2,2; +--error ER_TABLE_EXISTS_ERROR +create table if not exists t1 like t2; +disconnect user1; +connection default; +select * from t1; +unlock tables; +drop table t1,t2; -- cgit v1.2.1 From b31909ffbb967b147b9570af4ff7d03de6d5912c Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Sun, 16 Dec 2012 20:49:57 +0200 Subject: Removed lock wait timeout warning when using CREATE TABLE IF EXISTS mysql-test/r/create.result: Added test case to show that CREATE TABLE also is not waiting if table exists. mysql-test/t/create.test: Added test case to show that CREATE TABLE also is not waiting if table exists. sql/sql_base.cc: Clear also warnings from acquire_locks if we retry. --- mysql-test/t/create.test | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mysql-test/t/create.test') diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index c472c9f0a05..4c9592e9dab 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -2013,6 +2013,12 @@ create table if not exists t1 (a int, b int); create table if not exists t1 (a int, b int) select 2,2; --error ER_TABLE_EXISTS_ERROR create table if not exists t1 like t2; +--error ER_TABLE_EXISTS_ERROR +create table t1 (a int, b int); +--error ER_TABLE_EXISTS_ERROR +create table t1 (a int, b int) select 2,2; +--error ER_TABLE_EXISTS_ERROR +create table t1 like t2; disconnect user1; connection default; select * from t1; -- cgit v1.2.1 From 2dbce3d0896d571c7ffd631beeac4a6a902bea17 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 17 Dec 2012 22:34:56 +0200 Subject: Fixed the CREATE TABLE IF EXIST generates warnings instead of errors mysql-test/r/create.result: Updated test results mysql-test/t/create.test: Updated test sql/sql_base.cc: Use push_internal_handler/pop_internal_handler to avoid errors & warnings instead of clear_error Give a warnings instead of an error for CREATE TABLE IF EXISTS sql/sql_parse.cc: Check if we failed because of table exists (can only happen from create) sql/sql_table.cc: Check if we failed because of table exists (can only happen from create) --- mysql-test/t/create.test | 3 --- 1 file changed, 3 deletions(-) (limited to 'mysql-test/t/create.test') diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 4c9592e9dab..1fabb49138c 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -2007,11 +2007,8 @@ insert into t1 values (1,1); lock tables t1 read; connect (user1,localhost,root,,test); set @@lock_wait_timeout=5; ---error ER_TABLE_EXISTS_ERROR create table if not exists t1 (a int, b int); ---error ER_TABLE_EXISTS_ERROR create table if not exists t1 (a int, b int) select 2,2; ---error ER_TABLE_EXISTS_ERROR create table if not exists t1 like t2; --error ER_TABLE_EXISTS_ERROR create table t1 (a int, b int); -- cgit v1.2.1