You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4036 lines
136 KiB

  1. #### suite/funcs_1/views/views_master.test
  2. let $message= ! Attention: The file with the expected results is not
  3. | thoroughly checked.
  4. ! The server return codes are correct, but
  5. | most result sets where the table tb2 is
  6. ! involved are not checked.;
  7. --source include/show_msg80.inc
  8. # As long as
  9. # Bug#11589: mysqltest, --ps-protocol, strange output, float/double/real with zerofill
  10. # is not fixed, we must switch the ps-protocol for some statements off.
  11. # If this bug is fixed, please
  12. # 1. set the following variable to 0
  13. # 2. check, if the test passes
  14. # 3. remove the workarounds
  15. let $have_bug_11589= 1;
  16. if ($have_bug_11589)
  17. {
  18. let $message= There are some statements where the ps-protocol is switched off.
  19. Bug#11589: mysqltest, --ps-protocol, strange output, float/double/real with zerofill;
  20. --source include/show_msg80.inc
  21. }
  22. let $message= ! Attention: The file with the expected results suffers from
  23. Bug#10713: mysqldump includes database in create view and referenced tables;
  24. --source include/show_msg80.inc
  25. # The sub testcases are nearly independend. That is the reason why
  26. # we do not want to abort after the first error.
  27. --disable_abort_on_error
  28. # 3.3 Views
  29. # MySQL views are based on a subset of the view requirements described in
  30. # the following standard SQL document:
  31. #
  32. # * ISO/IEC 9075-2:2003 Information technology -- Database languages --
  33. # SQL -- Part 2: Foundation (SQL/Foundation)
  34. #
  35. # MySQL has also added some vendor-specific enhancements to the standard
  36. # SQL requirements.
  37. # FIXME (ML)
  38. # - Alter all object names so that they follow the v/t/..<number> scheme or
  39. # apply another method which prevents that customer data might be
  40. # accidently modified
  41. # - Remove any reference to the preloaded tables tb1 - tb4, if they could
  42. # be replaced without loss of value.
  43. # Example: failing CREATE VIEW statements
  44. # The goal is to split this script into two, where the first one does
  45. # not need the possibly huge tables.
  46. # Load records needed within the testcases.
  47. # We load them here and not within the testcases itself, because the
  48. # removal of any unneeded testcase during bug analysis should not alter
  49. # result sets.
  50. # Testcase 3.3.1.1
  51. insert into test.tb2 (f59,f60) values (76710,226546);
  52. insert into test.tb2 (f59,f60) values(2760,985654);
  53. insert into test.tb2 (f59,f60) values(569300,9114376);
  54. insert into test.tb2 (f59,f60) values(660,876546);
  55. insert into test.tb2 (f59,f60) values(250,87895654);
  56. insert into test.tb2 (f59,f60) values(340,9984376);
  57. insert into test.tb2 (f59,f60) values(3410,996546);
  58. insert into test.tb2 (f59,f60) values(2550,775654);
  59. insert into test.tb2 (f59,f60) values(3330,764376);
  60. insert into test.tb2 (f59,f60) values(441,16546);
  61. insert into test.tb2 (f59,f60) values(24,51654);
  62. insert into test.tb2 (f59,f60) values(323,14376);
  63. # Testcase 3.3.1.45
  64. insert into test.tb2 (f59,f60) values(34,41);
  65. insert into test.tb2 (f59,f60) values(04,74);
  66. insert into test.tb2 (f59,f60) values(15,87);
  67. insert into test.tb2 (f59,f60) values(22,93);
  68. # Testcase 3.3.1.46
  69. insert into test.tb2 (f59,f60) values(394,41);
  70. insert into test.tb2 (f59,f60) values(094,74);
  71. insert into test.tb2 (f59,f60) values(195,87);
  72. insert into test.tb2 (f59,f60) values(292,93);
  73. # Testcase 3.3.1.47
  74. insert into test.tb2 (f59,f60) values(0987,41) ;
  75. insert into test.tb2 (f59,f60) values(7876,74) ;
  76. # Testcase 3.3.1.52
  77. INSERT INTO tb2 (f59,f61) VALUES(321,765 );
  78. INSERT INTO tb2 (f59,f61) VALUES(9112,8771);
  79. # Testcase 3.3.1.53
  80. INSERT INTO tb2 (f59,f61) VALUES (500,900 ) ;
  81. INSERT INTO tb2 (f59,f61) VALUES (500,900 ) ;
  82. INSERT INTO tb2 (f59,f61) VALUES (500,900 ) ;
  83. # Testcase 3.3.1.A1
  84. Insert into tb2 (f59,f60,f61) values (107,105,106) ;
  85. Insert into tb2 (f59,f60,f61) values (109,108,104) ;
  86. # Testcase 3.3.1.A2
  87. Insert into tb2 (f59,f60,f61) values (207,205,206) ;
  88. Insert into tb2 (f59,f60,f61) values (209,208,204) ;
  89. # Testcase 3.3.1.A3
  90. Insert into tb2 (f59,f60,f61) values (27,25,26) ;
  91. Insert into tb2 (f59,f60,f61) values (29,28,24) ;
  92. # Testcase 3.3.1.63
  93. Insert into tb2 (f59,f60,f61) values (17,15,16) ;
  94. Insert into tb2 (f59,f60,f61) values (19,18,14) ;
  95. insert into tb2 (f59,f60,f61) values (107,105,106);
  96. insert into tb2 (f59,f60,f61) values (109,108,104);
  97. # Testcase 3.3.1.64
  98. INSERT INTO tb2 (f59,f60) VALUES( 299,899 );
  99. INSERT INTO tb2 (f59,f60) VALUES( 242,79 );
  100. INSERT INTO tb2 (f59,f60) VALUES( 424,89 );
  101. #
  102. #
  103. Use test;
  104. #
  105. # End of basic preparations.
  106. #
  107. ##############################################################################
  108. #==============================================================================
  109. # 3.3.1 Syntax checks for CREATE VIEW, CREATE OR REPLACE VIEW, ALTER VIEW,
  110. # and DROP VIEW:
  111. #==============================================================================
  112. let $message= Testcase 3.3.1.1 ;
  113. --source include/show_msg80.inc
  114. ###############################################################################
  115. # Testcase 3.3.1.1: Ensure that all clauses that should be supported
  116. # are supported.
  117. ###############################################################################
  118. --disable_warnings
  119. Drop table if exists t1;
  120. --enable_warnings
  121. Create table t1 (f59 INT, f60 INT) ;
  122. Insert into t1 values (100,4234);
  123. Insert into t1 values (990,6624);
  124. Insert into t1 values (710,765);
  125. Insert into t1 values (300,433334);
  126. Insert into t1 values (800,9788);
  127. Insert into t1 values (500,9866);
  128. #(01)
  129. --disable_warnings
  130. Drop view if exists v1 ;
  131. --enable_warnings
  132. CREATE VIEW v1 AS select f59,f60,f61
  133. FROM test.tb2 where f59=250;
  134. select * FROM v1 limit 0,10;
  135. #(02)
  136. Drop view if exists v1 ;
  137. CREATE VIEW v1 AS select f59,f60,f61
  138. FROM test.tb2 limit 100;
  139. select * FROM v1 limit 0,10;
  140. #(03)
  141. CREATE or REPLACE VIEW v1 AS select f59,f60,f61
  142. FROM test.tb2 limit 4,3;
  143. select * FROM v1 limit 0,10;
  144. #(04)
  145. CREATE or REPLACE VIEW v1 AS select distinct f59
  146. FROM test.tb2 limit 4,3;
  147. select * FROM v1 limit 0,10;
  148. #(05)
  149. ALTER VIEW v1 AS select f59
  150. FROM test.tb2 limit 6,2;
  151. select * FROM v1 limit 0,10;
  152. #(06)
  153. CREATE or REPLACE VIEW v1 AS select f59
  154. from tb2 order by f59 limit 100;
  155. select * FROM v1 limit 0,10;
  156. #(07)
  157. CREATE or REPLACE VIEW v1 AS select f59
  158. from tb2 order by f59 asc limit 100;
  159. select * FROM v1 limit 0,10;
  160. #(08)
  161. CREATE or REPLACE VIEW v1 AS select f59
  162. from tb2 order by f59 desc limit 100;
  163. select * FROM v1 limit 0,10;
  164. #(09)
  165. CREATE or REPLACE VIEW v1 AS select f59
  166. from tb2 group by f59 limit 100;
  167. select * FROM v1 limit 0,10;
  168. #(10)
  169. CREATE or REPLACE VIEW v1 AS select f59
  170. from tb2 group by f59 asc limit 100;
  171. select * FROM v1 limit 0,10;
  172. #(11)
  173. CREATE or REPLACE VIEW v1 AS select f59
  174. from tb2 group by f59 desc limit 100;
  175. select * FROM v1 limit 0,10;
  176. #(12)
  177. CREATE or REPLACE VIEW v1 AS (select f59 from tb2)
  178. union (select f59 from t1) limit 100;
  179. select * FROM v1 limit 0,10;
  180. #(13)
  181. CREATE or REPLACE VIEW v1 AS (select f59 FROM tb2)
  182. UNION DISTINCT(select f59 FROM t1) ;
  183. select * FROM v1 limit 0,10;
  184. #(14)
  185. CREATE or REPLACE VIEW v1 AS (select f59 FROM tb2)
  186. UNION ALL(select f59 FROM t1) ;
  187. select * FROM v1 limit 0,10;
  188. #(15)
  189. if ($have_bug_11589)
  190. {
  191. --disable_ps_protocol
  192. }
  193. CREATE or REPLACE VIEW v1 AS select *
  194. FROM test.tb2 WITH LOCAL CHECK OPTION ;
  195. select * FROM v1 limit 0,50;
  196. #(16)
  197. CREATE or REPLACE VIEW v1 AS select *
  198. FROM test.tb2 WITH CASCADED CHECK OPTION ;
  199. select * FROM v1 limit 0,10;
  200. --enable_ps_protocol
  201. #(17)
  202. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  203. FROM test.tb2 WITH CASCADED CHECK OPTION;
  204. SELECT * FROM v1 limit 0,10;
  205. #(18)
  206. CREATE or REPLACE VIEW v1 AS select f59, f60
  207. from test.tb2 where f59=3330 ;
  208. select * FROM v1 limit 0,10;
  209. DROP VIEW v1 ;
  210. DROP TABLE t1 ;
  211. let $message= Testcase 3.3.1.2 ;
  212. --source include/show_msg80.inc
  213. ###############################################################################
  214. # Testcase 3.3.1.2: Ensure that all clauses that should not be supported are
  215. # disallowed with an appropriate error message.
  216. ###############################################################################
  217. --disable_warnings
  218. DROP TABLE IF EXISTS t1 ;
  219. DROP VIEW IF EXISTS v1 ;
  220. DROP VIEW IF EXISTS v2 ;
  221. --enable_warnings
  222. CREATE TABLE t1 (f1 BIGINT) ;
  223. # User variables and parameters are not supported in VIEWs -> 3.3.1.40
  224. # SELECT INTO is illegal
  225. SET @x=0;
  226. --error 1350
  227. CREATE or REPLACE VIEW v1 AS Select 1 INTO @x;
  228. Select @x;
  229. # Subquery in the FROM clause is illegal
  230. --error 1349
  231. CREATE or REPLACE VIEW v1 AS Select 1
  232. FROM (SELECT 1 FROM t1) my_table;
  233. # Triggers cannot be associated with VIEWs
  234. CREATE VIEW v1 AS SELECT f1 FROM t1;
  235. # Show that 1. The trigger code basically works and the VIEW is updatable
  236. # 2. The VIEW is updatable
  237. # 3. Insert into view causes that the trigger is executed
  238. CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1 ;
  239. SET @a:=0 ;
  240. SELECT @a ;
  241. INSERT INTO v1 VALUES (1) ;
  242. SELECT @a ;
  243. SELECT * FROM t1;
  244. DROP TRIGGER tr1 ;
  245. SET @a:=0 ;
  246. --error 1347
  247. CREATE TRIGGER tr1 BEFORE INSERT ON v1 FOR EACH ROW SET @a:=1 ;
  248. # RENAME VIEW is not available even when we try it via rename table.
  249. # FIXME: Write a bug report for the ugly error message
  250. # 1017: Can't find file: './test/v1.frm' (errno: 2),
  251. # because the much more beautiful
  252. # 1347: 'test.v1' is not BASE TABLE
  253. # exists.
  254. --replace_result '\\' '/'
  255. # MLML --error 1017
  256. RENAME TABLE v1 TO v2;
  257. --error 1064
  258. RENAME VIEW v2 TO v1;
  259. #--error 1347
  260. ALTER TABLE v2 RENAME AS v1;
  261. --error 1064
  262. ALTER VIEW v1 RENAME AS v2;
  263. # VIEWs cannot contain a PRIMARY KEY or have an Index.
  264. --disable_warnings
  265. DROP TABLE IF EXISTS t1, t2 ;
  266. DROP VIEW IF EXISTS v1 ;
  267. DROP VIEW IF EXISTS v2 ;
  268. --enable_warnings
  269. CREATE TABLE t1 ( f1 DATE, f2 BLOB, f3 DOUBLE );
  270. CREATE VIEW v1 AS SELECT f1, f2, f3 FROM t1;
  271. ALTER TABLE t1 ADD PRIMARY KEY(f1);
  272. --error 1347
  273. ALTER TABLE v1 ADD PRIMARY KEY(f1);
  274. --error 1064
  275. ALTER VIEW v1 ADD PRIMARY KEY(f1);
  276. CREATE INDEX t1_idx ON t1(f3);
  277. --error 1347
  278. CREATE INDEX v1_idx ON v1(f3);
  279. DROP TABLE t1;
  280. DROP VIEW v1;
  281. let $message= Testcase 3.3.1.3 + 3.1.1.4 ;
  282. --source include/show_msg80.inc
  283. ###############################################################################
  284. # Testcase 3.1.1.3: Ensure that all supported clauses are supported only in
  285. # the correct order.
  286. # Testcase 3.1.1.4: Ensure that an appropriate error message is returned if
  287. # a clause is out-of-order in an SQL statement.
  288. ###############################################################################
  289. --disable_warnings
  290. DROP VIEW IF EXISTS v1 ;
  291. --enable_warnings
  292. # REPLACE after VIEW name
  293. --error 1064
  294. CREATE VIEW v1 or REPLACE AS Select * from tb2 my_table limit 50;
  295. # CHECK OPTION before AS SELECT
  296. --error 1064
  297. CREATE VIEW v1 WITH CASCADED CHECK OPTION AS Select *
  298. from tb2 my_table limit 50;
  299. # CHECK OPTION before AS SELECT
  300. --error 1064
  301. CREATE VIEW v1 WITH LOCAL CHECK OPTION AS Select *
  302. from tb2 my_table limit 50;
  303. # CREATE after SELECT
  304. --error 1064
  305. SELECT * FROM tb2 my_table CREATE VIEW As v1 limit 100 ;
  306. # AS forgotten
  307. --error 1064
  308. CREATE or REPLACE VIEW v1 Select f59, f60
  309. from test.tb2 my_table where f59 = 250 ;
  310. # positive case
  311. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  312. FROM test.tb2 my_table WITH CASCADED CHECK OPTION;
  313. DROP VIEW v1;
  314. # REPLACE OR CREATE instead of CREATE OR REPLACE
  315. --error 1064
  316. REPLACE OR CREATE VIEW v1 AS SELECT F59, F60
  317. FROM test.tb2 my_table WITH CASCADED CHECK OPTION;
  318. # AS after SELECT
  319. --error 1064
  320. CREATE OR REPLACE VIEW v1 SELECT AS F59, F60
  321. FROM test.tb2 my_table WITH CASCADED CHECK OPTION;
  322. --error 1064
  323. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  324. FROM test.tb2 my_table CASCADED WITH CHECK OPTION;
  325. # OPTION CHECK instead of CHECK OPTION
  326. --error 1064
  327. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  328. FROM test.tb2 my_table WITH CASCADED OPTION CHECK;
  329. # CHECK OPTION before WITH
  330. --error 1064
  331. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  332. FROM test.tb2 my_table CHECK OPTION WITH CASCADED;
  333. # CHECK OPTION before AS SELECT
  334. --error 1064
  335. CREATE OR REPLACE VIEW v1 WITH CASCADED CHECK OPTION
  336. AS SELECT F59, F60 FROM test.tb2 my_table;
  337. # VIEW <viewname> after AS SELECT
  338. --error 1064
  339. CREATE OR REPLACE AS SELECT F59, F60
  340. FROM test.tb2 my_table VIEW v1 WITH CASCADED CHECK OPTION;
  341. # VIEW <viewname> after CHECK OPTION
  342. --error 1064
  343. CREATE OR REPLACE AS SELECT F59, F60
  344. FROM test.tb2 my_table WITH CASCADED CHECK OPTION VIEW v1;
  345. # Variants with LOCAL CHECK OPTION
  346. --error 1064
  347. REPLACE OR CREATE VIEW v1 AS SELECT F59, F60
  348. FROM test.tb2 my_table WITH LOCAL CHECK OPTION;
  349. --error 1064
  350. CREATE OR REPLACE VIEW v1 SELECT AS F59, F60
  351. FROM test.tb2 my_table WITH LOCAL CHECK OPTION;
  352. --error 1064
  353. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  354. FROM test.tb2 my_table LOCAL WITH CHECK OPTION;
  355. --error 1064
  356. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  357. FROM test.tb2 my_table WITH LOCAL OPTION CHECK;
  358. --error 1064
  359. CREATE OR REPLACE VIEW v1 AS SELECT F59, F60
  360. FROM test.tb2 my_table CHECK OPTION WITH LOCAL;
  361. --error 1064
  362. CREATE OR REPLACE VIEW v1 WITH CASCADED CHECK OPTION
  363. AS SELECT F59, F60 FROM test.tb2 my_table;
  364. --error 1064
  365. CREATE OR REPLACE AS SELECT F59, F60
  366. FROM test.tb2 my_table VIEW v1 WITH LOCAL CHECK OPTION;
  367. --error 1064
  368. CREATE OR REPLACE AS SELECT F59, F60
  369. FROM test.tb2 my_table WITH LOCAL CHECK OPTION VIEW v1;
  370. --disable_warnings
  371. Drop table if exists t1 ;
  372. --enable_warnings
  373. CREATE table t1 (f1 int ,f2 int) ;
  374. INSERT INTO t1 values (235, 22);
  375. INSERT INTO t1 values (554, 11);
  376. # SELECTs of UNION in braces
  377. --error 1064
  378. CREATE or REPLACE view v1 as (Select from f59 tb2)
  379. Union ALL (Select from f1 t1);
  380. # by before order
  381. --error 1064
  382. CREATE or REPLACE view v1 as Select f59, f60
  383. from tb2 by order f59 limit 100 ;
  384. # by before group
  385. --error 1064
  386. CREATE or REPLACE view v1 as Select f59, f60
  387. from tb2 by group f59 ;
  388. let $message= Testcase 3.3.1.5 ;
  389. --source include/show_msg80.inc
  390. ###############################################################################
  391. # Testcase 3.3.1.5: Ensure that all clauses that are defined to be mandatory
  392. # are indeed required to be mandatory by the MySQL server
  393. # and tools.
  394. ###############################################################################
  395. --disable_warnings
  396. DROP VIEW IF EXISTS v1 ;
  397. --enable_warnings
  398. --error 1064
  399. CREATE VIEW v1 SELECT * FROM tb2 limit 100 ;
  400. --error 1064
  401. CREATE v1 AS SELECT * FROM tb2 limit 100 ;
  402. --error 1064
  403. VIEW v1 AS SELECT * FROM tb2 limit 100 ;
  404. # positive case
  405. CREATE VIEW v1 AS SELECT 1;
  406. DROP VIEW v1;
  407. --error 1064
  408. VIEW v1 AS SELECT 1;
  409. --error 1064
  410. CREATE v1 AS SELECT 1;
  411. --error 1064
  412. CREATE VIEW AS SELECT 1;
  413. --error 1064
  414. CREATE VIEW v1 SELECT 1;
  415. --error 1064
  416. CREATE VIEW v1 AS ;
  417. let $message= Testcase 3.3.1.6 ;
  418. --source include/show_msg80.inc
  419. ###############################################################################
  420. # Testcase 3.3.1.6: Ensure that any clauses that are defined to be optional
  421. # are indeed treated as optional by the MySQL server
  422. # and tools.
  423. ###############################################################################
  424. # Note: The positive test in 3.3.1.5 shows, that ALGORITHM ..., CHECK OPTION
  425. # and any column_list after the VIEW name are optional.
  426. # Therefore check here:
  427. # - ALGORITHM = <all possible algorithms>
  428. # - all possible CHECK OPTIONs
  429. # - some incomplete or wrong stuff
  430. --disable_warnings
  431. DROP VIEW IF EXISTS v1 ;
  432. --enable_warnings
  433. CREATE or REPLACE VIEW v1
  434. as SELECT * from tb2 limit 100 ;
  435. CREATE or REPLACE ALGORITHM = UNDEFINED VIEW v1
  436. as SELECT * from tb2 limit 100 ;
  437. CREATE or REPLACE ALGORITHM = MERGE VIEW v1
  438. as SELECT * from tb2 limit 100 ;
  439. CREATE or REPLACE ALGORITHM = TEMPTABLE VIEW v1
  440. as SELECT * from tb2 limit 100 ;
  441. CREATE or REPLACE ALGORITHM = TEMPTABLE VIEW v1
  442. as SELECT * from tb2 limit 100 ;
  443. # negative test cases
  444. --error 1064
  445. CREATE or REPLACE = TEMPTABLE VIEW v1
  446. as SELECT * from tb2 limit 100 ;
  447. --error 1064
  448. CREATE or REPLACE ALGORITHM TEMPTABLE VIEW v1
  449. as SELECT * from tb2 limit 100 ;
  450. --error 1064
  451. CREATE or REPLACE ALGORITHM = VIEW v1
  452. as SELECT * from tb2 limit 100 ;
  453. --error 1064
  454. CREATE or REPLACE TEMPTABLE = ALGORITHM VIEW v1
  455. as SELECT * from tb2 limit 100 ;
  456. --error 1064
  457. CREATE or REPLACE TEMPTABLE - ALGORITHM VIEW v1
  458. as SELECT * from tb2 limit 100 ;
  459. --error 1064
  460. CREATE or REPLACE GARBAGE = TEMPTABLE VIEW v1
  461. as SELECT * from tb2 limit 100 ;
  462. --error 1064
  463. CREATE or REPLACE ALGORITHM = GARBAGE VIEW v1
  464. as SELECT * from tb2 limit 100 ;
  465. Drop view if exists v1 ;
  466. CREATE or REPLACE VIEW v1
  467. AS SELECT * from tb2 where f59 < 1;
  468. CREATE or REPLACE VIEW v1
  469. AS SELECT * from tb2 where f59 < 1 WITH CHECK OPTION;
  470. CREATE or REPLACE VIEW v1
  471. AS SELECT * from tb2 where f59 < 1 WITH CASCADED CHECK OPTION;
  472. CREATE or REPLACE VIEW v1
  473. AS SELECT * from tb2 where f59 < 1 WITH LOCAL CHECK OPTION;
  474. # negative test cases
  475. --error 1064
  476. CREATE or REPLACE VIEW v1
  477. AS SELECT * from tb2 where f59 < 1 WITH NO CHECK OPTION;
  478. --error 1064
  479. CREATE or REPLACE VIEW v1
  480. AS SELECT * from tb2 where f59 < 1 CASCADED CHECK OPTION;
  481. --error 1064
  482. CREATE or REPLACE VIEW v1
  483. AS SELECT * from tb2 where f59 < 1 WITH CASCADED OPTION;
  484. --error 1064
  485. CREATE or REPLACE VIEW v1
  486. AS SELECT * from tb2 where f59 < 1 WITH CASCADED CHECK ;
  487. let $message= Testcase 3.3.1.7 ;
  488. --source include/show_msg80.inc
  489. ###############################################################################
  490. # Testcase 3.3.1.7: Ensure that all valid, fully-qualified, and non-qualified,
  491. # view names are accepted, at creation time, alteration time,
  492. # and drop time.
  493. ###############################################################################
  494. # Note(ML): non-qualified view name means a view name without preceeding
  495. # database name
  496. --disable_warnings
  497. DROP VIEW IF EXISTS v1 ;
  498. --enable_warnings
  499. Create view test.v1 AS Select * from test.tb2 limit 100 ;
  500. Alter view test.v1 AS Select F59 from test. tb2 limit 100 ;
  501. Drop view test.v1 ;
  502. Create view v1 AS Select * from test.tb2 limit 100 ;
  503. Alter view v1 AS Select F59 from test.tb2 limit 100 ;
  504. Drop view v1 ;
  505. let $message= Testcase 3.3.1.A0 ;
  506. --source include/show_msg80.inc
  507. ###############################################################################
  508. # Testcase 3.3.1.A0: Ensure that view names are treated case sensitive.
  509. ###############################################################################
  510. # Note(ML): Maybe this test produces portability problems on Windows.
  511. # FIXME There should be a test outside this one checking the
  512. # creation of objects with cases sensitive names.
  513. # If we have this test the following sub testcase should
  514. # be deleted.
  515. --disable_warnings
  516. DROP TABLE IF EXISTS t1 ;
  517. DROP VIEW IF EXISTS v1 ;
  518. DROP VIEW IF EXISTS V1 ;
  519. --enable_warnings
  520. eval CREATE TABLE t1 (f1 NUMERIC(4)) ENGINE = $engine_type;
  521. INSERT INTO t1 VALUES(1111), (2222);
  522. CREATE VIEW v1 AS SELECT * FROM t1 WHERE f1 = 1111;
  523. # We get here the sql code
  524. # - 0 on OS with cases sensitive view names (Example: UNIX)
  525. # - 1050 on OS without cases sensitive view names (Example: WINDOWS)
  526. --error 0,1050
  527. CREATE VIEW V1 AS SELECT * FROM t1 WHERE f1 = 2222;
  528. SELECT * FROM v1;
  529. # SELECT * FROM V1;
  530. --disable_warnings
  531. DROP TABLE IF EXISTS t1 ;
  532. DROP VIEW IF EXISTS v1 ;
  533. DROP VIEW IF EXISTS V1 ;
  534. --enable_warnings
  535. let $message= Testcase 3.3.1.8 ;
  536. --source include/show_msg80.inc
  537. ###############################################################################
  538. # Testcase 3.3.1.8: Ensure that any invalid view name is never accepted, and
  539. # that an appropriate error message is returned when the name
  540. # is rejected.
  541. ###############################################################################
  542. # Note(ML): There could be more negative tests here, but I assume that the
  543. # server routines checking if a table or view name is acceptable are
  544. # heavily tested in tests checking the creation of tables.
  545. --error 1064
  546. Create view select AS Select * from test.tb2 limit 100;
  547. --error 1064
  548. Create view as AS Select * from test.tb2 limit 100;
  549. --error 1064
  550. Create view where AS Select * from test.tb2 limit 100;
  551. --error 1064
  552. Create view from AS Select * from test.tb2 limit 100;
  553. --error 1064
  554. Create view while AS Select * from test.tb2 limit 100;
  555. --error 1064
  556. Create view asdkj*(&*&&^ as Select * from test.tb2 limit 100 ;
  557. --disable_warnings
  558. Drop view if exists test.procedure ;
  559. --enable_warnings
  560. Create view test.procedure as Select * from test.tb2 limit 100 ;
  561. Drop view if exists test.procedure ;
  562. let $message= Testcase 3.3.1.9 ;
  563. --source include/show_msg80.inc
  564. ###############################################################################
  565. # Testcase 3.3.1.9: Ensure that a reference to a non-existent view is rejected
  566. # with an appropriate error message
  567. ###############################################################################
  568. # Note(ML): The SELECT statement syntax does not contain any functionality to
  569. # claim, that the object after FROM must be a VIEW. SHOW's will be
  570. # checked in 3.3.11 Checks on SHOW, EXPLAIN, and DESCRIBE statements.
  571. # Let's check here a view based on a dropped view or table.
  572. --disable_warnings
  573. Drop TABLE IF EXISTS t1 ;
  574. Drop VIEW IF EXISTS v1;
  575. Drop VIEW IF EXISTS v2;
  576. Drop VIEW IF EXISTS v3;
  577. --enable_warnings
  578. CREATE TABLE t1 ( f1 char(5));
  579. INSERT INTO t1 SET f1 = 'abcde';
  580. CREATE VIEW v1 AS SELECT f1 FROM t1;
  581. CREATE VIEW v2 AS SELECT * FROM v1;
  582. # Only negative cases, positive cases will be checked later:
  583. DROP TABLE t1;
  584. --error 1356
  585. SELECT * FROM v1;
  586. --error 1356
  587. DELETE FROM v1;
  588. --error 1356
  589. UPDATE v1 SET f1 = 'aaaaa';
  590. --error 1356
  591. INSERT INTO v1 SET f1 = "fffff";
  592. # v2 is based on v1, which is now invalid
  593. --error 1356
  594. SELECT * FROM v2;
  595. --error 1356
  596. DELETE FROM v2;
  597. --error 1356
  598. UPDATE v2 SET f1 = 'aaaaa';
  599. --error 1356
  600. INSERT INTO v2 SET f1 = "fffff";
  601. DROP VIEW v1;
  602. # v2 is based on v1, which is now dropped
  603. --error 1356
  604. SELECT * FROM v2;
  605. --error 1356
  606. DELETE FROM v2;
  607. --error 1356
  608. UPDATE v2 SET f1 = 'aaaaa';
  609. --error 1356
  610. INSERT INTO v2 SET f1 = "fffff";
  611. DROP VIEW v2;
  612. # A VIEW based on itself is non sense.
  613. --disable_warnings
  614. DROP TABLE IF EXISTS t1 ;
  615. DROP VIEW IF EXISTS v1 ;
  616. --enable_warnings
  617. CREATE TABLE t1 (f1 FLOAT);
  618. # Create a new VIEW based on itself
  619. --error 1146
  620. CREATE VIEW v1 AS SELECT * FROM v1;
  621. # Replace a valid VIEW with one new based on itself
  622. CREATE VIEW v1 AS SELECT * FROM t1;
  623. --error 1146
  624. CREATE or REPLACE VIEW v1 AS SELECT * FROM v1;
  625. DROP VIEW v1;
  626. DROP TABLE t1;
  627. let $message= Testcase 3.3.1.10 ;
  628. --source include/show_msg80.inc
  629. ###############################################################################
  630. # Testcase 3.3.1.10: Ensure that it is not possible to create two views with
  631. # the same name in the same database.
  632. ###############################################################################
  633. --disable_warnings
  634. Drop view if exists test.v1 ;
  635. --enable_warnings
  636. Create view test.v1 AS Select * from test.tb2 ;
  637. --error 1050
  638. Create view test.v1 AS Select F59 from test.tb2 ;
  639. --error 1050
  640. Create view v1 AS Select F59 from test.tb2 ;
  641. let $message= Testcase 3.3.1.11 ;
  642. --source include/show_msg80.inc
  643. ###############################################################################
  644. # Testcase 3.3.1.11: Ensure that it is not possible to create a view and a base
  645. # table with the same name in the same database.
  646. ###############################################################################
  647. # The VIEW should get the same name like an already existing TABLE.
  648. --error 1050
  649. Create view test.tb2 AS Select f59,f60 from test.tb2 limit 100 ;
  650. --error 1050
  651. Create view tb2 AS Select f59,f60 from test.tb2 limit 100 ;
  652. # The TABLE should get the same name like an already existing VIEW.
  653. --disable_warnings
  654. Drop view if exists test.v111 ;
  655. --enable_warnings
  656. Create view test.v111 as select * from tb2 limit 50;
  657. --error 1050
  658. Create table test.v111(f1 int );
  659. --error 1050
  660. Create table v111(f1 int );
  661. DROP VIEW test.v111;
  662. let $message= Testcase 3.3.1.12 ;
  663. --source include/show_msg80.inc
  664. ###############################################################################
  665. # Testcase 3.3.1.12: Ensure that it is possible to create two or more views and
  666. # base tables with the same name, providing each resides in
  667. # a different database.
  668. ###############################################################################
  669. USE test;
  670. --disable_warnings
  671. Drop database if exists test2 ;
  672. --enable_warnings
  673. Create database test2 ;
  674. # Plan of sub tests
  675. # Object name object type in object type in
  676. # database test database test2
  677. # t1 TABLE TABLE
  678. # t2 TABLE VIEW
  679. # v1 VIEW TABLE
  680. # v2 VIEW VIEW
  681. --disable_warnings
  682. DROP TABLE IF EXISTS test.t0, test.t1, test.t2;
  683. DROP VIEW IF EXISTS test.v1;
  684. DROP VIEW IF EXISTS test.v2;
  685. --enable_warnings
  686. CREATE TABLE test.t1 ( f1 VARCHAR(20));
  687. CREATE TABLE test2.t1 ( f1 VARCHAR(20));
  688. CREATE TABLE test.t2 ( f1 VARCHAR(20));
  689. CREATE TABLE test2.v1 ( f1 VARCHAR(20));
  690. # t0 is an auxiliary table needed for the VIEWs
  691. CREATE TABLE test.t0 ( f1 VARCHAR(20));
  692. CREATE TABLE test2.t0 ( f1 VARCHAR(20));
  693. CREATE VIEW test2.t2 AS SELECT * FROM test2.t0;
  694. CREATE VIEW test.v1 AS SELECT * FROM test.t0;
  695. CREATE VIEW test.v2 AS SELECT * FROM test.t0;
  696. CREATE VIEW test2.v2 AS SELECT * FROM test2.t0;
  697. # Some additional tests on the just created objects to show that they are
  698. # accessable and do have the expected content.
  699. # INSERTs with full qualified table
  700. INSERT INTO test.t1 VALUES('test.t1 - 1');
  701. INSERT INTO test2.t1 VALUES('test2.t1 - 1');
  702. INSERT INTO test.t2 VALUES('test.t2 - 1');
  703. INSERT INTO test2.v1 VALUES('test2.v1 - 1');
  704. INSERT INTO test.t0 VALUES('test.t0 - 1');
  705. INSERT INTO test2.t0 VALUES('test2.t0 - 1');
  706. # INSERTs with not full qualified table name.
  707. USE test;
  708. INSERT INTO t1 VALUES('test.t1 - 2');
  709. INSERT INTO t2 VALUES('test.t2 - 2');
  710. INSERT INTO t0 VALUES('test.t0 - 2');
  711. USE test2;
  712. INSERT INTO t1 VALUES('test2.t1 - 2');
  713. INSERT INTO v1 VALUES('test2.v1 - 2');
  714. INSERT INTO t0 VALUES('test2.t0 - 2');
  715. # SELECTs with full qualified table
  716. SELECT * FROM t1;
  717. SELECT * FROM t2;
  718. SELECT * FROM v1;
  719. SELECT * FROM v2;
  720. USE test;
  721. SELECT * FROM t1;
  722. SELECT * FROM t2;
  723. SELECT * FROM v1;
  724. SELECT * FROM v2;
  725. let $message= Testcase 3.3.1.13 ;
  726. --source include/show_msg80.inc
  727. ###############################################################################
  728. # Testcase 3.3.1.13: Ensure that, if the CREATE OR REPLACE VIEW statement is
  729. # used to create a view using the name of an existing view,
  730. # it first cleanly drops the existing view and then creates
  731. # the new view.
  732. ###############################################################################
  733. --disable_warnings
  734. DROP TABLE IF EXISTS t1;
  735. DROP VIEW IF EXISTS v1;
  736. --enable_warnings
  737. CREATE TABLE t1 (f1 BIGINT);
  738. INSERT INTO t1 VALUES(1);
  739. CREATE VIEW test.v1 AS SELECT * FROM t1 limit 2;
  740. SHOW CREATE VIEW test.v1;
  741. SELECT * FROM test.v1;
  742. # Switch the algorithm
  743. CREATE OR REPLACE ALGORITHM = TEMPTABLE VIEW test.v1
  744. AS SELECT * FROM t1 limit 2;
  745. SHOW CREATE VIEW test.v1;
  746. SELECT * FROM test.v1;
  747. # Switch the base table
  748. CREATE OR REPLACE VIEW test.v1 AS SELECT * FROM tb2 limit 2;
  749. SHOW CREATE VIEW test.v1;
  750. if ($have_bug_11589)
  751. {
  752. --disable_ps_protocol
  753. }
  754. SELECT * FROM test.v1 ;
  755. --enable_ps_protocol
  756. # Switch the SELECT but not the base table
  757. CREATE OR REPLACE VIEW test.v1 AS SELECT F59 FROM tb2 limit 10,100;
  758. SHOW CREATE VIEW test.v1;
  759. SELECT * FROM test.v1;
  760. Drop table test.t1 ;
  761. Drop view test.v1 ;
  762. let $message= Testcase 3.3.1.14 ;
  763. --source include/show_msg80.inc
  764. ###############################################################################
  765. # Testcase 3.3.1.14: Ensure that, if the CREATE OR REPLACE VIEW statement is
  766. # used to create a view using the name of an existing base
  767. # table, it fails with an appropriate error message.
  768. ###############################################################################
  769. --error 1347
  770. CREATE OR REPLACE VIEW test.tb2 AS SELECT * From tb2 LIMIT 2;
  771. --error 1347
  772. CREATE OR REPLACE VIEW tb2 AS SELECT * From tb2 LIMIT 2;
  773. let $message= Testcase 3.3.1.15 ;
  774. --source include/show_msg80.inc
  775. ###############################################################################
  776. # Testcase 3.3.1.15: Ensure that, if the CREATE OR REPLACE VIEW statement is
  777. # used to create a view using a name that does not already
  778. # belong to an existing view or base table, it cleanly
  779. # creates the view.
  780. ###############################################################################
  781. --disable_warnings
  782. Drop table if exists test.v1 ;
  783. --enable_warnings
  784. CREATE OR REPLACE view test.v1 as select * from tb2 LIMIT 2;
  785. if ($have_bug_11589)
  786. {
  787. --disable_ps_protocol
  788. }
  789. SELECT * FROM test.v1;
  790. --enable_ps_protocol
  791. Drop view test.v1 ;
  792. let $message= Testcase 3.3.1.16 + 3.3.1.17 ;
  793. --source include/show_msg80.inc
  794. ###############################################################################
  795. # Testcase 3.3.1.16: Ensure that a view with a definition that does not include
  796. # an explicit column-name list takes its column names from
  797. # the underlying base table(s).
  798. # Testcase 3.3.1.17: Ensure that a view with a definition that does include an
  799. # explicit column-name list uses the explicit names and not
  800. # the name of the columns from the underlying base tables(s)
  801. ###############################################################################
  802. --disable_warnings
  803. Drop table if exists test.v1 ;
  804. --enable_warnings
  805. CREATE OR REPLACE VIEW v1 AS SELECT * From tb2;
  806. # Note(ML): The empty result is intended, because I want to compare
  807. # column names only
  808. SELECT * FROM tb2 WHERE 1 = 2;
  809. SELECT * FROM v1 WHERE 1 = 2;
  810. Drop view v1;
  811. --disable_warnings
  812. DROP TABLE IF EXISTS t1;
  813. DROP VIEW IF EXISTS v1;
  814. --enable_warnings
  815. CREATE TABLE t1 (f1 NUMERIC(15,3));
  816. INSERT INTO t1 VALUES(8.8);
  817. # 1. no explicit column in VIEW definition or SELECT
  818. CREATE VIEW v1 AS SELECT * FROM t1;
  819. SHOW CREATE VIEW v1;
  820. SELECT * FROM v1;
  821. # 2. no explicit column in VIEW definition, but in SELECT column_list
  822. CREATE OR REPLACE VIEW v1 AS SELECT f1 FROM t1;
  823. SHOW CREATE VIEW v1;
  824. SELECT * FROM v1;
  825. # 3. no explicit column in VIEW definition, but alias from SELECT column_list
  826. CREATE OR REPLACE VIEW v1 AS SELECT f1 As my_column FROM t1;
  827. SHOW CREATE VIEW v1;
  828. SELECT * FROM v1;
  829. # 4. Finally the requirement: explicit column_list in VIEW definition
  830. CREATE OR REPLACE VIEW v1(column1,column2)
  831. AS SELECT f1 As my_column, f1 FROM t1;
  832. SHOW CREATE VIEW v1;
  833. SELECT * FROM v1;
  834. CREATE OR REPLACE VIEW test.v1(column1,column2)
  835. AS SELECT f1 As my_column, f1 FROM test.t1;
  836. SHOW CREATE VIEW v1;
  837. SELECT * FROM v1;
  838. let $message= Testcase 3.3.1.18 ;
  839. --source include/show_msg80.inc
  840. ###############################################################################
  841. # Testcase 3.3.1.18: Ensure that a reference to a view with a definition that
  842. # includes an explicit column-name fails, with an appropriate
  843. # error message, if the reference includes columns names
  844. # from the underlying base table(s) rather than the view
  845. # column names.
  846. ###############################################################################
  847. # Note(ML): The goal is to check the merge algorithm.
  848. --disable_warnings
  849. Drop view if exists v1 ;
  850. Drop view if exists v1_1 ;
  851. --enable_warnings
  852. Create view v1
  853. as Select test.tb2.f59 as NewNameF1, test.tb2.f60
  854. from test.tb2 limit 0,100 ;
  855. Create view v1_1
  856. as Select test.tb2.f59 as NewNameF1, test.tb2.f60 as NewNameF2
  857. from tb2 limit 0,100 ;
  858. --error 1054
  859. SELECT NewNameF1,f60 FROM test.v1_1 ;
  860. --error 1054
  861. SELECT NewNameF1, v1_1.f60 FROM test.v1_1 ;
  862. --error 1054
  863. SELECT f59, f60 FROM test.v1 ;
  864. Use test ;
  865. --error 1054
  866. SELECT F59 FROM v1 ;
  867. let $message= Testcase 3.3.1.19 ;
  868. --source include/show_msg80.inc
  869. ###############################################################################
  870. # Testcase 3.3.1.19: Ensure that every column of a view must have a
  871. # distinct name
  872. ###############################################################################
  873. --disable_warnings
  874. DROP TABLE IF EXISTS t1, t2;
  875. DROP VIEW IF EXISTS v1;
  876. --enable_warnings
  877. CREATE TABLE t1( f1 BIGINT, f2 DECIMAL(5,2));
  878. INSERT INTO t1 VALUES(7, 7.7);
  879. CREATE TABLE t2( f1 BIGINT, f2 DECIMAL(5,2));
  880. INSERT INTO t2 VALUES(6, 6.6);
  881. # positive testcases
  882. CREATE VIEW v1 AS SELECT * FROM t1;
  883. SELECT * FROM v1;
  884. CREATE OR REPLACE VIEW v1 AS SELECT f1, f2 FROM t1;
  885. SELECT * FROM v1;
  886. CREATE OR REPLACE VIEW v1 AS SELECT f1 AS my_f1, f2 AS my_f2 FROM t1;
  887. SELECT * FROM v1;
  888. CREATE OR REPLACE VIEW v1 (my_f1, my_f2) AS SELECT f1, f2 FROM t1;
  889. SELECT * FROM v1;
  890. CREATE OR REPLACE VIEW v1 (my_f1, my_f2) AS SELECT t1.f1, t2.f2 FROM t1, t2;
  891. SELECT * FROM v1;
  892. # negative testcases (sometimes including the underlying SELECT)
  893. # duplicate via alias in SELECT
  894. SELECT f1, f2 AS f1 FROM t1;
  895. --error 1060
  896. CREATE OR REPLACE VIEW v1 AS SELECT f1, f2 AS f1 FROM t1;
  897. # duplicate via JOIN SELECT
  898. SELECT t1.f1, t2.f1 AS f1 FROM t1, t2;
  899. --error 1060
  900. CREATE OR REPLACE VIEW v1 AS SELECT t1.f1, t2.f1 AS f1 FROM t1, t2;
  901. # duplicate via VIEW definition
  902. --error 1060
  903. CREATE OR REPLACE VIEW v1 (my_col, my_col) AS SELECT * FROM t1;
  904. let $message= Testcase 3.3.1.20 ;
  905. --source include/show_msg80.inc
  906. ###############################################################################
  907. # Testcase 3.3.1.20: Ensure that, if a column-name list is provided for a
  908. # view definition, the list contains a name for every column
  909. # in the view
  910. ###############################################################################
  911. --disable_warnings
  912. DROP TABLE IF EXISTS t1;
  913. --enable_warnings
  914. CREATE TABLE t1( f1 BIGINT, f2 DECIMAL(5,2));
  915. # positive case
  916. CREATE OR REPLACE VIEW v1 (my_f1, my_f2) AS SELECT * FROM t1;
  917. CREATE OR REPLACE VIEW v1 (my_f1, my_f2) AS SELECT f1, f2 FROM t1;
  918. # negative cases, where we assign a wrong number of column names
  919. --error 1353
  920. CREATE OR REPLACE VIEW v1 (my_f1 ) AS SELECT * FROM t1;
  921. --error 1353
  922. CREATE OR REPLACE VIEW v1 (my_f1 ) AS SELECT f1, f2 FROM t1;
  923. --error 1353
  924. CREATE OR REPLACE VIEW v1 (my_f1, my_f2, my_f3) AS SELECT * FROM t1;
  925. --error 1353
  926. CREATE OR REPLACE VIEW v1 (my_f1, my_f2, my_f3) AS SELECT f1, f2 FROM t1;
  927. let $message= Testcase 3.3.1.21 ;
  928. --source include/show_msg80.inc
  929. ###############################################################################
  930. # Testcase 3.3.1.21: Ensure that a view column can be a direct copy of a
  931. # column from an underlying table.
  932. ###############################################################################
  933. --disable_warnings
  934. DROP VIEW IF EXISTS v1;
  935. --enable_warnings
  936. CREATE VIEW test.v1( F59, F60 ) AS SELECT F59, F60 From tb2 LIMIT 2;
  937. SELECT * FROM test.v1;
  938. Drop view if exists test.v1 ;
  939. let $message= Testcase 3.3.1.22 ;
  940. --source include/show_msg80.inc
  941. ###############################################################################
  942. # Testcase 3.3.1.22: Ensure that a view column can be based on any valid
  943. # expression, whether or not the expression includes a
  944. # reference of the column of an underlying table.
  945. ###############################################################################
  946. --disable_warnings
  947. DROP VIEW IF EXISTS v1;
  948. --enable_warnings
  949. CREATE VIEW test.v1( product ) AS SELECT f59*f60 From tb2 LIMIT 2;
  950. SELECT * FROM test.v1;
  951. CREATE OR REPLACE VIEW test.v1( product ) AS SELECT 1*2;
  952. SELECT * FROM test.v1;
  953. CREATE OR REPLACE VIEW test.v1( product ) AS SELECT USER();
  954. SELECT * FROM test.v1;
  955. Drop view if exists test.v1 ;
  956. let $message= Testcase 3.3.1.23 + 3.3.1.24 ;
  957. --source include/show_msg80.inc
  958. ###############################################################################
  959. # Testcase 3.3.1.23: Ensure that a view definition that includes a reference to
  960. # a non-existent table fails, with an appropriate error
  961. # message, at creation time.
  962. # Testcase 3.3.1.24: Ensure that a view definition that includes a reference to
  963. # a non-existent view fails, with an appropriate error
  964. # message, at creation time.
  965. ###############################################################################
  966. # Note(ML): The SELECT statement syntax does not contain any functionality to
  967. # claim, that the object after FROM must be a VIEW.
  968. # Testcase 3.3.1.24 should be deleted.
  969. USE test;
  970. --disable_warnings
  971. DROP TABLE IF EXISTS t1;
  972. DROP VIEW IF EXISTS v1;
  973. DROP VIEW IF EXISTS v2;
  974. --enable_warnings
  975. --error 1146
  976. CREATE VIEW test.v2 AS SELECT * FROM test.t1;
  977. --error 1146
  978. CREATE VIEW v2 AS Select * from test.v1;
  979. DROP VIEW IF EXISTS v2;
  980. let $message= Testcase 3.3.1.25 ;
  981. --source include/show_msg80.inc
  982. ###############################################################################
  983. # Testcase 3.3.1.25: Ensure that a view cannot be based on one or more
  984. # temporary tables.
  985. ###############################################################################
  986. # Note(ML): A temporary table hides permanent tables which have the same name.
  987. # So do not forget to drop the temporary table.
  988. --disable_warnings
  989. DROP TABLE IF EXISTS t1_temp;
  990. DROP TABLE IF EXISTS t2_temp;
  991. DROP VIEW IF EXISTS v1;
  992. --enable_warnings
  993. Create table t1_temp(f59 char(10),f60 int) ;
  994. Create temporary table t1_temp(f59 char(10),f60 int) ;
  995. Insert into t1_temp values('FER',90);
  996. Insert into t1_temp values('CAR',27);
  997. --error 1352
  998. Create view v1 as select * from t1_temp ;
  999. Create temporary table t2_temp(f59 char(10),f60 int) ;
  1000. Insert into t2_temp values('AAA',11);
  1001. Insert into t2_temp values('BBB',22);
  1002. --error 1352
  1003. Create or replace view v1
  1004. as select t1_temp.f59,t2_temp.f59 from t1_temp,t2_temp ;
  1005. DROP temporary table t1_temp;
  1006. DROP table t1_temp;
  1007. DROP temporary table t2_temp;
  1008. --disable_warnings
  1009. DROP TABLE IF EXISTS t1;
  1010. DROP VIEW IF EXISTS v1;
  1011. --enable_warnings
  1012. CREATE TABLE t1 (f1 char(10));
  1013. CREATE TEMPORARY TABLE t2 (f2 char(10));
  1014. INSERT INTO t1 VALUES('t1');
  1015. INSERT INTO t1 VALUES('A');
  1016. INSERT INTO t2 VALUES('t2');
  1017. INSERT INTO t2 VALUES('B');
  1018. # simple SELECT
  1019. --error 1352
  1020. CREATE OR REPLACE VIEW v1 AS SELECT f2 FROM t2;
  1021. # JOIN - temporary table first
  1022. --error 1352
  1023. CREATE OR REPLACE VIEW v1 AS SELECT * FROM t2, t1;
  1024. --error 1352
  1025. CREATE OR REPLACE VIEW v1 AS SELECT f2, f1 FROM t2, t1;
  1026. # JOIN - temporary table last
  1027. --error 1352
  1028. CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1, t2;
  1029. --error 1352
  1030. CREATE OR REPLACE VIEW v1 AS SELECT f1, f2 FROM t1, t2;
  1031. # UNION - temporary table first
  1032. --error 1352
  1033. CREATE OR REPLACE VIEW v1 AS SELECT * FROM t2 UNION SELECT * FROM t1;
  1034. --error 1352
  1035. CREATE OR REPLACE VIEW v1 AS SELECT f2 FROM t2 UNION SELECT f1 FROM t1;
  1036. # UNION - temporary table last
  1037. --error 1352
  1038. CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1 UNION SELECT * FROM t2;
  1039. --error 1352
  1040. CREATE OR REPLACE VIEW v1 AS SELECT f1 FROM t1 UNION SELECT f2 FROM t2;
  1041. # SUBQUERY - temporary table first
  1042. --error 1352
  1043. CREATE OR REPLACE VIEW v1 AS SELECT 1 FROM t2
  1044. WHERE f2 = ( SELECT f1 FROM t1 );
  1045. # SUBQUERY - temporary table last
  1046. --error 1352
  1047. CREATE OR REPLACE VIEW v1 AS SELECT 1 FROM t1
  1048. WHERE f1 = ( SELECT f2 FROM t2 );
  1049. DROP TABLE t1;
  1050. DROP TEMPORARY TABLE t2;
  1051. let $message= Testcase 3.3.1.26 ;
  1052. --source include/show_msg80.inc
  1053. ###############################################################################
  1054. # Testcase 3.3.1.26: Ensure that a view can be based on an underlying table
  1055. # within the same database
  1056. ###############################################################################
  1057. --disable_warnings
  1058. DROP VIEW IF EXISTS v1;
  1059. --enable_warnings
  1060. Create view test.v1 AS Select * from test.tb2 limit 2 ;
  1061. if ($have_bug_11589)
  1062. {
  1063. --disable_ps_protocol
  1064. }
  1065. Select * from test.v1;
  1066. --enable_ps_protocol
  1067. Drop view test.v1 ;
  1068. let $message= Testcase 3.3.1.27 ;
  1069. --source include/show_msg80.inc
  1070. ###############################################################################
  1071. # Testcase 3.3.1.27: Ensure that a view can be based on an underlying view
  1072. # within the same database.
  1073. ###############################################################################
  1074. --disable_warnings
  1075. DROP VIEW IF EXISTS test.v1;
  1076. Drop VIEW IF EXISTS test.v1_1 ;
  1077. --enable_warnings
  1078. Create view test.v1 AS Select * from test.tb2 limit 2 ;
  1079. Create view test.v1_1 AS Select F59 from test.v1 ;
  1080. Select * from test.v1_1 limit 20 ;
  1081. Drop view test.v1 ;
  1082. Drop view test.v1_1 ;
  1083. let $message= Testcase 3.3.1.28 ;
  1084. --source include/show_msg80.inc
  1085. ###############################################################################
  1086. # Testcase 3.3.1.28: Ensure that a view can be based on an underlying table
  1087. # from another database.
  1088. ###############################################################################
  1089. --disable_warnings
  1090. Drop database if exists test2 ;
  1091. --enable_warnings
  1092. create database test2 ;
  1093. Create view test2.v2 AS Select * from test.tb2 limit 50,50;
  1094. use test2 ;
  1095. Create view v1 AS Select * from test.tb2 limit 50 ;
  1096. if ($have_bug_11589)
  1097. {
  1098. --disable_ps_protocol
  1099. }
  1100. Select * from v1 ;
  1101. --enable_ps_protocol
  1102. Select * from test2.v2 ;
  1103. Drop view if exists test2.v1 ;
  1104. Drop view if exists test2.v2 ;
  1105. Drop database test2 ;
  1106. let $message= Testcase 3.3.1.29 ;
  1107. --source include/show_msg80.inc
  1108. ###############################################################################
  1109. # Testcase 3.3.1.29: Ensure that a view can be based on an underlying view from
  1110. # another database.
  1111. ###############################################################################
  1112. --disable_warnings
  1113. Drop database if exists test2 ;
  1114. Drop view if exists test.v1 ;
  1115. --enable_warnings
  1116. create database test2 ;
  1117. use test2;
  1118. Create view test.v1 AS Select * from test.tb2 limit 50 ;
  1119. Create view test2.v2 AS Select F59 from test.v1 ;
  1120. Drop view if exists test.v1 ;
  1121. Drop view if exists test2.v2 ;
  1122. # Note(ML): Testcase 3.3.1.30 (identical requirements like 3.3.1.26) omitted
  1123. let $message= Testcase 3.3.1.31 ;
  1124. --source include/show_msg80.inc
  1125. ###############################################################################
  1126. # Testcase 3.3.1.31: Ensure that a view can be based on a join of multiple
  1127. # tables within the same database.
  1128. ###############################################################################
  1129. --disable_warnings
  1130. Drop table if exists test.t1 ;
  1131. --enable_warnings
  1132. CREATE TABLE test.t1 ( f59 int, f60 int );
  1133. INSERT INTO test.t1 VALUES( 34, 654 );
  1134. INSERT INTO test.t1 VALUES( 906, 434 );
  1135. INSERT INTO test.t1 VALUES( 445, 765 );
  1136. Create or replace view test.v1
  1137. AS SELECT test.t1.F59, test.tb2.F60
  1138. FROM test.tb2 JOIN test.t1 ON test.tb2.F59 = test.t1.F59 ;
  1139. Select * from test.v1;
  1140. Drop view test.v1 ;
  1141. let $message= Testcase 3.3.1.32 ;
  1142. --source include/show_msg80.inc
  1143. ###############################################################################
  1144. # Testcase 3.3.1.32: Ensure that a view can be based on a join of multiple
  1145. # tables from another database.
  1146. ###############################################################################
  1147. --disable_warnings
  1148. Drop table if exists test.t1 ;
  1149. Drop database if exists test2 ;
  1150. Drop view if exists test.v1 ;
  1151. --enable_warnings
  1152. create database test2 ;
  1153. use test2 ;
  1154. CREATE TABLE t1 ( f59 int, f60 int );
  1155. INSERT INTO t1 VALUES( 34, 654 );
  1156. INSERT INTO t1 VALUES( 906, 434 );
  1157. INSERT INTO t1 VALUES( 445, 765 );
  1158. CREATE VIEW test2.v1
  1159. AS SELECT test.tb2.F59, test.tb2.F60
  1160. FROM test.tb2 INNER JOIN test2.t1 ON tb2.f59 = t1.f59;
  1161. Select * from test2.v1;
  1162. Use test;
  1163. let $message= Testcase 3.3.1.33 ;
  1164. --source include/show_msg80.inc
  1165. ###############################################################################
  1166. # Testcase 3.3.1.33: Ensure that a view can be based on a join of multiple
  1167. # views within the same database.
  1168. ###############################################################################
  1169. --disable_warnings
  1170. Drop view if exists test.v1_firstview ;
  1171. Drop view if exists test.v1_secondview ;
  1172. Drop view if exists test.v1 ;
  1173. --enable_warnings
  1174. CREATE VIEW test.v1_firstview AS SELECT * FROM test.tb2;
  1175. CREATE VIEW test.v1_secondview AS SELECT * FROM test.tb2;
  1176. CREATE VIEW test.v1
  1177. AS SELECT test.v1_firstview.f59, test.v1_firstview.f60
  1178. FROM test.v1_firstview INNER JOIN test.v1_secondview
  1179. ON test.v1_firstview.f59 = test.v1_secondview.f59 ;
  1180. SELECT * FROM test.v1 limit 0,10;
  1181. Drop view if exists test.v1_firstview ;
  1182. Drop view if exists test.v1_secondview ;
  1183. Drop view if exists test.v1 ;
  1184. let $message= Testcase 3.3.1.34 ;
  1185. --source include/show_msg80.inc
  1186. ###############################################################################
  1187. # Testcase 3.3.1.34: Ensure that a view can be based on a join of multiple
  1188. # views from another database.
  1189. ###############################################################################
  1190. --disable_warnings
  1191. Drop database if exists test2 ;
  1192. Drop view if exists test.v1_firstview ;
  1193. Drop view if exists test.v1_secondview ;
  1194. --enable_warnings
  1195. create database test2 ;
  1196. use test2 ;
  1197. CREATE VIEW test.v1_firstview AS SELECT * FROM test.tb2 ;
  1198. CREATE VIEW test.v1_secondview AS SELECT * FROM test.tb2 ;
  1199. CREATE VIEW v1
  1200. AS SELECT test.v1_firstview.F59, test.v1_firstview.F60
  1201. FROM test.v1_firstview INNER JOIN test.v1_secondview
  1202. ON test.v1_firstview.f59 = test.v1_secondview.f59 ;
  1203. SELECT * FROM v1 limit 0,10;
  1204. Drop view v1 ;
  1205. Drop view test.v1_firstview ;
  1206. Drop view test.v1_secondview ;
  1207. let $message= Testcase 3.3.1.35 ;
  1208. --source include/show_msg80.inc
  1209. ###############################################################################
  1210. # Testcase 3.3.1.35: Ensure that a view can be based on a join of multiple
  1211. # tables and/or views within the same database.
  1212. ###############################################################################
  1213. use test;
  1214. --disable_warnings
  1215. Drop view if exists test.v1;
  1216. Drop view if exists test.v1_firstview;
  1217. --enable_warnings
  1218. CREATE VIEW test.v1_firstview AS SELECT * FROM test.tb2;
  1219. CREATE VIEW test.v1
  1220. AS SELECT test.v1_firstview.f59, test.v1_firstview.f60
  1221. FROM test.v1_firstview INNER JOIN test.tb2
  1222. ON test.v1_firstview.f59 = test.tb2.f59;
  1223. SELECT * FROM test.v1 limit 0,10;
  1224. Drop view test.v1 ;
  1225. Drop view test.v1_firstview;
  1226. let $message= Testcase 3.3.1.36 ;
  1227. --source include/show_msg80.inc
  1228. ###############################################################################
  1229. # Testcase 3.3.1.36: Ensure that a view can be based on a join of multiple
  1230. # tables and/or views from another database.
  1231. ###############################################################################
  1232. --disable_warnings
  1233. Drop database if exists test2 ;
  1234. --enable_warnings
  1235. create database test2 ;
  1236. use test2 ;
  1237. CREATE VIEW v1_firstview AS SELECT * FROM test.tb2 ;
  1238. CREATE VIEW v1
  1239. AS SELECT v1_firstview.f59, v1_firstview.f60
  1240. FROM v1_firstview INNER JOIN test.tb2 ON v1_firstview.f59 = test.tb2.f59 ;
  1241. SELECT * FROM v1 limit 0,10;
  1242. Drop database test2 ;
  1243. let $message= Testcase 3.3.1.37 ;
  1244. --source include/show_msg80.inc
  1245. ###############################################################################
  1246. # Testcase 3.3.1.37: Ensure that a view can be based on a join of multiple
  1247. # tables and/or views, some of which reside in the same
  1248. # database and some of which reside in one other database.
  1249. ###############################################################################
  1250. # (Bug Associated)
  1251. # FIXME: ??? Bug number
  1252. # FIXME: reimplement this test
  1253. use test;
  1254. --disable_warnings
  1255. Drop table if exists t1;
  1256. Drop view if exists test.v1 ;
  1257. Drop view if exists test.v1_1 ;
  1258. Drop view if exists test.v1_1 ;
  1259. Drop view if exists test.v1_main ;
  1260. --enable_warnings
  1261. Create view test.v1 as Select f59, f60 FROM test.tb2;
  1262. Select * from test.v1 limit 0,10;
  1263. Create table t1(f59 int, f60 int);
  1264. Insert into t1 values (90,507) ;
  1265. Create view v1_1 as Select f59,f60 from t1 ;
  1266. Select * from v1_1 ;
  1267. Create view v1_main
  1268. as SELECT test.tb2.f59 FROM test.tb2 JOIN test.v1
  1269. ON test.tb2.f59 = test.v1.f59;
  1270. Select * from v1_main limit 0,10;
  1271. Drop table t1;
  1272. Drop view test.v1 ;
  1273. Drop view test.v1_1 ;
  1274. Drop view test.v1_main ;
  1275. let $message= Testcase 3.3.1.31 - 3.3.1.37 New Implementation ;
  1276. --source include/show_msg80.inc
  1277. ###############################################################################
  1278. # ML: The testcases 3.3.1.31 - 3.3.1.37 should be tested more systematic.
  1279. # Ensure that a view can be based on a join of multiple
  1280. # Testcase 3.3.1.31: tables within the same database
  1281. # Testcase 3.3.1.32: tables from another database.
  1282. # Testcase 3.3.1.33: views within the same database
  1283. # Testcase 3.3.1.34: views from another database
  1284. # Testcase 3.3.1.35: tables and/or views within the same database
  1285. # Testcase 3.3.1.36: tables and/or views from another database
  1286. # Testcase 3.3.1.37: tables and/or views, some of which reside in
  1287. # the same database and some of which reside in
  1288. # one other database.
  1289. ###############################################################################
  1290. USE test;
  1291. --disable_warnings
  1292. DROP DATABASE IF EXISTS test2;
  1293. DROP TABLE IF EXISTS t0,t1;
  1294. DROP VIEW IF EXISTS t3,t4;
  1295. --enable_warnings
  1296. CREATE DATABASE test2;
  1297. --disable_warnings
  1298. CREATE TABLE test1.t0 (f1 VARCHAR(20));
  1299. CREATE TABLE test1.t1 (f1 VARCHAR(20));
  1300. --enable_warnings
  1301. CREATE TABLE test2.t0 (f1 VARCHAR(20));
  1302. CREATE TABLE test2.t1 (f1 VARCHAR(20));
  1303. --disable_warnings
  1304. CREATE VIEW test1.t2 AS SELECT * FROM test1.t0;
  1305. CREATE VIEW test1.t3 AS SELECT * FROM test2.t0;
  1306. --enable_warnings
  1307. CREATE VIEW test2.t2 AS SELECT * FROM test2.t0;
  1308. CREATE VIEW test2.t3 AS SELECT * FROM test1.t0;
  1309. INSERT INTO test1.t0 VALUES('test1.t0');
  1310. INSERT INTO test1.t1 VALUES('test1.t1');
  1311. INSERT INTO test2.t0 VALUES('test2.t0');
  1312. INSERT INTO test2.t1 VALUES('test2.t1');
  1313. # The extreme simple standard JOIN VIEW is:
  1314. # CREATE OR REPLACE VIEW <database>.v1
  1315. # AS SELECT * FROM <table or view 1>,<table or view 2>
  1316. let $view= test.v1;
  1317. let $tab1= test.t0;
  1318. let $tab2= test.t1;
  1319. # eval CREATE OR REPLACE VIEW $view AS SELECT * FROM $tab1, $tab2;
  1320. # Produce at least all testcases via simple combinatorics, because it is better
  1321. # to check some useless combinations than to forget an important one.
  1322. let $view= test.v1;
  1323. let $num_tab1= 3;
  1324. while ($num_tab1)
  1325. {
  1326. let $num_tab2= 3;
  1327. while ($num_tab2)
  1328. {
  1329. let $num_db1= 2;
  1330. while ($num_db1)
  1331. {
  1332. let $num_db2= 2;
  1333. while ($num_db2)
  1334. {
  1335. # Maybe somebody needs to check the generated values
  1336. # --disable_query_log
  1337. # eval SELECT '$num_db1.$num_tab1,$num_db2.$num_tab2';
  1338. # --enable_query_log
  1339. eval CREATE OR REPLACE VIEW $view AS
  1340. SELECT ta.f1 AS col1,
  1341. tb.f1 AS col2
  1342. FROM test$num_db1.t$num_tab1 ta, test$num_db2.t$num_tab2 tb;
  1343. eval SELECT * FROM $view;
  1344. dec $num_db2;
  1345. }
  1346. dec $num_db1;
  1347. }
  1348. dec $num_tab2;
  1349. }
  1350. dec $num_tab1;
  1351. }
  1352. let $message= Testcase 3.3.1.38 ;
  1353. --source include/show_msg80.inc
  1354. ###############################################################################
  1355. # Testcase 3.3.1.38: Ensure that a view can be based on a join of multiple
  1356. # tables and/or views, some of which reside in the same
  1357. # database and some of which reside two or more other
  1358. # databases.
  1359. ###############################################################################
  1360. --disable_warnings
  1361. Drop table if exists test1.t1 ;
  1362. Drop view if exists test.v1 ;
  1363. Drop view if exists test.v1_main;
  1364. Drop view if exists test1.v1_1 ;
  1365. Drop database if exists test3 ;
  1366. --enable_warnings
  1367. Create view test.v1 as Select f59, f60 FROM test.tb2 limit 20 ;
  1368. Select * from test.v1 ;
  1369. Create table test1.t1 (f59 int,f60 int) ;
  1370. Insert into test1.t1 values (199,507) ;
  1371. Create view test1.v1_1 as Select f59,f60 from test1.t1 ;
  1372. Select * from test1.v1_1 ;
  1373. --disable_warnings
  1374. --enable_warnings
  1375. Create database test3 ;
  1376. Create table test3.t1(f59 int,f60 int) ;
  1377. Insert into test3.t1 values (1023,7670) ;
  1378. Create view test3.v1_2 as Select f59,f60 from test3.t1 ;
  1379. Select * from test3.v1_2 ;
  1380. use test ;
  1381. # ML: FIXME The SELECT should deliver at least one row.
  1382. Create view v1_main
  1383. as SELECT test.tb2.f59 as f1, test1.v1_1.f59 as f2,
  1384. test3.v1_2.f59 as f3
  1385. FROM (test.tb2,test1.v1_1,test.v1) JOIN test3.v1_2
  1386. ON (test.v1.f59 = test1.v1_1.f59) ;
  1387. Select * from v1_main ;
  1388. DROP VIEW test.v1 ;
  1389. DROP VIEW test1.v1_1 ;
  1390. DROP VIEW test.v1_main ;
  1391. DROP DATABASE test3;
  1392. let $message= Testcase 3.3.1.39 ;
  1393. --source include/show_msg80.inc
  1394. ###############################################################################
  1395. # Testcase 3.3.1.39: Ensure that a view definition that includes a subquery in
  1396. # a FROM clause is rejected with an appropriate error
  1397. # message at create time.
  1398. ###############################################################################
  1399. --disable_warnings
  1400. Drop view if exists test.v1 ;
  1401. --enable_warnings
  1402. --error 1349
  1403. CREATE VIEW test.v1
  1404. AS Select f59 from (Select * FROM tb2 limit 20) tx ;
  1405. --error 1146
  1406. SELECT * FROM test.v1 ;
  1407. --disable_warnings
  1408. Drop view if exists test.v1 ;
  1409. --enable_warnings
  1410. let $message= Testcase 3.3.1.40 ;
  1411. --source include/show_msg80.inc
  1412. ###############################################################################
  1413. # Testcase 3.3.1.40: Ensure that a view definition that includes references to
  1414. # one or more user variables is rejected with an appropriate
  1415. # error message at create time.
  1416. ###############################################################################
  1417. --disable_warnings
  1418. Drop view if exists test.v1 ;
  1419. --enable_warnings
  1420. Set @var1 = 'ABC' ;
  1421. Set @var2 = 'XYZ' ;
  1422. --error 1351
  1423. CREATE VIEW test.v1 AS SELECT @var1, @var2 ;
  1424. # System variables (name starts with '@@') are also not allowed
  1425. --error 1351
  1426. CREATE VIEW test.v1 AS SELECT @@global.sort_buffer_size;
  1427. --disable_warnings
  1428. Drop view if exists test.v1 ;
  1429. --enable_warnings
  1430. let $message= Testcase 3.3.1.41 ;
  1431. --source include/show_msg80.inc
  1432. ###############################################################################
  1433. # Testcase 3.3.1.41: Ensure that a view definition within a stored procedure
  1434. # definition cannot include references to any of the stored
  1435. # procedures parameters.
  1436. ###############################################################################
  1437. --disable_warnings
  1438. Drop view if exists test.v1 ;
  1439. Drop procedure if exists sp1 ;
  1440. --enable_warnings
  1441. delimiter //;
  1442. Create procedure sp1() DETERMINISTIC
  1443. Begin
  1444. DECLARE x char;
  1445. Set x = 200 ;
  1446. Create view test.v1 as SELECT * FROM tb2 WHERE f59 = x ;
  1447. End //
  1448. delimiter ;//
  1449. --error ER_SP_DOES_NOT_EXIST
  1450. Call sp1() ;
  1451. Drop view if exists test.v1 ;
  1452. Drop procedure sp1 ;
  1453. let $message= Testcase 3.3.1.42 ;
  1454. --source include/show_msg80.inc
  1455. ###############################################################################
  1456. # Testcase 3.3.1.42: Ensure that a view definition that attempts to create a
  1457. # temporary view (e.g. CREATE TEMPORARY VIEW or CREATE OR
  1458. # REPLACE TEMPORARY VIEW) fails, with an appropriate
  1459. # error message.
  1460. ###############################################################################
  1461. #(01)
  1462. --disable_warnings
  1463. Drop VIEW if exists test.v1 ;
  1464. --enable_warnings
  1465. --error 1064
  1466. CREATE TEMPORARY VIEW test.v1 AS
  1467. SELECT * FROM test.tb2 limit 2 ;
  1468. #(02)
  1469. --error 1064
  1470. CREATE OR REPLACE TEMPORARY VIEW test.v1 AS
  1471. SELECT * FROM test.tb2 limit 2 ;
  1472. --disable_warnings
  1473. Drop view if exists test.v1 ;
  1474. --enable_warnings
  1475. Use test;
  1476. let $message= Testcase 3.3.1.43 ;
  1477. --source include/show_msg80.inc
  1478. ###############################################################################
  1479. # Testcase 3.3.1.43: Ensure that all valid changes (i.e. INSERT, UPDATE, DELETE
  1480. # statements) to a view are shown in the view and are
  1481. # accepted as changes by the underlying table(s).
  1482. ###############################################################################
  1483. --disable_warnings
  1484. Drop view if exists test.v1 ;
  1485. --enable_warnings
  1486. CREATE VIEW test.v1 AS SELECT f59,f60 FROM test.tb2;
  1487. INSERT INTO test.v1 values(122,432);
  1488. if ($have_bug_11589)
  1489. {
  1490. --disable_ps_protocol
  1491. }
  1492. SELECT * FROM test.tb2 where f59 = 122 and f60 = 432 limit 0,20;
  1493. --enable_ps_protocol
  1494. UPDATE test.v1 SET f59 = 3000 WHERE test.v1.f59 = 122 ;
  1495. if ($have_bug_11589)
  1496. {
  1497. --disable_ps_protocol
  1498. }
  1499. SELECT * FROM test.tb2 where f59 = 3000 limit 0,20;
  1500. --enable_ps_protocol
  1501. DELETE FROM test.v1
  1502. where test.v1.f59 = 3000 and test.v1.f60 = 432;
  1503. SELECT * FROM test.tb2 where f59 = 3000 and f60 = 432;
  1504. drop view test.v1 ;
  1505. let $message= Testcase 3.3.1.44 ;
  1506. --source include/show_msg80.inc
  1507. ###############################################################################
  1508. # Testcase 3.3.1.44: Ensure that all invalid changes to a view are rejected
  1509. # with an appropriate error message and do not affect the
  1510. # data in the underlying tables(s).
  1511. ###############################################################################
  1512. # ML: Maybe we need some more tests here.
  1513. --disable_warnings
  1514. Drop view if exists test.v1 ;
  1515. --enable_warnings
  1516. # Note(ML): The modification will fail, because the VIEW contains 'limit'
  1517. CREATE VIEW test.v1 AS SELECT f59,f60 FROM test.tb2 limit 100;
  1518. --error ER_NON_INSERTABLE_TABLE
  1519. INSERT INTO test.v1 values(31, 32, 33) ;
  1520. Drop view test.v1 ;
  1521. let $message= Testcase 3.3.1.45 ;
  1522. --source include/show_msg80.inc
  1523. ###############################################################################
  1524. # Testcase 3.3.1.45: Ensure that, for a view with a definition that does not
  1525. # include WITH CHECK OPTION, all changes to the view which
  1526. # violate the view definition do not show in the view but
  1527. # are accepted as changes by the underlying table(s) unless
  1528. # a constraint on an underlying table also makes the change
  1529. # invalid.
  1530. ###############################################################################
  1531. --disable_warnings
  1532. Drop view if exists test.v1 ;
  1533. --enable_warnings
  1534. CREATE VIEW test.v1 AS SELECT * FROM test.tb2 where f59 = 04;
  1535. --enable_info
  1536. UPDATE test.v1 SET f59 = 30 where F59 = 04 ;
  1537. --disable_info
  1538. SELECT * FROM test.v1 where f59 = 30 ;
  1539. if ($have_bug_11589)
  1540. {
  1541. --disable_ps_protocol
  1542. }
  1543. SELECT * FROM test.tb2 where f59 = 30 ;
  1544. --enable_ps_protocol
  1545. --enable_info
  1546. UPDATE tb2 SET f59 = 100 where f59 = 30 ;
  1547. --disable_info
  1548. if ($have_bug_11589)
  1549. {
  1550. --disable_ps_protocol
  1551. }
  1552. SELECT * FROM tb2 where f59 = 100 ;
  1553. --enable_ps_protocol
  1554. SELECT * FROM test.v1 ;
  1555. drop view if exists test.v1 ;
  1556. --disable_warnings
  1557. Drop TABLE IF EXISTS test.t1 ;
  1558. Drop VIEW IF EXISTS test.v1 ;
  1559. --enable_warnings
  1560. eval CREATE TABLE t1 (f1 BIGINT, f2 VARCHAR(20), PRIMARY KEY(f1))
  1561. ENGINE = $engine_type;
  1562. INSERT INTO t1 VALUES(1,'one');
  1563. INSERT INTO t1 VALUES(2,'two');
  1564. INSERT INTO t1 VALUES(3,'three');
  1565. INSERT INTO t1 VALUES(5,'five');
  1566. CREATE VIEW v1 AS SELECT * FROM t1 WHERE f1 BETWEEN 2 AND 4;
  1567. ### SELECTs
  1568. # 1. Searched record is within the scope of the view
  1569. # 1.1 + exists within the base table
  1570. SELECT COUNT(*) FROM v1 WHERE f1 = 2;
  1571. # 1.2 + does not exists within the base table
  1572. SELECT COUNT(*) FROM v1 WHERE f1 = 4;
  1573. # 2. Searched record is outside of the scope of the view
  1574. # 2.1 + exists within the base table
  1575. SELECT COUNT(*) FROM v1 WHERE f1 = 5;
  1576. # 2.2 + does not exists within the base table
  1577. SELECT COUNT(*) FROM v1 WHERE f1 = 10;
  1578. INSERT INTO t1 VALUES(4,'four');
  1579. ### DELETEs
  1580. --enable_info
  1581. # 1. Searched record is within the scope of the view
  1582. # + exists within the base table
  1583. DELETE FROM v1 WHERE f1 = 3;
  1584. # 2. Searched record is outside of the scope of the view
  1585. # + exists within the base table
  1586. DELETE FROM v1 WHERE f1 = 5;
  1587. --disable_info
  1588. SELECT * FROM t1 ORDER BY f1;
  1589. SELECT * FROM v1 ORDER BY f1;
  1590. ### INSERTs
  1591. --enable_info
  1592. # 1. The record to be inserted will be within the scope of the view.
  1593. # But there is already a record with the PRIMARY KEY f1 = 2 .
  1594. --error 1062
  1595. INSERT INTO v1 VALUES(2,'two');
  1596. # 2. The record to be inserted will be within the scope of the view.
  1597. # There is no already existing record with the PRIMARY KEY f1 = 3 .
  1598. INSERT INTO v1 VALUES(3,'three');
  1599. # 3. The record to be inserted will be outside of the scope of the view.
  1600. # There is no already existing record with the PRIMARY KEY f1 = 6 .
  1601. INSERT INTO v1 VALUES(6,'six');
  1602. --disable_info
  1603. SELECT * FROM t1 ORDER BY f1;
  1604. SELECT * FROM v1 ORDER BY f1;
  1605. ### UPDATEs
  1606. --enable_info
  1607. # 1. The record to be updated is within the scope of the view
  1608. # and will stay inside the scope.
  1609. # But there is already a record with the PRIMARY KEY f1 = 2 .
  1610. --error 1062
  1611. UPDATE v1 SET f1 = 2 WHERE f1 = 3;
  1612. # 2. The record to be updated is within the scope of the view
  1613. # and will stay inside the scope.
  1614. UPDATE v1 SET f2 = 'number' WHERE f1 = 3;
  1615. # 3. The record to be updated is within the scope of the view
  1616. # and will leave the scope.
  1617. UPDATE v1 SET f1 = 10 WHERE f1 = 3;
  1618. # 4. The record to be updated is outside of the scope of the view.
  1619. UPDATE v1 SET f2 = 'number' WHERE f1 = 1;
  1620. --disable_info
  1621. let $message= Testcase 3.3.1.46 ;
  1622. --source include/show_msg80.inc
  1623. ###############################################################################
  1624. # Testcase 3.3.1.46: Ensure that, for a view with a definition that does
  1625. # include WITH CHECK OPTION, all changes to the view which
  1626. # violate the view definition are rejected with an
  1627. # appropriate error message and are not accepted as changes
  1628. # by the underlying table(s).
  1629. ###############################################################################
  1630. --disable_warnings
  1631. Drop view if exists test.v1 ;
  1632. --enable_warnings
  1633. CREATE VIEW test.v1 AS SELECT f59,f60
  1634. FROM test.tb2 where f59 = 195 WITH CHECK OPTION ;
  1635. --error 1369
  1636. UPDATE test.v1 SET f59 = 198 where f59=195 ;
  1637. SELECT * FROM test.v1 ;
  1638. drop view if exists test.v1 ;
  1639. let $message= Testcase 3.3.1.47 ;
  1640. --source include/show_msg80.inc
  1641. ###############################################################################
  1642. # Testcase 3.3.1.47: Ensure that, for a view with a definition that does
  1643. # include WITH LOCAL CHECK OPTION, all changes to the view
  1644. # which violate the view definition are rejected with an
  1645. # appropriate error message and are not accepted as changes
  1646. # by the underlying table(s).
  1647. ###############################################################################
  1648. --disable_warnings
  1649. Drop view if exists test.v1 ;
  1650. Drop view if exists test.v2 ;
  1651. --enable_warnings
  1652. CREATE VIEW test.v1 AS SELECT f59,f60
  1653. FROM test.tb2 where F59 = 0987 WITH LOCAL CHECK OPTION ;
  1654. CREATE VIEW test.v2 as SELECT * FROM test.v1 ;
  1655. # This UPDATE violates the definition of VIEW test.v1.
  1656. --error 1369
  1657. UPDATE test.v1 SET F59 = 919 where f59 = 0987 ;
  1658. SELECT * FROM test.v1 ;
  1659. # ML: This UPDATE violates the definition of VIEW test.v1, but this
  1660. # does not count, because the UPDATE runs on test.v2, which
  1661. # is defined without any CHECK OPTION.
  1662. # FIXME Does this testcase fit to 3.3.1.47 ?
  1663. UPDATE test.v2 SET F59 = 9879 where f59 = 919 ;
  1664. SELECT * FROM tb2 where f59 = 9879 ;
  1665. drop view if exists v1 ;
  1666. drop view if exists v2 ;
  1667. let $message= Testcase 3.3.1.48 ;
  1668. --source include/show_msg80.inc
  1669. ###############################################################################
  1670. # Testcase 3.3.1.48: Ensure that, for a view with a definition that does
  1671. # include WITH CASCADED CHECK OPTION, all changes to the
  1672. # view which violate the view definition are rejected with
  1673. # an appropriate error message and are not accepted as
  1674. # changes by the underlying table(s).
  1675. ###############################################################################
  1676. --disable_warnings
  1677. DROP TABLE IF EXISTS test.t1;
  1678. DROP VIEW IF EXISTS test.v1;
  1679. --enable_warnings
  1680. eval CREATE TABLE t1 (f1 ENUM('A', 'B', 'C') NOT NULL, f2 INTEGER)
  1681. ENGINE = $engine_type;
  1682. INSERT INTO t1 VALUES ('A', 1);
  1683. SELECT * FROM t1;
  1684. CREATE VIEW v1 AS SELECT * FROM t1 WHERE f2 BETWEEN 1 AND 2
  1685. WITH CASCADED CHECK OPTION ;
  1686. SELECT * FROM v1;
  1687. --enable_info
  1688. # positive cases
  1689. UPDATE v1 SET f2 = 2 WHERE f2 = 1;
  1690. INSERT INTO v1 VALUES('B',2);
  1691. --disable_info
  1692. # Bug#11771: View over InnoDB table, wrong result SELECT on VIEW,
  1693. # field->query_id wrong
  1694. SELECT * FROM v1;
  1695. # negative cases
  1696. --enable_info
  1697. --error 1369
  1698. UPDATE v1 SET f2 = 4;
  1699. --error 1369
  1700. INSERT INTO v1 VALUES('B',3);
  1701. --disable_info
  1702. # Bug#11771: View over InnoDB table, wrong result SELECT on VIEW,
  1703. # field->query_id wrong
  1704. SELECT * FROM v1;
  1705. let $message= Testcase 3.3.1.49 ;
  1706. --source include/show_msg80.inc
  1707. ###############################################################################
  1708. # Testcase 3.3.1.49: Ensure that the WITH [LOCAL | CASCADED] CHECK OPTION
  1709. # constraint is always correctly performed within the
  1710. # correct scope, including in cases where a view is based
  1711. # upon multiple other views whose definitions include every
  1712. # possible combination of the WITH CHECK OPTION variants.
  1713. ###############################################################################
  1714. --disable_warnings
  1715. Drop table if exists test.t1 ;
  1716. Drop view if exists test.v1 ;
  1717. Drop view if exists test.v2 ;
  1718. Drop view if exists test.v3 ;
  1719. --enable_warnings
  1720. Create table test.t1 (f59 INT, f60 INT) ;
  1721. Insert into test.t1 values (100,4234);
  1722. Insert into test.t1 values (290,6624);
  1723. Insert into test.t1 values (410,765);
  1724. Insert into test.t1 values (300,433334);
  1725. Insert into test.t1 values (800,9788);
  1726. Insert into test.t1 values (501,9866);
  1727. Create view test.v1 as select f59
  1728. FROM test.t1 where f59<500 with check option ;
  1729. Create view test.v2 as select *
  1730. from test.v1 where f59>0 with local check option ;
  1731. --disable_warnings
  1732. --enable_warnings
  1733. Create view test.v3 as select *
  1734. from test.v1 where f59>0 with cascaded check option ;
  1735. Insert into test.v2 values(23) ;
  1736. Insert into test.v3 values(24) ;
  1737. drop view if exists test.v1 ;
  1738. drop view if exists test.v2 ;
  1739. drop view if exists test.v3 ;
  1740. let $message= Testcase 3.3.1.49A ;
  1741. --source include/show_msg80.inc
  1742. # Testplan:
  1743. # -----------------------------------------------------------
  1744. # VIEW v1 is based on table t1 (*)
  1745. # VIEW v2 is based on view v1 (*)
  1746. # VIEW v3 is based on view v2 (*)
  1747. #
  1748. # (*) All variants like
  1749. # - without check option
  1750. # - WITH CASCADED CHECK OPTION
  1751. # - WITH CHECK OPTION (default = CASCADED)
  1752. # - WITH LOCAL CHECK OPTION
  1753. #
  1754. # The rules for updating and inserting column values:
  1755. # 1. Top VIEW WITH CASCADED CHECK OPTION
  1756. # --> The WHERE qualifications of all nested VIEWs have to be fulfilled.
  1757. # The CHECK OPTIONS of underlying VIEWs have no effect.
  1758. # 2. Top VIEW WITH LOCAL CHECK OPTION
  1759. # --> Only the WHERE qualification of this VIEW has to be fulfilled.
  1760. # The CHECK OPTIONS of underlying VIEWs have no effect.
  1761. # 3. Top VIEW without any CHECK OPTION
  1762. # --> The WHERE qualifications of all nested VIEWs need not to be fulfilled.
  1763. # The CHECK OPTIONS of underlying VIEWs have no effect.
  1764. #
  1765. # v3 | v2 | v1 | Qualifications to be checked
  1766. # ------------------------------------------------------------------------
  1767. # CASCADED | <any> | <any> | qual_v3 + qual_v2 + qual_v3
  1768. # <default> | <any> | <any> | qual_v3 + qual_v2 + qual_v3
  1769. # LOCAL | <any> | <any> | qual_v3
  1770. # <without> | <any> | <any> |
  1771. #
  1772. # Note: The CHECK OPTION does not influence the retrieval of rows
  1773. # (SELECT/DELETE/UPDATE). All WHERE qualifications will be applied
  1774. # for the retrieval of rows.
  1775. #
  1776. # The annoying redundant
  1777. # eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  1778. # @v3_to_v1_violation,$mysql_errno);
  1779. # could not be put into a file to be sourced because of
  1780. # Bug#10267 mysqltest, wrong number of loops when a script is sourced
  1781. # within a loop
  1782. #
  1783. USE test;
  1784. --disable_warnings
  1785. DROP TABLE IF EXISTS test.t1 ;
  1786. DROP TABLE IF EXISTS test.t1_results ;
  1787. DROP VIEW IF EXISTS test.v1;
  1788. DROP VIEW IF EXISTS test.v2;
  1789. DROP VIEW IF EXISTS test.v3;
  1790. --enable_warnings
  1791. CREATE TABLE t1 (f1 INTEGER, f2 CHAR(20));
  1792. CREATE TABLE t1_results (v3_to_v1_options VARCHAR(100), statement VARCHAR(10),
  1793. v3_to_v1_violation VARCHAR(20), errno CHAR(10));
  1794. --disable_query_log
  1795. SET @part1= '';
  1796. SET @part2= 'WITH CHECK OPTION';
  1797. SET @part3= 'WITH CASCADED CHECK OPTION';
  1798. SET @part4= 'WITH LOCAL CHECK OPTION';
  1799. --enable_query_log
  1800. let $num1= 4;
  1801. while ($num1)
  1802. {
  1803. --disable_query_log
  1804. eval SET @v1_part= @part$num1;
  1805. let $aux= `SELECT CONCAT('CREATE VIEW v1 AS SELECT f1, f2
  1806. FROM t1 WHERE f1 BETWEEN 0 AND 10 ', @v1_part)` ;
  1807. --enable_query_log
  1808. eval $aux ;
  1809. let $num2= 4;
  1810. while ($num2)
  1811. {
  1812. --disable_query_log
  1813. eval SET @v2_part= @part$num2;
  1814. let $aux= `SELECT CONCAT('CREATE VIEW v2 AS SELECT f1 AS col1, f2 AS col2
  1815. FROM v1 WHERE f1 BETWEEN 6 AND 16 ', @v2_part)` ;
  1816. --enable_query_log
  1817. eval $aux ;
  1818. let $num3= 4;
  1819. while ($num3)
  1820. {
  1821. --disable_query_log
  1822. eval SET @v3_part= @part$num3;
  1823. let $aux= `SELECT CONCAT('CREATE VIEW v3 (my_col1,my_col2) AS SELECT *
  1824. FROM v2 WHERE col1 MOD 2 = 0 ', @v3_part)` ;
  1825. eval $aux ;
  1826. --vertical_results
  1827. SELECT CONCAT(IF(@v3_part = '',' <nothing> ',
  1828. @v3_part), ' - ',
  1829. IF(@v2_part = '',' <nothing> ',
  1830. @v2_part), ' - ',
  1831. IF(@v1_part = '',' <nothing> ',
  1832. @v1_part))
  1833. AS "option_variant"
  1834. UNION SELECT RPAD('', 80, '-');
  1835. SET @v3_to_v1_options = CONCAT(IF(@v3_part = '',' <nothing> ',
  1836. @v3_part), ' - ',
  1837. IF(@v2_part = '',' <nothing> ',
  1838. @v2_part), ' - ',
  1839. IF(@v1_part = '',' <nothing> ',
  1840. @v1_part));
  1841. --horizontal_results
  1842. --enable_query_log
  1843. # 1. Visibility of records of t1 via SELECT on the VIEWs
  1844. # Outside v1 (0 to 10)
  1845. INSERT INTO t1 VALUES(16, 'sixteen');
  1846. # Inside v1 (0 to 10), Outside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1847. INSERT INTO t1 VALUES(0, 'zero');
  1848. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1849. # Outside v3 ( value MOD 2 = 0 )
  1850. INSERT INTO t1 VALUES(7, 'seven');
  1851. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1852. # Inside v3 ( value MOD 2 = 0 )
  1853. INSERT INTO t1 VALUES(8, 'eight');
  1854. SELECT * FROM v1;
  1855. SELECT * FROM v2;
  1856. SELECT * FROM v3;
  1857. SELECT * FROM t1;
  1858. DELETE FROM t1;
  1859. # 2. DELETEs within v3
  1860. # Outside v1 (0 to 10)
  1861. INSERT INTO t1 VALUES(16, 'sixteen');
  1862. # Inside v1 (0 to 10), Outside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1863. INSERT INTO t1 VALUES(0, 'zero');
  1864. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1865. # Outside v3 ( value MOD 2 = 0 )
  1866. INSERT INTO t1 VALUES(7, 'seven');
  1867. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1868. # Inside v3 ( value MOD 2 = 0 )
  1869. INSERT INTO t1 VALUES(8, 'eight');
  1870. --enable_info
  1871. # Outside v1 (0 to 10)
  1872. DELETE FROM v3 WHERE my_col1 = 16;
  1873. # Inside v1 (0 to 10), Outside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1874. DELETE FROM v3 WHERE my_col1 = 0;
  1875. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1876. # Outside v3 ( value MOD 2 = 0 )
  1877. DELETE FROM v3 WHERE my_col1 = 7;
  1878. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1879. # Inside v3 ( value MOD 2 = 0 )
  1880. DELETE FROM v3 WHERE my_col1 = 8;
  1881. --disable_info
  1882. SELECT * FROM t1;
  1883. DELETE FROM t1;
  1884. # 3. UPDATEs within v3 (modify my_col2, which is not part of any
  1885. # WHERE qualification)
  1886. # The behaviour should be similar to 3. DELETE.
  1887. # Outside v1 (0 to 10)
  1888. INSERT INTO t1 VALUES(16, 'sixteen');
  1889. # Inside v1 (0 to 10), Outside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1890. INSERT INTO t1 VALUES(0, 'zero');
  1891. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1892. # Outside v3 ( value MOD 2 = 0 )
  1893. INSERT INTO t1 VALUES(7, 'seven');
  1894. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1895. # Inside v3 ( value MOD 2 = 0 )
  1896. INSERT INTO t1 VALUES(8, 'eight');
  1897. --enable_info
  1898. # Outside v1 (0 to 10)
  1899. UPDATE v3 SET my_col2 = 'whatever' WHERE my_col1 = 16;
  1900. # Inside v1 (0 to 10), Outside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1901. UPDATE v3 SET my_col2 = 'whatever' WHERE my_col1 = 0;
  1902. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1903. # Outside v3 ( value MOD 2 = 0 )
  1904. UPDATE v3 SET my_col2 = 'whatever' WHERE my_col1 = 7;
  1905. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1906. # Inside v3 ( value MOD 2 = 0 )
  1907. UPDATE v3 SET my_col2 = 'whatever' WHERE my_col1 = 8;
  1908. --disable_info
  1909. SELECT * FROM t1;
  1910. DELETE FROM t1;
  1911. # 4. UPDATEs within v3 (modify my_col1 to values inside and outside
  1912. # of the WHERE qualifications)
  1913. --disable_query_log
  1914. SET @statement = 'UPDATE';
  1915. --enable_query_log
  1916. INSERT INTO t1 VALUES(8, 'eight');
  1917. # Alter to value outside of v3
  1918. --disable_query_log
  1919. SET @v3_to_v1_violation = 'v3_ _ ';
  1920. --enable_query_log
  1921. --enable_info
  1922. UPDATE v3 SET my_col1 = 7 WHERE my_col1 = 8;
  1923. --disable_info
  1924. --disable_query_log
  1925. eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  1926. @v3_to_v1_violation,$mysql_errno);
  1927. --enable_query_log
  1928. SELECT * FROM t1;
  1929. DELETE FROM t1;
  1930. INSERT INTO t1 VALUES(8, 'eight');
  1931. # Alter to value outside of v2
  1932. --disable_query_log
  1933. SET @v3_to_v1_violation = ' _v2_ ';
  1934. --enable_query_log
  1935. --enable_info
  1936. UPDATE v3 SET my_col1 = 0 WHERE my_col1 = 8;
  1937. --disable_info
  1938. --disable_query_log
  1939. eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  1940. @v3_to_v1_violation,$mysql_errno);
  1941. --enable_query_log
  1942. SELECT * FROM t1;
  1943. DELETE FROM t1;
  1944. INSERT INTO t1 VALUES(8, 'eight');
  1945. # Alter to value outside of v1
  1946. --disable_query_log
  1947. SET @v3_to_v1_violation = ' _ _v1';
  1948. --enable_query_log
  1949. --enable_info
  1950. UPDATE v3 SET my_col1 = 16 WHERE my_col1 = 8;
  1951. --disable_info
  1952. --disable_query_log
  1953. eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  1954. @v3_to_v1_violation,$mysql_errno);
  1955. --enable_query_log
  1956. SELECT * FROM t1;
  1957. DELETE FROM t1;
  1958. INSERT INTO t1 VALUES(8, 'eight');
  1959. # Alter to value inside of v1
  1960. --disable_query_log
  1961. SET @v3_to_v1_violation = ' _ _ ';
  1962. --enable_query_log
  1963. --enable_info
  1964. UPDATE v3 SET my_col1 = 10 WHERE my_col1 = 8;
  1965. --disable_info
  1966. --disable_query_log
  1967. eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  1968. @v3_to_v1_violation,$mysql_errno);
  1969. --enable_query_log
  1970. SELECT * FROM t1;
  1971. DELETE FROM t1;
  1972. # 5. INSERTs into v3
  1973. --disable_query_log
  1974. SET @statement = 'INSERT';
  1975. --enable_query_log
  1976. # Outside v1 (0 to 10)
  1977. --disable_query_log
  1978. SET @v3_to_v1_violation = ' _ _v1';
  1979. --enable_query_log
  1980. --enable_info
  1981. INSERT INTO v3 VALUES(16, 'sixteen');
  1982. --disable_info
  1983. --disable_query_log
  1984. eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  1985. @v3_to_v1_violation,$mysql_errno);
  1986. --enable_query_log
  1987. # Inside v1 (0 to 10), Outside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1988. --disable_query_log
  1989. SET @v3_to_v1_violation = ' _v2_ ';
  1990. --enable_query_log
  1991. --enable_info
  1992. INSERT INTO v3 VALUES(0, 'zero');
  1993. --disable_info
  1994. --disable_query_log
  1995. eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  1996. @v3_to_v1_violation,$mysql_errno);
  1997. --enable_query_log
  1998. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  1999. # Outside v3 ( value MOD 2 = 0 )
  2000. --disable_query_log
  2001. SET @v3_to_v1_violation = 'v3_ _ ';
  2002. --enable_query_log
  2003. --enable_info
  2004. INSERT INTO v3 VALUES(7, 'seven');
  2005. --disable_info
  2006. # Inside v1 (0 to 10), Inside v2 ((0 to 10) AND (6 to 16) -> (6 to 10))
  2007. # Inside v3 ( value MOD 2 = 0 )
  2008. --disable_query_log
  2009. SET @v3_to_v1_violation = ' _ _ ';
  2010. --enable_query_log
  2011. --enable_info
  2012. INSERT INTO v3 VALUES(8, 'eight');
  2013. --disable_info
  2014. --disable_query_log
  2015. eval INSERT INTO t1_results VALUES (@v3_to_v1_options,@statement,
  2016. @v3_to_v1_violation,$mysql_errno);
  2017. --enable_query_log
  2018. SELECT * FROM t1;
  2019. DELETE FROM t1;
  2020. DROP VIEW v3;
  2021. dec $num3;
  2022. }
  2023. DROP VIEW v2;
  2024. dec $num2;
  2025. }
  2026. DROP VIEW v1;
  2027. dec $num1;
  2028. }
  2029. SELECT * FROM t1_results ORDER BY v3_to_v1_options;
  2030. let $message=
  2031. Plausibility checks for INSERTs and UPDATEs ( 4. and 5. above).
  2032. All following SELECTs must give ROW NOT FOUND ;
  2033. --source include/show_msg80.inc
  2034. # Plausibility checks for INSERTs and UPDATEs ( 4. and 5. above):
  2035. # 1. There must be NO denied INSERT/UPDATE, when no WHERE qualification
  2036. # is violated. Expect ROW NOT FUND
  2037. SELECT * FROM t1_results
  2038. WHERE v3_to_v1_violation = ' _ _ ' AND errno <> 0
  2039. ORDER BY v3_to_v1_options;
  2040. # 2. There must be NO denied INSERT/UPDATE, when the toplevel VIEW v3 is
  2041. # defined without any CHECK OPTION. Expect ROW NOT FUND
  2042. SELECT * FROM t1_results
  2043. WHERE v3_to_v1_options LIKE ' %' AND errno <> 0
  2044. ORDER BY v3_to_v1_options;
  2045. # 3. There must be NO successful INSERT/UPDATE, when the toplevel VIEW v3 is
  2046. # defined with any CHECK OPTION and the WHERE qualification of this VIEW is
  2047. # violated. Expect ROW NOT FUND
  2048. SELECT * FROM t1_results
  2049. WHERE v3_to_v1_options LIKE 'WITH %'
  2050. AND v3_to_v1_violation LIKE 'v3_%' AND errno = 0
  2051. ORDER BY v3_to_v1_options;
  2052. # 4. There must be NO successful INSERT/UPDATE, when the toplevel VIEW v3 is
  2053. # defined with any CHECK OPTION and the CHECK OPTION does not contain LOCAL
  2054. # and the WHERE qualification of any VIEW is violated. Expect ROW NOT FUND
  2055. SELECT * FROM t1_results
  2056. WHERE v3_to_v1_options LIKE 'WITH %' AND v3_to_v1_options NOT LIKE 'WITH LOCAL %'
  2057. AND v3_to_v1_violation NOT LIKE ' _ _ ' AND errno = 0
  2058. ORDER BY v3_to_v1_options;
  2059. # 5. There must be NO failing INSERT/UPDATE getting a sql_errno <> 1369.
  2060. SELECT * FROM t1_results
  2061. WHERE errno <> 0 AND errno <> 1369
  2062. ORDER BY v3_to_v1_options;
  2063. let $message= End of plausibility checks;
  2064. --source include/show_msg80.inc
  2065. DROP TABLE t1_results;
  2066. let $message= Testcase 3.3.1.50 - 3.3.1.53;
  2067. --source include/show_msg80.inc
  2068. --disable_warnings
  2069. DROP VIEW IF EXISTS test.v1;
  2070. --enable_warnings
  2071. ###############################################################################
  2072. # Testcase 3.3.1.50: Ensure that a view that is a subset of every column and
  2073. # every row of a single underlying table, contains the
  2074. # correct row-and-column data; such a view has a definition
  2075. # that is semantically equivalent to CREATE VIEW <view name>
  2076. # AS SELECT * FROM <table name>.
  2077. ###############################################################################
  2078. CREATE VIEW test.v1 AS SELECT * FROM test.tb2 limit 5 ;
  2079. if ($have_bug_11589)
  2080. {
  2081. --disable_ps_protocol
  2082. }
  2083. SELECT * FROM test.v1 ;
  2084. --enable_ps_protocol
  2085. drop view test.v1 ;
  2086. ###############################################################################
  2087. # Testcase 3.3.1.51: Ensure that a view that is a subset of only some columns
  2088. # and every row of a single underlying table, contains the
  2089. # correct row-and-column data; such a view has a definition
  2090. # that is semantically equivalent to CREATE VIEW <view name>
  2091. # AS SELECT col1, col3 FROM <table name>.
  2092. ###############################################################################
  2093. CREATE VIEW test.v1 AS SELECT F59,F61 FROM test.tb2 limit 50 ;
  2094. SELECT * FROM test.v1 ;
  2095. drop view test.v1 ;
  2096. ###############################################################################
  2097. # Testcase 3.3.1.52: Ensure that a view that is a subset of every column and
  2098. # some rows of a single underlying table, contains the
  2099. # correct row-and-column data; such a view has a definition
  2100. # that is semantically equivalent to CREATE VIEW <view name>
  2101. # AS SELECT * FROM <table name> WHERE ....
  2102. ###############################################################################
  2103. CREATE VIEW test.v1 AS SELECT * FROM test.tb2 limit 20 ;
  2104. if ($have_bug_11589)
  2105. {
  2106. --disable_ps_protocol
  2107. }
  2108. SELECT * FROM test.v1;
  2109. --enable_ps_protocol
  2110. drop view test.v1 ;
  2111. ###############################################################################
  2112. # Testcase 3.3.1.53: Ensure that a view that is a subset of only some columns
  2113. # and some rows of a single underlying table, contains
  2114. # the correct row-and-column data; such a view has a
  2115. # definition that is semantically equivalent to CREATE VIEW
  2116. # <view name> AS SELECT col1, col3 FROM <table name> WHERE ..
  2117. ###############################################################################
  2118. CREATE VIEW test.v1 AS SELECT F59,f61 FROM test.tb2 limit 20 ;
  2119. SELECT * FROM test.v1 limit 50;
  2120. drop view test.v1 ;
  2121. let $message= Testcase 3.3.1.54 ;
  2122. --source include/show_msg80.inc
  2123. ###############################################################################
  2124. # Testcase 3.3.1.54: Ensure that a view that is a subset of some or all columns
  2125. # and/or column expressions and some or all rows of a single
  2126. # underlying table contains the correct row-and-column data.
  2127. ###############################################################################
  2128. USE test;
  2129. --disable_warnings
  2130. drop table if exists test.t1 ;
  2131. drop table if exists test.t2 ;
  2132. drop view if exists test.v1 ;
  2133. --enable_warnings
  2134. Create table t1 (f59 int, f60 int) ;
  2135. Create table t2 (f59 int, f60 int) ;
  2136. Insert into t1 values (1,10) ;
  2137. Insert into t1 values (2,20) ;
  2138. Insert into t1 values (47,80) ;
  2139. Insert into t2 values (1,1000) ;
  2140. Insert into t2 values (2,2000) ;
  2141. Insert into t2 values (31,97) ;
  2142. Create view test.v1 as select t1.f59, t1.f60
  2143. from t1,t2 where t1.f59=t2.f59 ;
  2144. Select * from test.v1 limit 50 ;
  2145. drop table test.t1 ;
  2146. drop table test.t2 ;
  2147. drop view test.v1 ;
  2148. # FIXME(ML): Implement an automatic check for 3.3.1.50 - 3.3.1.54
  2149. # CREATE VIEW ... AS <SELECT ... FROM tb2 ...>
  2150. # CREATE TEMPORARY TABLE ... AS <SELECT ... FROM tb2 ...>
  2151. # Comparison of the VIEW with the temporary table
  2152. let $message= Testcase 3.3.1.50 - 3.3.1.54 additional implementation;
  2153. --source include/show_msg80.inc
  2154. --disable_warnings
  2155. DROP TABLE IF EXISTS t1 ;
  2156. DROP VIEW IF EXISTS v1 ;
  2157. --enable_warnings
  2158. #
  2159. #
  2160. # Testplan
  2161. # ------------------------
  2162. #
  2163. # Testcase | all columns | all rows | column expressions
  2164. # ---------------------------------------------------
  2165. # 3.3.1.50 | yes | yes | no
  2166. # 3.3.1.51 | no | yes | no
  2167. # 3.3.1.52 | yes | no | no
  2168. # 3.3.1.53 | no | no | no
  2169. # 3.3.1.54 | no | no | yes
  2170. CREATE TABLE t1 ( f1 BIGINT, f2 char(10), f3 DECIMAL(10,5) );
  2171. INSERT INTO t1 VALUES(1, 'one', 1.1);
  2172. INSERT INTO t1 VALUES(2, 'two', 2.2);
  2173. INSERT INTO t1 VALUES(3, 'three', 3.3);
  2174. # 3.3.1.50
  2175. CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1;
  2176. SELECT * FROM v1;
  2177. # 3.3.1.51
  2178. CREATE OR REPLACE VIEW v1 AS SELECT f2 FROM t1;
  2179. SELECT * FROM v1;
  2180. # 3.3.1.52
  2181. CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1 WHERE f3 = 2.2;
  2182. SELECT * FROM v1;
  2183. # 3.3.1.53
  2184. CREATE OR REPLACE VIEW v1 AS SELECT f2 FROM t1 WHERE f3 = 2.2;
  2185. SELECT * FROM v1;
  2186. # 3.3.1.54
  2187. --vertical_results
  2188. SET sql_mode = 'traditional,ansi';
  2189. CREATE OR REPLACE VIEW v1 AS
  2190. SELECT f3 AS "pure column f3: ", f1 + f3 AS "sum of columns f1 + f3 = ",
  2191. 3 * (- 0.11111E+1) AS "product of constants 3 * (- 0.11111E+1): ",
  2192. '->' || CAST(f3 AS CHAR) || '<-'
  2193. AS "expression with '||'=CONCAT and CAST(DECIMAL column AS CHAR): "
  2194. FROM t1 WHERE f1 = 2;
  2195. SELECT * FROM v1;
  2196. SET sql_mode = '';
  2197. --horizontal_results
  2198. let $message= Testcases 3.3.1.55 - 3.3.1.62 ;
  2199. --source include/show_msg80.inc
  2200. ###############################################################################
  2201. # Testcase: Ensure that a view that is a subset of some or all columns and
  2202. # some or all rows of multiple tables joined with an
  2203. # 3.3.1.55 INNER JOIN
  2204. # 3.3.1.56 CROSS JOIN
  2205. # 3.3.1.57 STRAIGHT JOIN
  2206. # 3.3.1.58 NATURAL JOIN
  2207. # 3.3.1.59 LEFT OUTER JOIN
  2208. # 3.3.1.60 NATURAL LEFT OUTER JOIN
  2209. # 3.3.1.61 RIGHT OUTER
  2210. # 3.3.1.62 NATURAL RIGHT OUTER
  2211. # condition contains the correct row-and-column data.
  2212. ###############################################################################
  2213. --disable_warnings
  2214. Drop table if exists t1, t2 ;
  2215. Drop view if exists v1 ;
  2216. --enable_warnings
  2217. Create table t1 (f59 int, f60 char(10), f61 int, a char(1)) ;
  2218. Insert into t1 values (1, 'single', 3, '1') ;
  2219. Insert into t1 values (2, 'double', 6, '2') ;
  2220. Insert into t1 values (3, 'single-f3', 4, '3') ;
  2221. Create table t2 (f59 int, f60 char(10), f61 int, b char(1)) ;
  2222. Insert into t2 values (2, 'double', 6, '2') ;
  2223. Insert into t2 values (3, 'single-f3', 6, '3') ;
  2224. Insert into t2 values (4, 'single', 4, '4') ;
  2225. # Testcase 3.3.1.55 ;
  2226. create or replace view test.v1 as
  2227. Select t1.f59 t1_f59, t2.f59 t2_f59, t1.f60 t1_f60, t2.f60 t2_f60,
  2228. t1.f61 t1_f61, t2.f61 t2_f61
  2229. from t1 inner join t2 where t1.f59 = t2.f59 ;
  2230. select * from test.v1;
  2231. Select t1.f59 t1_f59, t2.f59 t2_f59, t1.f60 t1_f60, t2.f60 t2_f60,
  2232. t1.f61 t1_f61, t2.f61 t2_f61
  2233. from t1 inner join t2 where t1.f59 = t2.f59;
  2234. # Testcase 3.3.1.56 ;
  2235. Create or replace view test.v1 as
  2236. Select t1.f59 AS t1_f59, t2.f59 AS t2_f59
  2237. FROM t2 cross join t1;
  2238. Select * from v1;
  2239. Select t1.f59 AS t1_f59, t2.f59 AS t2_f59
  2240. FROM t2 cross join t1;
  2241. # Testcase 3.3.1.57 ;
  2242. Create or replace view test.v1 as
  2243. Select straight_join t1.f59 AS t1_f59, t2.f59 AS t2_f59
  2244. FROM t2,t1;
  2245. Select * from v1;
  2246. Select straight_join t1.f59 AS t1_f59, t2.f59 AS t2_f59
  2247. FROM t2,t1;
  2248. # Testcase 3.3.1.58 ;
  2249. Create or replace view test.v1 as
  2250. Select f59, f60, f61, a, b
  2251. FROM t2 natural join t1;
  2252. Select * from v1;
  2253. Select f59, f60, f61, a, b
  2254. FROM t2 natural join t1;
  2255. # Testcase 3.3.1.59 ;
  2256. Create or replace view test.v1 as
  2257. Select t1.f59 t1_f59, t2.f59 t2_f59, t1.f60 t1_f60, t2.f60 t2_f60,
  2258. t1.f61 t1_f61, t2.f61 t2_f61
  2259. FROM t2 left outer join t1 on t2.f59=t1.f59;
  2260. Select * from v1;
  2261. Select t1.f59 t1_f59, t2.f59 t2_f59, t1.f60 t1_f60, t2.f60 t2_f60,
  2262. t1.f61 t1_f61, t2.f61 t2_f61
  2263. FROM t2 left outer join t1 on t2.f59=t1.f59;
  2264. # Testcase 3.3.1.60 ;
  2265. Create or replace view test.v1 as
  2266. Select f59, f60, f61, t1.a, t2.b
  2267. FROM t2 natural left outer join t1;
  2268. Select * from v1;
  2269. Select f59, f60, f61, t1.a, t2.b
  2270. FROM t2 natural left outer join t1;
  2271. # Testcase 3.3.1.61 ;
  2272. Create or replace view test.v1 as
  2273. Select t1.f59 t1_f59, t2.f59 t2_f59, t1.f60 t1_f60, t2.f60 t2_f60,
  2274. t1.f61 t1_f61, t2.f61 t2_f61
  2275. FROM t2 right outer join t1 on t2.f59=t1.f59;
  2276. Select * from v1;
  2277. Select t1.f59 t1_f59, t2.f59 t2_f59, t1.f60 t1_f60, t2.f60 t2_f60,
  2278. t1.f61 t1_f61, t2.f61 t2_f61
  2279. FROM t2 right outer join t1 on t2.f59=t1.f59;
  2280. # Testcase 3.3.1.62 ;
  2281. Create or replace view test.v1 as
  2282. Select f59, f60, a, b
  2283. FROM t2 natural right outer join t1;
  2284. Select * from v1;
  2285. Select f59, f60, a, b
  2286. FROM t2 natural right outer join t1;
  2287. drop table t1, t2;
  2288. drop view v1 ;
  2289. Use test;
  2290. let $message= Testcase 3.3.1.A1 - 3.3.1.A3 ;
  2291. --source include/show_msg80.inc
  2292. ###############################################################################
  2293. # Testcase: Ensure that a view that is a subset of some or all columns and/or
  2294. # column expressions and some or all rows of multiple tables joined
  2295. # with the combination of
  2296. # 3.3.1.A1 LEFT JOIN
  2297. # 3.3.1.A2 INNER JOIN
  2298. # 3.3.1.A3 CROSS JOIN
  2299. # condition contains the correct row-and-column data
  2300. ###############################################################################
  2301. # Testcase 3.3.1.A1 ;
  2302. --disable_warnings
  2303. Drop table if exists t1 ;
  2304. Drop view if exists v1;
  2305. --enable_warnings
  2306. Create table t1 (f59 int, f60 int, f61 int) ;
  2307. Insert into t1 values (101,201,301) ;
  2308. Insert into t1 values (107,501,601) ;
  2309. Insert into t1 values (901,801,401) ;
  2310. Create or replace view test.v1 as
  2311. Select tb2.f59 FROM tb2 LEFT JOIN t1 on tb2.f59 = t1.f59 ;
  2312. Select * from test.v1 limit 0,10;
  2313. Drop view if exists test.v1 ;
  2314. # Testcase 3.3.1.A2 ;
  2315. --disable_warnings
  2316. Drop table if exists t1 ;
  2317. Drop view if exists v1;
  2318. --enable_warnings
  2319. Create table t1 (f59 int, f60 int, f61 int) ;
  2320. Insert into t1 values (201,201,201) ;
  2321. Insert into t1 values (207,201,201) ;
  2322. Insert into t1 values (201,201,201) ;
  2323. Create or replace view test.v1
  2324. as Select tb2.f59 FROM tb2 INNER JOIN t1 on tb2.f59 = t1.f59 ;
  2325. Select * from test.v1 limit 0,10;
  2326. Drop view if exists test.v1 ;
  2327. # Testcase 3.3.1.A3 ;
  2328. --disable_warnings
  2329. Drop table if exists t1 ;
  2330. Drop view if exists v1;
  2331. --enable_warnings
  2332. Create table t1 (f59 int, f60 int, f61 int) ;
  2333. Insert into t1 values (21,21,21) ;
  2334. Insert into t1 values (27,21,21) ;
  2335. Insert into t1 values (21,21,21) ;
  2336. Create or replace view test.v1
  2337. as Select tb2.f59 FROM tb2 CROSS JOIN t1 on tb2.f59 = t1.f59 ;
  2338. Select * from test.v1 limit 0,10;
  2339. Drop view test.v1 ;
  2340. let $message= Testcase 3.3.1.63 ;
  2341. --source include/show_msg80.inc
  2342. ###############################################################################
  2343. # Testcase 3.3.1.63: Ensure that a view that is a subset of some or all columns
  2344. # and/or column expressions and some or all rows of multiple
  2345. # tables joined with every possible combination of JOIN
  2346. # conditions, UNION, UNION ALL and UNION DISTINCT, nested at
  2347. # multiple levels, contains the correct row-and-column data.
  2348. ###############################################################################
  2349. --disable_warnings
  2350. Drop table if exists t1 ;
  2351. Drop view if exists test.v1 ;
  2352. --enable_warnings
  2353. Create table t1 (f59 int, f60 int, f61 int) ;
  2354. Insert into t1 values (11,21,31) ;
  2355. Insert into t1 values (17,51,61) ;
  2356. Insert into t1 values (91,81,41) ;
  2357. Create or replace view test.v1 as (Select f59 FROM tb2 where f59=17 )
  2358. Union ALL (Select f59 from t1 where f59=17 );
  2359. Select * from test.v1 limit 0,10;
  2360. Create or replace view test.v1 as (Select f59 FROM tb2 where f59=17 )
  2361. Union (Select f59 from t1 where f59=17 );
  2362. Select * from test.v1 limit 0,10;
  2363. Create or replace view test.v1 as (Select f59 FROM tb2 where f59=17 )
  2364. Union Distinct (Select f59 from t1 where f60=17 );
  2365. Select * from test.v1 limit 0,10;
  2366. Drop view test.v1 ;
  2367. --disable_warnings
  2368. drop table if exists t1;
  2369. drop view if exists test.v1;
  2370. --enable_warnings
  2371. create table t1 (f59 int, f60 int, f61 int);
  2372. insert into t1 values (101,201,301);
  2373. insert into t1 values (107,501,601);
  2374. insert into t1 values (901,801,401);
  2375. create or replace view test.v1 as
  2376. select tb2.f59 from tb2 join t1 on tb2.f59 = t1.f59;
  2377. select * from test.v1 limit 0,10;
  2378. create or replace view test.v1 as
  2379. (select f59 from tb2 where f59=107 )
  2380. union all
  2381. (select f59 from t1 where f59=107 );
  2382. select * from test.v1 limit 0,10;
  2383. create or replace view test.v1 as
  2384. (select f59 from tb2 where f59=107 )
  2385. union
  2386. (select f59 from t1 where f59=107 );
  2387. select * from test.v1 limit 0,10;
  2388. create or replace view test.v1 as
  2389. (select f59 from tb2 where f59=107 )
  2390. union distinct
  2391. (select f59 from t1 where f59=107 );
  2392. select * from test.v1 limit 0,10;
  2393. drop view if exists test.v1 ;
  2394. drop table t1;
  2395. let $message= Testcase 3.3.1.64 ;
  2396. --source include/show_msg80.inc
  2397. ###############################################################################
  2398. # Testcase 3.3.1.64: Ensure that all changes to a view definition, executed by
  2399. # the ALTER VIEW statement, are correctly recorded and have
  2400. # the correct effect on the data shown by the view.
  2401. ###############################################################################
  2402. --disable_warnings
  2403. Drop view if exists test.v1 ;
  2404. --enable_warnings
  2405. CREATE VIEW test.v1 AS SELECT F59
  2406. FROM test.tb2 where test.tb2.F59 = 109;
  2407. SELECT * FROM test.v1 limit 0,10;
  2408. ALTER VIEW test.v1 AS SELECT *
  2409. FROM test.tb2 WHERE test.tb2.f59 = 242 ;
  2410. if ($have_bug_11589)
  2411. {
  2412. --disable_ps_protocol
  2413. }
  2414. SELECT * FROM test.v1 limit 0,10;
  2415. --enable_ps_protocol
  2416. Drop view test.v1 ;
  2417. let $message= Testcase 3.3.1.65, 3.3.1.A4, 3.3.1.66, 3.3.1.67 ;
  2418. --source include/show_msg80.inc
  2419. ###############################################################################
  2420. # Testcase 3.3.1.65: Ensure that the DROP VIEW statement cleanly drops its
  2421. # target view.
  2422. # Testcase 3.3.1.A4: Ensure that the DROP VIEW IF EXISTS statement cleanly
  2423. # drops its target view.
  2424. # Testcase 3.3.1.66: Ensure that DROP VIEW <view name> fails, with an appro-
  2425. # priate error message, if the view named does not exist.
  2426. # Testcase 3.3.1.67: Ensure that DROP VIEW IF EXISTS <view name> does not fail,
  2427. # but merely returns an appropriate warning, if the view
  2428. # named does not exist.
  2429. ###############################################################################
  2430. --disable_warnings
  2431. DROP TABLE IF EXISTS t1;
  2432. DROP VIEW IF EXISTS test.v1 ;
  2433. --enable_warnings
  2434. eval CREATE TABLE t1 ( f1 VARCHAR(1000) ) ENGINE = $engine_type ;
  2435. CREATE VIEW v1 AS SELECT f1 FROM t1;
  2436. # DROP VIEW
  2437. DROP VIEW v1;
  2438. --error 1051
  2439. DROP VIEW v1;
  2440. CREATE VIEW v1 AS SELECT f1 FROM t1;
  2441. # DROP VIEW IF EXISTS
  2442. DROP VIEW IF EXISTS v1;
  2443. DROP VIEW IF EXISTS v1;
  2444. let $message= Testcase 3.3.1.68 ;
  2445. --source include/show_msg80.inc
  2446. ###############################################################################
  2447. # Testcase 3.3.1.68: Ensure that DROP VIEW <view name>, DROP VIEW <view name>
  2448. # RESTRICT, and DROP VIEW <view name> CASCADE all take
  2449. # exactly the same action, until such time as the RESTRICT
  2450. # and CASCADE keyword actions are implemented by MySQL.
  2451. ###############################################################################
  2452. --disable_warnings
  2453. DROP TABLE IF EXISTS t1;
  2454. DROP VIEW IF EXISTS v1_base ;
  2455. DROP VIEW IF EXISTS v1_top ;
  2456. --enable_warnings
  2457. CREATE TABLE t1 ( f1 DOUBLE);
  2458. --disable_query_log
  2459. SET @part1= '';
  2460. SET @part2= 'RESTRICT';
  2461. SET @part3= 'CASCADE';
  2462. --enable_query_log
  2463. let $num1= 3;
  2464. while ($num1)
  2465. {
  2466. CREATE VIEW v1_base AS SELECT * FROM t1;
  2467. CREATE VIEW v1_top AS SELECT * FROM v1_base;
  2468. --disable_query_log
  2469. let $aux1= `SELECT CONCAT('DROP VIEW v1_top ', @v1_part)` ;
  2470. let $aux2= `SELECT CONCAT('DROP VIEW v1_base ', @v1_part)` ;
  2471. eval SET @v1_part= @part$num1;
  2472. --enable_query_log
  2473. # 1. more non important sub testcase, where the view (v1_top) is not the base of
  2474. # another object
  2475. # DROP VIEW v1_top < |RESTRICD|CASCADE> must be successful.
  2476. eval $aux1 ;
  2477. # Check, that v1_top really no more exists + cleanup for the second sub test
  2478. --error 1051
  2479. DROP VIEW v1_top;
  2480. CREATE VIEW v1_top AS SELECT * FROM v1_base;
  2481. # 2. more important sub testcase, where the view (v1_base) is the base of
  2482. # another object (v1_top)
  2483. # DROP VIEW v1_base < |RESTRICT|CASCADE>
  2484. # If the RESTRICT and CASCADE keyword actions are implemented by MySQL,
  2485. # CASCADE will remove v1_base and the dependend view v1_top and
  2486. # RESTRICT will fail, because there exists the dependend view v1_top
  2487. eval $aux2 ;
  2488. # Check, if v1_base and v1_top exist + cleanup for next loop
  2489. DROP VIEW v1_base;
  2490. DROP VIEW v1_top;
  2491. dec $num1;
  2492. }
  2493. let $message= Testcase 3.3.1.69, 3.3.1.70, 3.3.1.A5 ;
  2494. --source include/show_msg80.inc
  2495. ###############################################################################
  2496. # Testcases : Ensure that, when a view is dropped, its definition no longer
  2497. # appears when a
  2498. # 3.3.1.69 SHOW CREATE VIEW, SHOW CREATE TABLE, SHOW TABLE STATUS,
  2499. # SHOW TABLE
  2500. # 3.3.1.70 CHECK TABLE statement is executed
  2501. # 3.3.1.A5 SHOW COLUMNS, SHOW FIELDS, DESCRIBE, EXPLAIN
  2502. # statement is executed
  2503. ###############################################################################
  2504. # Note(ML): There will be no non failing sub testcases with SHOW here.
  2505. # They will be done in 3.3.11 ff.
  2506. --disable_warnings
  2507. DROP TABLE IF EXISTS t1 ;
  2508. DROP VIEW IF EXISTS v1 ;
  2509. --enable_warnings
  2510. eval CREATE TABLE t1 (f59 INT, f60 INT, f61 INT) ENGINE = $engine_type;
  2511. CREATE VIEW v1 AS SELECT * FROM t1;
  2512. DROP VIEW v1 ;
  2513. # The negative tests:
  2514. # SELECT
  2515. --error 1146
  2516. SELECT * FROM v1 ;
  2517. #
  2518. --error 1146
  2519. SHOW CREATE VIEW v1 ;
  2520. --error 1146
  2521. SHOW CREATE TABLE v1 ;
  2522. # Attention: Like is a filter. So we will get an empty result set here.
  2523. SHOW TABLE STATUS like 'v1' ;
  2524. SHOW TABLES LIKE 'v1';
  2525. --error 1146
  2526. SHOW COLUMNS FROM v1;
  2527. --error 1146
  2528. SHOW FIELDS FROM v1;
  2529. CHECK TABLE v1;
  2530. --error 1146
  2531. DESCRIBE v1;
  2532. --error 1146
  2533. EXPLAIN SELECT * FROM v1;
  2534. Use test;
  2535. let $message= Testcase 3.3.1.A6 ;
  2536. --source include/show_msg80.inc
  2537. ###############################################################################
  2538. # Testcases 3.3.1.A6 : Ensure that nested views up to level @max_level work.
  2539. ###############################################################################
  2540. # 1. Simple nested VIEWs
  2541. # Configurable parameter @max_level = nesting level
  2542. # 128 must be good enough, it is already a pathologic value.
  2543. # We currently set it to 32, because of performance issues.
  2544. --disable_query_log
  2545. SET @max_level= 32;
  2546. --enable_query_log
  2547. --disable_warnings
  2548. DROP DATABASE IF EXISTS test3;
  2549. --enable_warnings
  2550. CREATE DATABASE test3;
  2551. eval CREATE TABLE test3.t1 (f1 DECIMAL(5,3)) ENGINE = $engine_type;
  2552. INSERT INTO test3.t1 SET f1 = 1.0;
  2553. CREATE VIEW test3.v0 AS SELECT * FROM test3.t1;
  2554. let $level= 1;
  2555. let $run= 1;
  2556. while ($run)
  2557. {
  2558. --disable_query_log
  2559. eval SET @aux = $level - 1;
  2560. --enable_query_log
  2561. let $sublevel= `SELECT @aux`;
  2562. eval CREATE VIEW test3.v$level AS SELECT * FROM test3.v$sublevel;
  2563. # DEBUG Please set $debug to 1, if the statements on the toplevel VIEW
  2564. # (direct after the while loop) show suspicious results.
  2565. let $debug= 0;
  2566. if ($debug)
  2567. {
  2568. eval SHOW CREATE VIEW test3.v$level;
  2569. eval SELECT * FROM test3.v$level;
  2570. eval EXPLAIN SELECT * FROM test3.v$level;
  2571. }
  2572. --disable_query_log
  2573. eval SET @aux = @max_level > $level;
  2574. --enable_query_log
  2575. inc $level;
  2576. # DEBUG
  2577. # eval SELECT @aux AS "@aux", $level AS "next level";
  2578. let $run= `SELECT @aux`;
  2579. }
  2580. #--------------------------------------------------------------------------
  2581. # Attention: If the following statements get suspicious/unexpected results
  2582. # and you assume that something with the non toplevel VIEWs might
  2583. # be wrong, please edit the while loop above and set $debug to 1.
  2584. #--------------------------------------------------------------------------
  2585. # 1.1 Check of top level VIEW
  2586. let $toplevel= `SELECT @max_level`;
  2587. eval SHOW CREATE VIEW test3.v$toplevel;
  2588. eval SELECT * FROM test3.v$toplevel;
  2589. eval EXPLAIN SELECT * FROM test3.v$toplevel;
  2590. # 1.2 Check the top level view when a base VIEW is dropped
  2591. DROP VIEW test3.v0;
  2592. eval SHOW CREATE VIEW test3.v$toplevel;
  2593. --error 1356
  2594. eval SELECT * FROM test3.v$toplevel;
  2595. --error 1356
  2596. eval EXPLAIN SELECT * FROM test3.v$toplevel;
  2597. # 2. Complicated nested VIEWs
  2598. # parameter @max_level = nesting level
  2599. # There is a limit(@join_limit = 61) for the number of tables which
  2600. # could be joined. This limit will be reached, when we set
  2601. # @max_level = @join_limit - 1 .
  2602. --disable_query_log
  2603. #++++++++++++++++++++++++++++++++++++++++++++++
  2604. # OBN - Reduced the value of join limit to 30
  2605. # Above seems to hang - FIXME
  2606. # ML - Reason unclear why it hangs for OBN on innodb and memory.
  2607. # Hypothesis: Maybe the consumption of virtual memory is high
  2608. # and OBN's box performs excessive paging.
  2609. # (RAM: OBN ~384MB RAM, ML 1 GB)
  2610. #++++++++++++++++++++++++++++++++++++++++++++++
  2611. let $message= FIXME - Setting join_limit to 30 - hangs for higher values;
  2612. --source include/show_msg.inc
  2613. #SET @join_limit = 61;
  2614. SET @join_limit = 30;
  2615. SET @max_level = @join_limit - 1;
  2616. --enable_query_log
  2617. --disable_warnings
  2618. DROP DATABASE IF EXISTS test3;
  2619. DROP TABLE IF EXISTS test1.t1;
  2620. DROP TABLE IF EXISTS test2.t1;
  2621. let $level= `SELECT @max_level + 1`;
  2622. while ($level)
  2623. {
  2624. dec $level;
  2625. eval DROP VIEW IF EXISTS test1.v$level;
  2626. }
  2627. --enable_warnings
  2628. CREATE DATABASE test3;
  2629. # Testplan for the content of the tables:
  2630. # ---------------------------------------------------------
  2631. # Records test1.t1 test2.t1 test3.t1
  2632. # NULL, 'numeric column is NULL' yes yes yes
  2633. # 0 , NULL yes yes yes
  2634. # 5 , 'five' yes yes yes
  2635. # 1 , 'one' yes yes no
  2636. # 2 , 'two' yes no yes
  2637. # 3 , 'three' no yes yes
  2638. USE test1;
  2639. eval CREATE TABLE t1 (f1 BIGINT, f2 CHAR(50)) ENGINE = $engine_type ;
  2640. INSERT INTO t1 VALUES (NULL, 'numeric column is NULL');
  2641. INSERT INTO t1 VALUES (0, NULL);
  2642. INSERT INTO t1 VALUES (5, 'five');
  2643. INSERT INTO t1 VALUES (1, 'one');
  2644. INSERT INTO t1 VALUES (2, 'two');
  2645. USE test2;
  2646. eval CREATE TABLE t1 (f1 DECIMAL(64,30), f2 VARCHAR(50)) ENGINE = $engine_type;
  2647. INSERT INTO t1 VALUES (NULL, 'numeric column is NULL');
  2648. INSERT INTO t1 VALUES (0.000000000000000000000000000000, NULL);
  2649. INSERT INTO t1 VALUES (5.000000000000000000000000000000, 'five');
  2650. INSERT INTO t1 VALUES (+1.000000000000000000000000000000, 'one');
  2651. INSERT INTO t1 VALUES (3.000000000000000, 'three');
  2652. USE test3;
  2653. eval CREATE TABLE t1 (f1 DOUBLE, f2 VARBINARY(50)) ENGINE = $engine_type;
  2654. INSERT INTO t1 VALUES (NULL, 'numeric column is NULL');
  2655. INSERT INTO t1 VALUES (+0.0E-35, NULL);
  2656. INSERT INTO t1 VALUES (+0.5E+1, 'five');
  2657. INSERT INTO t1 VALUES (20.0E-1, 'two');
  2658. INSERT INTO t1 VALUES (0.0300E2, 'three');
  2659. USE test;
  2660. CREATE OR REPLACE VIEW test1.v0 AS SELECT * FROM test2.t1;
  2661. --disable_query_log
  2662. SET @max_level = IFNULL(@limit1,@max_level);
  2663. --enable_query_log
  2664. let $level= 1;
  2665. let $run= 1;
  2666. while ($run)
  2667. {
  2668. --disable_query_log
  2669. eval SET @aux = $level - 1;
  2670. let $sublevel= `SELECT @aux`;
  2671. eval SET @AUX = $level MOD 3 + 1;
  2672. let $dbnum= `SELECT @AUX`;
  2673. --enable_query_log
  2674. eval CREATE OR REPLACE VIEW test1.v$level AS SELECT f1, f2
  2675. FROM test$dbnum.t1 tab1 NATURAL JOIN test1.v$sublevel tab2;
  2676. # DEBUG Please set $debug to 1, if the statements on the toplevel VIEW
  2677. # (direct after the while loop) show suspicious results.
  2678. let $debug= 0;
  2679. if ($debug)
  2680. {
  2681. eval SHOW CREATE VIEW test1.v$level;
  2682. eval SELECT * FROM test1.v$level;
  2683. eval SELECT f1, f2
  2684. FROM test$dbnum.t1 tab1 NATURAL JOIN test1.v$sublevel tab2;
  2685. eval SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2686. CAST(f2 AS CHAR) AS f2 FROM test1.v$level;
  2687. eval EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2688. CAST(f2 AS CHAR) AS f2 FROM test1.v$level;
  2689. }
  2690. --disable_query_log
  2691. eval SET @aux = @max_level > $level;
  2692. --enable_query_log
  2693. inc $level;
  2694. # DEBUG
  2695. # eval SELECT @aux AS "@aux", $level AS "next level";
  2696. let $run= `SELECT @aux`;
  2697. }
  2698. #--------------------------------------------------------------------------
  2699. # Atention: If the following statements get suspicious/unexpected results
  2700. # and you assume that something with the non toplevel VIEWs might
  2701. # be wrong, please edit the while loop above and set $debug to 1.
  2702. #--------------------------------------------------------------------------
  2703. # 2.1 Check of top level VIEW
  2704. let $toplevel= `SELECT @max_level`;
  2705. # Show should be easy
  2706. eval SHOW CREATE VIEW test1.v$toplevel;
  2707. # SELECT is much more complicated
  2708. eval SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2709. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2710. let $message= The output of following EXPLAIN is deactivated, because the result
  2711. differs on some platforms
  2712. FIXME Is this a bug ? ;
  2713. --source include/show_msg80.inc
  2714. if (1)
  2715. {
  2716. --disable_result_log
  2717. }
  2718. # EXPLAIN might be the hell
  2719. eval EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2720. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2721. if (1)
  2722. {
  2723. --enable_result_log
  2724. }
  2725. # 2.2 Check of top level VIEW when join limit is exceeded
  2726. # Exceed the limit for the number of tables which could be joined.
  2727. let $level= `SELECT @max_level + 1`;
  2728. let $sublevel= `SELECT @max_level`;
  2729. eval CREATE VIEW test1.v$level AS SELECT f1, f2
  2730. FROM test3.t1 tab1 NATURAL JOIN test1.v$sublevel tab2;
  2731. eval SHOW CREATE VIEW test1.v$level;
  2732. # the following line as written as '--eror 1116' and the command
  2733. # is successful so assuming no expected error was intended
  2734. # --error 1116
  2735. eval SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2736. CAST(f2 AS CHAR) AS f2 FROM test1.v$level;
  2737. let $message= The output of following EXPLAIN is deactivated, because the result
  2738. differs on some platforms
  2739. FIXME Is this a bug ? ;
  2740. --source include/show_msg80.inc
  2741. if (1)
  2742. {
  2743. --disable_result_log
  2744. }
  2745. # the following line as written as '--eror 1116' and the command
  2746. # is successful so assuming no expected error was intended
  2747. # --error 1116
  2748. eval EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2749. CAST(f2 AS CHAR) AS f2 FROM test1.v$level;
  2750. if (1)
  2751. {
  2752. --enable_result_log
  2753. }
  2754. eval DROP VIEW IF EXISTS test1.v$level;
  2755. # 2.3 Create a logical wrong (data type "garbage") base for the upper views
  2756. # and check the behaviour of the top level view.
  2757. # 2.3.1 Exchange numeric and string column
  2758. --disable_result_log
  2759. CREATE OR REPLACE VIEW test1.v0 AS
  2760. SELECT f1 as f2, f2 as f1 FROM test2.t1;
  2761. # 2.3.2 DATE instead of numeric
  2762. CREATE OR REPLACE VIEW test2.v0 AS
  2763. SELECT CAST('0001-01-01' AS DATE) as f1, f2 FROM test3.t1;
  2764. eval SHOW CREATE VIEW test1.v$toplevel;
  2765. eval SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2766. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2767. eval EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2768. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2769. # 2.3.3 UCS2 string instead of common string
  2770. CREATE OR REPLACE VIEW test3.v0 AS
  2771. SELECT f1 , CONVERT('ßÄäÖöÜü§' USING UCS2) as f2 FROM test1.t1;
  2772. eval SHOW CREATE VIEW test1.v$toplevel;
  2773. eval SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2774. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2775. eval EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2776. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2777. # 2.3.4 UCS2 string instead of numeric
  2778. CREATE OR REPLACE VIEW test3.v0 AS
  2779. SELECT CONVERT('ßÄäÖöÜü§' USING UCS2) as f1, f2 FROM test1.t1;
  2780. eval SHOW CREATE VIEW test1.v$toplevel;
  2781. eval SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2782. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2783. eval EXPLAIN SELECT CAST(f1 AS SIGNED INTEGER) AS f1,
  2784. CAST(f2 AS CHAR) AS f2 FROM test1.v$toplevel;
  2785. --enable_result_log
  2786. # Cleanup
  2787. let $level= `SELECT @max_level + 1`;
  2788. while ($level)
  2789. {
  2790. dec $level;
  2791. eval DROP VIEW IF EXISTS test1.v$level;
  2792. }
  2793. DROP DATABASE test3;
  2794. DROP TABLE test1.t1;
  2795. DROP TABLE test2.t1;
  2796. #==============================================================================
  2797. # 3.3.2 Updatable and Insertable-into views:
  2798. #==============================================================================
  2799. Use test;
  2800. let $message= Testcase 3.3.2.1;
  2801. --source include/show_msg80.inc
  2802. ###############################################################################
  2803. # Testcase 3.3.2.1: Ensure that every view which may theoretically accept new
  2804. # rows via the INSERT statement does, in fact, do so.
  2805. ###############################################################################
  2806. --disable_warnings
  2807. Drop view if exists test.v1 ;
  2808. --enable_warnings
  2809. Create View test.v1 AS SELECT f59,f60 FROM tb2 where f59 = 1995 ;
  2810. --enable_info
  2811. INSERT INTO test.v1 (f59,f60) values (879,700) ;
  2812. --disable_info
  2813. SELECT f59,f60 FROM test.v1 where f59 = 879 and f60 = 700 ;
  2814. DELETE FROM tb2 where f59 = 879 and f60 = 700 ;
  2815. Drop view test.v1 ;
  2816. let $message= Testcase 3.3.2.2;
  2817. --source include/show_msg80.inc
  2818. ###############################################################################
  2819. # Testcase 3.3.2.2: Ensure that, for every row inserted into a view,
  2820. # the correct new data also appears in every relevant
  2821. # underlying table.
  2822. ###############################################################################
  2823. --disable_warnings
  2824. Drop view if exists test.v1 ;
  2825. --enable_warnings
  2826. Create view test.v1 AS SELECT f59,f60,f61 FROM tb2 ;
  2827. --enable_info
  2828. INSERT INTO test.v1 ( f59 , f60 ) values (2005,0101) ;
  2829. --disable_info
  2830. if ($have_bug_11589)
  2831. {
  2832. --disable_ps_protocol
  2833. }
  2834. SELECT * FROM tb2 where f59 = 2005 and f60 = 0101 ;
  2835. --enable_ps_protocol
  2836. SELECT f59,f60 FROM test.v1 where f59 = 2005 and f60 = 0101 ;
  2837. DELETE FROM tb2 where f59 = 2005 and f60 = 0101 ;
  2838. Drop view test.v1 ;
  2839. let $message= Testcase 3.3.2.3;
  2840. --source include/show_msg80.inc
  2841. ###############################################################################
  2842. # Testcase 3.3.2.3: Ensure that every view which may theoretically accept data
  2843. # changes via the UPDATE statement does, in fact, do so.
  2844. ###############################################################################
  2845. Insert into tb2 (f59,f60,f61) values (780,105,106) ;
  2846. --disable_warnings
  2847. Drop view if exists test.v1 ;
  2848. --enable_warnings
  2849. CREATE VIEW test.v1 AS SELECT f59,f60,f61 FROM tb2 ;
  2850. --enable_info
  2851. UPDATE test.v1 SET f59 = 8 WHERE f59 = 780 and f60 = 105;
  2852. --disable_info
  2853. if ($have_bug_11589)
  2854. {
  2855. --disable_ps_protocol
  2856. }
  2857. SELECT * FROM tb2 where f59 = 8 and f60 = 105;
  2858. --enable_ps_protocol
  2859. SELECT f59,f60 FROM test.v1 where f59 = 8 and f60 = 105;
  2860. Drop view test.v1 ;
  2861. let $message= Testcase 3.3.2.4;
  2862. --source include/show_msg80.inc
  2863. ###############################################################################
  2864. # Testcase 3.3.2.4: Ensure that, for data values updated within a view, the
  2865. # correct new data also appears in every relevant
  2866. # underlying table.
  2867. ###############################################################################
  2868. Insert into tb2 (f59,f60,f61) values (781,105,106) ;
  2869. --disable_warnings
  2870. Drop view if exists test.v1 ;
  2871. --enable_warnings
  2872. CREATE VIEW test.v1 AS SELECT f59,f60,f61 FROM tb2 ;
  2873. --enable_info
  2874. UPDATE test.v1 SET f59 = 891 WHERE f60 = 105 ;
  2875. --disable_info
  2876. if ($have_bug_11589)
  2877. {
  2878. --disable_ps_protocol
  2879. }
  2880. SELECT * FROM tb2 where f59 = 891 and f60 = 105;
  2881. --enable_ps_protocol
  2882. SELECT f59,f60 FROM test.v1 where f59 = 891 and f60 = 105;
  2883. Drop view test.v1 ;
  2884. let $message= Testcase 3.3.2.5;
  2885. --source include/show_msg80.inc
  2886. ###############################################################################
  2887. # Testcase 3.3.2.5: Ensure that every view which may theoretically accept data
  2888. # deletions via the DELETE statement does, in fact, do so.
  2889. ###############################################################################
  2890. Insert into tb2 (f59,f60,f61) values (789,105,106) ;
  2891. --disable_warnings
  2892. Drop view if exists test.v1 ;
  2893. --enable_warnings
  2894. CREATE VIEW test.v1 AS SELECT f59,f60,f61 FROM tb2 where f59 = 789 ;
  2895. --enable_info
  2896. DELETE FROM test.v1 where f59 = 789 ;
  2897. --disable_info
  2898. SELECT * FROM tb2 where f59 = 789 ;
  2899. SELECT f59,f60 FROM test.v1 where f59 = 789;
  2900. Drop view test.v1 ;
  2901. let $message= Testcase 3.3.2.6;
  2902. --source include/show_msg80.inc
  2903. ###############################################################################
  2904. # Testcase 3.3.2.6: Ensure that, for data rows deleted from a view, the correct
  2905. # rows have also been deleted from every relevant
  2906. # underlying table.
  2907. ###############################################################################
  2908. Insert into tb2 (f59,f60,f61) values (711,105,106) ;
  2909. --disable_warnings
  2910. Drop view if exists test.v1 ;
  2911. --enable_warnings
  2912. CREATE VIEW test.v1 AS SELECT f59,f60,f61 FROM tb2 where f59 = 711 ;
  2913. --enable_info
  2914. DELETE FROM test.v1 where f59 = 711 ;
  2915. --disable_info
  2916. SELECT * FROM tb2 where f59 = 711 ;
  2917. SELECT f59,f60 FROM test.v1 where f59 = 711;
  2918. Drop view test.v1 ;
  2919. let $message= Testcase 3.3.2.1 - 3.3.2.6 alternative implementation;
  2920. --source include/show_msg80.inc
  2921. --disable_warnings
  2922. DROP TABLE IF EXISTS t1;
  2923. DROP VIEW IF EXISTS v1;
  2924. --enable_warnings
  2925. CREATE TABLE t1 ( f1 BIGINT, f2 CHAR(20), f3 NUMERIC(7,4),
  2926. f4 CHAR, PRIMARY KEY(f1));
  2927. # VIEW including the base table PRIMARY KEY, but not all base table columns (f4)
  2928. # no additional columns
  2929. CREATE VIEW v1 AS SELECT f1, f2, f3 FROM t1;
  2930. # Incomplete INSERT 1
  2931. # - f2 missing
  2932. # - PRIMARY KEY f1 included
  2933. # f2 gets the default NULL
  2934. INSERT INTO v1 SET f1 = 1;
  2935. SELECT * from t1;
  2936. DELETE FROM t1;
  2937. # Incomplete INSERT 2
  2938. # - f2 included
  2939. # - PRIMARY KEY f1 missing
  2940. # f1 gets the default 0, because we are in the native sql_mode
  2941. INSERT INTO v1 SET f2 = 'ABC';
  2942. # f1 gets the default 0, but this value is already exists
  2943. --error 1062
  2944. INSERT INTO v1 SET f2 = 'ABC';
  2945. SELECT * from t1;
  2946. DELETE FROM t1;
  2947. # Testplan for DELETE:
  2948. #
  2949. # Column within WHERE qualification
  2950. # f1 (PK)
  2951. # f2 (non PK)
  2952. # none
  2953. #
  2954. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2955. # DELETE f1
  2956. DELETE FROM v1 WHERE f1 = 1;
  2957. SELECT * from t1;
  2958. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2959. # DELETE f2
  2960. DELETE FROM v1 WHERE f2 = 'ABC';
  2961. SELECT * from t1;
  2962. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2963. # DELETE none
  2964. DELETE FROM v1;
  2965. SELECT * from t1;
  2966. # Testplan for UPDATE:
  2967. # Column to modify Column within WHERE qualification
  2968. # f1 (PK) f1(PK + same column to modify)
  2969. # f1 (PK) f2
  2970. # f1 (PK) none
  2971. # f2 (non PK) f1(PK)
  2972. # f2 (non PK) f2(non PK + same column to modify)
  2973. # f2 (non PK) f3(non PK)
  2974. # f2 (non PK) none
  2975. # f1,f2 f1,f2
  2976. #
  2977. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2978. # UPDATE f1 - f1
  2979. UPDATE v1 SET f1 = 2 WHERE f1 = 1;
  2980. SELECT * from t1;
  2981. DELETE FROM t1;
  2982. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2983. # UPDATE f1 - f2
  2984. UPDATE v1 SET f1 = 2 WHERE f2 = 'ABC';
  2985. SELECT * from t1;
  2986. DELETE FROM t1;
  2987. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2988. # UPDATE f1 - none
  2989. UPDATE v1 SET f1 = 2;
  2990. SELECT * from t1;
  2991. DELETE FROM t1;
  2992. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2993. # UPDATE f2 - f1
  2994. UPDATE v1 SET f2 = 'NNN' WHERE f1 = 1;
  2995. SELECT * from t1;
  2996. DELETE FROM t1;
  2997. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  2998. # UPDATE f2 - f2
  2999. UPDATE v1 SET f2 = 'NNN' WHERE f2 = 'ABC';
  3000. SELECT * from t1;
  3001. DELETE FROM t1;
  3002. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3003. # UPDATE f2 - f3
  3004. UPDATE v1 SET f2 = 'NNN' WHERE f3 = -1.2E-3;
  3005. SELECT * from t1;
  3006. DELETE FROM t1;
  3007. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3008. # UPDATE f2 - none
  3009. UPDATE v1 SET f2 = 'NNN';
  3010. SELECT * from t1;
  3011. DELETE FROM t1;
  3012. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3013. # UPDATE f1,f2 - f1,f2
  3014. UPDATE v1 SET f1 = 2, f2 = 'NNN' WHERE f1 = 1 AND f2 = 'ABC';
  3015. SELECT * from t1;
  3016. DELETE FROM t1;
  3017. DROP VIEW v1;
  3018. # VIEW without the PRIMARY KEY f1 of the base table
  3019. # no additional columns
  3020. CREATE VIEW v1 AS SELECT f2, f3 FROM t1;
  3021. # INSERT
  3022. # - PRIMARY KEY f1 missing in VIEW definition
  3023. # f1 gets the default 0, because we are in the native sql_mode
  3024. INSERT INTO v1 SET f2 = 'ABC';
  3025. # f1 gets the default 0 and this value is already exists
  3026. --error 1062
  3027. INSERT INTO v1 SET f2 = 'ABC';
  3028. SELECT * from t1;
  3029. DELETE FROM t1;
  3030. # Testplan for DELETE:
  3031. #
  3032. # Column within WHERE qualification
  3033. # f2 (non PK)
  3034. # none
  3035. #
  3036. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3037. # DELETE f2
  3038. DELETE FROM v1 WHERE f2 = 'ABC';
  3039. SELECT * from t1;
  3040. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3041. # DELETE none
  3042. DELETE FROM v1;
  3043. SELECT * from t1;
  3044. # Testplan for UPDATE:
  3045. #
  3046. # Column to modify Column within WHERE qualification
  3047. # f2 (non PK) f2(non PK + same column to modify)
  3048. # f2 (non PK) f3(non PK)
  3049. # f2 (non PK) none
  3050. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3051. # UPDATE f2 - f2
  3052. UPDATE v1 SET f2 = 'NNN' WHERE f2 = 'ABC';
  3053. SELECT * from t1;
  3054. DELETE FROM t1;
  3055. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3056. # UPDATE f2 - f3
  3057. UPDATE v1 SET f2 = 'NNN' WHERE f3 = -1.2E-3;
  3058. SELECT * from t1;
  3059. DELETE FROM t1;
  3060. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3061. # UPDATE f2 - none
  3062. UPDATE v1 SET f2 = 'NNN';
  3063. SELECT * from t1;
  3064. DELETE FROM t1;
  3065. DROP VIEW v1;
  3066. # VIEW with the PRIMARY KEY f1 of the base table
  3067. # but additional constant column
  3068. CREATE VIEW v1 AS SELECT f1, f2, f3, 'HELLO' AS my_greeting FROM t1;
  3069. # Maybe the SQL standard allows the following INSERT.
  3070. # But it would be a very sophisticated DBMS.
  3071. --error ER_NON_INSERTABLE_TABLE
  3072. INSERT INTO v1 SET f1 = 1;
  3073. SELECT * from t1;
  3074. DELETE FROM t1;
  3075. # The next INSERTs should never work, because my_greeting is a constant.
  3076. --error ER_NON_INSERTABLE_TABLE
  3077. INSERT INTO v1 SET f1 = 1, my_greeting = 'HELLO';
  3078. SELECT * from t1;
  3079. DELETE FROM t1;
  3080. # Testplan for DELETE:
  3081. #
  3082. # Column within WHERE qualification
  3083. # f1 (PK)
  3084. # f2 (non PK)
  3085. # my_greeting(non base table column)
  3086. # none
  3087. #
  3088. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3089. # DELETE f1
  3090. DELETE FROM v1 WHERE f1 = 1;
  3091. SELECT * from t1;
  3092. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3093. # DELETE f2
  3094. DELETE FROM v1 WHERE f2 = 'ABC';
  3095. SELECT * from t1;
  3096. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3097. # DELETE my_greeting
  3098. DELETE FROM v1 WHERE my_greeting = 'HELLO';
  3099. SELECT * from t1;
  3100. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3101. # DELETE none
  3102. DELETE FROM v1;
  3103. SELECT * from t1;
  3104. # Testplan for UPDATE:
  3105. #
  3106. # Column to modify Column within WHERE qualification
  3107. # f1 (PK) f1(PK + same column to modify)
  3108. # f1 (PK) f2
  3109. # f1 (PK) my_greeting(non base table column)
  3110. # f1 (PK) none
  3111. # f2 (non PK) f1(PK)
  3112. # f2 (non PK) f2(non PK + same column to modify)
  3113. # f2 (non PK) f3(non PK)
  3114. # f2 (non PK) my_greeting(non base table column)
  3115. # f2 (non PK) none
  3116. # my_greeting(non base table column) f1(PK)
  3117. # my_greeting(non base table column) f2(non PK)
  3118. # my_greeting(non base table column) my_greeting(same non base table column)
  3119. # my_greeting(non base table column) none
  3120. # f1,f2 f1,f2
  3121. #
  3122. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3123. # UPDATE f1 - f1
  3124. UPDATE v1 SET f1 = 2 WHERE f1 = 1;
  3125. SELECT * from t1;
  3126. DELETE FROM t1;
  3127. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3128. # UPDATE f1 - f2
  3129. UPDATE v1 SET f1 = 2 WHERE f2 = 'ABC';
  3130. SELECT * from t1;
  3131. DELETE FROM t1;
  3132. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3133. # UPDATE f1 - my_greeting
  3134. UPDATE v1 SET f1 = 2 WHERE my_greeting = 'HELLO';
  3135. SELECT * from t1;
  3136. DELETE FROM t1;
  3137. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3138. # UPDATE f1 - none
  3139. UPDATE v1 SET f1 = 2;
  3140. SELECT * from t1;
  3141. DELETE FROM t1;
  3142. #------------------------------------------------
  3143. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3144. # UPDATE f2 - f1
  3145. UPDATE v1 SET f2 = 'NNN' WHERE f1 = 1;
  3146. SELECT * from t1;
  3147. DELETE FROM t1;
  3148. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3149. # UPDATE f2 - f2
  3150. UPDATE v1 SET f2 = 'NNN' WHERE f2 = 'ABC';
  3151. SELECT * from t1;
  3152. DELETE FROM t1;
  3153. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3154. # UPDATE f2 - f3
  3155. UPDATE v1 SET f2 = 'NNN' WHERE f3 = -1.2E-3;
  3156. SELECT * from t1;
  3157. DELETE FROM t1;
  3158. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3159. # UPDATE f2 - my_greeting
  3160. UPDATE v1 SET f2 = 'NNN' WHERE my_greeting = 'HELLO';
  3161. SELECT * from t1;
  3162. DELETE FROM t1;
  3163. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3164. # UPDATE f2 - none
  3165. UPDATE v1 SET f2 = 'NNN';
  3166. SELECT * from t1;
  3167. DELETE FROM t1;
  3168. #------------------------------------------------
  3169. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3170. # UPDATE my_greeting - f1
  3171. --error 1348
  3172. UPDATE v1 SET my_greeting = 'Hej' WHERE f1 = 1;
  3173. SELECT * from t1;
  3174. DELETE FROM t1;
  3175. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3176. # UPDATE my_greeting - f2
  3177. --error 1348
  3178. UPDATE v1 SET my_greeting = 'Hej' WHERE f2 = 'ABC';
  3179. SELECT * from t1;
  3180. DELETE FROM t1;
  3181. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3182. # UPDATE my_greeting - my_greeting
  3183. --error 1348
  3184. UPDATE v1 SET my_greeting = 'Hej' WHERE my_greeting = 'HELLO';
  3185. SELECT * from t1;
  3186. DELETE FROM t1;
  3187. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3188. # UPDATE my_greeting - none
  3189. --error 1348
  3190. UPDATE v1 SET my_greeting = 'Hej';
  3191. SELECT * from t1;
  3192. DELETE FROM t1;
  3193. #------------------------------------------------
  3194. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3195. # UPDATE f1, f2 - f1, f2
  3196. UPDATE v1 SET f1 = 2, f2 = 'NNN' WHERE f1 = 1 AND f2 = 'ABC';
  3197. SELECT * from t1;
  3198. DELETE FROM t1;
  3199. DROP TABLE t1;
  3200. SET sql_mode = 'traditional';
  3201. CREATE TABLE t1 ( f1 BIGINT, f2 CHAR(20), f3 NUMERIC(7,4) NOT NULL,
  3202. f4 CHAR, PRIMARY KEY(f1));
  3203. # VIEW including the base table PRIMARY KEY, but not the NOT NULL
  3204. # base table column (f3)
  3205. # no additional columns
  3206. DROP VIEW v1;
  3207. CREATE VIEW v1 AS SELECT f1, f2, f4 FROM t1;
  3208. # This INSERT must fail
  3209. --error 1423
  3210. INSERT INTO v1 SET f1 = 1;
  3211. SELECT * from t1;
  3212. DELETE FROM t1;
  3213. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3214. # DELETE f1
  3215. DELETE FROM v1 WHERE f1 = 1;
  3216. INSERT INTO t1 VALUES(1, 'ABC', -1.2E-3, 'X');
  3217. # UPDATE f1 - f2
  3218. UPDATE v1 SET f4 = 'Y' WHERE f2 = 'ABC';
  3219. SELECT * from t1;
  3220. DELETE FROM t1;
  3221. # Switch back to the native SQL mode
  3222. SET sql_mode = '';
  3223. let $message= Testcases 3.3.2.7 - 3.3.2.9,
  3224. 3.3.2.10 - 3.3.2.11 omitted because of missing
  3225. features EXCEPT and INTERSECT ;
  3226. --source include/show_msg80.inc
  3227. ###############################################################################
  3228. # Testcase 3.3.2.7: Ensure that a view with a definition that includes
  3229. # UNION
  3230. # rejects all INSERT, UPDATE, or DELETE attempts
  3231. # with an appropriate error message.
  3232. # Testcase 3.3.2.8: Ensure that a view with a definition that includes
  3233. # UNION DISTINCT
  3234. # rejects all INSERT, UPDATE, or DELETE attempts
  3235. # with an appropriate error message.
  3236. # Testcase 3.3.2.9: Ensure that a view with a definition that includes
  3237. # UNION ALL
  3238. # rejects all INSERT, UPDATE, or DELETE attempts
  3239. # with an appropriate error message.
  3240. # Testcase 3.3.2.10: Ensure that a view with a definition that includes
  3241. # EXCEPT
  3242. # rejects all INSERT, UPDATE, or DELETE attempts
  3243. # with an appropriate error message.
  3244. # (Note: MySQL does not support EXCEPT at this time;
  3245. # this test is for the future.)
  3246. # Testcase 3.3.2.11: Ensure that a view with a definition that includes
  3247. # INTERSECT
  3248. # rejects all INSERT, UPDATE, or DELETE attempts
  3249. # with an appropriate error message.
  3250. # (Note: MySQL does not support INTERSECT at this time;
  3251. # this test is for the future.)
  3252. #
  3253. # Summary of 3.3.2.7 - 3.3.2.11
  3254. # Ensure that a view with a definition that includes
  3255. # UNION or UNION DISTINCT or UNION ALL or EXCEPT or INTERSECT
  3256. # rejects any INSERT or UPDATE or DELETE statement with an
  3257. # appropriate error message
  3258. #
  3259. # ML: I assume the type of the storage engine does not play any role.
  3260. ###############################################################################
  3261. INSERT INTO tb2 (f59,f60,f61) VALUES (77,185,126) ;
  3262. INSERT INTO tb2 (f59,f60,f61) VALUES (59,58,54) ;
  3263. --disable_warnings
  3264. DROP TABLE IF EXISTS t1 ;
  3265. DROP VIEW IF EXISTS v1 ;
  3266. --enable_warnings
  3267. CREATE TABLE t1 (f59 INT, f60 INT, f61 INT) ;
  3268. INSERT INTO t1 VALUES (19,41,32) ;
  3269. INSERT INTO t1 VALUES (59,54,71) ;
  3270. INSERT INTO t1 VALUES (21,91,99) ;
  3271. SET @variant1 = 'UNION ';
  3272. SET @variant2 = 'UNION ALL ';
  3273. SET @variant3 = 'UNION DISTINCT ';
  3274. SET @variant4 = 'EXCEPT ';
  3275. SET @variant5 = 'INTERSECT ';
  3276. # Attention: Set $num to 5, when EXCEPT and INTERSECT is supported
  3277. let $num= 3;
  3278. while ($num)
  3279. {
  3280. --disable_query_log
  3281. eval SET @variant= @variant$num;
  3282. let $aux= `SELECT CONCAT('CREATE VIEW v1 AS ',
  3283. 'SELECT f61 FROM tb2 WHERE f59=59 ',
  3284. @variant,
  3285. 'SELECT f61 FROM t1 WHERE f59=19')`;
  3286. --enable_query_log
  3287. # $aux contains the CREATE VIEW statement
  3288. eval $aux;
  3289. --error ER_NON_INSERTABLE_TABLE
  3290. INSERT INTO v1 VALUES (3000);
  3291. --error 1288
  3292. UPDATE v1 SET f61 = 100 WHERE f61 = 32;
  3293. --error 1288
  3294. DELETE FROM v1;
  3295. DROP VIEW v1 ;
  3296. dec $num;
  3297. }
  3298. let $message= Testcases 3.3.2.12 - 3.3.2.20;
  3299. --source include/show_msg80.inc
  3300. ###############################################################################
  3301. # Testcase 3.3.2.12: Ensure that a view with a definition that includes
  3302. # DISTINCT
  3303. # rejects all INSERT, UPDATE, or DELETE attempts
  3304. # with an appropriate error message.
  3305. # Testcase 3.3.2.13: Ensure that a view with a definition that includes
  3306. # DISTINCTROW
  3307. # rejects all INSERT, UPDATE, or DELETE attempts
  3308. # with an appropriate error message.
  3309. # Testcase 3.3.2.14: Ensure that a view with a definition that includes
  3310. # a set function
  3311. # rejects all INSERT, UPDATE, or DELETE attempts
  3312. # with an appropriate error message.
  3313. # Testcase 3.3.2.15: Ensure that a view with a definition that includes
  3314. # GROUP BY
  3315. # rejects all INSERT, UPDATE, or DELETE attempts
  3316. # with an appropriate error message.
  3317. # Testcase 3.3.2.16: Ensure that a view with a definition that includes
  3318. # HAVING
  3319. # rejects all INSERT, UPDATE, or DELETE attempts
  3320. # with an appropriate error message.
  3321. # Testcase 3.3.2.17: Ensure that a view with a definition that includes
  3322. # a subquery in the select list
  3323. # rejects all INSERT, UPDATE, or DELETE attempts
  3324. # with an appropriate error message.
  3325. # Testcase 3.3.2.18: Ensure that a view with a definition that includes
  3326. # a reference to a non-updatable view
  3327. # rejects all INSERT, UPDATE, or DELETE attempts
  3328. # with an appropriate error message.
  3329. # Testcase 3.3.2.19: Ensure that a view with a definition that includes
  3330. # a WHERE clause subquery that refers to a table also
  3331. # referenced in a FROM clause
  3332. # rejects all INSERT, UPDATE, or DELETE attempts
  3333. # with an appropriate error message.
  3334. # Testcase 3.3.2.20: Ensure that a view with a definition that includes
  3335. # ALGORITHM = TEMPTABLE
  3336. # rejects all INSERT, UPDATE, or DELETE attempts
  3337. # with an appropriate error message.
  3338. #
  3339. # Summary of 3.3.2.12 - 3.3.2.20:
  3340. # Ensure that a view with a definition that includes
  3341. # DISTINCT 3.3.2.12
  3342. # DISTINCTROW 3.3.2.13
  3343. # SET 3.3.2.14
  3344. # GROUP BY 3.3.2.15
  3345. # HAVING 3.3.2.16
  3346. # a sub query in the select list 3.3.2.17
  3347. # a reference to a non-updateable view 3.3.2.18
  3348. # a WHERE clause sub query that refers to a table also referenced in a
  3349. # FROM clause 3.3.2.19
  3350. # ALGORITHM = TEMPTABLE 3.3.2.20
  3351. # rejects
  3352. # any INSERT or UPDATE or DELETE statement
  3353. # with an appropriate error message.
  3354. #
  3355. ###############################################################################
  3356. --disable_warnings
  3357. DROP TABLE IF EXISTS t1, t2 ;
  3358. DROP VIEW IF EXISTS test.v1 ;
  3359. Drop view if exists v2 ;
  3360. --enable_warnings
  3361. CREATE TABLE t1 (f59 int, f60 int, f61 int) ;
  3362. INSERT INTO t1 VALUES (19,41,32) ;
  3363. INSERT INTO t1 VALUES (59,54,71) ;
  3364. INSERT INTO t1 VALUES (21,91,99) ;
  3365. CREATE TABLE t2 (f59 int, f60 int, f61 int) ;
  3366. INSERT INTO t2 VALUES (19,41,32) ;
  3367. INSERT INTO t2 VALUES (59,54,71) ;
  3368. INSERT INTO t2 VALUES (21,91,99) ;
  3369. CREATE VIEW v2 AS SELECT f59, f60, f61 FROM t2 LIMIT 5;
  3370. # For DISTINCT 3.3.2.12
  3371. SET @variant1= 'CREATE VIEW v1 AS SELECT DISTINCT(f61) FROM t1';
  3372. # For DISTINCTROW 3.3.2.13
  3373. SET @variant2= 'CREATE VIEW v1 AS SELECT DISTINCTROW(f61) FROM t1';
  3374. # For SET 3.3.2.14
  3375. SET @variant3= 'CREATE VIEW v1 AS SELECT SUM(f59) AS f61 FROM t1';
  3376. # For GROUP BY 3.3.2.15
  3377. SET @variant4= 'CREATE VIEW v1 AS SELECT f61 FROM t1 GROUP BY f61';
  3378. # For HAVING 3.3.2.16
  3379. SET @variant5= 'CREATE VIEW v1 AS SELECT f61 FROM t1 HAVING f61 > 0';
  3380. # For a sub query in the select list 3.3.2.17
  3381. SET @variant6= 'CREATE VIEW v1 AS SELECT (SELECT f60 FROM t2 WHERE f59=19) AS f61 FROM t1';
  3382. # For a WHERE clause sub query that refers to a table also referenced in a
  3383. # FROM clause 3.3.2.18
  3384. SET @variant7= 'CREATE VIEW v1 AS SELECT f61 FROM v2';
  3385. # Attention: The attempt to UPDATE the next VIEW fails like expected,
  3386. # but the error message
  3387. # ERROR 1093 (HY000) : You can't specify target table 'v1' for
  3388. # update in FORM clause"
  3389. # is wrong. The server must deliver ERROR 1288.
  3390. # Bug#10773 Incorrect message is displayed while updating a view
  3391. # ML FIXME (remove the comment above, replace --error 1288,1093 with
  3392. # --error 1288 and update the file with expected results)
  3393. # when Bug#10773 is solved
  3394. # For a reference to a non-updateable view 3.3.2.19
  3395. let $message= Some server responses suffer from
  3396. Bug#10773 Incorrect message is displayed while updating a view;
  3397. --source include/show_msg80.inc
  3398. SET @variant8= 'CREATE VIEW v1 AS SELECT f59 AS f61 FROM t1 WHERE f60 IN (SELECT f59 FROM t1)';
  3399. # For ALGORITHM = TEMPTABLE 3.3.2.20
  3400. SET @variant9= 'CREATE ALGORITHM = TEMPTABLE VIEW v1 (f61) AS select f60 from t1';
  3401. let $num= 9;
  3402. while ($num)
  3403. {
  3404. --disable_abort_on_error
  3405. --disable_query_log
  3406. eval SET @variant= @variant$num;
  3407. let $aux= `SELECT @variant`;
  3408. --enable_query_log
  3409. # CREATE VIEW v1 ...
  3410. eval $aux;
  3411. --error ER_NON_INSERTABLE_TABLE
  3412. INSERT INTO v1 VALUES (1002);
  3413. --error 1288, 1093
  3414. UPDATE v1 SET f61=1007;
  3415. --error 1288
  3416. DELETE FROM v1;
  3417. # The following "--error 0" will be no more needed, when
  3418. # Bug#12471: mysqltest, --error within loop affects wrong statement
  3419. # is fixed.
  3420. --error 0
  3421. DROP VIEW v1;
  3422. dec $num;
  3423. }
  3424. Drop TABLE t1, t2 ;
  3425. Drop VIEW v2 ;
  3426. let $message= Testcases 3.3.A1;
  3427. --source include/show_msg80.inc
  3428. ###############################################################################
  3429. # Testcase 3.3.A1: Check the effects of base table modifications on an already
  3430. # existing VIEW
  3431. #
  3432. # Attention: Many modifications are logical non sense.
  3433. # The consequence is in many cases a "garbage in garbage out" effect.
  3434. #
  3435. # There is no specification of the intended behaviour within
  3436. # the MySQL manual. That means I assume the observed effects are
  3437. # no bug as long we do not get a crash or obviously non
  3438. # reasonable results.
  3439. ###############################################################################
  3440. --disable_warnings
  3441. DROP TABLE IF EXISTS t1;
  3442. DROP TABLE IF EXISTS t2;
  3443. DROP VIEW IF EXISTS v1;
  3444. DROP VIEW IF EXISTS v2;
  3445. --enable_warnings
  3446. eval CREATE TABLE t1 (f1 BIGINT, f2 DATE DEFAULT NULL, f4 CHAR(5),
  3447. report char(10)) ENGINE = $engine_type;
  3448. CREATE VIEW v1 AS SELECT * FROM t1;
  3449. INSERT INTO t1 SET f1 = -1, f4 = 'ABC', report = 't1 0';
  3450. INSERT INTO v1 SET f1 = -1, f4 = 'ABC', report = 'v1 0';
  3451. # 0. Initial state
  3452. DESCRIBE t1;
  3453. DESCRIBE v1;
  3454. SELECT * FROM t1;
  3455. SELECT * FROM v1;
  3456. #
  3457. # 1. Name of one base table column is altered
  3458. ALTER TABLE t1 CHANGE COLUMN f4 f4x CHAR(5);
  3459. INSERT INTO t1 SET f1 = 0, f4x = 'ABC', report = 't1 1';
  3460. --error 1356
  3461. INSERT INTO v1 SET f1 = 0, f4 = 'ABC', report = 'v1 1';
  3462. --error 1054
  3463. INSERT INTO v1 SET f1 = 0, f4x = 'ABC', report = 'v1 1a';
  3464. --error 1356
  3465. INSERT INTO v1 SET f1 = 0, report = 'v1 1b';
  3466. DESCRIBE t1;
  3467. # Bug#12533 crash on DESCRIBE <view> after renaming base table column;
  3468. --error 1356
  3469. DESCRIBE v1;
  3470. SELECT * FROM t1;
  3471. --error 1356
  3472. SELECT * FROM v1;
  3473. ALTER TABLE t1 CHANGE COLUMN f4x f4 CHAR(5);
  3474. #
  3475. # 2. Length of one base table column is increased
  3476. ALTER TABLE t1 CHANGE COLUMN f4 f4 CHAR(10);
  3477. INSERT INTO t1 SET f1 = 2, f4 = '<-- 10 -->', report = 't1 2';
  3478. INSERT INTO v1 SET f1 = 2, f4 = '<-- 10 -->', report = 'v1 2';
  3479. DESCRIBE t1;
  3480. DESCRIBE v1;
  3481. SELECT * FROM t1;
  3482. SELECT * FROM v1;
  3483. #
  3484. # 3. Length of one base table column is reduced
  3485. ALTER TABLE t1 CHANGE COLUMN f4 f4 CHAR(8);
  3486. INSERT INTO t1 SET f1 = 3, f4 = '<-- 10 -->', report = 't1 3';
  3487. INSERT INTO v1 SET f1 = 3, f4 = '<-- 10 -->', report = 'v1 3';
  3488. DESCRIBE t1;
  3489. DESCRIBE v1;
  3490. SELECT * FROM t1;
  3491. SELECT * FROM v1;
  3492. #
  3493. # 4. Type of one base table column is altered string -> string
  3494. ALTER TABLE t1 CHANGE COLUMN f4 f4 VARCHAR(20);
  3495. INSERT INTO t1 SET f1 = 4, f4 = '<------ 20 -------->', report = 't1 4';
  3496. INSERT INTO v1 SET f1 = 4, f4 = '<------ 20 -------->', report = 'v1 4';
  3497. DESCRIBE t1;
  3498. DESCRIBE v1;
  3499. SELECT * FROM t1;
  3500. SELECT * FROM v1;
  3501. #
  3502. # 5. Type of one base table column altered numeric -> string
  3503. ALTER TABLE t1 CHANGE COLUMN f1 f1 VARCHAR(30);
  3504. INSERT INTO t1 SET f1 = '<------------- 30 ----------->',
  3505. f4 = '<------ 20 -------->', report = 't1 5';
  3506. INSERT INTO v1 SET f1 = '<------------- 30 ----------->',
  3507. f4 = '<------ 20 -------->', report = 'v1 5';
  3508. DESCRIBE t1;
  3509. DESCRIBE v1;
  3510. SELECT * FROM t1;
  3511. SELECT * FROM v1;
  3512. #
  3513. # 6. DROP of one base table column
  3514. ALTER TABLE t1 DROP COLUMN f2;
  3515. INSERT INTO t1 SET f1 = 'ABC', f4 = '<------ 20 -------->', report = 't1 6';
  3516. --error 1356
  3517. INSERT INTO v1 SET f1 = 'ABC', f4 = '<------ 20 -------->', report = 'v1 6';
  3518. DESCRIBE t1;
  3519. --error 1356
  3520. DESCRIBE v1;
  3521. SELECT * FROM t1;
  3522. --error 1356
  3523. SELECT * FROM v1;
  3524. #
  3525. # 7. Recreation of dropped base table column with the same data type like before
  3526. ALTER TABLE t1 ADD COLUMN f2 DATE DEFAULT NULL;
  3527. INSERT INTO t1 SET f1 = 'ABC', f2 = '1500-12-04',
  3528. f4 = '<------ 20 -------->', report = 't1 7';
  3529. INSERT INTO v1 SET f1 = 'ABC', f2 = '1500-12-04',
  3530. f4 = '<------ 20 -------->', report = 'v1 7';
  3531. DESCRIBE t1;
  3532. DESCRIBE v1;
  3533. SELECT * FROM t1;
  3534. SELECT * FROM v1;
  3535. #
  3536. # 8. Recreation of dropped base table column with a different data type
  3537. # like before
  3538. ALTER TABLE t1 DROP COLUMN f2;
  3539. ALTER TABLE t1 ADD COLUMN f2 FLOAT;
  3540. INSERT INTO t1 SET f1 = 'ABC', f2 = -3.3E-4,
  3541. f4 = '<------ 20 -------->', report = 't1 8';
  3542. INSERT INTO v1 SET f1 = 'ABC', f2 = -3.3E-4,
  3543. f4 = '<------ 20 -------->', report = 'v1 8';
  3544. DESCRIBE t1;
  3545. DESCRIBE v1;
  3546. SELECT * FROM t1;
  3547. SELECT * FROM v1;
  3548. #
  3549. # 9. Add a column to the base table
  3550. ALTER TABLE t1 ADD COLUMN f3 NUMERIC(7,2);
  3551. INSERT INTO t1 SET f1 = 'ABC', f2 = -3.3E-4,
  3552. f3 = -2.2, f4 = '<------ 20 -------->', report = 't1 9';
  3553. --error 1054
  3554. INSERT INTO v1 SET f1 = 'ABC', f2 = -3.3E-4,
  3555. f3 = -2.2, f4 = '<------ 20 -------->', report = 'v1 9';
  3556. INSERT INTO v1 SET f1 = 'ABC', f2 = -3.3E-4,
  3557. f4 = '<------ 20 -------->', report = 'v1 9a';
  3558. DESCRIBE t1;
  3559. DESCRIBE v1;
  3560. SELECT * FROM t1;
  3561. SELECT * FROM v1;
  3562. #
  3563. # 10. VIEW with numeric function is "victim" of data type change
  3564. DROP TABLE t1;
  3565. DROP VIEW v1;
  3566. eval CREATE TABLE t1 (f1 CHAR(10), f2 BIGINT) ENGINE = $engine_type;
  3567. INSERT INTO t1 SET f1 = 'ABC', f2 = 3;
  3568. CREATE VIEW v1 AS SELECT f1, SQRT(f2) my_sqrt FROM t1;
  3569. DESCRIBE t1;
  3570. DESCRIBE v1;
  3571. SELECT * FROM t1;
  3572. SELECT * FROM v1;
  3573. ALTER TABLE t1 CHANGE COLUMN f2 f2 VARCHAR(30);
  3574. INSERT INTO t1 SET f1 = 'ABC', f2 = 'DEF';
  3575. DESCRIBE t1;
  3576. DESCRIBE v1;
  3577. SELECT * FROM t1;
  3578. SELECT * FROM v1;
  3579. # Some statements for comparison
  3580. # - the ugly SQRT('DEF) as constant
  3581. SELECT SQRT('DEF');
  3582. # - Will a VIEW based on the same definition show the same result ?
  3583. CREATE VIEW v2 AS SELECT SQRT('DEF');
  3584. SELECT * FROM v2;
  3585. # - Will a VIEW v2 created after the base table column recreation show the same
  3586. # result set like v1 ?
  3587. CREATE OR REPLACE VIEW v2 AS SELECT f1, SQRT(f2) my_sqrt FROM t1;
  3588. DESCRIBE v2;
  3589. SELECT * FROM v2;
  3590. # - What will be the content of base table created with AS SELECT ?
  3591. CREATE TABLE t2 AS SELECT f1, SQRT(f2) my_sqrt FROM t1;
  3592. if ($have_bug_11589)
  3593. {
  3594. --disable_ps_protocol
  3595. }
  3596. SELECT * FROM t2;
  3597. --enable_ps_protocol
  3598. DROP TABLE t2;
  3599. CREATE TABLE t2 AS SELECT * FROM v1;
  3600. if ($have_bug_11589)
  3601. {
  3602. --disable_ps_protocol
  3603. }
  3604. SELECT * FROM t2;
  3605. --enable_ps_protocol
  3606. DROP TABLE t2;
  3607. CREATE TABLE t2 AS SELECT * FROM v2;
  3608. if ($have_bug_11589)
  3609. {
  3610. --disable_ps_protocol
  3611. }
  3612. SELECT * FROM t2;
  3613. --enable_ps_protocol
  3614. #
  3615. DROP TABLE t1;
  3616. DROP TABLE t2;
  3617. DROP VIEW v1;
  3618. DROP VIEW v2;
  3619. # Clean up
  3620. --disable_warnings
  3621. DROP TABLE IF EXISTS t1;
  3622. DROP TABLE IF EXISTS t2;
  3623. DROP VIEW IF EXISTS v1;
  3624. DROP VIEW IF EXISTS v1_1;
  3625. DROP VIEW IF EXISTS v1_2;
  3626. DROP VIEW IF EXISTS v1_firstview;
  3627. DROP VIEW IF EXISTS v1_secondview;
  3628. DROP VIEW IF EXISTS v2;
  3629. DROP DATABASE IF EXISTS test2;
  3630. DROP DATABASE IF EXISTS test3;
  3631. --enable_warnings
  3632. # FIXME sub testcases, which might be included, if they fit good into
  3633. # the requirements and the completeness of the tests is increased
  3634. # Bug#10970 Views: dependence on temporary table allowed
  3635. # Bug#4663 constant function in WHERE clause evaluated in view definition
  3636. # Bug#6808 Views: CREATE VIEW v ... FROM t AS v fails
  3637. # Bug#10977 Views: no warning if column name is truncated
  3638. # Bug#9505: Views: privilege needed on underlying function
  3639. # --source suite/funcs_1/Views/Views_403x406.test
  3640. # --source suite/funcs_1/Views/Views_407.test
  3641. # --source suite/funcs_1/Views/Views_408x411.test