CREATE USER test2@localhost;
CREATE DATABASE testdb;
USE testdb;
USE test;
GRANT CREATE, ALTER, DROP, INSERT, SELECT on test.* TO test2@localhost;
GRANT CREATE, ALTER, DROP, INSERT, SELECT on testdb.* TO test2@localhost;
connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
SELECT * FROM testdb.t_10;
a	b
2	Two
4	Four
6	Six
8	Eight
SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
a	b
1	One
3	Three
5	Five
9	Nine
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
SELECT * FROM testdb.t_10;
a	b
1	One
3	Three
5	Five
9	Nine
SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
a	b
2	Two
4	Four
6	Six
8	Eight
ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
SELECT * FROM t_10;
a	b
2	Two
4	Four
6	Six
8	Eight
SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
a	b
1	One
3	Three
5	Five
9	Nine
ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
SELECT * FROM t_10;
a	b
1	One
3	Three
5	Five
9	Nine
SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
a	b
2	Two
4	Four
6	Six
8	Eight
disconnect test2;
connection default;
REVOKE INSERT ON testdb.* FROM test2@localhost;
connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
ERROR 42000: INSERT command denied to user 'test2'@'localhost' for table 't_10'
ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
ERROR 42000: INSERT command denied to user 'test2'@'localhost' for table 'tp'
disconnect test2;
connection default;
DROP TABLE IF EXISTS t_10;
DROP TABLE IF EXISTS t_100;
DROP TABLE IF EXISTS t_1000;
DROP TABLE IF EXISTS tp;
DROP TABLE IF EXISTS tsp;
DROP TABLE IF EXISTS tsp_00;
DROP TABLE IF EXISTS tsp_01;
DROP TABLE IF EXISTS tsp_02;
DROP TABLE IF EXISTS tsp_03;
DROP TABLE IF EXISTS tsp_04;
DROP TABLE IF EXISTS t_empty;
DROP TABLE IF EXISTS t_null;
DROP USER test2@localhost;
DROP DATABASE testdb;
