2000-12-28 03:56:38 +02:00
#
# Test of rename table
#
2009-02-11 10:27:52 +01:00
--source include/count_sessions.inc
2003-01-06 01:48:59 +02:00
--disable_warnings
2001-01-02 21:46:33 -07:00
drop table if exists t0,t1,t2,t3,t4;
2004-09-03 02:25:27 +03:00
# Clear up from other tests (to ensure that SHOW TABLES below is right)
2004-10-07 10:50:13 +03:00
drop table if exists t0,t5,t6,t7,t8,t9,t1_1,t1_2,t9_1,t9_2;
2003-01-06 01:48:59 +02:00
--enable_warnings
2000-12-28 03:56:38 +02:00
create table t0 SELECT 1,"table 1";
create table t2 SELECT 2,"table 2";
create table t3 SELECT 3,"table 3";
rename table t0 to t1;
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
select * from t1;
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t1;
select * from t1;
2001-10-08 07:24:04 +03:00
2000-12-28 03:56:38 +02:00
# The following should give errors
2013-04-09 15:50:30 +02:00
--error ER_TABLE_EXISTS_ERROR
2001-10-08 07:24:04 +03:00
rename table t1 to t2;
2013-04-09 15:50:30 +02:00
--error ER_TABLE_EXISTS_ERROR
2001-10-08 07:24:04 +03:00
rename table t1 to t1;
2013-04-09 15:50:30 +02:00
--error ER_TABLE_EXISTS_ERROR
2001-10-08 07:24:04 +03:00
rename table t3 to t4, t2 to t3, t1 to t2, t4 to t2;
2000-12-28 03:56:38 +02:00
show tables like "t_";
2013-04-09 15:50:30 +02:00
--error ER_TABLE_EXISTS_ERROR
2001-10-08 07:24:04 +03:00
rename table t3 to t1, t2 to t3, t1 to t2, t4 to t1;
2013-04-09 15:50:30 +02:00
--error ER_NO_SUCH_TABLE
2001-10-08 07:24:04 +03:00
rename table t3 to t4, t5 to t3, t1 to t2, t4 to t1;
2000-12-28 03:56:38 +02:00
select * from t1;
select * from t2;
select * from t3;
2003-01-06 01:48:59 +02:00
# This should give a warning for t4
2000-12-28 03:56:38 +02:00
drop table if exists t1,t2,t3,t4;
2004-04-01 22:47:09 +05:00
#
2006-10-30 14:42:28 +01:00
# Bug #2397 RENAME TABLES is not blocked by
# FLUSH TABLES WITH READ LOCK
2004-04-01 22:47:09 +05:00
#
connect (con1,localhost,root,,);
connect (con2,localhost,root,,);
connection con1;
CREATE TABLE t1 (a int);
CREATE TABLE t3 (a int);
connection con2;
FLUSH TABLES WITH READ LOCK;
connection con1;
send RENAME TABLE t1 TO t2, t3 to t4;
connection con2;
show tables;
UNLOCK TABLES;
2006-05-06 09:41:24 +04:00
connection con1;
reap;
connection con2;
2006-10-30 14:42:28 +01:00
# Wait for the the tables to be renamed
# i.e the query below succeds
let $query= select * from t2, t4;
2009-02-11 10:27:52 +01:00
source include/wait_for_query_to_succeed.inc;
2006-10-30 14:42:28 +01:00
2004-04-01 22:47:09 +05:00
show tables;
drop table t2, t4;
2005-07-28 03:22:47 +03:00
2006-05-06 09:41:24 +04:00
disconnect con2;
disconnect con1;
connection default;
2006-11-03 12:25:34 +03:00
2006-11-03 12:16:31 +03:00
--echo End of 4.1 tests
2006-11-03 12:25:34 +03:00
2010-05-28 09:25:11 +04:00
--echo #
--echo # Bug#14959: "ALTER TABLE isn't able to rename a view"
--echo # Bug#53976: "ALTER TABLE RENAME is allowed on views
--echo # (not documented, broken)"
--echo #
2006-10-13 21:59:52 +04:00
create table t1(f1 int);
create view v1 as select * from t1;
2010-05-28 09:25:11 +04:00
--error ER_WRONG_OBJECT
2006-10-13 21:59:52 +04:00
alter table v1 rename to v2;
drop view v1;
drop table t1;
2006-11-03 12:25:34 +03:00
--echo End of 5.0 tests
2009-02-11 10:27:52 +01:00
--source include/wait_until_count_sessions.inc
2018-05-22 14:36:06 +03:00
#
# Test of rename with temporary tables
#
CREATE OR REPLACE TABLE t1 (a INT);
CREATE OR REPLACE TABLE t2 (a INT);
CREATE OR REPLACE TEMPORARY TABLE t1_tmp (b INT);
CREATE OR REPLACE TEMPORARY TABLE t2_tmp (b INT);
# Can't rename table over another one
--error ER_TABLE_EXISTS_ERROR
rename table t1 to t2;
--error ER_TABLE_EXISTS_ERROR
rename table t1 to tmp, tmp to t2;
--error ER_TABLE_EXISTS_ERROR
rename table t1_tmp to t2_tmp;
--error ER_TABLE_EXISTS_ERROR
rename table t1_tmp to tmp, tmp to t2_tmp;
show create table t1_tmp;
show create table t2_tmp;
# The following should work
rename table t1 to t1_tmp;
rename table t2_tmp to t2;
rename table t2 to tmp, tmp to t2;
rename table t1_tmp to tmp, tmp to t1_tmp;
show tables;
SHOW CREATE TABLE t1_tmp;
drop table t1_tmp;
SHOW CREATE TABLE t1_tmp;
drop table t1_tmp;
SHOW CREATE TABLE t2;
drop table t2;
SHOW CREATE TABLE t2;
drop table t2;
CREATE TABLE t1 (a INT);
insert into t1 values (1);
CREATE TEMPORARY TABLE t1 (b INT);
insert into t1 values (2);
RENAME TABLE t1 TO tmp, t1 TO t2;
select * from tmp;
select * from t2;
drop table tmp,t2;
2018-07-13 16:54:47 +02:00
#
# MDEV-11741 handler::ha_reset(): Assertion `bitmap_is_set_all(&table->s->all_set)' failed or server crash in mi_reset or buffer overrun or unexpected ER_CANT_REMOVE_ALL_FIELDS
#
create table t1 (a int) engine=memory;
--error ER_BAD_DB_ERROR
rename table t1 to non_existent.t2;
drop table t1;
2019-12-30 13:34:28 +02:00
--echo #
--echo # Test rename IF EXISTS
--echo #
rename table if exists t1 to t2;
alter table if exists t1 rename to t2;
create table t2 (a int);
alter table if exists t1 rename to t2;
rename table if exists t1 to t2;
create table t1 (a int);
--error ER_TABLE_EXISTS_ERROR
rename table if exists t1 to t2;
--error ER_TABLE_EXISTS_ERROR
alter table if exists t1 rename to t2;
drop table t2;
rename table if exists t1 to t2;
alter table if exists t2 rename to t1;
drop table t1;