Debian Codegraph @

mysql-test/suite/funcs_1/datadict/is_views.inc

raw
1 # suite/funcs_1/datadict/is_views.inc
2 #
3 # Check the layout of information_schema.views and the impact of
4 # CREATE/ALTER/DROP TABLE/VIEW/SCHEMA ... on it.
5 #
6 # Note:
7 # - This test should not check storage engine properties.
8 # - Please do not change the storage engines used within this test
9 # except you know that the impact is acceptable.
10 # Some storage engines might not support the modification of
11 # properties like in the following tests.
12 #
13 # Author:
14 # 2008-01-23 mleich WL#4203 Reorganize and fix the data dictionary tests of
15 # testsuite funcs_1
16 # Create this script based on older scripts and new code.
17 # Last Change:
18 # 2008-06-11 mleich Move t/is_views.test to this file and
19 # create variants for embedded/non embedded server.
20 #
21
22 let $engine_type = MEMORY;
23 let $other_engine_type = MyISAM;
24
25 let $is_table = VIEWS;
26
27 # The table INFORMATION_SCHEMA.VIEWS must exist
28 eval SHOW TABLES FROM information_schema LIKE '$is_table';
29
30 --echo #######################################################################
31 --echo # Testcase 3.2.1.1: INFORMATION_SCHEMA tables can be queried via SELECT
32 --echo #######################################################################
33 # Ensure that every INFORMATION_SCHEMA table can be queried with a SELECT
34 # statement, just as if it were an ordinary user-defined table.
35 #
36 --source suite/funcs_1/datadict/is_table_query.inc
37
38
39 --echo #########################################################################
40 --echo # Testcase 3.2.13.1: INFORMATION_SCHEMA.VIEWS layout
41 --echo #########################################################################
42 # Ensure that the INFORMATION_SCHEMA.VIEWS table has the following columns,
43 # in the following order:
44 #
45 # TABLE_CATALOG (always shows NULL),
46 # TABLE_SCHEMA (shows the database, or schema, in which an accessible
47 # view resides),
48 # TABLE_NAME (shows the name of a view accessible to the current user),
49 # VIEW_DEFINITION (shows the SELECT statement that makes up the
50 # view's definition),
51 # CHECK_OPTION (shows the value of the WITH CHECK OPTION clause used to define
52 # the view, either NONE, LOCAL or CASCADED),
53 # IS_UPDATABLE (shows whether the view is an updatable view),
54 # DEFINER (added with 5.0.14),
55 # SECURITY_TYPE (added with 5.0.14).
56 #
57 --source suite/funcs_1/datadict/datadict_bug_12777.inc
58 eval DESCRIBE information_schema.$is_table;
59 --source suite/funcs_1/datadict/datadict_bug_12777.inc
60 --replace_result ENGINE=MyISAM "" ENGINE=Aria "" " PAGE_CHECKSUM=1" "" " PAGE_CHECKSUM=0" ""
61 eval SHOW CREATE TABLE information_schema.$is_table;
62 --source suite/funcs_1/datadict/datadict_bug_12777.inc
63 eval SHOW COLUMNS FROM information_schema.$is_table;
64
65 # Note: Retrieval of information within information_schema.columns about
66 # information_schema.views is in is_columns_is.test.
67
68 # Show that TABLE_CATALOG is always 'def'.
69 SELECT table_catalog, table_schema, table_name
70 FROM information_schema.views WHERE table_catalog <> 'def';
71
72
73 --echo ################################################################################
74 --echo # Testcase 3.2.13.2 + 3.2.13.3: INFORMATION_SCHEMA.VIEWS accessible information
75 --echo ################################################################################
76 # 3.2.13.2: Ensure that the table shows the relevant information on every view for
77 # which the current user or PUBLIC has the SHOW CREATE VIEW privilege.
78 # 3.2.13.3: Ensure that the table does not show any information on any views for which
79 # the current user and PUBLIC have no SHOW CREATE VIEW privilege.
80 #
81 --disable_warnings
82 DROP DATABASE IF EXISTS db_datadict;
83 --enable_warnings
84 CREATE DATABASE db_datadict;
85
86 --error 0,ER_CANNOT_USER
87 DROP USER 'testuser1'@'localhost';
88 CREATE USER 'testuser1'@'localhost';
89 --error 0,ER_CANNOT_USER
90 DROP USER 'testuser2'@'localhost';
91 CREATE USER 'testuser2'@'localhost';
92 --error 0,ER_CANNOT_USER
93 DROP USER 'test_no_views'@'localhost';
94 CREATE USER 'test_no_views'@'localhost';
95
96 --replace_result $engine_type <engine_type>
97 eval
98 CREATE TABLE db_datadict.t1(f1 INT, f2 INT, f3 INT)
99 ENGINE = $engine_type;
100 CREATE VIEW db_datadict.v_granted_to_1 AS SELECT * FROM db_datadict.t1;
101 CREATE VIEW db_datadict.v_granted_glob AS SELECT f2, f3 FROM db_datadict.t1;
102
103 GRANT SELECT ON db_datadict.t1 TO 'testuser1'@'localhost';
104 GRANT SELECT ON db_datadict.v_granted_to_1 TO 'testuser1'@'localhost';
105 GRANT SHOW VIEW, CREATE VIEW ON db_datadict.* TO 'testuser2'@'localhost';
106
107 let $select = SELECT * FROM information_schema.views
108 WHERE table_schema = 'db_datadict' ORDER BY table_name;
109 eval $select;
110
111 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
112 connect (testuser1, localhost, testuser1, ,"*NO-ONE*");
113 eval $select;
114
115 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
116 connect (testuser2, localhost, testuser2, ,"*NO-ONE*");
117 eval $select;
118
119 --replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
120 connect (test_no_views, localhost, test_no_views, ,"*NO-ONE*");
121 eval $select;
122
123 # Cleanup
124 connection default;
125 disconnect testuser1;
126 disconnect testuser2;
127 disconnect test_no_views;
128 DROP USER 'testuser1'@'localhost';
129 DROP USER 'testuser2'@'localhost';
130 DROP USER 'test_no_views'@'localhost';
131 DROP DATABASE db_datadict;
132
133 --echo #########################################################################
134 --echo # 3.2.1.13+3.2.1.14+3.2.1.15: INFORMATION_SCHEMA.VIEWS modifications
135 --echo #########################################################################
136 # 3.2.1.13: Ensure that the creation of any new database object (e.g. table or
137 # column) automatically inserts all relevant information on that
138 # object into every appropriate INFORMATION_SCHEMA table.
139 # 3.2.1.14: Ensure that the alteration of any existing database object
140 # automatically updates all relevant information on that object in
141 # every appropriate INFORMATION_SCHEMA table.
142 # 3.2.1.15: Ensure that the dropping of any existing database object
143 # automatically deletes all relevant information on that object from
144 # every appropriate INFORMATION_SCHEMA table.
145 #
146 --disable_warnings
147 DROP TABLE IF EXISTS test.t1_my_table;
148 DROP DATABASE IF EXISTS db_datadict;
149 --enable_warnings
150 CREATE DATABASE db_datadict;
151 --replace_result $engine_type <engine_type>
152 eval
153 CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10))
154 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci
155 ENGINE = $engine_type;
156 --error 0,ER_CANNOT_USER
157 DROP USER 'testuser1'@'localhost';
158 CREATE USER 'testuser1'@'localhost';
159
160 # Check just created VIEW
161 SELECT * FROM information_schema.views
162 WHERE table_name LIKE 't1_%'
163 ORDER BY table_schema, table_name;
164 CREATE VIEW test.t1_view AS SELECT DISTINCT f1 FROM test.t1_table;
165 CREATE ALGORITHM=MERGE VIEW test.t1_view1 AS SELECT f1 FROM test.t1_table;
166 CREATE ALGORITHM=TEMPTABLE VIEW test.t1_view2 AS SELECT f1 FROM test.t1_table;
167 SELECT * FROM information_schema.views
168 WHERE table_name LIKE 't1_%'
169 ORDER BY table_schema, table_name;
170 DROP VIEW test.t1_view1;
171 DROP VIEW test.t1_view2;
172
173 #
174 # Check modification of DEFINER, SECURITY_TYPE, IS_UPDATABLE, VIEW_DEFINITION,
175 # CHECK_OPTION
176 SELECT table_name,definer FROM information_schema.views
177 WHERE table_name = 't1_view';
178 ALTER DEFINER = 'testuser1'@'localhost' VIEW test.t1_view AS
179 SELECT DISTINCT f1 FROM test.t1_table;
180 # The next result set could suffer from
181 # Bug#22763 Disrepancy between SHOW CREATE VIEW and I_S.VIEWS
182 # because the VIEW definition is missing.
183 # Therefore we exclude the problematic columns from the result set.
184 SELECT table_name,definer,security_type FROM information_schema.views
185 WHERE table_name LIKE 't1_%';
186 ALTER DEFINER = 'root'@'localhost' SQL SECURITY INVOKER VIEW test.t1_view AS
187 SELECT f1 FROM test.t1_table WITH LOCAL CHECK OPTION;
188 SELECT table_name,definer,security_type FROM information_schema.views
189 WHERE table_name LIKE 't1_%';
190 #
191 # Check modification of TABLE_SCHEMA
192 SELECT table_schema,table_name FROM information_schema.views
193 WHERE table_name LIKE 't1_%'
194 ORDER BY table_schema,table_name;
195 --error ER_FORBID_SCHEMA_CHANGE
196 RENAME TABLE test.t1_view TO db_datadict.t1_view;
197 # Workaround for missing move to another database
198 DROP VIEW test.t1_view;
199 CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table;
200 SELECT table_schema,table_name FROM information_schema.views
201 WHERE table_name LIKE 't1_%'
202 ORDER BY table_schema,table_name;
203 #
204 # Check modification of TABLE_NAME
205 SELECT table_name FROM information_schema.views
206 WHERE table_name LIKE 't1_%'
207 ORDER BY table_name;
208 RENAME TABLE db_datadict.t1_view TO db_datadict.t1_viewx;
209 SELECT table_name FROM information_schema.views
210 WHERE table_name LIKE 't1_%'
211 ORDER BY table_name;
212 #
213 # Check impact of DROP VIEW
214 SELECT table_name FROM information_schema.views
215 WHERE table_name LIKE 't1_%'
216 ORDER BY table_name;
217 DROP VIEW db_datadict.t1_viewx;
218 SELECT table_name FROM information_schema.views
219 WHERE table_name LIKE 't1_%'
220 ORDER BY table_name;
221 CREATE VIEW db_datadict.t1_view AS SELECT * FROM test.t1_table;
222 #
223 # Check impact of DROP base TABLE of VIEW
224 SELECT table_name FROM information_schema.views
225 WHERE table_name LIKE 't1_%'
226 ORDER BY table_name;
227 DROP TABLE test.t1_table;
228 SELECT table_name FROM information_schema.views
229 WHERE table_name LIKE 't1_%'
230 ORDER BY table_name;
231 --replace_result $engine_type <engine_type>
232 eval
233 CREATE TABLE test.t1_table (f1 BIGINT, f2 CHAR(10))
234 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci COMMENT = 'Initial Comment'
235 ENGINE = $engine_type;
236 #
237 # Check impact of DROP SCHEMA
238 SELECT table_name FROM information_schema.views
239 WHERE table_name LIKE 't1_%'
240 ORDER BY table_name;
241 DROP DATABASE db_datadict;
242 SELECT table_name FROM information_schema.views
243 WHERE table_name LIKE 't1_%'
244 ORDER BY table_name;
245
246 # Cleanup
247 DROP USER 'testuser1'@'localhost';
248 DROP TABLE test.t1_table;
249
250 --echo ########################################################################
251 --echo # Testcases 3.2.1.3-3.2.1.5 + 3.2.1.8-3.2.1.12: INSERT/UPDATE/DELETE and
252 --echo # DDL on INFORMATION_SCHEMA table are not supported
253 --echo ########################################################################
254 # 3.2.1.3: Ensure that no user may execute an INSERT statement on any
255 # INFORMATION_SCHEMA table.
256 # 3.2.1.4: Ensure that no user may execute an UPDATE statement on any
257 # INFORMATION_SCHEMA table.
258 # 3.2.1.5: Ensure that no user may execute a DELETE statement on any
259 # INFORMATION_SCHEMA table.
260 # 3.2.1.8: Ensure that no user may create an index on an
261 # INFORMATION_SCHEMA table.
262 # 3.2.1.9: Ensure that no user may alter the definition of an
263 # INFORMATION_SCHEMA table.
264 # 3.2.1.10: Ensure that no user may drop an INFORMATION_SCHEMA table.
265 # 3.2.1.11: Ensure that no user may move an INFORMATION_SCHEMA table to any
266 # other database.
267 # 3.2.1.12: Ensure that no user may directly add to, alter, or delete any data
268 # in an INFORMATION_SCHEMA table.
269 #
270 --disable_warnings
271 DROP DATABASE IF EXISTS db_datadict;
272 --enable_warnings
273 CREATE DATABASE db_datadict;
274 CREATE VIEW db_datadict.v1 AS SELECT 1;
275
276 --error ER_DBACCESS_DENIED_ERROR
277 INSERT INTO information_schema.views
278 SELECT * FROM information_schema.views;
279 --error ER_DBACCESS_DENIED_ERROR
280 INSERT INTO information_schema.views(table_schema, table_name)
281 VALUES ('db2', 'v2');
282
283 --error ER_DBACCESS_DENIED_ERROR,ER_NON_UPDATABLE_TABLE
284 UPDATE information_schema.views SET table_schema = 'test'
285 WHERE table_name = 't1';
286
287 --error ER_DBACCESS_DENIED_ERROR
288 DELETE FROM information_schema.views WHERE table_name = 't1';
289 --error ER_DBACCESS_DENIED_ERROR
290 TRUNCATE information_schema.views;
291
292 --error ER_DBACCESS_DENIED_ERROR
293 CREATE INDEX my_idx_on_views ON information_schema.views(table_schema);
294
295 --error ER_DBACCESS_DENIED_ERROR
296 ALTER TABLE information_schema.views DROP PRIMARY KEY;
297 --error ER_DBACCESS_DENIED_ERROR
298 ALTER TABLE information_schema.views ADD f1 INT;
299
300 --error ER_DBACCESS_DENIED_ERROR
301 DROP TABLE information_schema.views;
302
303 --error ER_DBACCESS_DENIED_ERROR
304 ALTER TABLE information_schema.views RENAME db_datadict.views;
305 --error ER_DBACCESS_DENIED_ERROR
306 ALTER TABLE information_schema.views RENAME information_schema.xviews;
307
308 # Cleanup
309 DROP DATABASE db_datadict;
310