2014-01-29 14:37:17 +01:00
|
|
|
#
|
2014-03-19 14:15:57 +01:00
|
|
|
# Check CREATE OR REPLACE TABLE
|
2014-01-29 14:37:17 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
--source include/have_innodb.inc
|
2014-02-05 20:36:16 +01:00
|
|
|
--source include/have_metadata_lock_info.inc
|
2014-01-29 14:37:17 +01:00
|
|
|
--disable_warnings
|
2014-01-31 11:06:28 +01:00
|
|
|
drop table if exists t1,t2,t3;
|
2014-01-29 14:37:17 +01:00
|
|
|
--enable_warnings
|
|
|
|
|
|
|
|
#
|
|
|
|
# Create help table
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE t2 (a int);
|
|
|
|
INSERT INTO t2 VALUES(1),(2),(3);
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Check first syntax and wrong usage
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
--error ER_WRONG_USAGE
|
|
|
|
CREATE OR REPLACE TABLE IF NOT EXISTS t1 (a int);
|
|
|
|
--error ER_WRONG_USAGE
|
|
|
|
create or replace trigger trg before insert on t1 for each row set @a:=1;
|
|
|
|
|
|
|
|
# check that we don't try to create a log table in use
|
|
|
|
--error ER_BAD_LOG_STATEMENT
|
|
|
|
create or replace table mysql.general_log (a int);
|
|
|
|
--error ER_BAD_LOG_STATEMENT
|
|
|
|
create or replace table mysql.slow_log (a int);
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Usage when table doesn't exist
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
--error ER_TABLE_EXISTS_ERROR
|
|
|
|
CREATE TABLE t1 (a int);
|
|
|
|
DROP TABLE t1;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int);
|
|
|
|
--error ER_TABLE_EXISTS_ERROR
|
|
|
|
CREATE TEMPORARY TABLE t1 (a int, b int, c int);
|
|
|
|
DROP TEMPORARY TABLE t1;
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Testing with temporary tables
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int);
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int);
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
DROP TEMPORARY TABLE t1;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
# Test also with InnoDB
|
|
|
|
create temporary table t1 (i int) engine=InnoDB;
|
|
|
|
create or replace temporary table t1 (a int, b int) engine=InnoDB;
|
|
|
|
create or replace temporary table t1 (j int);
|
|
|
|
show create table t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
# Using lock tables on normal tables with create or replace on temp tables
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
LOCK TABLES t1 write;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int);
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int);
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int) engine= innodb;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int) engine= innodb;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int, b int) engine=myisam;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
DROP TEMPORARY TABLE t1;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
# Verify that table is still locked
|
|
|
|
--error ER_TABLE_NOT_LOCKED
|
|
|
|
CREATE OR REPLACE TABLE t2 (a int);
|
|
|
|
DROP TABLE t1;
|
|
|
|
UNLOCK TABLES;
|
|
|
|
|
|
|
|
#
|
|
|
|
# Using CREATE SELECT
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (a int) SELECT * from t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t1 (b int) SELECT * from t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
CREATE TEMPORARY TABLE t1 AS SELECT a FROM t2;
|
|
|
|
CREATE TEMPORARY TABLE IF NOT EXISTS t1(a int, b int) SELECT 1,2 FROM t2;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2014-01-31 11:06:28 +01:00
|
|
|
CREATE TABLE t1 (a int);
|
|
|
|
CREATE OR REPLACE TABLE t1 AS SELECT 1;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
create table t1 (a int);
|
|
|
|
--error ER_UPDATE_TABLE_USED
|
|
|
|
create or replace table t1 as select * from t1;
|
|
|
|
--error ER_UPDATE_TABLE_USED
|
|
|
|
create or replace table t1 as select a from (select a from t1) as t3;
|
|
|
|
--error ER_UPDATE_TABLE_USED
|
|
|
|
create or replace table t1 as select a from t2 where t2.a in (select a from t1);
|
|
|
|
drop table t1;
|
2014-01-29 14:37:17 +01:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Testing with normal tables
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int, b int);
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
CREATE TABLE t1 (a int) SELECT * from t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
TRUNCATE TABLE t1;
|
|
|
|
CREATE TABLE IF NOT EXISTS t1 (a int) SELECT * from t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
CREATE TABLE t1 (i int);
|
|
|
|
CREATE OR REPLACE TABLE t1 AS SELECT 1;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
# Using lock tables with CREATE OR REPLACE
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
LOCK TABLES t1 write,t2 write;
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int, b int);
|
|
|
|
# Verify if table is still locked
|
|
|
|
SELECT * FROM t1;
|
|
|
|
INSERT INTO t1 values(1,1);
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int, b int, c int);
|
|
|
|
INSERT INTO t1 values(1,1,1);
|
|
|
|
--error ER_TABLE_NOT_LOCKED
|
|
|
|
CREATE OR REPLACE TABLE t3 (a int);
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
# Using lock tables with CREATE OR REPLACE ... SELECT
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
LOCK TABLES t1 write,t2 write;
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int, b int) select a,1 from t2;
|
|
|
|
# Verify if table is still locked
|
|
|
|
SELECT * FROM t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
INSERT INTO t1 values(1,1,1);
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int, b int, c int, d int);
|
|
|
|
INSERT INTO t1 values(1,1,1,1);
|
|
|
|
--error ER_TABLE_NOT_LOCKED
|
|
|
|
CREATE OR REPLACE TABLE t3 (a int);
|
|
|
|
UNLOCK TABLES;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
LOCK TABLES t1 write,t2 write, t1 as t1_read read;
|
|
|
|
CREATE OR REPLACE TABLE t1 (a int, b int) select a,1 from t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
SELECT * FROM t2;
|
|
|
|
--error ER_TABLE_NOT_LOCKED
|
|
|
|
SELECT * FROM t1 as t1_read;
|
|
|
|
DROP TABLE t1;
|
|
|
|
UNLOCK TABLES;
|
|
|
|
|
2014-01-31 11:06:28 +01:00
|
|
|
CREATE OR REPLACE TABLE t1 (a int);
|
|
|
|
LOCK TABLE t1 WRITE;
|
|
|
|
CREATE OR REPLACE TABLE t1 AS SELECT 1;
|
|
|
|
SELECT * from t1;
|
|
|
|
--error ER_TABLE_NOT_LOCKED
|
|
|
|
SELECT * from t2;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2014-01-29 14:37:17 +01:00
|
|
|
--echo #
|
|
|
|
--echo # Test also with InnoDB (transactional engine)
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
create table t1 (i int) engine=innodb;
|
|
|
|
lock table t1 write;
|
|
|
|
create or replace table t1 (j int);
|
|
|
|
unlock tables;
|
|
|
|
show create table t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
create table t1 (i int) engine=InnoDB;
|
|
|
|
lock table t1 write, t2 write;
|
|
|
|
create or replace table t1 (j int) engine=innodb;
|
|
|
|
unlock tables;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
create table t1 (i int) engine=InnoDB;
|
|
|
|
create table t3 (i int) engine=InnoDB;
|
|
|
|
insert into t3 values(1),(2),(3);
|
2014-03-23 17:39:10 +01:00
|
|
|
create table t4 (i int) engine=InnoDB;
|
|
|
|
insert into t4 values(1);
|
|
|
|
lock table t1 write, t2 write, t3 write, t4 write;
|
2014-01-29 14:37:17 +01:00
|
|
|
create or replace table t1 (a int, i int) engine=innodb select t2.a,t3.i from t2,t3;
|
2014-03-23 17:39:10 +01:00
|
|
|
select * from t4;
|
2014-01-29 14:37:17 +01:00
|
|
|
unlock tables;
|
|
|
|
select * from t1 order by a,i;
|
2014-03-23 17:39:10 +01:00
|
|
|
drop table t1,t3,t4;
|
2014-01-29 14:37:17 +01:00
|
|
|
|
2014-03-12 10:26:40 +01:00
|
|
|
--echo #
|
|
|
|
--echo # Test the meta data locks are freed properly
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
create database mysqltest2;
|
|
|
|
|
|
|
|
drop table if exists test.t1,mysqltest2.t2;
|
|
|
|
create table test.t1 (i int);
|
|
|
|
create table mysqltest2.t2 like test.t1;
|
|
|
|
lock table test.t1 write, mysqltest2.t2 write;
|
2014-03-15 13:56:35 +01:00
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-03-12 10:26:40 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
--error ER_TABLE_MUST_HAVE_COLUMNS
|
|
|
|
create or replace table test.t1;
|
|
|
|
show tables;
|
2014-03-15 13:56:35 +01:00
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-03-12 10:26:40 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
--error ER_TABLE_MUST_HAVE_COLUMNS
|
|
|
|
create or replace table mysqltest2.t2;
|
2014-03-15 13:56:35 +01:00
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-03-12 10:26:40 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
create table t1 (i int);
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
create table test.t1 (i int);
|
|
|
|
create table mysqltest2.t2 like test.t1;
|
|
|
|
lock table test.t1 write, mysqltest2.t2 write;
|
2014-03-15 13:56:35 +01:00
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-03-12 10:26:40 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
--error ER_DUP_FIELDNAME
|
|
|
|
create or replace table test.t1 (a int) select 1 as 'a', 2 as 'a';
|
|
|
|
show tables;
|
2014-03-15 13:56:35 +01:00
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-03-12 10:26:40 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
--error ER_DUP_FIELDNAME
|
|
|
|
create or replace table mysqltest2.t2 (a int) select 1 as 'a', 2 as 'a';
|
2014-03-15 13:56:35 +01:00
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-03-12 10:26:40 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
create table t1 (i int);
|
|
|
|
drop table t1;
|
|
|
|
drop database mysqltest2;
|
|
|
|
|
2014-01-29 14:37:17 +01:00
|
|
|
--echo #
|
|
|
|
--echo # Testing CREATE .. LIKE
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
create or replace table t1 like t2;
|
|
|
|
create or replace table t1 like t2;
|
|
|
|
show create table t1;
|
|
|
|
drop table t1;
|
|
|
|
create table t1 (b int);
|
|
|
|
lock tables t1 write, t2 read;
|
|
|
|
create or replace table t1 like t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
INSERT INTO t1 values(1);
|
|
|
|
CREATE OR REPLACE TABLE t1 like t2;
|
|
|
|
INSERT INTO t1 values(2);
|
|
|
|
unlock tables;
|
|
|
|
show create table t1;
|
|
|
|
drop table t1;
|
|
|
|
|
2014-01-31 11:06:28 +01:00
|
|
|
create or replace table t1 like t2;
|
|
|
|
--error ER_NONUNIQ_TABLE
|
|
|
|
create or replace table t1 like t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
CREATE TEMPORARY TABLE t1 like t2;
|
|
|
|
--error ER_NONUNIQ_TABLE
|
|
|
|
CREATE OR REPLACE TABLE t1 like t1;
|
|
|
|
--error ER_NONUNIQ_TABLE
|
|
|
|
CREATE OR REPLACE TABLE t1 like t1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
CREATE TEMPORARY TABLE t1 like t2;
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t3 like t1;
|
|
|
|
--error ER_NONUNIQ_TABLE
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE t3 like t3;
|
|
|
|
drop table t1,t3;
|
|
|
|
|
2014-01-29 14:37:17 +01:00
|
|
|
--echo #
|
|
|
|
--echo # Test with prepared statements
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
prepare stmt1 from 'create or replace table t1 select * from t2';
|
|
|
|
execute stmt1;
|
|
|
|
select * from t1;
|
|
|
|
execute stmt1;
|
|
|
|
select * from t1;
|
|
|
|
drop table t1;
|
|
|
|
execute stmt1;
|
|
|
|
select * from t1;
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Test with views
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
create view t1 as select 1;
|
|
|
|
create table if not exists t1 (a int);
|
2014-01-31 11:06:28 +01:00
|
|
|
--error ER_IT_IS_A_VIEW
|
2014-01-29 14:37:17 +01:00
|
|
|
create or replace table t1 (a int);
|
2014-01-31 11:06:28 +01:00
|
|
|
--error ER_IT_IS_A_VIEW
|
2014-01-29 14:37:17 +01:00
|
|
|
drop table t1;
|
|
|
|
drop view t1;
|
|
|
|
|
2014-02-05 20:36:16 +01:00
|
|
|
--echo #
|
|
|
|
--echo # MDEV-5602 CREATE OR REPLACE obtains stricter locks than the
|
|
|
|
--echo # connection had before
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
create table t1 (a int);
|
|
|
|
lock table t1 write, t2 read;
|
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-02-05 20:36:16 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
create or replace table t1 (i int);
|
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-02-05 20:36:16 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
create or replace table t1 like t2;
|
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-02-05 20:36:16 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
create or replace table t1 select 1 as f1;
|
|
|
|
--replace_column 1 #
|
2016-06-15 11:57:44 +02:00
|
|
|
--sorted_result
|
2014-02-05 20:36:16 +01:00
|
|
|
select * from information_schema.metadata_lock_info;
|
|
|
|
drop table t1;
|
|
|
|
unlock tables;
|
|
|
|
|
2014-09-08 19:56:56 +02:00
|
|
|
--echo #
|
|
|
|
--echo # MDEV-6560
|
|
|
|
--echo # Assertion `! is_set() ' failed in Diagnostics_area::set_ok_status
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE TABLE t1 (col_int_nokey INT) ENGINE=InnoDB;
|
|
|
|
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp LIKE t1;
|
|
|
|
LOCK TABLE t1 WRITE;
|
|
|
|
|
|
|
|
--connect (con1,localhost,root,,test)
|
2014-09-17 15:11:24 +02:00
|
|
|
--let $con_id = `SELECT CONNECTION_ID()`
|
|
|
|
--send CREATE OR REPLACE TABLE t1 LIKE tmp
|
2014-09-08 19:56:56 +02:00
|
|
|
--connection default
|
2015-01-19 14:19:14 +01:00
|
|
|
let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist
|
|
|
|
WHERE state= 'Waiting for table metadata lock';
|
|
|
|
--source include/wait_condition.inc
|
2014-09-16 14:04:50 +02:00
|
|
|
--replace_result $con_id con_id
|
2014-09-17 15:11:24 +02:00
|
|
|
--eval KILL QUERY $con_id
|
2014-09-08 19:56:56 +02:00
|
|
|
|
2014-09-17 15:11:24 +02:00
|
|
|
--connection con1
|
2015-01-19 14:19:14 +01:00
|
|
|
--error ER_QUERY_INTERRUPTED
|
2014-09-08 19:56:56 +02:00
|
|
|
--reap
|
2014-09-17 15:11:24 +02:00
|
|
|
--send CREATE OR REPLACE TABLE t1 (a int)
|
2014-09-08 19:56:56 +02:00
|
|
|
|
2014-09-17 15:11:24 +02:00
|
|
|
--connection default
|
2015-01-19 14:19:14 +01:00
|
|
|
let $wait_condition= SELECT COUNT(*)=1 FROM information_schema.processlist
|
|
|
|
WHERE state= 'Waiting for table metadata lock';
|
|
|
|
--source include/wait_condition.inc
|
2014-09-16 14:04:50 +02:00
|
|
|
--replace_result $con_id con_id
|
2014-09-17 15:11:24 +02:00
|
|
|
--eval KILL QUERY $con_id
|
2014-09-08 19:56:56 +02:00
|
|
|
|
2014-09-17 15:11:24 +02:00
|
|
|
--connection con1
|
2015-01-19 14:19:14 +01:00
|
|
|
--error ER_QUERY_INTERRUPTED
|
2014-09-08 19:56:56 +02:00
|
|
|
--reap
|
|
|
|
--disconnect con1
|
2014-09-17 15:11:24 +02:00
|
|
|
--connection default
|
|
|
|
|
2014-09-08 19:56:56 +02:00
|
|
|
drop table t1;
|
|
|
|
|
2014-01-29 14:37:17 +01:00
|
|
|
#
|
|
|
|
# Cleanup
|
|
|
|
#
|
|
|
|
DROP TABLE t2;
|