| 1 |
########### suite/sysschema/t/pr_create_synonym_db.test ############# |
| 2 |
# # |
| 3 |
# Testing of of the sys.pr_create_synonym_db() procedure # |
| 4 |
# # |
| 5 |
# Creation: # |
| 6 |
# 2016-05-23 jkrogh Implement this test as part of bug 22011361 # |
| 7 |
# # |
| 8 |
##################################################################### |
| 9 |
|
| 10 |
-- source include/not_embedded.inc |
| 11 |
# Create a couple of tables and a view |
| 12 |
CREATE TABLE t1 (t1_id int PRIMARY KEY, t1_val varchar(10)); |
| 13 |
CREATE TABLE t2 (t2_id int PRIMARY KEY, t1_id int, t2_val int, INDEX (t1_id)); |
| 14 |
CREATE TABLE `is` (t1_id int PRIMARY KEY, t1_val varchar(10)); |
| 15 |
CREATE TABLE `ab``c` (t1_id int PRIMARY KEY, t1_val varchar(10)); |
| 16 |
CREATE SQL SECURITY INVOKER VIEW myview AS SELECT * FROM t1 NATURAL JOIN t2; |
| 17 |
|
| 18 |
# Make synonym db of test into test1 |
| 19 |
CALL sys.create_synonym_db('test', 'test1'); |
| 20 |
# Verify there's one view in test1 per table and view in test |
| 21 |
SELECT TABLE_NAME, SECURITY_TYPE FROM information_schema.VIEWS WHERE TABLE_SCHEMA = 'test1' ORDER BY TABLE_NAME; |
| 22 |
# Try again (should fail) |
| 23 |
-- error ER_SIGNAL_EXCEPTION |
| 24 |
CALL sys.create_synonym_db('test', 'test1'); |
| 25 |
|
| 26 |
# Try to make the synonym db for an existing empty schema |
| 27 |
CREATE SCHEMA test2; |
| 28 |
-- error ER_SIGNAL_EXCEPTION |
| 29 |
CALL sys.create_synonym_db('test', 'test2'); |
| 30 |
# Ensure test2 is still empty |
| 31 |
SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'test2'; |
| 32 |
|
| 33 |
# Use a reserved identifer, Bug #22011361 |
| 34 |
CALL sys.create_synonym_db('test', 'is'); |
| 35 |
# Verify there's one view in is per table and view in test |
| 36 |
SELECT TABLE_NAME, SECURITY_TYPE FROM information_schema.VIEWS WHERE TABLE_SCHEMA = 'is' ORDER BY TABLE_NAME; |
| 37 |
|
| 38 |
# Copy the is schema to i`s schema: |
| 39 |
CALL sys.create_synonym_db('is', 'i`s'); |
| 40 |
# Verify there's one view in i`s per table and view in is |
| 41 |
SELECT TABLE_NAME, SECURITY_TYPE FROM information_schema.VIEWS WHERE TABLE_SCHEMA = 'i`s' ORDER BY TABLE_NAME; |
| 42 |
|
| 43 |
# Clean up |
| 44 |
DROP SCHEMA test1; |
| 45 |
DROP SCHEMA test2; |
| 46 |
DROP SCHEMA `is`; |
| 47 |
DROP SCHEMA `i``s`; |
| 48 |
DROP VIEW test.myview; |
| 49 |
DROP TABLE test.t1; |
| 50 |
DROP TABLE test.t2; |
| 51 |
DROP TABLE `is`; |
| 52 |
DROP TABLE `ab``c`; |
| 53 |
|
| 54 |
--echo # |
| 55 |
--echo # MDEV-28342: sys.create_synonym_db fails |
| 56 |
--echo # when a temporary table masks a base table |
| 57 |
--echo # |
| 58 |
|
| 59 |
create database db; |
| 60 |
use db; |
| 61 |
create table a(a int); |
| 62 |
create table t (b int); |
| 63 |
create table b(a int); |
| 64 |
create temporary table b (a int); |
| 65 |
call sys.create_synonym_db('db','db_copy'); |
| 66 |
|
| 67 |
use db_copy; |
| 68 |
show tables; |
| 69 |
|
| 70 |
drop database db; |
| 71 |
drop database db_copy; |
| 72 |
--echo # MDEV-28343: sys.create_synonym_db fails with ER_VIEW_SELECT_TMPTABLE |
| 73 |
--echo # when schema contains temporary tables |
| 74 |
--echo # |
| 75 |
|
| 76 |
create database mytestdb; |
| 77 |
use mytestdb; |
| 78 |
create table t (b int); |
| 79 |
# This temporary table will not be created as an view in synonym db |
| 80 |
create temporary table tmp (a int); |
| 81 |
call sys.create_synonym_db('mytestdb','db_syn1'); |
| 82 |
use db_syn1; |
| 83 |
show tables; |
| 84 |
drop database db_syn1; |
| 85 |
|
| 86 |
use mytestdb; |
| 87 |
# This temporary table will shadow the base table and no views will be created |
| 88 |
create temporary table t (b int); |
| 89 |
call sys.create_synonym_db('mytestdb','db_syn1'); |
| 90 |
|
| 91 |
use db_syn1; |
| 92 |
show tables; |
| 93 |
|
| 94 |
drop database mytestdb; |
| 95 |
drop database db_syn1; |