File: pr_create_synonym_db.test

package info (click to toggle)
mariadb 1%3A11.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 765,428 kB
  • sloc: ansic: 2,382,827; cpp: 1,803,532; asm: 378,315; perl: 63,176; sh: 46,496; pascal: 40,776; java: 39,363; yacc: 20,428; python: 19,506; sql: 17,864; xml: 12,463; ruby: 8,544; makefile: 6,059; cs: 5,855; ada: 1,700; lex: 1,193; javascript: 1,039; objc: 80; tcl: 73; awk: 46; php: 22
file content (95 lines) | stat: -rw-r--r-- 3,333 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
########### suite/sysschema/t/pr_create_synonym_db.test #############
#                                                                   #
# Testing of of the sys.pr_create_synonym_db() procedure            #
#                                                                   #
# Creation:                                                         #
# 2016-05-23 jkrogh Implement this test as part of bug 22011361     #
#                                                                   #
#####################################################################

-- source include/not_embedded.inc
# Create a couple of tables and a view
CREATE TABLE t1 (t1_id int PRIMARY KEY, t1_val varchar(10));
CREATE TABLE t2 (t2_id int PRIMARY KEY, t1_id int, t2_val int, INDEX (t1_id));
CREATE TABLE `is` (t1_id int PRIMARY KEY, t1_val varchar(10));
CREATE TABLE `ab``c` (t1_id int PRIMARY KEY, t1_val varchar(10));
CREATE SQL SECURITY INVOKER VIEW myview AS SELECT * FROM t1 NATURAL JOIN t2;

# Make synonym db of test into test1
CALL sys.create_synonym_db('test', 'test1');
# Verify there's one view in test1 per table and view in test
SELECT TABLE_NAME, SECURITY_TYPE FROM information_schema.VIEWS WHERE TABLE_SCHEMA = 'test1' ORDER BY TABLE_NAME;
# Try again (should fail)
-- error ER_SIGNAL_EXCEPTION
CALL sys.create_synonym_db('test', 'test1');

# Try to make the synonym db for an existing empty schema
CREATE SCHEMA test2;
-- error ER_SIGNAL_EXCEPTION
CALL sys.create_synonym_db('test', 'test2');
# Ensure test2 is still empty
SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'test2';

# Use a reserved identifer, Bug #22011361
CALL sys.create_synonym_db('test', 'is');
# Verify there's one view in is per table and view in test
SELECT TABLE_NAME, SECURITY_TYPE FROM information_schema.VIEWS WHERE TABLE_SCHEMA = 'is' ORDER BY TABLE_NAME;

# Copy the is schema to i`s schema:
CALL sys.create_synonym_db('is', 'i`s');
# Verify there's one view in i`s per table and view in is
SELECT TABLE_NAME, SECURITY_TYPE FROM information_schema.VIEWS WHERE TABLE_SCHEMA = 'i`s' ORDER BY TABLE_NAME;

# Clean up
DROP SCHEMA test1;
DROP SCHEMA test2;
DROP SCHEMA `is`;
DROP SCHEMA `i``s`;
DROP VIEW test.myview;
DROP TABLE test.t1;
DROP TABLE test.t2;
DROP TABLE `is`;
DROP TABLE `ab``c`;

--echo #
--echo # MDEV-28342: sys.create_synonym_db fails
--echo #             when a temporary table masks a base table
--echo #

create database db;
use db;
create table a(a int);
create table t (b int);
create table b(a int);
create temporary table b (a int);
call sys.create_synonym_db('db','db_copy');

use db_copy;
show tables;

drop database db;
drop database db_copy;
--echo # MDEV-28343: sys.create_synonym_db fails with ER_VIEW_SELECT_TMPTABLE
--echo #             when schema contains temporary tables
--echo #

create database mytestdb;
use mytestdb;
create table t (b int);
# This temporary table will not be created as an view in synonym db
create temporary table tmp (a int);
call sys.create_synonym_db('mytestdb','db_syn1');
use db_syn1;
show tables;
drop database db_syn1;

use mytestdb;
# This temporary table will shadow the base table and no views will be created
create temporary table t (b int);
call sys.create_synonym_db('mytestdb','db_syn1');

use db_syn1;
show tables;

drop database mytestdb;
drop database db_syn1;