1SET optimizer_switch='outer_join_with_cache=off'; 2create view v1 (c,d) as select a,b from t1; 3ERROR 42S02: Table 'test.t1' doesn't exist 4create temporary table t1 (a int, b int); 5create view v1 (c) as select b+1 from t1; 6ERROR HY000: View's SELECT refers to a temporary table 't1' 7drop table t1; 8create table t1 (a int, b int); 9insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); 10create view v1 (c,d) as select a,b+@@global.max_user_connections from t1; 11ERROR HY000: View's SELECT contains a variable or parameter 12create view v1 (c,d) as select a,b from t1 13where a = @@global.max_user_connections; 14ERROR HY000: View's SELECT contains a variable or parameter 15create view v1 (c) as select b+1 from t1; 16select c from v1; 17c 183 194 205 216 2211 23select is_updatable from information_schema.views where table_name='v1'; 24is_updatable 25NO 26create temporary table t1 (a int, b int); 27select * from t1; 28a b 29select c from v1; 30c 313 324 335 346 3511 36show create table v1; 37View Create View character_set_client collation_connection 38v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 39show create view v1; 40View Create View character_set_client collation_connection 41v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 42show create view t1; 43ERROR HY000: 'test.t1' is not of type 'VIEW' 44drop table t1; 45select a from v1; 46ERROR 42S22: Unknown column 'a' in 'field list' 47select v1.a from v1; 48ERROR 42S22: Unknown column 'v1.a' in 'field list' 49select b from v1; 50ERROR 42S22: Unknown column 'b' in 'field list' 51select v1.b from v1; 52ERROR 42S22: Unknown column 'v1.b' in 'field list' 53explain extended select c from v1; 54id select_type table type possible_keys key key_len ref rows filtered Extra 551 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 56Warnings: 57Note 1003 select `test`.`t1`.`b` + 1 AS `c` from `test`.`t1` 58create algorithm=temptable view v2 (c) as select b+1 from t1; 59show create view v2; 60View Create View character_set_client collation_connection 61v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 62select c from v2; 63c 643 654 665 676 6811 69explain extended select c from v2; 70id select_type table type possible_keys key key_len ref rows filtered Extra 711 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 100.00 722 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 73Warnings: 74Note 1003 /* select#1 */ select `v2`.`c` AS `c` from `test`.`v2` 75create view v3 (c) as select a+1 from v1; 76ERROR 42S22: Unknown column 'a' in 'field list' 77create view v3 (c) as select b+1 from v1; 78ERROR 42S22: Unknown column 'b' in 'field list' 79create view v3 (c) as select c+1 from v1; 80select c from v3; 81c 824 835 846 857 8612 87explain extended select c from v3; 88id select_type table type possible_keys key key_len ref rows filtered Extra 891 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 90Warnings: 91Note 1003 select `test`.`t1`.`b` + 1 + 1 AS `c` from `test`.`t1` 92create algorithm=temptable view v4 (c) as select c+1 from v2; 93select c from v4; 94c 954 965 976 987 9912 100explain extended select c from v4; 101id select_type table type possible_keys key key_len ref rows filtered Extra 1021 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 100.00 1032 DERIVED <derived3> ALL NULL NULL NULL NULL 5 100.00 1043 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 105Warnings: 106Note 1003 /* select#1 */ select `v4`.`c` AS `c` from `test`.`v4` 107create view v5 (c) as select c+1 from v2; 108select c from v5; 109c 1104 1115 1126 1137 11412 115explain extended select c from v5; 116id select_type table type possible_keys key key_len ref rows filtered Extra 1171 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 1183 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 119Warnings: 120Note 1003 /* select#1 */ select `v2`.`c` + 1 AS `c` from `test`.`v2` 121create algorithm=temptable view v6 (c) as select c+1 from v1; 122select c from v6; 123c 1244 1255 1266 1277 12812 129explain extended select c from v6; 130id select_type table type possible_keys key key_len ref rows filtered Extra 1311 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 100.00 1322 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 133Warnings: 134Note 1003 /* select#1 */ select `v6`.`c` AS `c` from `test`.`v6` 135show tables; 136Tables_in_test 137t1 138v1 139v2 140v3 141v4 142v5 143v6 144show full tables; 145Tables_in_test Table_type 146t1 BASE TABLE 147v1 VIEW 148v2 VIEW 149v3 VIEW 150v4 VIEW 151v5 VIEW 152v6 VIEW 153show table status; 154Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary 155t1 MyISAM 10 Fixed 5 9 45 # 1024 0 NULL # # # latin1_swedish_ci NULL # N 156v1 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # # NULL NULL NULL VIEW # NULL 157v2 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # # NULL NULL NULL VIEW # NULL 158v3 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # # NULL NULL NULL VIEW # NULL 159v4 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # # NULL NULL NULL VIEW # NULL 160v5 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # # NULL NULL NULL VIEW # NULL 161v6 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # # NULL NULL NULL VIEW # NULL 162drop view v1,v2,v3,v4,v5,v6; 163create view v1 (c,d,e,f) as select a,b, 164a in (select a+2 from t1), a = all (select a from t1) from t1; 165create view v2 as select c, d from v1; 166select * from v1; 167c d e f 1681 2 0 0 1691 3 0 0 1702 4 0 0 1712 5 0 0 1723 10 1 0 173select * from v2; 174c d 1751 2 1761 3 1772 4 1782 5 1793 10 180create view v1 (c,d,e,f) as select a,b, a in (select a+2 from t1), a = all (select a from t1) from t1; 181ERROR 42S01: Table 'v1' already exists 182create or replace view v1 (c,d,e,f) as select a,b, a in (select a+2 from t1), a = all (select a from t1) from t1; 183drop view v2; 184alter view v2 as select c, d from v1; 185ERROR 42S02: Table 'test.v2' doesn't exist 186create or replace view v2 as select c, d from v1; 187alter view v1 (c,d) as select a,max(b) from t1 group by a; 188select * from v1; 189c d 1901 3 1912 5 1923 10 193select * from v2; 194c d 1951 3 1962 5 1973 10 198drop view v100; 199ERROR 42S02: Unknown VIEW: 'test.v100' 200drop view t1; 201ERROR 42S02: Unknown VIEW: 'test.t1' 202drop table v1; 203ERROR 42S02: 'test.v1' is a view 204drop view v1,v2; 205drop table t1; 206create table t1 (a int); 207insert into t1 values (1), (2), (3); 208create view v1 (a) as select a+1 from t1; 209create view v2 (a) as select a-1 from t1; 210select * from t1 natural left join v1; 211a 2121 2132 2143 215select * from v2 natural left join t1; 216a 2170 2181 2192 220select * from v2 natural left join v1; 221a 2220 2231 2242 225drop view v1, v2; 226drop table t1; 227create table t1 (a int); 228insert into t1 values (1), (2), (3), (1), (2), (3); 229create view v1 as select distinct a from t1; 230select * from v1; 231a 2321 2332 2343 235explain select * from v1; 236id select_type table type possible_keys key key_len ref rows Extra 2371 PRIMARY <derived2> ALL NULL NULL NULL NULL 6 2382 DERIVED t1 ALL NULL NULL NULL NULL 6 Using temporary 239select * from t1; 240a 2411 2422 2433 2441 2452 2463 247drop view v1; 248drop table t1; 249create table t1 (a int); 250create view v1 as select distinct a from t1 WITH CHECK OPTION; 251ERROR HY000: CHECK OPTION on non-updatable view `test`.`v1` 252create view v1 as select a from t1 WITH CHECK OPTION; 253create view v2 as select a from t1 WITH CASCADED CHECK OPTION; 254create view v3 as select a from t1 WITH LOCAL CHECK OPTION; 255drop view v3 RESTRICT; 256drop view v2 CASCADE; 257drop view v1; 258drop table t1; 259create table t1 (a int, b int); 260insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); 261create view v1 (c) as select b+1 from t1; 262select test.c from v1 test; 263c 2643 2654 2665 2676 26811 269create algorithm=temptable view v2 (c) as select b+1 from t1; 270select test.c from v2 test; 271c 2723 2734 2745 2756 27611 277select test1.* from v1 test1, v2 test2 where test1.c=test2.c; 278c 2793 2804 2815 2826 28311 284select test2.* from v1 test1, v2 test2 where test1.c=test2.c; 285c 2863 2874 2885 2896 29011 291drop table t1; 292drop view v1,v2; 293create table t1 (a int); 294insert into t1 values (1), (2), (3), (4); 295create view v1 as select a+1 from t1 order by 1 desc limit 2; 296select * from v1; 297a+1 2985 2994 300explain select * from v1; 301id select_type table type possible_keys key key_len ref rows Extra 3021 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 3032 DERIVED t1 ALL NULL NULL NULL NULL 4 Using filesort 304drop view v1; 305drop table t1; 306create table t1 (a int); 307insert into t1 values (1), (2), (3), (4); 308create view v1 as select a+1 from t1; 309create table t2 select * from v1; 310show columns from t2; 311Field Type Null Key Default Extra 312a+1 bigint(12) YES NULL 313select * from t2; 314a+1 3152 3163 3174 3185 319drop view v1; 320drop table t1,t2; 321create table t1 (a int, b int, primary key(a)); 322insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10); 323create view v1 (a,c) as select a, b+1 from t1; 324create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; 325select is_updatable from information_schema.views where table_name='v2'; 326is_updatable 327NO 328select is_updatable from information_schema.views where table_name='v1'; 329is_updatable 330YES 331update v1 set c=a+c; 332ERROR HY000: Column 'c' is not updatable 333update v2 set a=a+c; 334ERROR HY000: The target table v2 of the UPDATE is not updatable 335update v1 set a=a+c; 336select * from v1; 337a c 33813 3 33924 4 34035 5 34146 6 34261 11 343select * from t1; 344a b 34513 2 34624 3 34735 4 34846 5 34961 10 350drop table t1; 351drop view v1,v2; 352create table t1 (a int, b int, primary key(a)); 353insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10); 354create table t2 (x int); 355insert into t2 values (10), (20); 356create view v1 (a,c) as select a, b+1 from t1; 357create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; 358update t2,v1 set v1.c=v1.a+v1.c where t2.x=v1.a; 359ERROR HY000: Column 'c' is not updatable 360update t2,v2 set v2.a=v2.v2.a+c where t2.x=v2.a; 361ERROR HY000: The target table v2 of the UPDATE is not updatable 362update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.a; 363select * from v1; 364a c 36513 3 36624 4 36730 5 36840 6 36950 11 370select * from t1; 371a b 37213 2 37324 3 37430 4 37540 5 37650 10 377drop table t1,t2; 378drop view v1,v2; 379create table t1 (a int, b int, primary key(b)); 380insert into t1 values (1,20), (2,30), (3,40), (4,50), (5,100); 381create view v1 (c) as select b from t1 where a<3; 382select * from v1; 383c 38420 38530 386explain extended select * from v1; 387id select_type table type possible_keys key key_len ref rows filtered Extra 3881 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where 389Warnings: 390Note 1003 select `test`.`t1`.`b` AS `c` from `test`.`t1` where `test`.`t1`.`a` < 3 391update v1 set c=c+1; 392select * from t1; 393a b 3941 21 3952 31 3963 40 3974 50 3985 100 399create view v2 (c) as select b from t1 where a>=3; 400select * from v1, v2; 401c c 40221 40 40331 40 40421 50 40531 50 40621 100 40731 100 408drop view v1, v2; 409drop table t1; 410create table t1 (a int, b int, primary key(a)); 411insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10); 412create view v1 (a,c) as select a, b+1 from t1; 413create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; 414delete from v2 where c < 4; 415ERROR HY000: The target table v2 of the DELETE is not updatable 416delete from v1 where c < 4; 417select * from v1; 418a c 4192 4 4203 5 4214 6 4225 11 423select * from t1; 424a b 4252 3 4263 4 4274 5 4285 10 429drop table t1; 430drop view v1,v2; 431create table t1 (a int, b int, primary key(a)); 432insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10); 433create table t2 (x int); 434insert into t2 values (1), (2), (3), (4); 435create view v1 (a,c) as select a, b+1 from t1; 436create algorithm=temptable view v2 (a,c) as select a, b+1 from t1; 437delete v2 from t2,v2 where t2.x=v2.a; 438ERROR HY000: The target table v2 of the DELETE is not updatable 439delete v1 from t2,v1 where t2.x=v1.a; 440select * from v1; 441a c 4425 11 443select * from t1; 444a b 4455 10 446drop table t1,t2; 447drop view v1,v2; 448create table t1 (a int, b int, c int, primary key(a,b)); 449insert into t1 values (10,2,-1), (20,3,-2), (30,4,-3), (40,5,-4), (50,10,-5); 450create view v1 (x,y) as select a, b from t1; 451create view v2 (x,y) as select a, c from t1; 452set updatable_views_with_limit=NO; 453update v1 set x=x+1; 454update v2 set x=x+1; 455update v1 set x=x+1 limit 1; 456update v2 set x=x+1 limit 1; 457ERROR HY000: The target table v2 of the UPDATE is not updatable 458set updatable_views_with_limit=YES; 459update v1 set x=x+1 limit 1; 460update v2 set x=x+1 limit 1; 461Warnings: 462Note 1355 View being updated does not have complete key of underlying table in it 463set updatable_views_with_limit=DEFAULT; 464show variables like "updatable_views_with_limit"; 465Variable_name Value 466updatable_views_with_limit YES 467select * from t1; 468a b c 46915 2 -1 47022 3 -2 47132 4 -3 47242 5 -4 47352 10 -5 474drop table t1; 475drop view v1,v2; 476create table t1 (a int, b int, c int, primary key(a,b)); 477insert into t1 values (10,2,-1), (20,3,-2); 478create view v1 (x,y,z) as select c, b, a from t1; 479create view v2 (x,y) as select b, a from t1; 480create view v3 (x,y,z) as select b, a, b from t1; 481create view v4 (x,y,z) as select c+1, b, a from t1; 482create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1; 483insert into v3 values (-60,4,30); 484ERROR HY000: The target table v3 of the INSERT is not insertable-into 485insert into v4 values (-60,4,30); 486ERROR HY000: The target table v4 of the INSERT is not insertable-into 487insert into v5 values (-60,4,30); 488ERROR HY000: The target table v5 of the INSERT is not insertable-into 489insert into v1 values (-60,4,30); 490insert into v1 (z,y,x) values (50,6,-100); 491insert into v2 values (5,40); 492select * from t1; 493a b c 49410 2 -1 49520 3 -2 49630 4 -60 49750 6 -100 49840 5 NULL 499drop table t1; 500drop view v1,v2,v3,v4,v5; 501create table t1 (a int, b int, c int, primary key(a,b)); 502insert into t1 values (10,2,-1), (20,3,-2); 503create table t2 (a int, b int, c int, primary key(a,b)); 504insert into t2 values (30,4,-60); 505create view v1 (x,y,z) as select c, b, a from t1; 506create view v2 (x,y) as select b, a from t1; 507create view v3 (x,y,z) as select b, a, b from t1; 508create view v4 (x,y,z) as select c+1, b, a from t1; 509create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1; 510insert into v3 select c, b, a from t2; 511ERROR HY000: The target table v3 of the INSERT is not insertable-into 512insert into v4 select c, b, a from t2; 513ERROR HY000: The target table v4 of the INSERT is not insertable-into 514insert into v5 select c, b, a from t2; 515ERROR HY000: The target table v5 of the INSERT is not insertable-into 516insert into v1 select c, b, a from t2; 517insert into v1 (z,y,x) select a+20,b+2,-100 from t2; 518insert into v2 select b+1, a+10 from t2; 519select * from t1; 520a b c 52110 2 -1 52220 3 -2 52330 4 -60 52450 6 -100 52540 5 NULL 526drop table t1, t2; 527drop view v1,v2,v3,v4,v5; 528create table t1 (a int, primary key(a)); 529insert into t1 values (1), (2), (3); 530create view v1 (x) as select a from t1 where a > 1; 531select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x); 532a x 5331 NULL 5342 2 5353 3 536drop table t1; 537drop view v1; 538create table t1 (a int, primary key(a)); 539insert into t1 values (1), (2), (3), (200); 540create view v1 (x) as select a from t1 where a > 1; 541create view v2 (y) as select x from v1 where x < 100; 542select * from v2; 543y 5442 5453 546drop table t1; 547drop view v1,v2; 548create table t1 (a int, primary key(a)); 549insert into t1 values (1), (2), (3), (200); 550create ALGORITHM=TEMPTABLE view v1 (x) as select a from t1; 551create view v2 (y) as select x from v1; 552update v2 set y=10 where y=2; 553ERROR HY000: The target table v2 of the UPDATE is not updatable 554drop table t1; 555drop view v1,v2; 556create table t1 (a int not null auto_increment, b int not null, primary key(a), unique(b)); 557create view v1 (x) as select b from t1; 558insert into v1 values (1); 559select last_insert_id(); 560last_insert_id() 5610 562insert into t1 (b) values (2); 563select last_insert_id(); 564last_insert_id() 5652 566select * from t1; 567a b 5681 1 5692 2 570drop view v1; 571drop table t1; 572set sql_mode='ansi'; 573create table t1 ("a*b" int); 574create view v1 as select "a*b" from t1; 575show create view v1; 576View Create View character_set_client collation_connection 577v1 CREATE VIEW "v1" AS select "t1"."a*b" AS "a*b" from "t1" latin1 latin1_swedish_ci 578drop view v1; 579drop table t1; 580set sql_mode=default; 581create table t1 (t_column int); 582create view v1 as select 'a'; 583select * from v1, t1; 584a t_column 585drop view v1; 586drop table t1; 587create table `t1a``b` (col1 char(2)); 588create view v1 as select * from `t1a``b`; 589select * from v1; 590col1 591describe v1; 592Field Type Null Key Default Extra 593col1 char(2) YES NULL 594drop view v1; 595drop table `t1a``b`; 596create table t1 (col1 char(5),col2 char(5)); 597create view v1 as select * from t1; 598drop table t1; 599create table t1 (col1 char(5),newcol2 char(5)); 600insert into v1 values('a','aa'); 601ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 602drop table t1; 603select * from v1; 604ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 605drop view v1; 606create view v1 (a,a) as select 'a','a'; 607ERROR 42S21: Duplicate column name 'a' 608create table t1 (col1 int,col2 char(22)); 609insert into t1 values(5,'Hello, world of views'); 610create view v1 as select * from t1; 611create view v2 as select * from v1; 612update v2 set col2='Hello, view world'; 613select is_updatable from information_schema.views; 614is_updatable 615YES 616YES 617YES 618select * from t1; 619col1 col2 6205 Hello, view world 621drop view v2, v1; 622drop table t1; 623create table t1 (a int, b int); 624create view v1 as select a, sum(b) from t1 group by a; 625select b from v1 use index (some_index) where b=1; 626ERROR 42000: Key 'some_index' doesn't exist in table 'v1' 627drop view v1; 628drop table t1; 629create table t1 (col1 char(5),col2 char(5)); 630create view v1 (col1,col2) as select col1,col2 from t1; 631insert into v1 values('s1','p1'),('s1','p2'),('s1','p3'),('s1','p4'),('s2','p1'),('s3','p2'),('s4','p4'); 632select distinct first.col2 from t1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1); 633col2 634p1 635p2 636p4 637select distinct first.col2 from v1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1); 638col2 639p1 640p2 641p4 642drop view v1; 643drop table t1; 644create table t1 (a int); 645create view v1 as select a from t1; 646insert into t1 values (1); 647SET @v0 = '2'; 648PREPARE stmt FROM 'UPDATE v1 SET a = ?'; 649EXECUTE stmt USING @v0; 650DEALLOCATE PREPARE stmt; 651SET @v0 = '3'; 652PREPARE stmt FROM 'insert into v1 values (?)'; 653EXECUTE stmt USING @v0; 654DEALLOCATE PREPARE stmt; 655SET @v0 = '4'; 656PREPARE stmt FROM 'insert into v1 (a) values (?)'; 657EXECUTE stmt USING @v0; 658DEALLOCATE PREPARE stmt; 659select * from t1; 660a 6612 6623 6634 664drop view v1; 665drop table t1; 666CREATE VIEW v02 AS SELECT * FROM DUAL; 667ERROR HY000: No tables used 668SHOW TABLES; 669Tables_in_test 670CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2); 671select * from v1; 672EXISTS (SELECT 1 UNION SELECT 2) 6731 674drop view v1; 675create table t1 (col1 int,col2 char(22)); 676create view v1 as select * from t1; 677create index i1 on v1 (col1); 678ERROR HY000: 'test.v1' is not of type 'BASE TABLE' 679drop view v1; 680drop table t1; 681CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version(); 682SHOW CREATE VIEW v1; 683View Create View character_set_client collation_connection 684v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4` latin1 latin1_swedish_ci 685drop view v1; 686create table t1 (s1 int); 687create table t2 (s2 int); 688insert into t1 values (1), (2); 689insert into t2 values (2), (3); 690create view v1 as select * from t1,t2 union all select * from t1,t2; 691select * from v1; 692s1 s2 6931 2 6942 2 6951 3 6962 3 6971 2 6982 2 6991 3 7002 3 701drop view v1; 702drop tables t1, t2; 703create table t1 (col1 int); 704insert into t1 values (1); 705create view v1 as select count(*) from t1; 706insert into t1 values (null); 707select * from v1; 708count(*) 7092 710drop view v1; 711drop table t1; 712create table t1 (a int); 713create table t2 (a int); 714create view v1 as select a from t1; 715create view v2 as select a from t2 where a in (select a from v1); 716show create view v2; 717View Create View character_set_client collation_connection 718v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where `t2`.`a` in (select `v1`.`a` from `v1`) latin1 latin1_swedish_ci 719drop view v2, v1; 720drop table t1, t2; 721CREATE VIEW `v 1` AS select 5 AS `5`; 722show create view `v 1`; 723View Create View character_set_client collation_connection 724v 1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v 1` AS select 5 AS `5` latin1 latin1_swedish_ci 725drop view `v 1`; 726create database mysqltest; 727create table mysqltest.t1 (a int, b int); 728create view mysqltest.v1 as select a from mysqltest.t1; 729alter view mysqltest.v1 as select b from mysqltest.t1; 730alter view mysqltest.v1 as select a from mysqltest.t1; 731drop database mysqltest; 732CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2)); 733insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer'); 734select * from t1 WHERE match (c2) against ('Beer'); 735c1 c2 7361 real Beer 7377 almost real Beer 738CREATE VIEW v1 AS SELECT * from t1 WHERE match (c2) against ('Beer'); 739select * from v1; 740c1 c2 7411 real Beer 7427 almost real Beer 743drop view v1; 744drop table t1; 745create table t1 (a int); 746insert into t1 values (1),(1),(2),(2),(3),(3); 747create view v1 as select a from t1; 748select distinct a from v1; 749a 7501 7512 7523 753select distinct a from v1 limit 2; 754a 7551 7562 757select distinct a from t1 limit 2; 758a 7591 7602 761prepare stmt1 from "select distinct a from v1 limit 2"; 762execute stmt1; 763a 7641 7652 766execute stmt1; 767a 7681 7692 770deallocate prepare stmt1; 771drop view v1; 772drop table t1; 773create table t1 (tg_column bigint); 774create view v1 as select count(tg_column) as vg_column from t1; 775select avg(vg_column) from v1; 776avg(vg_column) 7770.0000 778drop view v1; 779drop table t1; 780create table t1 (col1 bigint not null, primary key (col1)); 781create table t2 (col1 bigint not null, key (col1)); 782create view v1 as select * from t1; 783create view v2 as select * from t2; 784insert into v1 values (1); 785insert into v2 values (1); 786create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1; 787select * from v3; 788a b 7891 1 790show create view v3; 791View Create View character_set_client collation_connection 792v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `v1`.`col1` AS `a`,`v2`.`col1` AS `b` from (`v1` join `v2`) where `v1`.`col1` = `v2`.`col1` latin1 latin1_swedish_ci 793drop view v3, v2, v1; 794drop table t2, t1; 795create function `f``1` () returns int return 5; 796create view v1 as select test.`f``1` (); 797show create view v1; 798View Create View character_set_client collation_connection 799v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`f``1`() AS `test.``f````1`` ()` latin1 latin1_swedish_ci 800select * from v1; 801test.`f``1` () 8025 803drop view v1; 804drop function `f``1`; 805create function a() returns int return 5; 806create view v1 as select a(); 807select * from v1; 808a() 8095 810drop view v1; 811drop function a; 812create table t2 (col1 char collate latin1_german2_ci); 813create view v2 as select col1 collate latin1_german1_ci from t2; 814show create view v2; 815View Create View character_set_client collation_connection 816v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`col1` collate latin1_german1_ci AS `col1 collate latin1_german1_ci` from `t2` latin1 latin1_swedish_ci 817show create view v2; 818View Create View character_set_client collation_connection 819v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`col1` collate latin1_german1_ci AS `col1 collate latin1_german1_ci` from `t2` latin1 latin1_swedish_ci 820drop view v2; 821drop table t2; 822create table t1 (a int); 823insert into t1 values (1), (2); 824create view v1 as select 5 from t1 order by 1; 825show create view v1; 826View Create View character_set_client collation_connection 827v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 5 AS `5` from `t1` order by 1 latin1 latin1_swedish_ci 828select * from v1; 8295 8305 8315 832drop view v1; 833drop table t1; 834create function x1 () returns int return 5; 835create table t1 (s1 int); 836create view v1 as select x1() from t1; 837drop function x1; 838select * from v1; 839ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 840show table status; 841Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary 842t1 MyISAM 10 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL # N 843v1 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # NULL NULL NULL NULL View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them # NULL 844Warnings: 845Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 846drop view v1; 847drop table t1; 848create table t1 (a varchar(20)); 849create view v1 as select a from t1; 850alter table t1 change a aa int; 851select * from v1; 852ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 853show table status; 854Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary 855t1 MyISAM 10 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL # N 856v1 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # NULL NULL NULL NULL View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them # NULL 857Warnings: 858Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 859show create view v1; 860View Create View character_set_client collation_connection 861v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci 862Warnings: 863Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 864drop view v1; 865drop table t1; 866create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1; 867show create view v1; 868View Create View character_set_client collation_connection 869v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 99999999999999999999999999999999999999999999999999999 AS `col1` latin1 latin1_swedish_ci 870drop view v1; 871SET @old_cs_client = @@character_set_client; 872SET @old_cs_results = @@character_set_results; 873SET @old_cs_connection = @@character_set_connection; 874set names utf8; 875create table tü (cü char); 876create view vü as select cü from tü; 877insert into vü values ('ü'); 878select * from vü; 879cü 880ü 881drop view vü; 882drop table tü; 883SET character_set_client = @old_cs_client; 884SET character_set_results = @old_cs_results; 885SET character_set_connection = @old_cs_connection; 886create table t1 (a int, b int); 887insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); 888create view v1(c) as select a+1 from t1 where b >= 4; 889select c from v1 where exists (select * from t1 where a=2 and b=c); 890c 8914 892drop view v1; 893drop table t1; 894create view v1 as select cast(1 as char(3)); 895show create view v1; 896View Create View character_set_client collation_connection 897v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(1 as char(3) charset latin1) AS `cast(1 as char(3))` latin1 latin1_swedish_ci 898select * from v1; 899cast(1 as char(3)) 9001 901drop view v1; 902create table t1 (a int); 903create view v1 as select a from t1; 904create view v3 as select a from t1; 905create database mysqltest; 906rename table v1 to mysqltest.v1; 907ERROR HY000: Changing schema from 'test' to 'mysqltest' is not allowed 908rename table v1 to v2; 909rename table v3 to v1, v2 to t1; 910ERROR 42S01: Table 't1' already exists 911drop table t1; 912drop view v2,v3; 913drop database mysqltest; 914create view v1 as select 'a',1; 915create view v2 as select * from v1 union all select * from v1; 916create view v3 as select * from v2 where 1 = (select `1` from v2); 917create view v4 as select * from v3; 918select * from v4; 919ERROR 21000: Subquery returns more than 1 row 920drop view v4, v3, v2, v1; 921create view v1 as select 5 into @w; 922ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into @w' at line 1 923create view v1 as select 5 into outfile 'ttt'; 924ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into outfile 'ttt'' at line 1 925create table t1 (a int); 926create view v1 as select a from t1 procedure analyse(); 927ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'procedure analyse()' at line 1 928create view v1 as select 1 from (select 1) as d1; 929drop view v1; 930drop table t1; 931create table t1 (s1 int, primary key (s1)); 932create view v1 as select * from t1; 933insert into v1 values (1) on duplicate key update s1 = 7; 934insert into v1 values (1) on duplicate key update s1 = 7; 935select * from t1; 936s1 9377 938drop view v1; 939drop table t1; 940create table t1 (col1 int); 941create table t2 (col1 int); 942create table t3 (col1 datetime not null); 943create view v1 as select * from t1; 944create view v2 as select * from v1; 945create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1; 946insert into v2 values ((select max(col1) from v1)); 947ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v2' 948insert into t1 values ((select max(col1) from v1)); 949ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 't1' 950insert into v2 values ((select max(col1) from v1)); 951ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v2' 952insert into v2 values ((select max(col1) from t1)); 953ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v2' 954insert into t1 values ((select max(col1) from t1)); 955ERROR HY000: Table 't1' is specified twice, both as a target for 'INSERT' and as a separate source for data 956insert into v2 values ((select max(col1) from t1)); 957ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v2' 958insert into v2 values ((select max(col1) from v2)); 959ERROR HY000: Table 'v2' is specified twice, both as a target for 'INSERT' and as a separate source for data 960insert into t1 values ((select max(col1) from v2)); 961ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 't1' 962insert into v2 values ((select max(col1) from v2)); 963ERROR HY000: Table 'v2' is specified twice, both as a target for 'INSERT' and as a separate source for data 964insert into v3 (col1) values ((select max(col1) from v1)); 965ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v3' 966insert into v3 (col1) values ((select max(col1) from t1)); 967ERROR HY000: The definition of table 'v3' prevents operation INSERT on table 'v3' 968insert into v3 (col1) values ((select max(col1) from v2)); 969ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3' 970insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2)); 971ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3' 972insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2)); 973insert into t3 values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2)); 974ERROR 23000: Column 'col1' cannot be null 975create algorithm=temptable view v4 as select * from t1; 976insert into t1 values (1),(2),(3); 977insert into t1 (col1) values ((select max(col1) from v4)); 978select * from t1; 979col1 980NULL 9811 9822 9833 9843 985drop view v4,v3,v2,v1; 986drop table t1,t2,t3; 987create table t1 (s1 int); 988create view v1 as select * from t1; 989handler v1 open as xx; 990ERROR HY000: 'test.v1' is not of type 'BASE TABLE' 991drop view v1; 992drop table t1; 993create table t1(a int); 994insert into t1 values (0), (1), (2), (3); 995create table t2 (a int); 996insert into t2 select a from t1 where a > 1; 997create view v1 as select a from t1 where a > 1; 998select * from t1 left join (t2 as t, v1) on v1.a=t1.a; 999a a a 10000 NULL NULL 10011 NULL NULL 10022 2 2 10032 3 2 10043 2 3 10053 3 3 1006select * from t1 left join (t2 as t, t2) on t2.a=t1.a; 1007a a a 10080 NULL NULL 10091 NULL NULL 10102 2 2 10112 3 2 10123 2 3 10133 3 3 1014drop view v1; 1015drop table t1, t2; 1016create table t1 (s1 char); 1017create view v1 as select s1 collate latin1_german1_ci as s1 from t1; 1018insert into v1 values ('a'); 1019select * from v1; 1020s1 1021a 1022update v1 set s1='b'; 1023select * from v1; 1024s1 1025b 1026update v1,t1 set v1.s1='c' where t1.s1=v1.s1; 1027select * from v1; 1028s1 1029c 1030prepare stmt1 from "update v1,t1 set v1.s1=? where t1.s1=v1.s1"; 1031set @arg='d'; 1032execute stmt1 using @arg; 1033select * from v1; 1034s1 1035d 1036set @arg='e'; 1037execute stmt1 using @arg; 1038select * from v1; 1039s1 1040e 1041deallocate prepare stmt1; 1042drop view v1; 1043drop table t1; 1044create table t1 (a int); 1045create table t2 (a int); 1046create view v1 as select * from t1; 1047lock tables t1 read, v1 read; 1048select * from v1; 1049a 1050select * from t2; 1051ERROR HY000: Table 't2' was not locked with LOCK TABLES 1052unlock tables; 1053drop view v1; 1054drop table t1, t2; 1055create table t1 (a int); 1056create view v1 as select * from t1 where a < 2 with check option; 1057insert into v1 values(1); 1058insert into v1 values(3); 1059ERROR 44000: CHECK OPTION failed `test`.`v1` 1060insert ignore into v1 values (2),(3),(0); 1061Warnings: 1062Warning 1369 CHECK OPTION failed `test`.`v1` 1063Warning 1369 CHECK OPTION failed `test`.`v1` 1064select * from t1; 1065a 10661 10670 1068delete from t1; 1069insert into v1 SELECT 1; 1070insert into v1 SELECT 3; 1071ERROR 44000: CHECK OPTION failed `test`.`v1` 1072create table t2 (a int); 1073insert into t2 values (2),(3),(0); 1074insert ignore into v1 SELECT a from t2; 1075Warnings: 1076Warning 1369 CHECK OPTION failed `test`.`v1` 1077Warning 1369 CHECK OPTION failed `test`.`v1` 1078select * from t1 order by a desc; 1079a 10801 10810 1082update v1 set a=-1 where a=0; 1083update v1 set a=2 where a=1; 1084ERROR 44000: CHECK OPTION failed `test`.`v1` 1085select * from t1 order by a desc; 1086a 10871 1088-1 1089update v1 set a=0 where a=0; 1090insert into t2 values (1); 1091update v1,t2 set v1.a=v1.a-1 where v1.a=t2.a; 1092select * from t1 order by a desc; 1093a 10940 1095-1 1096update v1 set a=a+1; 1097update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a; 1098Warnings: 1099Warning 1369 CHECK OPTION failed `test`.`v1` 1100select * from t1; 1101a 11021 11031 1104drop view v1; 1105drop table t1, t2; 1106create table t1 (a int); 1107create view v1 as select * from t1 where a < 2 with check option; 1108create view v2 as select * from v1 where a > 0 with local check option; 1109create view v3 as select * from v1 where a > 0 with cascaded check option; 1110insert into v2 values (1); 1111insert into v3 values (1); 1112insert into v2 values (0); 1113ERROR 44000: CHECK OPTION failed `test`.`v2` 1114insert into v3 values (0); 1115ERROR 44000: CHECK OPTION failed `test`.`v3` 1116insert into v2 values (2); 1117insert into v3 values (2); 1118ERROR 44000: CHECK OPTION failed `test`.`v3` 1119select * from t1; 1120a 11211 11221 11232 1124drop view v3,v2,v1; 1125drop table t1; 1126create table t1 (a int, primary key (a)); 1127create view v1 as select * from t1 where a < 2 with check option; 1128insert into v1 values (1) on duplicate key update a=2; 1129insert into v1 values (1) on duplicate key update a=2; 1130ERROR 44000: CHECK OPTION failed `test`.`v1` 1131insert ignore into v1 values (1) on duplicate key update a=2; 1132Warnings: 1133Warning 1369 CHECK OPTION failed `test`.`v1` 1134select * from t1; 1135a 11361 1137drop view v1; 1138drop table t1; 1139create table t1 (s1 int); 1140create view v1 as select * from t1; 1141create view v2 as select * from v1; 1142alter view v1 as select * from v2; 1143ERROR 42S02: Table 'test.v1' doesn't exist 1144alter view v1 as select * from v1; 1145ERROR 42S02: Table 'test.v1' doesn't exist 1146create or replace view v1 as select * from v2; 1147ERROR 42S02: Table 'test.v1' doesn't exist 1148create or replace view v1 as select * from v1; 1149ERROR 42S02: Table 'test.v1' doesn't exist 1150drop view v2,v1; 1151drop table t1; 1152create table t1 (a int); 1153create view v1 as select * from t1; 1154show create view v1; 1155View Create View character_set_client collation_connection 1156v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci 1157alter algorithm=undefined view v1 as select * from t1 with check option; 1158show create view v1; 1159View Create View character_set_client collation_connection 1160v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` WITH CASCADED CHECK OPTION latin1 latin1_swedish_ci 1161alter algorithm=merge view v1 as select * from t1 with cascaded check option; 1162show create view v1; 1163View Create View character_set_client collation_connection 1164v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` WITH CASCADED CHECK OPTION latin1 latin1_swedish_ci 1165alter algorithm=temptable view v1 as select * from t1; 1166show create view v1; 1167View Create View character_set_client collation_connection 1168v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci 1169drop view v1; 1170drop table t1; 1171create table t1 (s1 int); 1172create table t2 (s1 int); 1173create view v2 as select * from t2 where s1 in (select s1 from t1); 1174insert into v2 values (5); 1175insert into t1 values (5); 1176select * from v2; 1177s1 11785 1179update v2 set s1 = 0; 1180select * from v2; 1181s1 1182select * from t2; 1183s1 11840 1185alter view v2 as select * from t2 where s1 in (select s1 from t1) with check option; 1186insert into v2 values (5); 1187update v2 set s1 = 1; 1188ERROR 44000: CHECK OPTION failed `test`.`v2` 1189insert into t1 values (1); 1190update v2 set s1 = 1; 1191select * from v2; 1192s1 11931 1194select * from t2; 1195s1 11960 11971 1198prepare stmt1 from "select * from v2;"; 1199execute stmt1; 1200s1 12011 1202insert into t1 values (0); 1203execute stmt1; 1204s1 12050 12061 1207deallocate prepare stmt1; 1208drop view v2; 1209drop table t1, t2; 1210create table t1 (t time); 1211create view v1 as select substring_index(t,':',2) as t from t1; 1212insert into t1 (t) values ('12:24:10'); 1213select substring_index(t,':',2) from t1; 1214substring_index(t,':',2) 121512:24 1216select substring_index(t,':',2) from v1; 1217substring_index(t,':',2) 121812:24 1219drop view v1; 1220drop table t1; 1221create table t1 (s1 tinyint); 1222create view v1 as select * from t1 where s1 <> 0 with local check option; 1223create view v2 as select * from v1 with cascaded check option; 1224insert into v2 values (0); 1225ERROR 44000: CHECK OPTION failed `test`.`v2` 1226drop view v2, v1; 1227drop table t1; 1228create table t1 (s1 int); 1229create view v1 as select * from t1 where s1 < 5 with check option; 1230insert ignore into v1 values (6); 1231ERROR 44000: CHECK OPTION failed `test`.`v1` 1232insert ignore into v1 values (6),(3); 1233Warnings: 1234Warning 1369 CHECK OPTION failed `test`.`v1` 1235select * from t1; 1236s1 12373 1238drop view v1; 1239drop table t1; 1240SET sql_mode = 'NO_ENGINE_SUBSTITUTION'; 1241create table t1 (s1 tinyint); 1242create trigger t1_bi before insert on t1 for each row set new.s1 = 500; 1243create view v1 as select * from t1 where s1 <> 127 with check option; 1244insert into v1 values (0); 1245ERROR 44000: CHECK OPTION failed `test`.`v1` 1246select * from v1; 1247s1 1248select * from t1; 1249s1 1250drop trigger t1_bi; 1251drop view v1; 1252drop table t1; 1253SET sql_mode = default; 1254create table t1 (s1 tinyint); 1255create view v1 as select * from t1 where s1 <> 0; 1256create view v2 as select * from v1 where s1 <> 1 with cascaded check option; 1257insert into v2 values (0); 1258ERROR 44000: CHECK OPTION failed `test`.`v2` 1259select * from v2; 1260s1 1261select * from t1; 1262s1 1263drop view v2, v1; 1264drop table t1; 1265create table t1 (a int, b char(10)); 1266create view v1 as select * from t1 where a != 0 with check option; 1267load data infile '../../std_data/loaddata3.dat' into table v1 fields terminated by '' enclosed by '' ignore 1 lines; 1268ERROR 44000: CHECK OPTION failed `test`.`v1` 1269select * from t1; 1270a b 12711 row 1 12722 row 2 1273select * from v1; 1274a b 12751 row 1 12762 row 2 1277delete from t1; 1278load data infile '../../std_data/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines; 1279Warnings: 1280Note 1265 Data truncated for column 'a' at row 1 1281Note 1265 Data truncated for column 'a' at row 2 1282Warning 1366 Incorrect integer value: 'error ' for column `test`.`t1`.`a` at row 3 1283Warning 1369 CHECK OPTION failed `test`.`v1` 1284Note 1265 Data truncated for column 'a' at row 3 1285Warning 1366 Incorrect integer value: 'wrong end ' for column `test`.`t1`.`a` at row 4 1286Warning 1369 CHECK OPTION failed `test`.`v1` 1287select * from t1 order by a,b; 1288a b 12891 row 1 12902 row 2 12913 row 3 1292select * from v1 order by a,b; 1293a b 12941 row 1 12952 row 2 12963 row 3 1297drop view v1; 1298drop table t1; 1299create table t1 (a text, b text); 1300create view v1 as select * from t1 where a <> 'Field A' with check option; 1301load data infile '../../std_data/loaddata2.dat' into table v1 fields terminated by ',' enclosed by ''''; 1302ERROR 44000: CHECK OPTION failed `test`.`v1` 1303select concat('|',a,'|'), concat('|',b,'|') from t1; 1304concat('|',a,'|') concat('|',b,'|') 1305select concat('|',a,'|'), concat('|',b,'|') from v1; 1306concat('|',a,'|') concat('|',b,'|') 1307delete from t1; 1308load data infile '../../std_data/loaddata2.dat' ignore into table v1 fields terminated by ',' enclosed by ''''; 1309Warnings: 1310Warning 1369 CHECK OPTION failed `test`.`v1` 1311Warning 1261 Row 2 doesn't contain data for all columns 1312select concat('|',a,'|'), concat('|',b,'|') from t1; 1313concat('|',a,'|') concat('|',b,'|') 1314|Field 1| |Field 2' 1315Field 3,'Field 4| 1316|Field 5' ,'Field 6| NULL 1317|Field 6| | 'Field 7'| 1318select concat('|',a,'|'), concat('|',b,'|') from v1; 1319concat('|',a,'|') concat('|',b,'|') 1320|Field 1| |Field 2' 1321Field 3,'Field 4| 1322|Field 5' ,'Field 6| NULL 1323|Field 6| | 'Field 7'| 1324drop view v1; 1325drop table t1; 1326create table t1 (s1 smallint); 1327create view v1 as select * from t1 where 20 < (select (s1) from t1); 1328insert into v1 values (30); 1329ERROR HY000: The target table v1 of the INSERT is not insertable-into 1330create view v2 as select * from t1; 1331create view v3 as select * from t1 where 20 < (select (s1) from v2); 1332insert into v3 values (30); 1333ERROR HY000: The target table v3 of the INSERT is not insertable-into 1334create view v4 as select * from v2 where 20 < (select (s1) from t1); 1335insert into v4 values (30); 1336ERROR HY000: The target table v4 of the INSERT is not insertable-into 1337drop view v4, v3, v2, v1; 1338drop table t1; 1339create table t1 (a int); 1340create view v1 as select * from t1; 1341check table t1,v1; 1342Table Op Msg_type Msg_text 1343test.t1 check status OK 1344test.v1 check status OK 1345check table v1,t1; 1346Table Op Msg_type Msg_text 1347test.v1 check status OK 1348test.t1 check status OK 1349drop table t1; 1350check table v1; 1351Table Op Msg_type Msg_text 1352test.v1 check Error Table 'test.t1' doesn't exist 1353test.v1 check Error View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1354test.v1 check error Corrupt 1355drop view v1; 1356create table t1 (a int); 1357create table t2 (a int); 1358create table t3 (a int); 1359insert into t1 values (1), (2), (3); 1360insert into t2 values (1), (3); 1361insert into t3 values (1), (2), (4); 1362create view v3 (a,b) as select t1.a as a, t2.a as b from t1 left join t2 on (t1.a=t2.a); 1363select * from t3 left join v3 on (t3.a = v3.a); 1364a a b 13651 1 1 13662 2 NULL 13674 NULL NULL 1368explain extended select * from t3 left join v3 on (t3.a = v3.a); 1369id select_type table type possible_keys key key_len ref rows filtered Extra 13701 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 13711 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where 13721 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where 1373Warnings: 1374Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `b` from `test`.`t3` left join (`test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t3`.`a`)) on(`test`.`t1`.`a` = `test`.`t3`.`a`) where 1 1375create view v1 (a) as select a from t1; 1376create view v2 (a) as select a from t2; 1377create view v4 (a,b) as select v1.a as a, v2.a as b from v1 left join v2 on (v1.a=v2.a); 1378select * from t3 left join v4 on (t3.a = v4.a); 1379a a b 13801 1 1 13812 2 NULL 13824 NULL NULL 1383explain extended select * from t3 left join v4 on (t3.a = v4.a); 1384id select_type table type possible_keys key key_len ref rows filtered Extra 13851 SIMPLE t3 ALL NULL NULL NULL NULL 3 100.00 13861 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where 13871 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where 1388Warnings: 1389Note 1003 select `test`.`t3`.`a` AS `a`,`test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `b` from `test`.`t3` left join (`test`.`t1` left join (`test`.`t2`) on(`test`.`t2`.`a` = `test`.`t3`.`a`)) on(`test`.`t1`.`a` = `test`.`t3`.`a`) where 1 1390prepare stmt1 from "select * from t3 left join v4 on (t3.a = v4.a);"; 1391execute stmt1; 1392a a b 13931 1 1 13942 2 NULL 13954 NULL NULL 1396execute stmt1; 1397a a b 13981 1 1 13992 2 NULL 14004 NULL NULL 1401deallocate prepare stmt1; 1402drop view v4,v3,v2,v1; 1403drop tables t1,t2,t3; 1404create table t1 (a int, primary key (a), b int); 1405create table t2 (a int, primary key (a)); 1406insert into t1 values (1,100), (2,200); 1407insert into t2 values (1), (3); 1408create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2; 1409update v3 set a= 10 where a=1; 1410select * from t1; 1411a b 141210 100 14132 200 1414select * from t2; 1415a 14161 14173 1418create view v2 (a,b) as select t1.b as a, t2.a as b from t1, t2; 1419set updatable_views_with_limit=NO; 1420update v2 set a= 10 where a=200 limit 1; 1421ERROR HY000: The target table v2 of the UPDATE is not updatable 1422set updatable_views_with_limit=DEFAULT; 1423select * from v3; 1424a b 14252 1 142610 1 14272 3 142810 3 1429select * from v2; 1430a b 1431100 1 1432200 1 1433100 3 1434200 3 1435set @a= 10; 1436set @b= 100; 1437prepare stmt1 from "update v3 set a= ? where a=?"; 1438execute stmt1 using @a,@b; 1439select * from v3; 1440a b 14412 1 144210 1 14432 3 144410 3 1445set @a= 300; 1446set @b= 10; 1447execute stmt1 using @a,@b; 1448select * from v3; 1449a b 14502 1 1451300 1 14522 3 1453300 3 1454deallocate prepare stmt1; 1455drop view v3,v2; 1456drop tables t1,t2; 1457create table t1 (a int, primary key (a), b int); 1458create table t2 (a int, primary key (a), b int); 1459insert into t2 values (1000, 2000); 1460create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2; 1461insert into v3 values (1,2); 1462ERROR HY000: Can not insert into join view 'test.v3' without fields list 1463insert into v3 select * from t2; 1464ERROR HY000: Can not insert into join view 'test.v3' without fields list 1465insert into v3(a,b) values (1,2); 1466ERROR HY000: Can not modify more than one base table through a join view 'test.v3' 1467insert into v3(a,b) select * from t2; 1468ERROR HY000: Can not modify more than one base table through a join view 'test.v3' 1469insert into v3(a) values (1); 1470insert into v3(b) values (10); 1471insert into v3(a) select a from t2; 1472insert into v3(b) select b from t2; 1473Warnings: 1474Warning 1048 Column 'a' cannot be null 1475insert into v3(a) values (1) on duplicate key update a=a+10000+VALUES(a); 1476select * from t1; 1477a b 147810002 NULL 147910 NULL 14801000 NULL 1481select * from t2; 1482a b 14831000 2000 148410 NULL 14852000 NULL 14860 NULL 1487delete from v3; 1488ERROR HY000: Can not delete from join view 'test.v3' 1489delete v3,t1 from v3,t1; 1490ERROR HY000: Can not delete from join view 'test.v3' 1491delete t1,v3 from t1,v3; 1492ERROR HY000: Can not delete from join view 'test.v3' 1493delete from t1; 1494prepare stmt1 from "insert into v3(a) values (?);"; 1495set @a= 100; 1496execute stmt1 using @a; 1497set @a= 300; 1498execute stmt1 using @a; 1499deallocate prepare stmt1; 1500prepare stmt1 from "insert into v3(a) select ?;"; 1501set @a= 101; 1502execute stmt1 using @a; 1503set @a= 301; 1504execute stmt1 using @a; 1505deallocate prepare stmt1; 1506select * from v3; 1507a b 1508100 0 1509100 10 1510100 1000 1511100 2000 1512101 0 1513101 10 1514101 1000 1515101 2000 1516300 0 1517300 10 1518300 1000 1519300 2000 1520301 0 1521301 10 1522301 1000 1523301 2000 1524drop view v3; 1525drop tables t1,t2; 1526create table t1(f1 int); 1527create view v1 as select f1 from t1; 1528select * from v1 where F1 = 1; 1529f1 1530drop view v1; 1531drop table t1; 1532create table t1(c1 int); 1533create table t2(c2 int); 1534insert into t1 values (1),(2),(3); 1535insert into t2 values (1); 1536SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2); 1537c1 15381 1539SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1); 1540c1 15411 1542create view v1 as SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2); 1543create view v2 as SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1); 1544select * from v1; 1545c1 15461 1547select * from v2; 1548c1 15491 1550select * from (select c1 from v2) X; 1551c1 15521 1553drop view v2, v1; 1554drop table t1, t2; 1555CREATE TABLE t1 (C1 INT, C2 INT); 1556CREATE TABLE t2 (C2 INT); 1557CREATE VIEW v1 AS SELECT C2 FROM t2; 1558CREATE VIEW v2 AS SELECT C1 FROM t1 LEFT OUTER JOIN v1 USING (C2); 1559SELECT * FROM v2; 1560C1 1561drop view v2, v1; 1562drop table t1, t2; 1563create table t1 (col1 char(5),col2 int,col3 int); 1564insert into t1 values ('one',10,25), ('two',10,50), ('two',10,50), ('one',20,25), ('one',30,25); 1565create view v1 as select * from t1; 1566select col1,group_concat(col2,col3) from t1 group by col1; 1567col1 group_concat(col2,col3) 1568one 1025,2025,3025 1569two 1050,1050 1570select col1,group_concat(col2,col3) from v1 group by col1; 1571col1 group_concat(col2,col3) 1572one 1025,2025,3025 1573two 1050,1050 1574drop view v1; 1575drop table t1; 1576create table t1 (s1 int, s2 char); 1577create view v1 as select s1, s2 from t1; 1578select s2 from v1 vq1 where 2 = (select count(*) from v1 vq2 having vq1.s2 = vq2.s2); 1579ERROR 42S22: Unknown column 'vq2.s2' in 'having clause' 1580select s2 from v1 vq1 where 2 = (select count(*) aa from v1 vq2 having vq1.s2 = aa); 1581s2 1582drop view v1; 1583drop table t1; 1584CREATE TABLE t1 (a1 int); 1585CREATE TABLE t2 (a2 int); 1586INSERT INTO t1 VALUES (1), (2), (3), (4); 1587INSERT INTO t2 VALUES (1), (2), (3); 1588CREATE VIEW v1(a,b) AS SELECT a1,a2 FROM t1 JOIN t2 ON a1=a2 WHERE a1>1; 1589SELECT * FROM v1; 1590a b 15912 2 15923 3 1593CREATE TABLE t3 SELECT * FROM v1; 1594SELECT * FROM t3; 1595a b 15962 2 15973 3 1598DROP VIEW v1; 1599DROP TABLE t1,t2,t3; 1600create table t1 (a int); 1601create table t2 like t1; 1602create table t3 like t1; 1603create view v1 as select t1.a x, t2.a y from t1 join t2 where t1.a=t2.a; 1604insert into t3 select x from v1; 1605insert into t2 select x from v1; 1606drop view v1; 1607drop table t1,t2,t3; 1608CREATE TABLE t1 (col1 int PRIMARY KEY, col2 varchar(10)); 1609INSERT INTO t1 VALUES(1,'trudy'); 1610INSERT INTO t1 VALUES(2,'peter'); 1611INSERT INTO t1 VALUES(3,'sanja'); 1612INSERT INTO t1 VALUES(4,'monty'); 1613INSERT INTO t1 VALUES(5,'david'); 1614INSERT INTO t1 VALUES(6,'kent'); 1615INSERT INTO t1 VALUES(7,'carsten'); 1616INSERT INTO t1 VALUES(8,'ranger'); 1617INSERT INTO t1 VALUES(10,'matt'); 1618CREATE TABLE t2 (col1 int, col2 int, col3 char(1)); 1619INSERT INTO t2 VALUES (1,1,'y'); 1620INSERT INTO t2 VALUES (1,2,'y'); 1621INSERT INTO t2 VALUES (2,1,'n'); 1622INSERT INTO t2 VALUES (3,1,'n'); 1623INSERT INTO t2 VALUES (4,1,'y'); 1624INSERT INTO t2 VALUES (4,2,'n'); 1625INSERT INTO t2 VALUES (4,3,'n'); 1626INSERT INTO t2 VALUES (6,1,'n'); 1627INSERT INTO t2 VALUES (8,1,'y'); 1628CREATE VIEW v1 AS SELECT * FROM t1; 1629SELECT a.col1,a.col2,b.col2,b.col3 1630FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1 1631WHERE b.col2 IS NULL OR 1632b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1); 1633col1 col2 col2 col3 16341 trudy 2 y 16352 peter 1 n 16363 sanja 1 n 16374 monty 3 n 16385 david NULL NULL 16396 kent 1 n 16407 carsten NULL NULL 16418 ranger 1 y 164210 matt NULL NULL 1643SELECT a.col1,a.col2,b.col2,b.col3 1644FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1 1645WHERE b.col2 IS NULL OR 1646b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1); 1647col1 col2 col2 col3 16481 trudy 2 y 16492 peter 1 n 16503 sanja 1 n 16514 monty 3 n 16525 david NULL NULL 16536 kent 1 n 16547 carsten NULL NULL 16558 ranger 1 y 165610 matt NULL NULL 1657CREATE VIEW v2 AS SELECT * FROM t2; 1658SELECT a.col1,a.col2,b.col2,b.col3 1659FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1 1660WHERE b.col2 IS NULL OR 1661b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1); 1662col1 col2 col2 col3 16631 trudy 2 y 16642 peter 1 n 16653 sanja 1 n 16664 monty 3 n 16675 david NULL NULL 16686 kent 1 n 16697 carsten NULL NULL 16708 ranger 1 y 167110 matt NULL NULL 1672SELECT a.col1,a.col2,b.col2,b.col3 1673FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1 1674WHERE a.col1 IN (1,5,9) AND 1675(b.col2 IS NULL OR 1676b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1)); 1677col1 col2 col2 col3 16781 trudy 2 y 16795 david NULL NULL 1680CREATE VIEW v3 AS SELECT * FROM t1 WHERE col1 IN (1,5,9); 1681SELECT a.col1,a.col2,b.col2,b.col3 1682FROM v2 b RIGHT JOIN v3 a ON a.col1=b.col1 1683WHERE b.col2 IS NULL OR 1684b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1); 1685col1 col2 col2 col3 16861 trudy 2 y 16875 david NULL NULL 1688DROP VIEW v1,v2,v3; 1689DROP TABLE t1,t2; 1690create table t1 as select 1 A union select 2 union select 3; 1691create table t2 as select * from t1; 1692create view v1 as select * from t1 where a in (select * from t2); 1693select * from v1 A, v1 B where A.a = B.a; 1694A A 16951 1 16962 2 16973 3 1698create table t3 as select a a,a b from t2; 1699create view v2 as select * from t3 where 1700a in (select * from t1) or b in (select * from t2); 1701select * from v2 A, v2 B where A.a = B.b; 1702a b a b 17031 1 1 1 17042 2 2 2 17053 3 3 3 1706drop view v1, v2; 1707drop table t1, t2, t3; 1708CREATE TABLE t1 (a int); 1709CREATE TABLE t2 (b int); 1710INSERT INTO t1 VALUES (1), (2), (3), (4); 1711INSERT INTO t2 VALUES (4), (2); 1712CREATE VIEW v1 AS SELECT * FROM t1,t2 WHERE t1.a=t2.b; 1713SELECT * FROM v1; 1714a b 17152 2 17164 4 1717CREATE VIEW v2 AS SELECT * FROM v1; 1718SELECT * FROM v2; 1719a b 17202 2 17214 4 1722DROP VIEW v2,v1; 1723DROP TABLE t1, t2; 1724create table t1 (a int); 1725create view v1 as select sum(a) from t1 group by a; 1726create procedure p1() 1727begin 1728select * from v1; 1729end// 1730call p1(); 1731sum(a) 1732call p1(); 1733sum(a) 1734drop procedure p1; 1735drop view v1; 1736drop table t1; 1737CREATE TABLE t1(a char(2) primary key, b char(2)); 1738CREATE TABLE t2(a char(2), b char(2), index i(a)); 1739INSERT INTO t1 VALUES ('a','1'), ('b','2'); 1740INSERT INTO t2 VALUES ('a','5'), ('a','6'), ('b','5'), ('b','6'); 1741CREATE VIEW v1 AS 1742SELECT t1.b as c, t2.b as d FROM t1,t2 WHERE t1.a=t2.a; 1743SELECT d, c FROM v1 ORDER BY d,c; 1744d c 17455 1 17465 2 17476 1 17486 2 1749DROP VIEW v1; 1750DROP TABLE t1, t2; 1751create table t1 (s1 int); 1752create view v1 as select sum(distinct s1) from t1; 1753select * from v1; 1754sum(distinct s1) 1755NULL 1756drop view v1; 1757create view v1 as select avg(distinct s1) from t1; 1758select * from v1; 1759avg(distinct s1) 1760NULL 1761drop view v1; 1762drop table t1; 1763create view v1 as select cast(1 as decimal); 1764select * from v1; 1765cast(1 as decimal) 17661 1767drop view v1; 1768create table t1(f1 int); 1769create table t2(f2 int); 1770insert into t1 values(1),(2),(3); 1771insert into t2 values(1),(2),(3); 1772create view v1 as select * from t1,t2 where f1=f2; 1773create table t3 (f1 int, f2 int); 1774insert into t3 select * from v1 order by 1; 1775select * from t3; 1776f1 f2 17771 1 17782 2 17793 3 1780drop view v1; 1781drop table t1,t2,t3; 1782create view v1 as select '\\','\\shazam'; 1783select * from v1; 1784\ \shazam 1785\ \shazam 1786drop view v1; 1787create view v1 as select '\'','\shazam'; 1788select * from v1; 1789' shazam 1790' shazam 1791drop view v1; 1792create view v1 as select 'k','K'; 1793select * from v1; 1794k My_exp_K 1795k K 1796drop view v1; 1797create table t1 (s1 int); 1798create view v1 as select s1, 's1' from t1; 1799select * from v1; 1800s1 My_exp_s1 1801drop view v1; 1802create view v1 as select 's1', s1 from t1; 1803select * from v1; 1804My_exp_s1 s1 1805drop view v1; 1806create view v1 as select 's1', s1, 1 as My_exp_s1 from t1; 1807select * from v1; 1808My_exp_1_s1 s1 My_exp_s1 1809drop view v1; 1810create view v1 as select 1 as My_exp_s1, 's1', s1 from t1; 1811select * from v1; 1812My_exp_s1 My_exp_1_s1 s1 1813drop view v1; 1814create view v1 as select 1 as s1, 's1', 's1' from t1; 1815select * from v1; 1816s1 My_exp_s1 My_exp_1_s1 1817drop view v1; 1818create view v1 as select 's1', 's1', 1 as s1 from t1; 1819select * from v1; 1820My_exp_1_s1 My_exp_s1 s1 1821drop view v1; 1822create view v1 as select s1, 's1', 's1' from t1; 1823select * from v1; 1824s1 My_exp_s1 My_exp_1_s1 1825drop view v1; 1826create view v1 as select 's1', 's1', s1 from t1; 1827select * from v1; 1828My_exp_1_s1 My_exp_s1 s1 1829drop view v1; 1830create view v1 as select 1 as s1, 's1', s1 from t1; 1831ERROR 42S21: Duplicate column name 's1' 1832create view v1 as select 's1', s1, 1 as s1 from t1; 1833ERROR 42S21: Duplicate column name 's1' 1834drop table t1; 1835create view v1(k, K) as select 1,2; 1836ERROR 42S21: Duplicate column name 'K' 1837create view v1 as SELECT TIME_FORMAT(SEC_TO_TIME(3600),'%H:%i') as t; 1838select * from v1; 1839t 184001:00 1841drop view v1; 1842create table t1 (a timestamp default now()); 1843create table t2 (b timestamp default now()); 1844create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now(); 1845SHOW CREATE VIEW v1; 1846View Create View character_set_client collation_connection 1847v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t2`.`b` AS `b`,`t1`.`a` < current_timestamp() AS `t1.a < now()` from (`t1` join `t2`) where `t1`.`a` < current_timestamp() latin1 latin1_swedish_ci 1848drop view v1; 1849drop table t1, t2; 1850CREATE TABLE t1 ( a varchar(50) ); 1851CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER(); 1852SHOW CREATE VIEW v1; 1853View Create View character_set_client collation_connection 1854v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` where `t1`.`a` = current_user() latin1 latin1_swedish_ci 1855DROP VIEW v1; 1856CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION(); 1857SHOW CREATE VIEW v1; 1858View Create View character_set_client collation_connection 1859v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` where `t1`.`a` = version() latin1 latin1_swedish_ci 1860DROP VIEW v1; 1861CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE(); 1862SHOW CREATE VIEW v1; 1863View Create View character_set_client collation_connection 1864v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` where `t1`.`a` = database() latin1 latin1_swedish_ci 1865DROP VIEW v1; 1866DROP TABLE t1; 1867CREATE TABLE t1 (col1 time); 1868CREATE TABLE t2 (col1 time); 1869CREATE VIEW v1 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1; 1870CREATE VIEW v2 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2; 1871CREATE VIEW v3 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1; 1872CREATE VIEW v4 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2; 1873CREATE VIEW v5 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1; 1874CREATE VIEW v6 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2; 1875DROP TABLE t1; 1876CHECK TABLE v1, v2, v3, v4, v5, v6; 1877Table Op Msg_type Msg_text 1878test.v1 check Error Table 'test.t1' doesn't exist 1879test.v1 check Error View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1880test.v1 check error Corrupt 1881test.v2 check status OK 1882test.v3 check Error Table 'test.t1' doesn't exist 1883test.v3 check Error View 'test.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1884test.v3 check error Corrupt 1885test.v4 check status OK 1886test.v5 check Error Table 'test.t1' doesn't exist 1887test.v5 check Error View 'test.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1888test.v5 check error Corrupt 1889test.v6 check status OK 1890drop view v1, v2, v3, v4, v5, v6; 1891drop table t2; 1892drop function if exists f1; 1893drop function if exists f2; 1894CREATE TABLE t1 (col1 time); 1895CREATE TABLE t2 (col1 time); 1896CREATE TABLE t3 (col1 time); 1897create function f1 () returns int return (select max(col1) from t1); 1898create function f2 () returns int return (select max(col1) from t2); 1899CREATE VIEW v1 AS SELECT f1() FROM t3; 1900CREATE VIEW v2 AS SELECT f2() FROM t3; 1901CREATE VIEW v3 AS SELECT f1() FROM t3; 1902CREATE VIEW v4 AS SELECT f2() FROM t3; 1903CREATE VIEW v5 AS SELECT f1() FROM t3; 1904CREATE VIEW v6 AS SELECT f2() FROM t3; 1905drop function f1; 1906CHECK TABLE v1, v2, v3, v4, v5, v6; 1907Table Op Msg_type Msg_text 1908test.v1 check Error FUNCTION test.f1 does not exist 1909test.v1 check Error View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1910test.v1 check error Corrupt 1911test.v2 check status OK 1912test.v3 check Error FUNCTION test.f1 does not exist 1913test.v3 check Error View 'test.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1914test.v3 check error Corrupt 1915test.v4 check status OK 1916test.v5 check Error FUNCTION test.f1 does not exist 1917test.v5 check Error View 'test.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 1918test.v5 check error Corrupt 1919test.v6 check status OK 1920create function f1 () returns int return (select max(col1) from t1); 1921DROP TABLE t1; 1922CHECK TABLE v1, v2, v3, v4, v5, v6; 1923Table Op Msg_type Msg_text 1924test.v1 check status OK 1925test.v2 check status OK 1926test.v3 check status OK 1927test.v4 check status OK 1928test.v5 check status OK 1929test.v6 check status OK 1930drop function f1; 1931drop function f2; 1932drop view v1, v2, v3, v4, v5, v6; 1933drop table t2,t3; 1934create table t1 (f1 date); 1935insert into t1 values ('2005-01-01'),('2005-02-02'); 1936create view v1 as select * from t1; 1937select * from v1 where f1='2005.02.02'; 1938f1 19392005-02-02 1940select * from v1 where '2005.02.02'=f1; 1941f1 19422005-02-02 1943drop view v1; 1944drop table t1; 1945CREATE VIEW v1 AS SELECT ENCRYPT("dhgdhgd"); 1946SELECT * FROM v1; 1947drop view v1; 1948CREATE VIEW v1 AS SELECT SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1); 1949SELECT * FROM v1; 1950SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1) 1951dkjhgd 1952drop view v1; 1953create table t1 (f59 int, f60 int, f61 int); 1954insert into t1 values (19,41,32); 1955create view v1 as select f59, f60 from t1 where f59 in 1956(select f59 from t1); 1957update v1 set f60=2345; 1958ERROR HY000: The target table v1 of the UPDATE is not updatable 1959drop view v1; 1960drop table t1; 1961create table t1 (s1 int); 1962create view v1 as select var_samp(s1) from t1; 1963show create view v1; 1964View Create View character_set_client collation_connection 1965v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select var_samp(`t1`.`s1`) AS `var_samp(s1)` from `t1` latin1 latin1_swedish_ci 1966drop view v1; 1967drop table t1; 1968set sql_mode='strict_all_tables'; 1969CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL); 1970CREATE VIEW v1 (vcol1) AS SELECT col1 FROM t1; 1971CREATE VIEW v2 (vcol1) AS SELECT col1 FROM t1 WHERE col2 > 2; 1972INSERT INTO t1 (col1) VALUES(12); 1973ERROR HY000: Field 'col2' doesn't have a default value 1974INSERT INTO v1 (vcol1) VALUES(12); 1975ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value 1976INSERT INTO v2 (vcol1) VALUES(12); 1977ERROR HY000: Field of view 'test.v2' underlying table doesn't have a default value 1978set sql_mode=default; 1979drop view v2,v1; 1980drop table t1; 1981create table t1 (f1 int); 1982insert into t1 values (1); 1983create view v1 as select f1 from t1; 1984select f1 as alias from v1; 1985alias 19861 1987drop view v1; 1988drop table t1; 1989CREATE TABLE t1 (s1 int, s2 int); 1990INSERT INTO t1 VALUES (1,2); 1991CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1; 1992SELECT * FROM v1; 1993s1 s2 19942 1 1995CREATE PROCEDURE p1 () SELECT * FROM v1; 1996CALL p1(); 1997s1 s2 19982 1 1999ALTER VIEW v1 AS SELECT s1 AS s1, s2 AS s2 FROM t1; 2000CALL p1(); 2001s1 s2 20021 2 2003DROP VIEW v1; 2004CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1; 2005CALL p1(); 2006s1 s2 20072 1 2008DROP PROCEDURE p1; 2009DROP VIEW v1; 2010DROP TABLE t1; 2011create table t1 (f1 int, f2 int); 2012create view v1 as select f1 as f3, f2 as f1 from t1; 2013insert into t1 values (1,3),(2,1),(3,2); 2014select * from v1 order by f1; 2015f3 f1 20162 1 20173 2 20181 3 2019drop view v1; 2020drop table t1; 2021CREATE TABLE t1 (f1 char); 2022INSERT INTO t1 VALUES ('A'); 2023CREATE VIEW v1 AS SELECT * FROM t1; 2024INSERT INTO t1 VALUES('B'); 2025SELECT * FROM v1; 2026f1 2027A 2028B 2029SELECT * FROM t1; 2030f1 2031A 2032B 2033DROP VIEW v1; 2034DROP TABLE t1; 2035CREATE TABLE t1 ( bug_table_seq INTEGER NOT NULL); 2036CREATE OR REPLACE VIEW v1 AS SELECT * from t1; 2037DROP PROCEDURE IF EXISTS p1; 2038Warnings: 2039Note 1305 PROCEDURE test.p1 does not exist 2040CREATE PROCEDURE p1 ( ) 2041BEGIN 2042DO (SELECT @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1); 2043INSERT INTO t1 VALUES (1); 2044END // 2045CALL p1(); 2046DROP PROCEDURE p1; 2047DROP VIEW v1; 2048DROP TABLE t1; 2049create table t1(f1 datetime); 2050insert into t1 values('2005.01.01 12:0:0'); 2051create view v1 as select f1, subtime(f1, '1:1:1') as sb from t1; 2052select * from v1; 2053f1 sb 20542005-01-01 12:00:00 2005-01-01 10:58:59 2055drop view v1; 2056drop table t1; 2057CREATE TABLE t1 ( 2058aid int PRIMARY KEY, 2059fn varchar(20) NOT NULL, 2060ln varchar(20) NOT NULL 2061); 2062CREATE TABLE t2 ( 2063aid int NOT NULL, 2064pid int NOT NULL 2065); 2066INSERT INTO t1 VALUES(1,'a','b'), (2,'c','d'); 2067INSERT INTO t2 values (1,1), (2,1), (2,2); 2068CREATE VIEW v1 AS SELECT t1.*,t2.pid FROM t1,t2 WHERE t1.aid = t2.aid; 2069SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM t1,t2 2070WHERE t1.aid = t2.aid GROUP BY pid; 2071pid GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) 20721 a b,c d 20732 c d 2074SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM v1 GROUP BY pid; 2075pid GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) 20761 a b,c d 20772 c d 2078DROP VIEW v1; 2079DROP TABLE t1,t2; 2080CREATE TABLE t1 (id int PRIMARY KEY, f varchar(255)); 2081CREATE VIEW v1 AS SELECT id, f FROM t1 WHERE id <= 2; 2082INSERT INTO t1 VALUES (2, 'foo2'); 2083INSERT INTO t1 VALUES (1, 'foo1'); 2084SELECT * FROM v1; 2085id f 20861 foo1 20872 foo2 2088SELECT * FROM v1; 2089id f 20901 foo1 20912 foo2 2092DROP VIEW v1; 2093DROP TABLE t1; 2094CREATE TABLE t1 (pk int PRIMARY KEY, b int); 2095CREATE TABLE t2 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); 2096CREATE TABLE t3 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); 2097CREATE TABLE t4 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); 2098CREATE TABLE t5 (pk int PRIMARY KEY, fk int, INDEX idx(fk)); 2099CREATE VIEW v1 AS 2100SELECT t1.pk as a FROM t1,t2,t3,t4,t5 2101WHERE t1.b IS NULL AND 2102t1.pk=t2.fk AND t2.pk=t3.fk AND t3.pk=t4.fk AND t4.pk=t5.fk; 2103SELECT a FROM v1; 2104a 2105DROP VIEW v1; 2106DROP TABLE t1,t2,t3,t4,t5; 2107create view v1 as select timestampdiff(day,'1997-01-01 00:00:00','1997-01-02 00:00:00') as f1; 2108select * from v1; 2109f1 21101 2111drop view v1; 2112create table t1(a int); 2113create procedure p1() create view v1 as select * from t1; 2114drop table t1; 2115call p1(); 2116ERROR 42S02: Table 'test.t1' doesn't exist 2117call p1(); 2118ERROR 42S02: Table 'test.t1' doesn't exist 2119drop procedure p1; 2120create table t1 (f1 int); 2121create table t2 (f1 int); 2122insert into t1 values (1); 2123insert into t2 values (2); 2124create view v1 as select * from t1 union select * from t2 union all select * from t2; 2125select * from v1; 2126f1 21271 21282 21292 2130drop view v1; 2131drop table t1,t2; 2132CREATE TEMPORARY TABLE t1 (a int); 2133CREATE FUNCTION f1 () RETURNS int RETURN (SELECT COUNT(*) FROM t1); 2134CREATE VIEW v1 AS SELECT f1(); 2135ERROR HY000: View's SELECT refers to a temporary table 't1' 2136DROP FUNCTION f1; 2137DROP TABLE t1; 2138DROP TABLE IF EXISTS t1; 2139DROP VIEW IF EXISTS v1; 2140CREATE TABLE t1 (f4 CHAR(5)); 2141CREATE VIEW v1 AS SELECT * FROM t1; 2142DESCRIBE v1; 2143Field Type Null Key Default Extra 2144f4 char(5) YES NULL 2145ALTER TABLE t1 CHANGE COLUMN f4 f4x CHAR(5); 2146DESCRIBE v1; 2147ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 2148DROP TABLE t1; 2149DROP VIEW v1; 2150create table t1 (f1 char); 2151create view v1 as select strcmp(f1,'a') from t1; 2152select * from v1; 2153strcmp(f1,'a') 2154drop view v1; 2155drop table t1; 2156create table t1 (f1 int, f2 int,f3 int); 2157insert into t1 values (1,10,20),(2,0,0); 2158create view v1 as select * from t1; 2159select if(sum(f1)>1,f2,f3) from v1 group by f1; 2160if(sum(f1)>1,f2,f3) 216120 21620 2163drop view v1; 2164drop table t1; 2165create table t1 ( 2166r_object_id char(16) NOT NULL, 2167group_name varchar(32) NOT NULL 2168); 2169create table t2 ( 2170r_object_id char(16) NOT NULL, 2171i_position int(11) NOT NULL, 2172users_names varchar(32) default NULL 2173); 2174create view v1 as select r_object_id, group_name from t1; 2175create view v2 as select r_object_id, i_position, users_names from t2; 2176create unique index r_object_id on t1(r_object_id); 2177create index group_name on t1(group_name); 2178create unique index r_object_id_i_position on t2(r_object_id,i_position); 2179create index users_names on t2(users_names); 2180insert into t1 values('120001a080000542','tstgroup1'); 2181insert into t2 values('120001a080000542',-1, 'guser01'); 2182insert into t2 values('120001a080000542',-2, 'guser02'); 2183select v1.r_object_id, v2.users_names from v1, v2 2184where (v1.group_name='tstgroup1') and v2.r_object_id=v1.r_object_id 2185order by users_names; 2186r_object_id users_names 2187120001a080000542 guser01 2188120001a080000542 guser02 2189drop view v1, v2; 2190drop table t1, t2; 2191create table t1 (s1 int); 2192create view abc as select * from t1 as abc; 2193drop table t1; 2194drop view abc; 2195flush status; 2196create table t1(f1 char(1)); 2197create view v1 as select * from t1; 2198select * from (select f1 as f2, f1 as f3 from v1) v where v.f2='a'; 2199f2 f3 2200show status like "Created_tmp%"; 2201Variable_name Value 2202Created_tmp_disk_tables 0 2203Created_tmp_files 0 2204Created_tmp_tables 0 2205drop view v1; 2206drop table t1; 2207set @tmp=@@optimizer_switch; 2208set @@optimizer_switch='derived_merge=OFF'; 2209create table t1(f1 char(1)); 2210create view v1 as select * from t1; 2211select * from (select f1 as f2, f1 as f3 from v1) v where v.f2='a'; 2212f2 f3 2213show status like "Created_tmp%"; 2214Variable_name Value 2215Created_tmp_disk_tables 0 2216Created_tmp_files 0 2217Created_tmp_tables 1 2218drop view v1; 2219drop table t1; 2220set @@optimizer_switch=@tmp; 2221create view v1 as SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET'); 2222select * from v1; 2223CONVERT_TZ('2004-01-01 12:00:00','GMT','MET') 2224NULL 2225drop view v1; 2226CREATE TABLE t1 (date DATE NOT NULL); 2227INSERT INTO t1 VALUES ('2005-09-06'); 2228CREATE VIEW v1 AS SELECT DAYNAME(date) FROM t1; 2229SHOW CREATE VIEW v1; 2230View Create View character_set_client collation_connection 2231v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select dayname(`t1`.`date`) AS `DAYNAME(date)` from `t1` latin1 latin1_swedish_ci 2232CREATE VIEW v2 AS SELECT DAYOFWEEK(date) FROM t1; 2233SHOW CREATE VIEW v2; 2234View Create View character_set_client collation_connection 2235v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select dayofweek(`t1`.`date`) AS `DAYOFWEEK(date)` from `t1` latin1 latin1_swedish_ci 2236CREATE VIEW v3 AS SELECT WEEKDAY(date) FROM t1; 2237SHOW CREATE VIEW v3; 2238View Create View character_set_client collation_connection 2239v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select weekday(`t1`.`date`) AS `WEEKDAY(date)` from `t1` latin1 latin1_swedish_ci 2240SELECT DAYNAME('2005-09-06'); 2241DAYNAME('2005-09-06') 2242Tuesday 2243SELECT DAYNAME(date) FROM t1; 2244DAYNAME(date) 2245Tuesday 2246SELECT * FROM v1; 2247DAYNAME(date) 2248Tuesday 2249SELECT DAYOFWEEK('2005-09-06'); 2250DAYOFWEEK('2005-09-06') 22513 2252SELECT DAYOFWEEK(date) FROM t1; 2253DAYOFWEEK(date) 22543 2255SELECT * FROM v2; 2256DAYOFWEEK(date) 22573 2258SELECT WEEKDAY('2005-09-06'); 2259WEEKDAY('2005-09-06') 22601 2261SELECT WEEKDAY(date) FROM t1; 2262WEEKDAY(date) 22631 2264SELECT * FROM v3; 2265WEEKDAY(date) 22661 2267DROP TABLE t1; 2268DROP VIEW v1, v2, v3; 2269CREATE TABLE t1 ( a int, b int ); 2270INSERT INTO t1 VALUES (1,1),(2,2),(3,3); 2271CREATE VIEW v1 AS SELECT a,b FROM t1; 2272SELECT t1.a FROM t1 GROUP BY t1.a HAVING a > 1; 2273a 22742 22753 2276SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1; 2277a 22782 22793 2280DROP VIEW v1; 2281DROP TABLE t1; 2282CREATE TABLE t1 ( a int, b int ); 2283INSERT INTO t1 VALUES (1,1),(2,2),(3,3); 2284CREATE VIEW v1 AS SELECT a,b FROM t1; 2285SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1; 2286a 22872 22883 2289SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1; 2290a 22912 22923 2293SELECT t_1.a FROM t1 AS t_1 GROUP BY t_1.a HAVING t_1.a IN (1,2,3); 2294a 22951 22962 22973 2298SELECT v_1.a FROM v1 AS v_1 GROUP BY v_1.a HAVING v_1.a IN (1,2,3); 2299a 23001 23012 23023 2303DROP VIEW v1; 2304DROP TABLE t1; 2305CREATE TABLE t1 (a INT, b INT, INDEX(a,b)); 2306CREATE TABLE t2 LIKE t1; 2307CREATE TABLE t3 (a INT); 2308INSERT INTO t1 VALUES (1,1),(2,2),(3,3); 2309INSERT INTO t2 VALUES (1,1),(2,2),(3,3); 2310INSERT INTO t3 VALUES (1),(2),(3); 2311CREATE VIEW v1 AS SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b; 2312CREATE VIEW v2 AS SELECT t3.* FROM t1,t3 WHERE t1.a=t3.a; 2313EXPLAIN SELECT t1.* FROM t1 JOIN t2 WHERE t1.a=t2.a AND t1.b=t2.b AND t1.a=1; 2314id select_type table type possible_keys key key_len ref rows Extra 23151 SIMPLE t1 ref a a 5 const 1 Using where; Using index 23161 SIMPLE t2 ref a a 10 const,test.t1.b 1 Using index 2317EXPLAIN SELECT * FROM v1 WHERE a=1; 2318id select_type table type possible_keys key key_len ref rows Extra 23191 SIMPLE t1 ref a a 5 const 1 Using where; Using index 23201 SIMPLE t2 ref a a 10 const,test.t1.b 1 Using index 2321EXPLAIN SELECT * FROM v2 WHERE a=1; 2322id select_type table type possible_keys key key_len ref rows Extra 23231 SIMPLE t1 ref a a 5 const 1 Using index 23241 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 2325DROP VIEW v1,v2; 2326DROP TABLE t1,t2,t3; 2327create table t1 (f1 int); 2328create view v1 as select t1.f1 as '123 2329456' from t1; 2330select * from v1; 2331123 2332456 2333drop view v1; 2334drop table t1; 2335create table t1 (f1 int, f2 int); 2336insert into t1 values(1,1),(1,2),(1,3); 2337create view v1 as select f1 ,group_concat(f2 order by f2 asc) from t1 group by f1; 2338create view v2 as select f1 ,group_concat(f2 order by f2 desc) from t1 group by f1; 2339select * from v1; 2340f1 group_concat(f2 order by f2 asc) 23411 1,2,3 2342select * from v2; 2343f1 group_concat(f2 order by f2 desc) 23441 3,2,1 2345drop view v1,v2; 2346drop table t1; 2347create table t1 (x int, y int); 2348create table t2 (x int, y int, z int); 2349create table t3 (x int, y int, z int); 2350create table t4 (x int, y int, z int); 2351create view v1 as 2352select t1.x 2353from ( 2354(t1 join t2 on ((t1.y = t2.y))) 2355join 2356(t3 left join t4 on (t3.y = t4.y) and (t3.z = t4.z)) 2357); 2358prepare stmt1 from "select count(*) from v1 where x = ?"; 2359set @parm1=1; 2360execute stmt1 using @parm1; 2361count(*) 23620 2363execute stmt1 using @parm1; 2364count(*) 23650 2366drop view v1; 2367drop table t1,t2,t3,t4; 2368CREATE TABLE t1(id INT); 2369CREATE VIEW v1 AS SELECT id FROM t1; 2370OPTIMIZE TABLE v1; 2371Table Op Msg_type Msg_text 2372test.v1 optimize Error 'test.v1' is not of type 'BASE TABLE' 2373test.v1 optimize status Operation failed 2374ANALYZE TABLE v1; 2375Table Op Msg_type Msg_text 2376test.v1 analyze Error 'test.v1' is not of type 'BASE TABLE' 2377test.v1 analyze status Operation failed 2378REPAIR TABLE v1; 2379Table Op Msg_type Msg_text 2380test.v1 repair Error 'test.v1' is not of type 'BASE TABLE' 2381test.v1 repair status Operation failed 2382DROP TABLE t1; 2383OPTIMIZE TABLE v1; 2384Table Op Msg_type Msg_text 2385test.v1 optimize Error 'test.v1' is not of type 'BASE TABLE' 2386test.v1 optimize status Operation failed 2387ANALYZE TABLE v1; 2388Table Op Msg_type Msg_text 2389test.v1 analyze Error 'test.v1' is not of type 'BASE TABLE' 2390test.v1 analyze status Operation failed 2391REPAIR TABLE v1; 2392Table Op Msg_type Msg_text 2393test.v1 repair Error 'test.v1' is not of type 'BASE TABLE' 2394test.v1 repair status Operation failed 2395DROP VIEW v1; 2396create definer = current_user() sql security invoker view v1 as select 1; 2397show create view v1; 2398View Create View character_set_client collation_connection 2399v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1` latin1 latin1_swedish_ci 2400drop view v1; 2401create definer = current_user sql security invoker view v1 as select 1; 2402show create view v1; 2403View Create View character_set_client collation_connection 2404v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1` latin1 latin1_swedish_ci 2405drop view v1; 2406create table t1 (id INT, primary key(id)); 2407insert into t1 values (1),(2); 2408create view v1 as select * from t1; 2409explain select id from v1 order by id; 2410id select_type table type possible_keys key key_len ref rows Extra 24111 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index 2412drop view v1; 2413drop table t1; 2414create table t1(f1 int, f2 int); 2415insert into t1 values (null, 10), (null,2); 2416select f1, sum(f2) from t1 group by f1; 2417f1 sum(f2) 2418NULL 12 2419create view v1 as select * from t1; 2420select f1, sum(f2) from v1 group by f1; 2421f1 sum(f2) 2422NULL 12 2423drop view v1; 2424drop table t1; 2425drop procedure if exists p1; 2426create procedure p1 () deterministic 2427begin 2428create view v1 as select 1; 2429end; 2430// 2431call p1(); 2432show create view v1; 2433View Create View character_set_client collation_connection 2434v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1` latin1 latin1_swedish_ci 2435drop view v1; 2436drop procedure p1; 2437CREATE VIEW v1 AS SELECT 42 AS Meaning; 2438DROP FUNCTION IF EXISTS f1; 2439CREATE FUNCTION f1() RETURNS INTEGER 2440BEGIN 2441DECLARE retn INTEGER; 2442SELECT Meaning FROM v1 INTO retn; 2443RETURN retn; 2444END 2445// 2446Warnings: 2447Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 2448CREATE VIEW v2 AS SELECT f1(); 2449select * from v2; 2450f1() 245142 2452drop view v2,v1; 2453drop function f1; 2454create table t1 (id numeric, warehouse_id numeric); 2455create view v1 as select id from t1; 2456create view v2 as 2457select t1.warehouse_id, v1.id as receipt_id 2458from t1, v1 where t1.id = v1.id; 2459insert into t1 (id, warehouse_id) values(3, 2); 2460insert into t1 (id, warehouse_id) values(4, 2); 2461insert into t1 (id, warehouse_id) values(5, 1); 2462select v2.receipt_id as alias1, v2.receipt_id as alias2 from v2 2463order by v2.receipt_id; 2464alias1 alias2 24653 3 24664 4 24675 5 2468drop view v2, v1; 2469drop table t1; 2470CREATE TABLE t1 (a int PRIMARY KEY, b int); 2471INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10); 2472CREATE VIEW v1 AS SELECT * FROM t1; 2473SELECT MAX(a) FROM t1; 2474MAX(a) 24755 2476SELECT MAX(a) FROM v1; 2477MAX(a) 24785 2479EXPLAIN SELECT MAX(a) FROM t1; 2480id select_type table type possible_keys key key_len ref rows Extra 24811 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 2482EXPLAIN SELECT MAX(a) FROM v1; 2483id select_type table type possible_keys key key_len ref rows Extra 24841 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 2485SELECT MIN(a) FROM t1; 2486MIN(a) 24870 2488SELECT MIN(a) FROM v1; 2489MIN(a) 24900 2491EXPLAIN SELECT MIN(a) FROM t1; 2492id select_type table type possible_keys key key_len ref rows Extra 24931 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 2494EXPLAIN SELECT MIN(a) FROM v1; 2495id select_type table type possible_keys key key_len ref rows Extra 24961 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 2497DROP VIEW v1; 2498DROP TABLE t1; 2499CREATE TABLE t1 (x varchar(10)); 2500INSERT INTO t1 VALUES (null), ('foo'), ('bar'), (null); 2501CREATE VIEW v1 AS SELECT * FROM t1; 2502SELECT IF(x IS NULL, 'blank', 'not blank') FROM v1 GROUP BY x; 2503IF(x IS NULL, 'blank', 'not blank') 2504blank 2505not blank 2506not blank 2507SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM t1 GROUP BY x; 2508x 2509blank 2510not blank 2511not blank 2512Warnings: 2513Warning 1052 Column 'x' in group statement is ambiguous 2514SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1; 2515x 2516blank 2517not blank 2518not blank 2519blank 2520SELECT IF(x IS NULL, 'blank', 'not blank') AS y FROM v1 GROUP BY y; 2521y 2522blank 2523not blank 2524SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x; 2525x 2526blank 2527not blank 2528not blank 2529Warnings: 2530Warning 1052 Column 'x' in group statement is ambiguous 2531DROP VIEW v1; 2532DROP TABLE t1; 2533drop table if exists t1; 2534drop view if exists v1; 2535create table t1 (id int); 2536create view v1 as select * from t1; 2537drop table t1; 2538show create view v1; 2539drop view v1; 2540// 2541View Create View character_set_client collation_connection 2542v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`id` AS `id` from `t1` latin1 latin1_swedish_ci 2543create table t1(f1 int, f2 int); 2544create view v1 as select ta.f1 as a, tb.f1 as b from t1 ta, t1 tb where ta.f1=tb 2545.f1 and ta.f2=tb.f2; 2546insert into t1 values(1,1),(2,2); 2547create view v2 as select * from v1 where a > 1 with local check option; 2548select * from v2; 2549a b 25502 2 2551update v2 set b=3 where a=2; 2552select * from v2; 2553a b 25543 3 2555drop view v2, v1; 2556drop table t1; 2557CREATE TABLE t1 (a int); 2558INSERT INTO t1 VALUES (1), (2); 2559CREATE VIEW v1 AS SELECT SQRT(a) my_sqrt FROM t1; 2560SELECT my_sqrt FROM v1 ORDER BY my_sqrt; 2561my_sqrt 25621 25631.4142135623730951 2564DROP VIEW v1; 2565DROP TABLE t1; 2566CREATE TABLE t1 (id int PRIMARY KEY); 2567CREATE TABLE t2 (id int PRIMARY KEY); 2568INSERT INTO t1 VALUES (1), (3); 2569INSERT INTO t2 VALUES (1), (2), (3); 2570CREATE VIEW v2 AS SELECT * FROM t2; 2571SELECT COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id=t2.id; 2572COUNT(*) 25732 2574SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id; 2575id id 25761 1 25773 3 2578SELECT COUNT(*) FROM t1 LEFT JOIN v2 ON t1.id=v2.id; 2579COUNT(*) 25802 2581DROP VIEW v2; 2582DROP TABLE t1, t2; 2583CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, 2584td date DEFAULT NULL, KEY idx(td)); 2585INSERT INTO t1 VALUES 2586(1, '2005-01-01'), (2, '2005-01-02'), (3, '2005-01-02'), 2587(4, '2005-01-03'), (5, '2005-01-04'), (6, '2005-01-05'), 2588(7, '2005-01-05'), (8, '2005-01-05'), (9, '2005-01-06'); 2589CREATE VIEW v1 AS SELECT * FROM t1; 2590SELECT * FROM t1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE); 2591id td 25922 2005-01-02 25933 2005-01-02 25944 2005-01-03 25955 2005-01-04 2596SELECT * FROM v1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE); 2597id td 25982 2005-01-02 25993 2005-01-02 26004 2005-01-03 26015 2005-01-04 2602DROP VIEW v1; 2603DROP TABLE t1; 2604create table t1 (a int); 2605create view v1 as select * from t1; 2606create view v2 as select * from v1; 2607drop table t1; 2608rename table v2 to t1; 2609select * from v1; 2610ERROR HY000: `test`.`v1` contains view recursion 2611drop view t1, v1; 2612create table t1 (a int); 2613create function f1() returns int 2614begin 2615declare mx int; 2616select max(a) from t1 into mx; 2617return mx; 2618end// 2619Warnings: 2620Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 2621create view v1 as select f1() as a; 2622create view v2 as select * from v1; 2623drop table t1; 2624rename table v2 to t1; 2625select * from v1; 2626ERROR HY000: Recursive stored functions and triggers are not allowed 2627drop function f1; 2628drop view t1, v1; 2629create table t1 (dt datetime); 2630insert into t1 values (20040101000000), (20050101000000), (20060101000000); 2631create view v1 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from t1; 2632select * from v1; 2633ldt 26342004-01-01 03:00:00 26352005-01-01 03:00:00 26362006-01-01 03:00:00 2637drop view v1; 2638create view v1 as select * from t1 where convert_tz(dt, 'UTC', 'Europe/Moscow') >= 20050101000000; 2639select * from v1; 2640dt 26412005-01-01 00:00:00 26422006-01-01 00:00:00 2643create view v2 as select * from v1 where dt < 20060101000000; 2644select * from v2; 2645dt 26462005-01-01 00:00:00 2647drop view v2; 2648create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1; 2649select * from v2; 2650ldt 26512005-01-01 03:00:00 26522006-01-01 03:00:00 2653drop view v1, v2; 2654drop table t1; 2655CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, d datetime); 2656CREATE VIEW v1 AS 2657SELECT id, date(d) + INTERVAL TIME_TO_SEC(d) SECOND AS t, COUNT(*) 2658FROM t1 GROUP BY id, t; 2659SHOW CREATE VIEW v1; 2660View Create View character_set_client collation_connection 2661v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`id` AS `id`,cast(`t1`.`d` as date) + interval time_to_sec(`t1`.`d`) second AS `t`,count(0) AS `COUNT(*)` from `t1` group by `t1`.`id`,cast(`t1`.`d` as date) + interval time_to_sec(`t1`.`d`) second latin1 latin1_swedish_ci 2662SELECT * FROM v1; 2663id t COUNT(*) 2664DROP VIEW v1; 2665DROP TABLE t1; 2666CREATE TABLE t1 (i INT, j BIGINT); 2667INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2); 2668CREATE VIEW v1 AS SELECT MIN(j) AS j FROM t1; 2669CREATE VIEW v2 AS SELECT MIN(i) FROM t1 WHERE j = ( SELECT * FROM v1 ); 2670SELECT * FROM v2; 2671MIN(i) 26721 2673DROP VIEW v2, v1; 2674DROP TABLE t1; 2675CREATE TABLE t1( 2676fName varchar(25) NOT NULL, 2677lName varchar(25) NOT NULL, 2678DOB date NOT NULL, 2679test_date date NOT NULL, 2680uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY); 2681INSERT INTO t1(fName, lName, DOB, test_date) VALUES 2682('Hank', 'Hill', '1964-09-29', '2007-01-01'), 2683('Tom', 'Adams', '1908-02-14', '2007-01-01'), 2684('Homer', 'Simpson', '1968-03-05', '2007-01-01'); 2685CREATE VIEW v1 AS 2686SELECT (year(test_date)-year(DOB)) AS Age 2687FROM t1 HAVING Age < 75; 2688SHOW CREATE VIEW v1; 2689View Create View character_set_client collation_connection 2690v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select year(`t1`.`test_date`) - year(`t1`.`DOB`) AS `Age` from `t1` having `Age` < 75 latin1 latin1_swedish_ci 2691SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75; 2692Age 269343 269439 2695SELECT * FROM v1; 2696Age 269743 269839 2699DROP VIEW v1; 2700DROP TABLE t1; 2701CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a char(6) DEFAULT 'xxx'); 2702INSERT INTO t1(id) VALUES (1), (2), (3), (4); 2703INSERT INTO t1 VALUES (5,'yyy'), (6,'yyy'); 2704SELECT * FROM t1; 2705id a 27061 xxx 27072 xxx 27083 xxx 27094 xxx 27105 yyy 27116 yyy 2712CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a; 2713SELECT * FROM v1; 2714a m 2715xxx 1 2716yyy 5 2717CREATE TABLE t2 SELECT * FROM v1; 2718INSERT INTO t2(m) VALUES (0); 2719SELECT * FROM t2; 2720a m 2721xxx 1 2722yyy 5 2723xxx 0 2724DROP VIEW v1; 2725DROP TABLE t1,t2; 2726CREATE TABLE t1 (id int PRIMARY KEY, e ENUM('a','b') NOT NULL DEFAULT 'b'); 2727INSERT INTO t1(id) VALUES (1), (2), (3); 2728INSERT INTO t1 VALUES (4,'a'); 2729SELECT * FROM t1; 2730id e 27311 b 27322 b 27333 b 27344 a 2735CREATE VIEW v1(m, e) AS SELECT MIN(id), e FROM t1 GROUP BY e; 2736CREATE TABLE t2 SELECT * FROM v1; 2737SELECT * FROM t2; 2738m e 27394 a 27401 b 2741DROP VIEW v1; 2742DROP TABLE t1,t2; 2743CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL); 2744CREATE VIEW v1 AS SELECT a, b FROM t1; 2745INSERT IGNORE INTO v1 (b) VALUES (2); 2746Warnings: 2747Warning 1423 Field of view 'test.v1' underlying table doesn't have a default value 2748SET SQL_MODE = STRICT_ALL_TABLES; 2749INSERT INTO v1 (b) VALUES (4); 2750ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value 2751SET SQL_MODE = ''; 2752SELECT * FROM t1; 2753a b 27540 2 2755DROP VIEW v1; 2756DROP TABLE t1; 2757CREATE TABLE t1 (firstname text, surname text); 2758INSERT INTO t1 VALUES 2759("Bart","Simpson"),("Milhouse","van Houten"),("Montgomery","Burns"); 2760CREATE VIEW v1 AS SELECT CONCAT(firstname," ",surname) AS name FROM t1; 2761SELECT CONCAT(LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," ")), 2762LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," "))) AS f1 2763FROM v1; 2764f1 2765BartBart 2766Milhouse vanMilhouse van 2767MontgomeryMontgomery 2768DROP VIEW v1; 2769DROP TABLE t1; 2770CREATE TABLE t1 (i int, j int); 2771CREATE VIEW v1 AS SELECT COALESCE(i,j) FROM t1; 2772DESCRIBE v1; 2773Field Type Null Key Default Extra 2774COALESCE(i,j) int(11) YES NULL 2775CREATE TABLE t2 SELECT COALESCE(i,j) FROM t1; 2776DESCRIBE t2; 2777Field Type Null Key Default Extra 2778COALESCE(i,j) int(11) YES NULL 2779DROP VIEW v1; 2780DROP TABLE t1,t2; 2781CREATE TABLE t1 (s varchar(10)); 2782INSERT INTO t1 VALUES ('yadda'), ('yady'); 2783SELECT TRIM(BOTH 'y' FROM s) FROM t1; 2784TRIM(BOTH 'y' FROM s) 2785adda 2786ad 2787CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1; 2788SELECT * FROM v1; 2789TRIM(BOTH 'y' FROM s) 2790adda 2791ad 2792DROP VIEW v1; 2793SELECT TRIM(LEADING 'y' FROM s) FROM t1; 2794TRIM(LEADING 'y' FROM s) 2795adda 2796ady 2797CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1; 2798SELECT * FROM v1; 2799TRIM(LEADING 'y' FROM s) 2800adda 2801ady 2802DROP VIEW v1; 2803SELECT TRIM(TRAILING 'y' FROM s) FROM t1; 2804TRIM(TRAILING 'y' FROM s) 2805yadda 2806yad 2807CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1; 2808SELECT * FROM v1; 2809TRIM(TRAILING 'y' FROM s) 2810yadda 2811yad 2812DROP VIEW v1; 2813DROP TABLE t1; 2814CREATE TABLE t1 (x INT, y INT); 2815CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1; 2816SHOW CREATE VIEW v1; 2817View Create View character_set_client collation_connection 2818v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select `t1`.`x` AS `x` from `t1` latin1 latin1_swedish_ci 2819ALTER VIEW v1 AS SELECT x, y FROM t1; 2820SHOW CREATE VIEW v1; 2821View Create View character_set_client collation_connection 2822v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select `t1`.`x` AS `x`,`t1`.`y` AS `y` from `t1` latin1 latin1_swedish_ci 2823DROP VIEW v1; 2824DROP TABLE t1; 2825CREATE TABLE t1 (s1 char); 2826INSERT INTO t1 VALUES ('Z'); 2827CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1; 2828CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1; 2829INSERT INTO v1 (col) VALUES ('b'); 2830INSERT INTO v2 (col) VALUES ('c'); 2831SELECT s1 FROM t1; 2832s1 2833Z 2834b 2835c 2836DROP VIEW v1, v2; 2837DROP TABLE t1; 2838CREATE TABLE t1 (id INT); 2839CREATE VIEW v1 AS SELECT id FROM t1; 2840SHOW TABLES; 2841Tables_in_test 2842t1 2843v1 2844DROP VIEW v2,v1; 2845ERROR 42S02: Unknown VIEW: 'test.v2' 2846SHOW TABLES; 2847Tables_in_test 2848t1 2849CREATE VIEW v1 AS SELECT id FROM t1; 2850DROP VIEW t1,v1; 2851ERROR 42S02: Unknown VIEW: 'test.t1' 2852show warnings; 2853Level Code Message 2854Warning 1347 'test.t1' is not of type 'VIEW' 2855Error 4092 Unknown VIEW: 'test.t1' 2856SHOW TABLES; 2857Tables_in_test 2858t1 2859DROP TABLE t1; 2860DROP VIEW IF EXISTS v1; 2861set GLOBAL sql_mode=""; 2862set LOCAL sql_mode=""; 2863CREATE DATABASE bug21261DB; 2864USE bug21261DB; 2865connect root,localhost,root,,bug21261DB; 2866connection root; 2867CREATE TABLE t1 (x INT); 2868CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1; 2869GRANT INSERT, UPDATE ON v1 TO 'user21261'@'localhost'; 2870GRANT INSERT, UPDATE ON t1 TO 'user21261'@'localhost'; 2871CREATE TABLE t2 (y INT); 2872GRANT SELECT ON t2 TO 'user21261'@'localhost'; 2873connect user21261, localhost, user21261,, bug21261DB; 2874connection user21261; 2875INSERT INTO v1 (x) VALUES (5); 2876UPDATE v1 SET x=1; 2877connection root; 2878GRANT SELECT ON v1 TO 'user21261'@'localhost'; 2879GRANT SELECT ON t1 TO 'user21261'@'localhost'; 2880connection user21261; 2881UPDATE v1,t2 SET x=1 WHERE x=y; 2882connection root; 2883SELECT * FROM t1; 2884x 28851 2886REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user21261'@'localhost'; 2887DROP USER 'user21261'@'localhost'; 2888DROP VIEW v1; 2889DROP TABLE t1; 2890DROP DATABASE bug21261DB; 2891connection default; 2892USE test; 2893disconnect root; 2894disconnect user21261; 2895set GLOBAL sql_mode=default; 2896set LOCAL sql_mode=default; 2897create table t1 (f1 datetime); 2898create view v1 as select * from t1 where f1 between now() and now() + interval 1 minute; 2899show create view v1; 2900View Create View character_set_client collation_connection 2901v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f1` AS `f1` from `t1` where `t1`.`f1` between current_timestamp() and current_timestamp() + interval 1 minute latin1 latin1_swedish_ci 2902drop view v1; 2903drop table t1; 2904DROP TABLE IF EXISTS t1; 2905DROP VIEW IF EXISTS v1; 2906DROP VIEW IF EXISTS v2; 2907CREATE TABLE t1(a INT, b INT); 2908CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost 2909VIEW v1 AS SELECT a FROM t1; 2910ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345...' is too long for user name (should be no longer than 80) 2911CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY 2912VIEW v2 AS SELECT b FROM t1; 2913ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) 2914DROP TABLE t1; 2915DROP FUNCTION IF EXISTS f1; 2916DROP FUNCTION IF EXISTS f2; 2917DROP VIEW IF EXISTS v1, v2; 2918DROP TABLE IF EXISTS t1; 2919CREATE TABLE t1 (i INT); 2920CREATE VIEW v1 AS SELECT * FROM t1; 2921CREATE FUNCTION f1() RETURNS INT 2922BEGIN 2923INSERT INTO v1 VALUES (0); 2924RETURN 0; 2925END | 2926SELECT f1(); 2927f1() 29280 2929CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1; 2930CREATE FUNCTION f2() RETURNS INT 2931BEGIN 2932INSERT INTO v2 VALUES (0); 2933RETURN 0; 2934END | 2935SELECT f2(); 2936ERROR HY000: The target table v2 of the INSERT is not insertable-into 2937DROP FUNCTION f1; 2938DROP FUNCTION f2; 2939DROP VIEW v1, v2; 2940DROP TABLE t1; 2941CREATE TABLE t1 (s1 int); 2942CREATE VIEW v1 AS SELECT * FROM t1; 2943EXPLAIN SELECT * FROM t1; 2944id select_type table type possible_keys key key_len ref rows Extra 29451 SIMPLE t1 system NULL NULL NULL NULL 0 Const row not found 2946EXPLAIN SELECT * FROM v1; 2947id select_type table type possible_keys key key_len ref rows Extra 29481 SIMPLE t1 system NULL NULL NULL NULL 0 Const row not found 2949INSERT INTO t1 VALUES (1), (3), (2); 2950EXPLAIN SELECT * FROM t1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1); 2951id select_type table type possible_keys key key_len ref rows Extra 29521 PRIMARY t ALL NULL NULL NULL NULL 3 Using where 29532 SUBQUERY t1 ALL NULL NULL NULL NULL 3 2954EXPLAIN SELECT * FROM v1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1); 2955id select_type table type possible_keys key key_len ref rows Extra 29561 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where 29572 SUBQUERY t1 ALL NULL NULL NULL NULL 3 2958DROP VIEW v1; 2959DROP TABLE t1; 2960create table t1 (s1 int); 2961create view v1 as select s1 as a, s1 as b from t1; 2962insert into v1 values (1,1); 2963ERROR HY000: The target table v1 of the INSERT is not insertable-into 2964update v1 set a = 5; 2965drop view v1; 2966drop table t1; 2967CREATE TABLE t1(pk int PRIMARY KEY); 2968CREATE TABLE t2(pk int PRIMARY KEY, fk int, ver int, org int); 2969CREATE ALGORITHM=MERGE VIEW v1 AS 2970SELECT t1.* 2971FROM t1 JOIN t2 2972ON t2.fk = t1.pk AND 2973t2.ver = (SELECT MAX(t.ver) FROM t2 t WHERE t.org = t2.org); 2974SHOW WARNINGS; 2975Level Code Message 2976SHOW CREATE VIEW v1; 2977View Create View character_set_client collation_connection 2978v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`pk` AS `pk` from (`t1` join `t2` on(`t2`.`fk` = `t1`.`pk` and `t2`.`ver` = (select max(`t`.`ver`) from `t2` `t` where `t`.`org` = `t2`.`org`))) latin1 latin1_swedish_ci 2979DROP VIEW v1; 2980DROP TABLE t1, t2; 2981DROP FUNCTION IF EXISTS f1; 2982DROP VIEW IF EXISTS v1; 2983DROP TABLE IF EXISTS t1; 2984CREATE TABLE t1 (i INT); 2985INSERT INTO t1 VALUES (1); 2986CREATE VIEW v1 AS SELECT MAX(i) FROM t1; 2987CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW 2988SET NEW.i = (SELECT * FROM v1) + 1; 2989INSERT INTO t1 VALUES (1); 2990CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1); 2991UPDATE t1 SET i= f1(); 2992DROP FUNCTION f1; 2993DROP VIEW v1; 2994DROP TABLE t1; 2995CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL); 2996CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION; 2997INSERT INTO v1 (val) VALUES (2); 2998INSERT INTO v1 (val) VALUES (4); 2999INSERT INTO v1 (val) VALUES (6); 3000ERROR 44000: CHECK OPTION failed `test`.`v1` 3001UPDATE v1 SET val=6 WHERE id=2; 3002ERROR 44000: CHECK OPTION failed `test`.`v1` 3003DROP VIEW v1; 3004DROP TABLE t1; 3005DROP VIEW IF EXISTS v1, v2; 3006DROP TABLE IF EXISTS t1; 3007CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT); 3008CREATE VIEW v1 AS SELECT j FROM t1; 3009CREATE VIEW v2 AS SELECT * FROM t1; 3010INSERT INTO t1 (j) VALUES (1); 3011SELECT LAST_INSERT_ID(); 3012LAST_INSERT_ID() 30131 3014INSERT INTO v1 (j) VALUES (2); 3015# LAST_INSERT_ID() should not change. 3016SELECT LAST_INSERT_ID(); 3017LAST_INSERT_ID() 30181 3019INSERT INTO v2 (j) VALUES (3); 3020# LAST_INSERT_ID() should be updated. 3021SELECT LAST_INSERT_ID(); 3022LAST_INSERT_ID() 30233 3024INSERT INTO v1 (j) SELECT j FROM t1; 3025# LAST_INSERT_ID() should not change. 3026SELECT LAST_INSERT_ID(); 3027LAST_INSERT_ID() 30283 3029SELECT * FROM t1; 3030i j 30311 1 30322 2 30333 3 30344 1 30355 2 30366 3 3037DROP VIEW v1, v2; 3038DROP TABLE t1; 3039CREATE VIEW v AS SELECT !0 * 5 AS x FROM DUAL; 3040SHOW CREATE VIEW v; 3041View Create View character_set_client collation_connection 3042v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select !0 * 5 AS `x` latin1 latin1_swedish_ci 3043SELECT !0 * 5 AS x FROM DUAL; 3044x 30455 3046SELECT * FROM v; 3047x 30485 3049DROP VIEW v; 3050DROP VIEW IF EXISTS v1; 3051CREATE VIEW v1 AS SELECT 'The\ZEnd'; 3052SELECT * FROM v1; 3053TheEnd 3054TheEnd 3055SHOW CREATE VIEW v1; 3056View Create View character_set_client collation_connection 3057v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 'The\ZEnd' AS `TheEnd` latin1 latin1_swedish_ci 3058DROP VIEW v1; 3059CREATE TABLE t1 (mydate DATETIME); 3060INSERT INTO t1 VALUES 3061('2007-01-01'), ('2007-01-02'), ('2007-01-30'), ('2007-01-31'); 3062CREATE VIEW v1 AS SELECT mydate from t1; 3063SELECT * FROM t1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31'; 3064mydate 30652007-01-01 00:00:00 30662007-01-02 00:00:00 30672007-01-30 00:00:00 30682007-01-31 00:00:00 3069SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31'; 3070mydate 30712007-01-01 00:00:00 30722007-01-02 00:00:00 30732007-01-30 00:00:00 30742007-01-31 00:00:00 3075DROP VIEW v1; 3076DROP TABLE t1; 3077CREATE TABLE t1 (a int); 3078CREATE TABLE t2 (b int); 3079INSERT INTO t1 VALUES (1), (2); 3080INSERT INTO t2 VALUES (1), (2); 3081CREATE VIEW v1 AS 3082SELECT t2.b FROM t1,t2 WHERE t1.a = t2.b WITH CHECK OPTION; 3083SELECT * FROM v1; 3084b 30851 30862 3087UPDATE v1 SET b=3; 3088ERROR 44000: CHECK OPTION failed `test`.`v1` 3089SELECT * FROM v1; 3090b 30911 30922 3093SELECT * FROM t1; 3094a 30951 30962 3097SELECT * FROM t2; 3098b 30991 31002 3101DROP VIEW v1; 3102DROP TABLE t1,t2; 3103create table t1(f1 int, f2 int); 3104insert into t1 values(1,2),(1,3),(1,1),(2,3),(2,1),(2,2); 3105select * from t1; 3106f1 f2 31071 2 31081 3 31091 1 31102 3 31112 1 31122 2 3113create view v1 as select * from t1 order by f2; 3114select * from v1; 3115f1 f2 31161 1 31172 1 31181 2 31192 2 31201 3 31212 3 3122explain extended select * from v1; 3123id select_type table type possible_keys key key_len ref rows filtered Extra 31241 SIMPLE t1 ALL NULL NULL NULL NULL 6 100.00 Using filesort 3125Warnings: 3126Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f2` 3127select * from v1 order by f1; 3128f1 f2 31291 2 31301 3 31311 1 31322 3 31332 1 31342 2 3135explain extended select * from v1 order by f1; 3136id select_type table type possible_keys key key_len ref rows filtered Extra 31371 SIMPLE t1 ALL NULL NULL NULL NULL 6 100.00 Using filesort 3138Warnings: 3139Note 1926 View 'test'.'v1' ORDER BY clause ignored because there is other ORDER BY clause already 3140Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f1` 3141drop view v1; 3142drop table t1; 3143CREATE TABLE t1 ( 3144id int(11) NOT NULL PRIMARY KEY, 3145country varchar(32), 3146code int(11) default NULL 3147); 3148INSERT INTO t1 VALUES 3149(1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); 3150CREATE VIEW v1 AS SELECT * FROM t1; 3151SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id); 3152code COUNT(DISTINCT country) 3153200 1 3154100 2 3155SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id); 3156code COUNT(DISTINCT country) 3157200 1 3158100 2 3159DROP VIEW v1; 3160DROP TABLE t1; 3161DROP VIEW IF EXISTS v1; 3162SELECT * FROM (SELECT 1) AS t into @w; 3163Warnings: 3164Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 3165CREATE VIEW v1 AS SELECT * FROM (SELECT 1) AS t into @w; 3166ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into @w' at line 1 3167# Previously the following would fail. 3168SELECT * FROM (SELECT 1) AS t into @w; 3169Warnings: 3170Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 3171drop view if exists view_24532_a; 3172drop view if exists view_24532_b; 3173drop table if exists table_24532; 3174create table table_24532 ( 3175a int, 3176b bigint, 3177c int(4), 3178d bigint(48) 3179); 3180create view view_24532_a as 3181select 3182a IS TRUE, 3183a IS NOT TRUE, 3184a IS FALSE, 3185a IS NOT FALSE, 3186a IS UNKNOWN, 3187a IS NOT UNKNOWN, 3188a is NULL, 3189a IS NOT NULL, 3190ISNULL(a), 3191b IS TRUE, 3192b IS NOT TRUE, 3193b IS FALSE, 3194b IS NOT FALSE, 3195b IS UNKNOWN, 3196b IS NOT UNKNOWN, 3197b is NULL, 3198b IS NOT NULL, 3199ISNULL(b), 3200c IS TRUE, 3201c IS NOT TRUE, 3202c IS FALSE, 3203c IS NOT FALSE, 3204c IS UNKNOWN, 3205c IS NOT UNKNOWN, 3206c is NULL, 3207c IS NOT NULL, 3208ISNULL(c), 3209d IS TRUE, 3210d IS NOT TRUE, 3211d IS FALSE, 3212d IS NOT FALSE, 3213d IS UNKNOWN, 3214d IS NOT UNKNOWN, 3215d is NULL, 3216d IS NOT NULL, 3217ISNULL(d) 3218from table_24532; 3219describe view_24532_a; 3220Field Type Null Key Default Extra 3221a IS TRUE int(1) NO 0 3222a IS NOT TRUE int(1) NO 0 3223a IS FALSE int(1) NO 0 3224a IS NOT FALSE int(1) NO 0 3225a IS UNKNOWN int(1) NO 0 3226a IS NOT UNKNOWN int(1) NO 0 3227a is NULL int(1) NO 0 3228a IS NOT NULL int(1) NO 0 3229ISNULL(a) int(1) NO 0 3230b IS TRUE int(1) NO 0 3231b IS NOT TRUE int(1) NO 0 3232b IS FALSE int(1) NO 0 3233b IS NOT FALSE int(1) NO 0 3234b IS UNKNOWN int(1) NO 0 3235b IS NOT UNKNOWN int(1) NO 0 3236b is NULL int(1) NO 0 3237b IS NOT NULL int(1) NO 0 3238ISNULL(b) int(1) NO 0 3239c IS TRUE int(1) NO 0 3240c IS NOT TRUE int(1) NO 0 3241c IS FALSE int(1) NO 0 3242c IS NOT FALSE int(1) NO 0 3243c IS UNKNOWN int(1) NO 0 3244c IS NOT UNKNOWN int(1) NO 0 3245c is NULL int(1) NO 0 3246c IS NOT NULL int(1) NO 0 3247ISNULL(c) int(1) NO 0 3248d IS TRUE int(1) NO 0 3249d IS NOT TRUE int(1) NO 0 3250d IS FALSE int(1) NO 0 3251d IS NOT FALSE int(1) NO 0 3252d IS UNKNOWN int(1) NO 0 3253d IS NOT UNKNOWN int(1) NO 0 3254d is NULL int(1) NO 0 3255d IS NOT NULL int(1) NO 0 3256ISNULL(d) int(1) NO 0 3257create view view_24532_b as 3258select 3259a IS TRUE, 3260if(ifnull(a, 0), 1, 0) as old_istrue, 3261a IS NOT TRUE, 3262if(ifnull(a, 0), 0, 1) as old_isnottrue, 3263a IS FALSE, 3264if(ifnull(a, 1), 0, 1) as old_isfalse, 3265a IS NOT FALSE, 3266if(ifnull(a, 1), 1, 0) as old_isnotfalse 3267from table_24532; 3268describe view_24532_b; 3269Field Type Null Key Default Extra 3270a IS TRUE int(1) NO 0 3271old_istrue int(1) NO 0 3272a IS NOT TRUE int(1) NO 0 3273old_isnottrue int(1) NO 0 3274a IS FALSE int(1) NO 0 3275old_isfalse int(1) NO 0 3276a IS NOT FALSE int(1) NO 0 3277old_isnotfalse int(1) NO 0 3278show create view view_24532_b; 3279View Create View character_set_client collation_connection 3280view_24532_b CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_24532_b` AS select `table_24532`.`a` is true AS `a IS TRUE`,if(ifnull(`table_24532`.`a`,0),1,0) AS `old_istrue`,`table_24532`.`a` is not true AS `a IS NOT TRUE`,if(ifnull(`table_24532`.`a`,0),0,1) AS `old_isnottrue`,`table_24532`.`a` is false AS `a IS FALSE`,if(ifnull(`table_24532`.`a`,1),0,1) AS `old_isfalse`,`table_24532`.`a` is not false AS `a IS NOT FALSE`,if(ifnull(`table_24532`.`a`,1),1,0) AS `old_isnotfalse` from `table_24532` latin1 latin1_swedish_ci 3281insert into table_24532 values (0, 0, 0, 0); 3282select * from view_24532_b; 3283a IS TRUE old_istrue a IS NOT TRUE old_isnottrue a IS FALSE old_isfalse a IS NOT FALSE old_isnotfalse 32840 0 1 1 1 1 0 0 3285update table_24532 set a=1; 3286select * from view_24532_b; 3287a IS TRUE old_istrue a IS NOT TRUE old_isnottrue a IS FALSE old_isfalse a IS NOT FALSE old_isnotfalse 32881 1 0 0 0 0 1 1 3289update table_24532 set a=NULL; 3290select * from view_24532_b; 3291a IS TRUE old_istrue a IS NOT TRUE old_isnottrue a IS FALSE old_isfalse a IS NOT FALSE old_isnotfalse 32920 0 1 1 0 0 1 1 3293drop view view_24532_a; 3294drop view view_24532_b; 3295drop table table_24532; 3296CREATE TABLE t1 ( 3297lid int NOT NULL PRIMARY KEY, 3298name char(10) NOT NULL 3299); 3300INSERT INTO t1 (lid, name) VALUES 3301(1, 'YES'), (2, 'NO'); 3302CREATE TABLE t2 ( 3303id int NOT NULL PRIMARY KEY, 3304gid int NOT NULL, 3305lid int NOT NULL, 3306dt date 3307); 3308INSERT INTO t2 (id, gid, lid, dt) VALUES 3309(1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'), 3310(3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02'); 3311SELECT DISTINCT t2.gid AS lgid, 3312(SELECT t1.name FROM t1, t2 3313WHERE t1.lid = t2.lid AND t2.gid = lgid 3314ORDER BY t2.dt DESC LIMIT 1 3315) as clid 3316FROM t2; 3317lgid clid 33181 NO 33192 YES 3320CREATE VIEW v1 AS 3321SELECT DISTINCT t2.gid AS lgid, 3322(SELECT t1.name FROM t1, t2 3323WHERE t1.lid = t2.lid AND t2.gid = lgid 3324ORDER BY t2.dt DESC LIMIT 1 3325) as clid 3326FROM t2; 3327SELECT * FROM v1; 3328lgid clid 33291 NO 33302 YES 3331DROP VIEW v1; 3332DROP table t1,t2; 3333CREATE TABLE t1 (a INT); 3334INSERT INTO t1 VALUES (1),(2),(3); 3335CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a; 3336SELECT * FROM t1 UNION SELECT * FROM v1; 3337a 33381 33392 33403 3341EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1; 3342id select_type table type possible_keys key key_len ref rows Extra 33431 PRIMARY t1 ALL NULL NULL NULL NULL 3 33442 UNION t1 ALL NULL NULL NULL NULL 3 3345NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 3346SELECT * FROM v1 UNION SELECT * FROM t1; 3347a 33481 33492 33503 3351EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1; 3352id select_type table type possible_keys key key_len ref rows Extra 33531 PRIMARY t1 ALL NULL NULL NULL NULL 3 33542 UNION t1 ALL NULL NULL NULL NULL 3 3355NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 3356SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; 3357a 33581 33592 33603 3361EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; 3362id select_type table type possible_keys key key_len ref rows Extra 33631 PRIMARY t1 ALL NULL NULL NULL NULL 3 33642 UNION t1 ALL NULL NULL NULL NULL 3 3365NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL Using filesort 3366DROP VIEW v1; 3367DROP TABLE t1; 3368CREATE VIEW v1 AS SELECT CAST( 1.23456789 AS DECIMAL( 7,5 ) ) AS col; 3369SELECT * FROM v1; 3370col 33711.23457 3372DESCRIBE v1; 3373Field Type Null Key Default Extra 3374col decimal(7,5) NO 0.00000 3375DROP VIEW v1; 3376CREATE VIEW v1 AS SELECT CAST(1.23456789 AS DECIMAL(8,0)) AS col; 3377SHOW CREATE VIEW v1; 3378View Create View character_set_client collation_connection 3379v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select cast(1.23456789 as decimal(8,0)) AS `col` latin1 latin1_swedish_ci 3380DROP VIEW v1; 3381CREATE TABLE t1 (a INT); 3382CREATE TABLE t2 (b INT, c INT DEFAULT 0); 3383INSERT INTO t1 (a) VALUES (1), (2); 3384INSERT INTO t2 (b) VALUES (1), (2); 3385CREATE VIEW v1 AS SELECT t2.b,t2.c FROM t1, t2 3386WHERE t1.a=t2.b AND t2.b < 3 WITH CHECK OPTION; 3387SELECT * FROM v1; 3388b c 33891 0 33902 0 3391UPDATE v1 SET c=1 WHERE b=1; 3392SELECT * FROM v1; 3393b c 33941 1 33952 0 3396DROP VIEW v1; 3397DROP TABLE t1,t2; 3398CREATE TABLE t1 (id int); 3399CREATE TABLE t2 (id int, c int DEFAULT 0); 3400INSERT INTO t1 (id) VALUES (1); 3401INSERT INTO t2 (id) VALUES (1); 3402CREATE VIEW v1 AS 3403SELECT t2.c FROM t1, t2 3404WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; 3405UPDATE v1 SET c=1; 3406DROP VIEW v1; 3407DROP TABLE t1,t2; 3408CREATE TABLE t1 (a1 INT, c INT DEFAULT 0); 3409CREATE TABLE t2 (a2 INT); 3410CREATE TABLE t3 (a3 INT); 3411CREATE TABLE t4 (a4 INT); 3412INSERT INTO t1 (a1) VALUES (1),(2); 3413INSERT INTO t2 (a2) VALUES (1),(2); 3414INSERT INTO t3 (a3) VALUES (1),(2); 3415INSERT INTO t4 (a4) VALUES (1),(2); 3416CREATE VIEW v1 AS 3417SELECT t1.a1, t1.c FROM t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3 3418WITH CHECK OPTION; 3419SELECT * FROM v1; 3420a1 c 34211 0 34222 0 3423UPDATE v1 SET c=3; 3424ERROR 44000: CHECK OPTION failed `test`.`v1` 3425PREPARE t FROM 'UPDATE v1 SET c=3'; 3426EXECUTE t; 3427ERROR 44000: CHECK OPTION failed `test`.`v1` 3428EXECUTE t; 3429ERROR 44000: CHECK OPTION failed `test`.`v1` 3430INSERT INTO v1(a1, c) VALUES (3, 3); 3431ERROR 44000: CHECK OPTION failed `test`.`v1` 3432UPDATE v1 SET c=1 WHERE a1=1; 3433SELECT * FROM v1; 3434a1 c 34351 1 34362 0 3437SELECT * FROM t1; 3438a1 c 34391 1 34402 0 3441CREATE VIEW v2 AS SELECT t1.a1, t1.c 3442FROM (t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3) 3443JOIN (t3 JOIN t4 ON t3.a3=t4.a4) 3444ON t2.a2=t3.a3 WITH CHECK OPTION; 3445SELECT * FROM v2; 3446a1 c 34471 1 34482 0 3449UPDATE v2 SET c=3; 3450ERROR 44000: CHECK OPTION failed `test`.`v2` 3451PREPARE t FROM 'UPDATE v2 SET c=3'; 3452EXECUTE t; 3453ERROR 44000: CHECK OPTION failed `test`.`v2` 3454EXECUTE t; 3455ERROR 44000: CHECK OPTION failed `test`.`v2` 3456INSERT INTO v2(a1, c) VALUES (3, 3); 3457ERROR 44000: CHECK OPTION failed `test`.`v2` 3458UPDATE v2 SET c=2 WHERE a1=1; 3459SELECT * FROM v2; 3460a1 c 34611 2 34622 0 3463SELECT * FROM t1; 3464a1 c 34651 2 34662 0 3467DROP VIEW v1,v2; 3468DROP TABLE t1,t2,t3,t4; 3469CREATE TABLE t1 (a int, b int); 3470INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2); 3471CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1; 3472SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; 3473b SUM(a) 34743 4 3475EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; 3476id select_type table type possible_keys key key_len ref rows Extra 34771 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where 3478SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; 3479a SUM(b) 34801 6 34812 3 3482EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; 3483id select_type table type possible_keys key key_len ref rows Extra 34841 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where; Using temporary; Using filesort 3485SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; 3486a SUM(b) 34871 10 3488EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; 3489id select_type table type possible_keys key key_len ref rows Extra 34901 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where 3491DROP VIEW v1; 3492DROP TABLE t1; 3493CREATE TABLE t1 ( 3494person_id int NOT NULL PRIMARY KEY, 3495username varchar(40) default NULL, 3496status_flg char(1) NOT NULL default 'A' 3497); 3498CREATE TABLE t2 ( 3499person_role_id int NOT NULL auto_increment PRIMARY KEY, 3500role_id int NOT NULL, 3501person_id int NOT NULL, 3502INDEX idx_person_id (person_id), 3503INDEX idx_role_id (role_id) 3504); 3505CREATE TABLE t3 ( 3506role_id int NOT NULL auto_increment PRIMARY KEY, 3507role_name varchar(100) default NULL, 3508app_name varchar(40) NOT NULL, 3509INDEX idx_app_name(app_name) 3510); 3511CREATE VIEW v1 AS 3512SELECT profile.person_id AS person_id 3513FROM t1 profile, t2 userrole, t3 role 3514WHERE userrole.person_id = profile.person_id AND 3515role.role_id = userrole.role_id AND 3516profile.status_flg = 'A' 3517 ORDER BY profile.person_id,role.app_name,role.role_name; 3518INSERT INTO t1 VALUES 3519(6,'Sw','A'), (-1136332546,'ols','e'), (0,' *\n','0'), 3520(-717462680,'ENTS Ta','0'), (-904346964,'ndard SQL\n','0'); 3521INSERT INTO t2 VALUES 3522(1,3,6),(2,4,7),(3,5,8),(4,6,9),(5,1,6),(6,1,7),(7,1,8),(8,1,9),(9,1,10); 3523INSERT INTO t3 VALUES 3524(1,'NUCANS_APP_USER','NUCANSAPP'),(2,'NUCANS_TRGAPP_USER','NUCANSAPP'), 3525(3,'IA_INTAKE_COORDINATOR','IACANS'),(4,'IA_SCREENER','IACANS'), 3526(5,'IA_SUPERVISOR','IACANS'),(6,'IA_READONLY','IACANS'), 3527(7,'SOC_USER','SOCCANS'),(8,'CAYIT_USER','CAYITCANS'), 3528(9,'RTOS_DCFSPOS_SUPERVISOR','RTOS'); 3529EXPLAIN SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6; 3530id select_type table type possible_keys key key_len ref rows Extra 35311 SIMPLE profile const PRIMARY PRIMARY 4 const 1 Using temporary; Using filesort 35321 SIMPLE userrole ref idx_person_id,idx_role_id idx_person_id 4 const 2 35331 SIMPLE role eq_ref PRIMARY PRIMARY 4 test.userrole.role_id 1 3534SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6; 3535a b 35366 6 35376 6 3538DROP VIEW v1; 3539DROP TABLE t1,t2,t3; 3540create table t1 (i int); 3541insert into t1 values (1), (2), (1), (3), (2), (4); 3542create view v1 as select distinct i from t1; 3543select * from v1; 3544i 35451 35462 35473 35484 3549select table_name, is_updatable from information_schema.views 3550where table_name = 'v1'; 3551table_name is_updatable 3552v1 NO 3553drop view v1; 3554drop table t1; 3555CREATE TABLE t1 (a INT); 3556INSERT INTO t1 VALUES (1),(2); 3557CREATE VIEW v1 AS SELECT * FROM t1; 3558SELECT * FROM v1 USE KEY(non_existant); 3559ERROR 42000: Key 'non_existant' doesn't exist in table 'v1' 3560SELECT * FROM v1 FORCE KEY(non_existant); 3561ERROR 42000: Key 'non_existant' doesn't exist in table 'v1' 3562SELECT * FROM v1 IGNORE KEY(non_existant); 3563ERROR 42000: Key 'non_existant' doesn't exist in table 'v1' 3564DROP VIEW v1; 3565DROP TABLE t1; 3566CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL DEFAULT 0, 3567PRIMARY KEY(a), KEY (b)); 3568INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(); 3569CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a; 3570SHOW CREATE VIEW v1; 3571View Create View character_set_client collation_connection 3572v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` FORCE INDEX (PRIMARY) FORCE INDEX (`b`) order by `t1`.`a` latin1 latin1_swedish_ci 3573EXPLAIN SELECT * FROM v1; 3574id select_type table type possible_keys key key_len ref rows Extra 35751 SIMPLE t1 index NULL PRIMARY 4 NULL 15 3576CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a; 3577SHOW CREATE VIEW v2; 3578View Create View character_set_client collation_connection 3579v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` USE INDEX () order by `t1`.`a` latin1 latin1_swedish_ci 3580EXPLAIN SELECT * FROM v2; 3581id select_type table type possible_keys key key_len ref rows Extra 35821 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort 3583CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a; 3584SHOW CREATE VIEW v3; 3585View Create View character_set_client collation_connection 3586v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` IGNORE INDEX (`b`) order by `t1`.`a` latin1 latin1_swedish_ci 3587EXPLAIN SELECT * FROM v3; 3588id select_type table type possible_keys key key_len ref rows Extra 35891 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort 3590DROP VIEW v1; 3591DROP VIEW v2; 3592DROP VIEW v3; 3593DROP TABLE t1; 3594# 3595# Bug#29477 Not all fields of the target table were checked to have 3596# a default value when inserting into a view. 3597# 3598create table t1(f1 int, f2 int not null); 3599create view v1 as select f1 from t1; 3600insert ignore into v1 values(1); 3601Warnings: 3602Warning 1423 Field of view 'test.v1' underlying table doesn't have a default value 3603set @old_mode=@@sql_mode; 3604set @@sql_mode=traditional; 3605insert into v1 values(1); 3606ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value 3607set @@sql_mode=@old_mode; 3608drop view v1; 3609drop table t1; 3610create table t1 (a int, key(a)); 3611create table t2 (c int); 3612create view v1 as select a b from t1; 3613create view v2 as select 1 a from t2, v1 where c in 3614(select 1 from t1 where b = a); 3615insert into t1 values (1), (1); 3616insert into t2 values (1), (1); 3617prepare stmt from "select * from v2 where a = 1"; 3618execute stmt; 3619a 36201 36211 36221 36231 3624drop view v1, v2; 3625drop table t1, t2; 3626CREATE TABLE t1 (a INT); 3627CREATE VIEW v1 AS SELECT p.a AS a FROM t1 p, t1 q; 3628INSERT INTO t1 VALUES (1), (1); 3629SELECT MAX(a), COUNT(DISTINCT a) FROM v1 GROUP BY a; 3630MAX(a) COUNT(DISTINCT a) 36311 1 3632DROP VIEW v1; 3633DROP TABLE t1; 3634# ----------------------------------------------------------------- 3635# -- Bug#34337 Server crash when Altering a view using a table name. 3636# ----------------------------------------------------------------- 3637 3638DROP TABLE IF EXISTS t1; 3639 3640CREATE TABLE t1(c1 INT); 3641 3642SELECT * FROM t1; 3643c1 3644ALTER ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW t1 (c2) AS SELECT (1); 3645ERROR HY000: 'test.t1' is not of type 'VIEW' 3646 3647DROP TABLE t1; 3648 3649# -- End of test case for Bug#34337. 3650 3651# ----------------------------------------------------------------- 3652# -- Bug#35193 VIEW query is rewritten without "FROM DUAL", 3653# -- causing syntax error 3654# ----------------------------------------------------------------- 3655 3656CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE 1; 3657 3658SELECT * FROM v1; 36591 36601 3661SHOW CREATE TABLE v1; 3662View Create View character_set_client collation_connection 3663v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1` from DUAL where 1 latin1 latin1_swedish_ci 3664 3665DROP VIEW v1; 3666 3667# -- End of test case for Bug#35193. 3668 3669CREATE VIEW v1 AS SELECT 1; 3670DROP VIEW v1; 3671CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, INDEX (c2)); 3672INSERT INTO t1 VALUES (1,1), (2,2), (3,3); 3673SELECT * FROM t1 USE INDEX (PRIMARY) WHERE c1=2; 3674c1 c2 36752 2 3676SELECT * FROM t1 USE INDEX (c2) WHERE c2=2; 3677c1 c2 36782 2 3679CREATE VIEW v1 AS SELECT c1, c2 FROM t1; 3680SHOW INDEX FROM v1; 3681Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 3682SELECT * FROM v1 USE INDEX (PRIMARY) WHERE c1=2; 3683ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1' 3684SELECT * FROM v1 FORCE INDEX (PRIMARY) WHERE c1=2; 3685ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1' 3686SELECT * FROM v1 IGNORE INDEX (PRIMARY) WHERE c1=2; 3687ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1' 3688SELECT * FROM v1 USE INDEX (c2) WHERE c2=2; 3689ERROR 42000: Key 'c2' doesn't exist in table 'v1' 3690SELECT * FROM v1 FORCE INDEX (c2) WHERE c2=2; 3691ERROR 42000: Key 'c2' doesn't exist in table 'v1' 3692SELECT * FROM v1 IGNORE INDEX (c2) WHERE c2=2; 3693ERROR 42000: Key 'c2' doesn't exist in table 'v1' 3694DROP VIEW v1; 3695DROP TABLE t1; 3696# 3697# Bug #45806 crash when replacing into a view with a join! 3698# 3699CREATE TABLE t1(a INT UNIQUE); 3700CREATE VIEW v1 AS SELECT t1.a FROM t1, t1 AS a; 3701INSERT INTO t1 VALUES (1), (2); 3702REPLACE INTO v1(a) SELECT 1 FROM t1,t1 AS c; 3703SELECT * FROM v1; 3704a 37051 37062 37071 37082 3709REPLACE INTO v1(a) SELECT 3 FROM t1,t1 AS c; 3710SELECT * FROM v1; 3711a 37121 37132 37143 37151 37162 37173 37181 37192 37203 3721DELETE FROM t1 WHERE a=3; 3722INSERT INTO v1(a) SELECT 1 FROM t1,t1 AS c 3723ON DUPLICATE KEY UPDATE `v1`.`a`= 1; 3724SELECT * FROM v1; 3725a 37261 37272 37281 37292 3730CREATE VIEW v2 AS SELECT t1.a FROM t1, v1 AS a; 3731REPLACE INTO v2(a) SELECT 1 FROM t1,t1 AS c; 3732SELECT * FROM v2 order by 1; 3733a 37341 37351 37361 37371 37382 37392 37402 37412 3742REPLACE INTO v2(a) SELECT 3 FROM t1,t1 AS c; 3743SELECT * FROM v2 order by 1; 3744a 37451 37461 37471 37481 37491 37501 37511 37521 37531 37542 37552 37562 37572 37582 37592 37602 37612 37622 37633 37643 37653 37663 37673 37683 37693 37703 37713 3772INSERT INTO v2(a) SELECT 1 FROM t1,t1 AS c 3773ON DUPLICATE KEY UPDATE `v2`.`a`= 1; 3774SELECT * FROM v2 order by 1; 3775a 37761 37771 37781 37791 37801 37811 37821 37831 37841 37852 37862 37872 37882 37892 37902 37912 37922 37932 37943 37953 37963 37973 37983 37993 38003 38013 38023 3803DROP VIEW v1; 3804DROP VIEW v2; 3805DROP TABLE t1; 3806# -- End of test case for Bug#45806 3807# ----------------------------------------------------------------- 3808# -- Bug#40825: Error 1356 while selecting from a view 3809# -- with a "HAVING" clause though query works 3810# ----------------------------------------------------------------- 3811 3812CREATE TABLE t1 (c INT); 3813 3814CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias; 3815SHOW CREATE VIEW v1; 3816View Create View character_set_client collation_connection 3817v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`c` AS `view_column` from `t1` having `view_column` <> 0 latin1 latin1_swedish_ci 3818SELECT * FROM v1; 3819view_column 3820 3821DROP VIEW v1; 3822DROP TABLE t1; 3823 3824# -- End of test case for Bug#40825 3825 3826# ----------------------------------------------------------------- 3827# -- End of 5.0 tests. 3828# ----------------------------------------------------------------- 3829DROP DATABASE IF EXISTS `d-1`; 3830CREATE DATABASE `d-1`; 3831USE `d-1`; 3832CREATE TABLE `t-1` (c1 INT); 3833CREATE VIEW `v-1` AS SELECT c1 FROM `t-1`; 3834SHOW TABLES; 3835Tables_in_d-1 3836t-1 3837v-1 3838RENAME TABLE `t-1` TO `t-2`; 3839RENAME TABLE `v-1` TO `v-2`; 3840SHOW TABLES; 3841Tables_in_d-1 3842t-2 3843v-2 3844DROP TABLE `t-2`; 3845DROP VIEW `v-2`; 3846DROP DATABASE `d-1`; 3847USE test; 3848 3849# 3850# Bug#26676 VIEW using old table schema in a session. 3851# 3852 3853DROP VIEW IF EXISTS v1; 3854DROP TABLE IF EXISTS t1; 3855CREATE TABLE t1(c1 INT, c2 INT); 3856INSERT INTO t1 VALUES (1, 2), (3, 4); 3857 3858SELECT * FROM t1; 3859c1 c2 38601 2 38613 4 3862 3863CREATE VIEW v1 AS SELECT * FROM t1; 3864 3865SELECT * FROM v1; 3866c1 c2 38671 2 38683 4 3869 3870ALTER TABLE t1 ADD COLUMN c3 INT AFTER c2; 3871 3872SELECT * FROM t1; 3873c1 c2 c3 38741 2 NULL 38753 4 NULL 3876 3877SELECT * FROM v1; 3878c1 c2 38791 2 38803 4 3881 3882SHOW CREATE VIEW v1; 3883View Create View character_set_client collation_connection 3884v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`c1` AS `c1`,`t1`.`c2` AS `c2` from `t1` latin1 latin1_swedish_ci 3885 3886DROP VIEW v1; 3887DROP TABLE t1; 3888 3889# End of test case for Bug#26676. 3890 3891# ----------------------------------------------------------------- 3892# -- Bug#32538 View definition picks up character set, but not collation 3893# ----------------------------------------------------------------- 3894 3895DROP VIEW IF EXISTS v1; 3896 3897SET collation_connection = latin1_general_ci; 3898CREATE VIEW v1 AS SELECT _latin1 'text1' AS c1, 'text2' AS c2; 3899 3900SELECT COLLATION(c1), COLLATION(c2) FROM v1; 3901COLLATION(c1) COLLATION(c2) 3902latin1_swedish_ci latin1_general_ci 3903 3904SHOW CREATE VIEW v1; 3905View Create View character_set_client collation_connection 3906v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select _latin1'text1' AS `c1`,'text2' AS `c2` latin1 latin1_general_ci 3907 3908SELECT * FROM v1 WHERE c1 = 'text1'; 3909ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin1_general_ci,COERCIBLE) for operation '=' 3910 3911SELECT * FROM v1 WHERE c2 = 'text2'; 3912c1 c2 3913text1 text2 3914 3915use test; 3916SET names latin1; 3917 3918SELECT COLLATION(c1), COLLATION(c2) FROM v1; 3919COLLATION(c1) COLLATION(c2) 3920latin1_swedish_ci latin1_general_ci 3921 3922SELECT * FROM v1 WHERE c1 = 'text1'; 3923c1 c2 3924text1 text2 3925 3926SELECT * FROM v1 WHERE c2 = 'text2'; 3927ERROR HY000: Illegal mix of collations (latin1_general_ci,COERCIBLE) and (latin1_swedish_ci,COERCIBLE) for operation '=' 3928 3929DROP VIEW v1; 3930 3931# -- End of test case for Bug#32538. 3932 3933drop view if exists a; 3934drop procedure if exists p; 3935create procedure p() 3936begin 3937declare continue handler for sqlexception begin end; 3938create view a as select 1; 3939end| 3940call p(); 3941call p(); 3942drop view a; 3943drop procedure p; 3944# 3945# Bug #44860: ALTER TABLE on view crashes server 3946# 3947CREATE TABLE t1 (a INT); 3948CREATE VIEW v1 AS SELECT a FROM t1; 3949ALTER TABLE v1; 3950ERROR HY000: 'test.v1' is not of type 'BASE TABLE' 3951DROP VIEW v1; 3952DROP TABLE t1; 3953# 3954# Bug#48449: hang on show create view after upgrading when 3955# view contains function of view 3956# 3957DROP VIEW IF EXISTS v1,v2; 3958DROP TABLE IF EXISTS t1,t2; 3959DROP FUNCTION IF EXISTS f1; 3960CREATE TABLE t1 (a INT); 3961CREATE TABLE t2 (a INT); 3962CREATE FUNCTION f1() RETURNS INT 3963BEGIN 3964SELECT a FROM v2 INTO @a; 3965RETURN @a; 3966END// 3967Warnings: 3968Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 3969# Trigger pre-locking when opening v2. 3970CREATE VIEW v1 AS SELECT f1() FROM t1; 3971SHOW CREATE VIEW v1; 3972View Create View character_set_client collation_connection 3973v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `f1`() AS `f1()` from `t1` latin1 latin1_swedish_ci 3974Warnings: 3975Note 1599 View `test`.`v2` has no creation context 3976DROP VIEW v1,v2; 3977DROP TABLE t1,t2; 3978DROP FUNCTION f1; 3979CREATE TABLE t1(f1 INT); 3980INSERT INTO t1 VALUES (); 3981CREATE VIEW v1 AS SELECT 1 FROM t1 WHERE 3982ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE f1 >= ANY ( SELECT '1' ))); 3983DROP VIEW v1; 3984DROP TABLE t1; 3985# 3986# Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817 3987# 3988CREATE TABLE t1 (a CHAR(1) CHARSET latin1, b CHAR(1) CHARSET utf8); 3989CREATE VIEW v1 AS SELECT 1 from t1 3990WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1')); 3991DROP VIEW v1; 3992DROP TABLE t1; 3993# 3994# Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846 3995# 3996CREATE TABLE t1(a int); 3997CREATE VIEW v1 AS SELECT 1 FROM t1 GROUP BY 3998SUBSTRING(1 FROM (SELECT 3 FROM t1 WHERE a >= ANY(SELECT 1))); 3999DROP VIEW v1; 4000DROP TABLE t1; 4001# 4002# Bug#57352 valgrind warnings when creating view 4003# 4004CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f; 4005DROP VIEW v1; 4006# 4007# Bug 11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY 4008# 4009CREATE TABLE t1 (a INT); 4010CREATE VIEW v1 AS SELECT s.* FROM t1 s, t1 b HAVING a; 4011SELECT * FROM v1; 4012a 4013DROP VIEW v1; 4014DROP TABLE t1; 4015# 4016# LP BUG#777809 (a retrograded condition for view ON) 4017# 4018CREATE TABLE t1 ( f1 int NOT NULL , f6 int NOT NULL ) ; 4019INSERT IGNORE INTO t1 VALUES (20, 2); 4020CREATE TABLE t2 ( f3 int NOT NULL ) ; 4021INSERT IGNORE INTO t2 VALUES (7); 4022CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2; 4023PREPARE prep_stmt FROM 'SELECT t1.f6 FROM t1 RIGHT JOIN v2 ON v2.f3 WHERE t1.f1 != 0'; 4024EXECUTE prep_stmt; 4025f6 40262 4027EXECUTE prep_stmt; 4028f6 40292 4030drop view v2; 4031drop table t1,t2; 4032# ----------------------------------------------------------------- 4033# -- End of 5.1 tests. 4034# ----------------------------------------------------------------- 4035# 4036# Bug #794005: crash in st_table::mark_virtual_columns_for_write 4037# 4038CREATE TABLE t1 (a int); 4039insert into t1 values (1); 4040CREATE TABLE t2 (a int); 4041insert into t2 values (1); 4042CREATE VIEW v2 AS SELECT * FROM t2; 4043CREATE VIEW v1 AS SELECT * FROM v2; 4044CREATE VIEW v3 AS SELECT t2.a,v1.a as b FROM t2,v1 where t2.a=v1.a; 4045CREATE OR REPLACE ALGORITHM = TEMPTABLE VIEW v2 AS SELECT * FROM t1; 4046UPDATE v1 SET a = 10; 4047ERROR HY000: The target table v1 of the UPDATE is not updatable 4048REPLACE v1 SET a = 10; 4049ERROR HY000: The target table v1 of the INSERT is not insertable-into 4050INSERT into v1 values (20); 4051ERROR HY000: The target table v1 of the INSERT is not insertable-into 4052DELETE from v1; 4053ERROR HY000: The target table v1 of the DELETE is not updatable 4054UPDATE v3 SET b= 10; 4055ERROR HY000: The target table v3 of the UPDATE is not updatable 4056REPLACE v3 SET b= 10; 4057ERROR HY000: The target table v3 of the INSERT is not insertable-into 4058INSERT into v3(b) values (20); 4059ERROR HY000: The target table v3 of the INSERT is not insertable-into 4060DELETE from v3 where b=20; 4061ERROR HY000: Can not delete from join view 'test.v3' 4062DELETE from v3 where a=20; 4063ERROR HY000: Can not delete from join view 'test.v3' 4064DELETE v1 from v1,t1 where v1.a=t1.a; 4065ERROR HY000: The target table v1 of the DELETE is not updatable 4066UPDATE v3 SET a = 10; 4067REPLACE v3 SET a = 11; 4068INSERT INTO v3(a) values (20); 4069select * from t1; 4070a 40711 4072select * from t2; 4073a 407410 407511 407620 4077CREATE OR REPLACE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM t2; 4078DELETE from v1 where a=11; 4079DELETE v1 from v1,t1 where v1.a=t1.a; 4080select * from t1; 4081a 40821 4083select * from t2; 4084a 408510 408620 4087DROP VIEW v1,v2,v3; 4088DROP TABLE t1,t2; 4089# 4090# MDEV-6251: SIGSEGV in query optimizer (in set_check_materialized 4091# with MERGE view) 4092# 4093CREATE TABLE t1 (a1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4094CREATE TABLE t2 (b1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4095CREATE TABLE t3 (c1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4096CREATE TABLE t4 (d1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4097CREATE TABLE t5 (e1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4098CREATE TABLE t6 (f1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4099CREATE OR REPLACE view v1 AS 4100SELECT 1 4101FROM t1 a_alias_1 4102LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4103LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4104LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4105LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4106LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4107LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4108; 4109SELECT 1 4110FROM (( SELECT 1 4111FROM t1 a_alias_1 4112LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4113LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4114LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4115LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4116LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4117LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4118) t1) 4119LEFT OUTER JOIN (( SELECT 1 4120FROM t1 a_alias_1 4121LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4122LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4123LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4124LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4125LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4126LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4127) t2) ON 1=1 4128LEFT OUTER JOIN (( SELECT 1 4129FROM t1 a_alias_1 4130LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4131LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4132LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4133LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4134LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4135LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4136) t3) ON 1=1 4137LEFT OUTER JOIN (( SELECT 1 4138FROM t1 a_alias_1 4139LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4140LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4141LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4142LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4143LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4144LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4145) t4) ON 1=1 4146LEFT OUTER JOIN (( SELECT 1 4147FROM t1 a_alias_1 4148LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4149LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4150LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4151LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4152LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4153LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4154) t5) ON 1=1 4155LEFT OUTER JOIN (( SELECT 1 4156FROM t1 a_alias_1 4157LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4158LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4159LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4160LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4161LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4162LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4163) t6) ON 1=1 4164LEFT OUTER JOIN (( SELECT 1 4165FROM t1 a_alias_1 4166LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4167LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4168LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4169LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4170LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4171LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4172) t7) ON 1=1 4173LEFT OUTER JOIN (( SELECT 1 4174FROM t1 a_alias_1 4175LEFT JOIN (t2 b_alias_1 JOIN t1 a_alias_2) ON b_alias_1.b1 = a_alias_1.a1 AND a_alias_2.a1 = a_alias_1.a1 4176LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4177LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4178LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4179LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4180LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4181) t8) ON 1=1 4182; 41831 4184SELECT 1 4185FROM (v1 t1) 4186LEFT OUTER JOIN (v1 t2) ON 1=1 4187LEFT OUTER JOIN (v1 t3) ON 1=1 4188LEFT OUTER JOIN (v1 t4) ON 1=1 4189LEFT OUTER JOIN (v1 t5) ON 1=1 4190LEFT OUTER JOIN (v1 t6) ON 1=1 4191LEFT OUTER JOIN (v1 t7) ON 1=1 4192LEFT OUTER JOIN (v1 t8) ON 1=1 4193; 41941 4195drop view v1; 4196drop table t1,t2,t3,t4,t5,t6; 4197# ----------------------------------------------------------------- 4198# -- End of 5.2 tests. 4199# ----------------------------------------------------------------- 4200# 4201# Bug #59696 Optimizer does not use equalities for conditions over view 4202# 4203CREATE TABLE t1 (a int NOT NULL); 4204INSERT INTO t1 VALUES 4205(9), (2), (8), (1), (3), (4), (2), (5), 4206(9), (2), (8), (1), (3), (4), (2), (5); 4207CREATE TABLE t2 (pk int PRIMARY KEY, c int NOT NULL); 4208INSERT INTO t2 VALUES 4209(9,90), (16, 160), (11,110), (1,10), (18,180), (2,20), 4210(14,140), (15, 150), (12,120), (3,30), (17,170), (19,190); 4211EXPLAIN EXTENDED 4212SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8; 4213id select_type table type possible_keys key key_len ref rows filtered Extra 42141 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where 42151 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 4216Warnings: 4217Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` > 8 4218FLUSH STATUS; 4219SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8; 4220a c 42219 90 42229 90 4223SHOW STATUS LIKE 'Handler_read_%'; 4224Variable_name Value 4225Handler_read_first 0 4226Handler_read_key 1 4227Handler_read_last 0 4228Handler_read_next 0 4229Handler_read_prev 0 4230Handler_read_retry 0 4231Handler_read_rnd 0 4232Handler_read_rnd_deleted 0 4233Handler_read_rnd_next 17 4234CREATE VIEW v AS SELECT * FROM t2; 4235EXPLAIN EXTENDED 4236SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8; 4237id select_type table type possible_keys key key_len ref rows filtered Extra 42381 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where 42391 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 4240Warnings: 4241Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` > 8 4242FLUSH STATUS; 4243SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8; 4244a c 42459 90 42469 90 4247SHOW STATUS LIKE 'Handler_read_%'; 4248Variable_name Value 4249Handler_read_first 0 4250Handler_read_key 1 4251Handler_read_last 0 4252Handler_read_next 0 4253Handler_read_prev 0 4254Handler_read_retry 0 4255Handler_read_rnd 0 4256Handler_read_rnd_deleted 0 4257Handler_read_rnd_next 17 4258DROP VIEW v; 4259DROP TABLE t1, t2; 4260# 4261# Bug#702403: crash with multiple equalities and a view 4262# 4263CREATE TABLE t1 (a int); 4264INSERT INTO t1 VALUES (10); 4265CREATE TABLE t2 (pk int PRIMARY KEY, b int, INDEX idx (b)); 4266INSERT INTO t2 VALUES (1,2), (3,4); 4267CREATE TABLE t3 (pk int PRIMARY KEY, b int, INDEX idx (b)); 4268INSERT INTO t3 VALUES (1,2), (3,4); 4269CREATE VIEW v1 AS SELECT * FROM t1; 4270EXPLAIN 4271SELECT * FROM v1, t2, t3 4272WHERE t3.pk = v1.a AND t2.b = 1 AND t2.b = t3.pk AND v1.a BETWEEN 2 AND 5; 4273id select_type table type possible_keys key key_len ref rows Extra 42741 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 4275SELECT * FROM v1, t2, t3 4276WHERE t3.pk = v1.a AND t2.b = 1 AND t2.b = t3.pk AND v1.a BETWEEN 2 AND 5; 4277a pk b pk b 4278DROP VIEW v1; 4279DROP TABLE t1, t2, t3; 4280# 4281# Bug#717577: substitution for best field in a query over a view and 4282# with OR in the WHERE condition 4283# 4284create table t1 (a int, b int); 4285insert into t1 values (2,4), (1,3); 4286create table t2 (c int); 4287insert into t2 values (6), (4), (1), (3), (8), (3), (4), (2); 4288select * from t1,t2 where t2.c=t1.a and t2.c < 3 or t2.c=t1.b and t2.c >=4; 4289a b c 42902 4 4 42911 3 1 42922 4 4 42932 4 2 4294explain extended 4295select * from t1,t2 where t2.c=t1.a and t2.c < 3 or t2.c=t1.b and t2.c >=4; 4296id select_type table type possible_keys key key_len ref rows filtered Extra 42971 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 42981 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4299Warnings: 4300Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`c` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 or `test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t1`.`b` >= 4 4301create view v1 as select * from t2; 4302select * from t1,v1 where v1.c=t1.a and v1.c < 3 or v1.c=t1.b and v1.c >=4; 4303a b c 43042 4 4 43051 3 1 43062 4 4 43072 4 2 4308explain extended 4309select * from t1,v1 where v1.c=t1.a and v1.c < 3 or v1.c=t1.b and v1.c >=4; 4310id select_type table type possible_keys key key_len ref rows filtered Extra 43111 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 43121 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4313Warnings: 4314Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`c` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 or `test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t1`.`b` >= 4 4315create view v2 as select * from v1; 4316select * from t1,v2 where v2.c=t1.a and v2.c < 3 or v2.c=t1.b and v2.c >=4; 4317a b c 43182 4 4 43191 3 1 43202 4 4 43212 4 2 4322explain extended 4323select * from t1,v2 where v2.c=t1.a and v2.c < 3 or v2.c=t1.b and v2.c >=4; 4324id select_type table type possible_keys key key_len ref rows filtered Extra 43251 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 43261 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4327Warnings: 4328Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`c` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 or `test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t1`.`b` >= 4 4329create view v3 as select * from t1; 4330select * from v3,v2 where v2.c=v3.a and v2.c < 3 or v2.c=v3.b and v2.c >=4; 4331a b c 43322 4 4 43331 3 1 43342 4 4 43352 4 2 4336explain extended 4337select * from v3,v2 where v2.c=v3.a and v2.c < 3 or v2.c=v3.b and v2.c >=4; 4338id select_type table type possible_keys key key_len ref rows filtered Extra 43391 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 43401 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4341Warnings: 4342Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`c` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 or `test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t1`.`b` >= 4 4343drop view v1,v2,v3; 4344drop table t1,t2; 4345# 4346# Bug#724942: substitution of the constant into a view field 4347# 4348CREATE TABLE t1 (a int); 4349INSERT INTO t1 VALUES (2), (9), (9), (6), (5), (4), (7); 4350CREATE VIEW v1 AS SELECT * FROM t1; 4351SELECT * FROM v1 WHERE a > -1 OR a > 6 AND a = 3; 4352a 43532 43549 43559 43566 43575 43584 43597 4360EXPLAIN EXTENDED 4361SELECT * FROM v1 WHERE a > -1 OR a > 6 AND a = 3; 4362id select_type table type possible_keys key key_len ref rows filtered Extra 43631 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where 4364Warnings: 4365Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > -1 4366SELECT * FROM v1 WHERE a > -1 OR a AND a = 0; 4367a 43682 43699 43709 43716 43725 43734 43747 4375EXPLAIN EXTENDED 4376SELECT * FROM v1 WHERE a > -1 OR a AND a = 0; 4377id select_type table type possible_keys key key_len ref rows filtered Extra 43781 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where 4379Warnings: 4380Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > -1 4381CREATE VIEW v2 AS SELECT * FROM v1; 4382SELECT * FROM v2 WHERE a > -1 OR a AND a = 0; 4383a 43842 43859 43869 43876 43885 43894 43907 4391EXPLAIN EXTENDED 4392SELECT * FROM v2 WHERE a > -1 OR a AND a = 0; 4393id select_type table type possible_keys key key_len ref rows filtered Extra 43941 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where 4395Warnings: 4396Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > -1 4397DROP VIEW v1,v2; 4398DROP TABLE t1; 4399CREATE TABLE t1 (a varchar(10), KEY (a)) ; 4400INSERT INTO t1 VALUES 4401('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'), ('MM'), 4402('AA'), ('DD'), ('CC'), ('GG'); 4403CREATE VIEW v1 AS SELECT * FROM t1; 4404# t1 and v1 should return the same result set 4405SELECT * FROM v1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4406a 4407KK 4408MM 4409ZZ 4410ZZ 4411SELECT * FROM t1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4412a 4413KK 4414MM 4415ZZ 4416ZZ 4417# t1 and v1 should propagate constants in the same way 4418EXPLAIN EXTENDED 4419SELECT * FROM v1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4420id select_type table type possible_keys key key_len ref rows filtered Extra 44211 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4422Warnings: 4423Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 'JJ' or `test`.`t1`.`a` = 'VV' and `test`.`t1`.`a` <> 0 4424EXPLAIN EXTENDED 4425SELECT * FROM t1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4426id select_type table type possible_keys key key_len ref rows filtered Extra 44271 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4428Warnings: 4429Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 'JJ' or `test`.`t1`.`a` = 'VV' and `test`.`t1`.`a` <> 0 4430# t1 and v1 should return the same result set 4431SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV'; 4432a 4433KK 4434MM 4435ZZ 4436ZZ 4437SELECT * FROM t1 WHERE a > 'JJ' OR a AND a = 'VV'; 4438a 4439KK 4440MM 4441ZZ 4442ZZ 4443# t1 and v1 should propagate constants in the same way 4444EXPLAIN EXTENDED 4445SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV'; 4446id select_type table type possible_keys key key_len ref rows filtered Extra 44471 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4448Warnings: 4449Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 'JJ' or `test`.`t1`.`a` = 'VV' and `test`.`t1`.`a` <> 0 4450EXPLAIN EXTENDED 4451SELECT * FROM t1 WHERE a > 'JJ' OR a AND a = 'VV'; 4452id select_type table type possible_keys key key_len ref rows filtered Extra 44531 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4454Warnings: 4455Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 'JJ' or `test`.`t1`.`a` = 'VV' and `test`.`t1`.`a` <> 0 4456DROP VIEW v1; 4457DROP TABLE t1; 4458# 4459# Bug#777745: crash with equality propagation 4460# over view fields 4461# 4462CREATE TABLE t1 (a int NOT NULL ) ; 4463INSERT INTO t1 VALUES (2), (1); 4464CREATE TABLE t2 (a int NOT NULL , b int NOT NULL) ; 4465INSERT INTO t2 VALUES (2,20),(2,30); 4466CREATE VIEW v2 AS SELECT * FROM t2; 4467EXPLAIN 4468SELECT * FROM t1,v2 4469WHERE v2.a = t1.a AND v2.a = 2 AND v2.a IS NULL AND t1.a != 0; 4470id select_type table type possible_keys key key_len ref rows Extra 44711 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 4472SELECT * FROM t1,v2 4473WHERE v2.a = t1.a AND v2.a = 2 AND v2.a IS NULL AND t1.a != 0; 4474a a b 4475EXPLAIN 4476SELECT * FROM t1,v2 4477WHERE v2.a = t1.a AND v2.a = 2 AND v2.a+1 > 2 AND t1.a != 0; 4478id select_type table type possible_keys key key_len ref rows Extra 44791 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where 44801 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 4481SELECT * FROM t1,v2 4482WHERE v2.a = t1.a AND v2.a = 2 AND v2.a+1 > 2 AND t1.a != 0; 4483a a b 44842 2 20 44852 2 30 4486DROP VIEW v2; 4487DROP TABLE t1,t2; 4488# 4489# Bug#794038: crash with INSERT/UPDATE/DELETE 4490# over a non-updatable view 4491# 4492CREATE TABLE t1 (a int); 4493CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT * FROM t1; 4494CREATE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM v1; 4495CREATE ALGORITHM = TEMPTABLE VIEW v3 AS SELECT * FROM v2; 4496INSERT INTO v3 VALUES (1); 4497ERROR HY000: The target table v3 of the INSERT is not insertable-into 4498UPDATE v3 SET a=0; 4499ERROR HY000: The target table v3 of the UPDATE is not updatable 4500DELETE FROM v3; 4501ERROR HY000: The target table v3 of the DELETE is not updatable 4502DROP VIEW v1,v2,v3; 4503DROP TABLE t1; 4504# 4505# Bug#798621: crash with a view string field equal 4506# to a constant 4507# 4508CREATE TABLE t1 (a varchar(32), b int) ; 4509INSERT INTO t1 VALUES ('j', NULL), ('c', 8), ('c', 1); 4510CREATE VIEW v1 AS SELECT * FROM t1; 4511CREATE TABLE t2 (a varchar(32)) ; 4512INSERT INTO t2 VALUES ('j'), ('c'); 4513SELECT * FROM v1 LEFT JOIN t2 ON t2.a = v1.a 4514WHERE v1.b = 1 OR v1.a = 'a' AND LENGTH(v1.a) >= v1.b; 4515a b a 4516c 1 c 4517EXPLAIN EXTENDED 4518SELECT * FROM v1 LEFT JOIN t2 ON t2.a = v1.a 4519WHERE v1.b = 1 OR v1.a = 'a' AND LENGTH(v1.a) >= v1.b; 4520id select_type table type possible_keys key key_len ref rows filtered Extra 45211 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where 45221 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where 4523Warnings: 4524Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`a` = `test`.`t1`.`a`) where `test`.`t1`.`b` = 1 or `test`.`t1`.`a` = 'a' and octet_length(`test`.`t1`.`a`) >= `test`.`t1`.`b` 4525DROP VIEW v1; 4526DROP TABLE t1,t2; 4527# Bug#798625: duplicate of the previous one, but without crash 4528CREATE TABLE t1 (f1 int NOT NULL, f2 int, f3 int, f4 varchar(32), f5 int) ; 4529INSERT INTO t1 VALUES (20,5,2,'r', 0); 4530CREATE VIEW v1 AS SELECT * FROM t1; 4531SELECT v1.f4 FROM v1 4532WHERE f1<>0 OR f2<>0 AND f4='v' AND (f2<>0 OR f3<>0 AND f5<>0 OR f4 LIKE '%b%'); 4533f4 4534r 4535EXPLAIN EXTENDED 4536SELECT v1.f4 FROM v1 4537WHERE f1<>0 OR f2<>0 AND f4='v' AND (f2<>0 OR f3<>0 AND f5<>0 OR f4 LIKE '%b%'); 4538id select_type table type possible_keys key key_len ref rows filtered Extra 45391 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 4540Warnings: 4541Note 1003 select 'r' AS `f4` from dual where 1 4542DROP VIEW v1; 4543DROP TABLE t1; 4544# 4545# Bug#798576: abort on a GROUP BY query over a view with left join 4546# that can be converted to inner join 4547# 4548CREATE TABLE t1 (a int NOT NULL , b int NOT NULL) ; 4549INSERT INTO t1 VALUES (214,0), (6,6), (6,0), (7,0); 4550CREATE TABLE t2 (b int) ; 4551INSERT INTO t2 VALUES (88), (78), (6); 4552CREATE ALGORITHM=MERGE VIEW v1 AS 4553SELECT t1.a, t2.b FROM (t2 LEFT JOIN t1 ON t2.b > t1.a) WHERE t1.b <= 0; 4554SELECT * FROM v1; 4555a b 45566 88 45576 78 45587 88 45597 78 4560SELECT a, MIN(b) FROM v1 GROUP BY a; 4561a MIN(b) 45626 78 45637 78 4564DROP VIEW v1; 4565DROP TABLE t1,t2; 4566# 4567# LP bug #793386: unexpected 'Duplicate column name ''' error 4568# at the second execution of a PS using a view 4569# 4570CREATE TABLE t1 (f1 int, f2 int, f3 int, f4 int); 4571CREATE VIEW v1 AS 4572SELECT t.f1, t.f2, s.f3, s.f4 FROM t1 t, t1 s 4573WHERE t.f4 >= s.f2 AND s.f3 < 0; 4574PREPARE stmt1 FROM 4575"SELECT s.f1 AS f1, s.f2 AS f2, s.f3 AS f3, t.f4 AS f4 4576 FROM v1 AS t LEFT JOIN v1 AS s ON t.f4=s.f4 WHERE t.f2 <> 1225"; 4577EXECUTE stmt1; 4578f1 f2 f3 f4 4579EXECUTE stmt1; 4580f1 f2 f3 f4 4581DEALLOCATE PREPARE stmt1; 4582DROP VIEW v1; 4583DROP TABLE t1; 4584# 4585# LP BUG#806071 (2 views with ORDER BY) 4586# 4587CREATE TABLE t1 (f1 int); 4588INSERT INTO t1 VALUES (1),(1); 4589CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT f1 FROM t1; 4590CREATE ALGORITHM=MERGE VIEW v2 AS SELECT f1 FROM v1 ORDER BY f1; 4591SELECT * FROM v2 AS a1, v2 AS a2; 4592f1 f1 45931 1 45941 1 45951 1 45961 1 4597EXPLAIN EXTENDED SELECT * FROM v2 AS a1, v2 AS a2; 4598id select_type table type possible_keys key key_len ref rows filtered Extra 45991 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort 46001 PRIMARY <derived5> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join) 46015 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 46023 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 4603Warnings: 4604Note 1926 View 'test'.'v2' ORDER BY clause ignored because there is other ORDER BY clause already 4605Note 1003 /* select#1 */ select `v1`.`f1` AS `f1`,`v1`.`f1` AS `f1` from `test`.`v1` join `test`.`v1` order by `v1`.`f1` 4606DROP VIEW v1, v2; 4607DROP TABLE t1; 4608# 4609# LP bug #823189: dependent subquery with RIGHT JOIN 4610# referencing view in WHERE 4611# 4612CREATE TABLE t1 (a varchar(32)); 4613INSERT INTO t1 VALUES ('y'), ('w'); 4614CREATE TABLE t2 (a int); 4615INSERT INTO t2 VALUES (10); 4616CREATE TABLE t3 (a varchar(32), b int); 4617CREATE TABLE t4 (a varchar(32)); 4618INSERT INTO t4 VALUES ('y'), ('w'); 4619CREATE VIEW v1 AS SELECT * FROM t1; 4620EXPLAIN EXTENDED 4621SELECT * FROM t1, t2 4622WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4623WHERE t4.a >= t1.a); 4624id select_type table type possible_keys key key_len ref rows filtered Extra 46251 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 46261 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where 46272 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 0.00 Const row not found 46282 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 4629Warnings: 4630Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 4631Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,10 AS `a` from `test`.`t1` where !<expr_cache><10,`test`.`t1`.`a`>(<in_optimizer>(10,<exists>(/* select#2 */ select NULL from `test`.`t4` where `test`.`t4`.`a` >= `test`.`t1`.`a` and trigcond(<cache>(10) = NULL or 1) having trigcond(NULL is null)))) 4632SELECT * FROM t1, t2 4633WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4634WHERE t4.a >= t1.a); 4635a a 4636EXPLAIN EXTENDED 4637SELECT * FROM v1, t2 4638WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4639WHERE t4.a >= v1.a); 4640id select_type table type possible_keys key key_len ref rows filtered Extra 46411 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 46421 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where 46432 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 0.00 Const row not found 46442 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 4645Warnings: 4646Note 1276 Field or reference 'v1.a' of SELECT #2 was resolved in SELECT #1 4647Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,10 AS `a` from `test`.`t1` where !<expr_cache><10,`test`.`t1`.`a`>(<in_optimizer>(10,<exists>(/* select#2 */ select NULL from `test`.`t4` where `test`.`t4`.`a` >= `test`.`t1`.`a` and trigcond(<cache>(10) = NULL or 1) having trigcond(NULL is null)))) 4648SELECT * FROM v1, t2 4649WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4650WHERE t4.a >= v1.a); 4651a a 4652DROP VIEW v1; 4653DROP TABLE t1,t2,t3,t4; 4654# 4655# LP bug #823237: dependent subquery with LEFT JOIN 4656# referencing view in WHERE 4657# (duplicate of LP bug #823189) 4658# 4659CREATE TABLE t1 (a int); 4660CREATE TABLE t2 ( b int, d int, e int); 4661INSERT INTO t2 VALUES (7,8,0); 4662CREATE TABLE t3 ( c int); 4663INSERT INTO t3 VALUES (0); 4664CREATE TABLE t4 (a int, b int, c int); 4665INSERT INTO t4 VALUES (93,1,0), (95,NULL,0); 4666CREATE VIEW v4 AS SELECT * FROM t4; 4667EXPLAIN EXTENDED 4668SELECT * FROM t3 , t4 4669WHERE t4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4670WHERE t2.b > t4.b); 4671id select_type table type possible_keys key key_len ref rows filtered Extra 46721 PRIMARY t3 system NULL NULL NULL NULL 1 100.00 46731 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 46742 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 100.00 46752 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 Const row not found 4676Warnings: 4677Note 1276 Field or reference 'test.t4.b' of SELECT #2 was resolved in SELECT #1 4678Note 1003 /* select#1 */ select 0 AS `c`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c` from `test`.`t4` where `test`.`t4`.`c` <= <expr_cache><`test`.`t4`.`b`>((/* select#2 */ select 0 from dual where 7 > `test`.`t4`.`b`)) 4679SELECT * FROM t3 , t4 4680WHERE t4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4681WHERE t2.b > t4.b); 4682c a b c 46830 93 1 0 4684EXPLAIN EXTENDED 4685SELECT * FROM t3, v4 4686WHERE v4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4687WHERE t2.b > v4.b); 4688id select_type table type possible_keys key key_len ref rows filtered Extra 46891 PRIMARY t3 system NULL NULL NULL NULL 1 100.00 46901 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 46912 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 100.00 46922 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 Const row not found 4693Warnings: 4694Note 1276 Field or reference 'v4.b' of SELECT #2 was resolved in SELECT #1 4695Note 1003 /* select#1 */ select 0 AS `c`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t4`.`c` AS `c` from `test`.`t4` where `test`.`t4`.`c` <= <expr_cache><`test`.`t4`.`b`>((/* select#2 */ select 0 from dual where 7 > `test`.`t4`.`b`)) 4696SELECT * FROM t3, v4 4697WHERE v4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4698WHERE t2.b > v4.b); 4699c a b c 47000 93 1 0 4701DROP VIEW v4; 4702DROP TABLE t1,t2,t3,t4; 4703drop table if exists t_9801; 4704drop view if exists v_9801; 4705create table t_9801 (s1 int); 4706create view v_9801 as 4707select sum(s1) from t_9801 with check option; 4708ERROR HY000: CHECK OPTION on non-updatable view `test`.`v_9801` 4709create view v_9801 as 4710select sum(s1) from t_9801 group by s1 with check option; 4711ERROR HY000: CHECK OPTION on non-updatable view `test`.`v_9801` 4712create view v_9801 as 4713select sum(s1) from t_9801 group by s1 with rollup with check option; 4714ERROR HY000: CHECK OPTION on non-updatable view `test`.`v_9801` 4715drop table t_9801; 4716# 4717# Bug #47335 assert in get_table_share 4718# 4719DROP TABLE IF EXISTS t1; 4720DROP VIEW IF EXISTS v1; 4721CREATE TEMPORARY TABLE t1 (id INT); 4722ALTER VIEW t1 AS SELECT 1 AS f1; 4723ERROR 42S02: Table 'test.t1' doesn't exist 4724DROP TABLE t1; 4725CREATE VIEW v1 AS SELECT 1 AS f1; 4726CREATE TEMPORARY TABLE v1 (id INT); 4727ALTER VIEW v1 AS SELECT 2 AS f1; 4728DROP TABLE v1; 4729SELECT * FROM v1; 4730f1 47312 4732DROP VIEW v1; 4733# 4734# Bug #47635 assert in start_waiting_global_read_lock 4735# during CREATE VIEW 4736# 4737DROP TABLE IF EXISTS t1, t2; 4738DROP VIEW IF EXISTS t2; 4739CREATE TABLE t1 (f1 integer); 4740CREATE TEMPORARY TABLE IF NOT EXISTS t1 (f1 integer); 4741CREATE TEMPORARY TABLE t2 (f1 integer); 4742DROP TABLE t1; 4743FLUSH TABLES WITH READ LOCK; 4744CREATE VIEW t2 AS SELECT * FROM t1; 4745ERROR HY000: Can't execute the query because you have a conflicting read lock 4746UNLOCK TABLES; 4747DROP TABLE t1, t2; 4748# 4749# Bug#48315 Metadata lock is not taken for merged views that 4750# use an INFORMATION_SCHEMA table 4751# 4752DROP VIEW IF EXISTS v1; 4753DROP PROCEDURE IF EXISTS p1; 4754connect con2, localhost, root; 4755connect con3, localhost, root; 4756connection default; 4757CREATE VIEW v1 AS SELECT schema_name FROM information_schema.schemata; 4758CREATE PROCEDURE p1() SELECT COUNT(*), GET_LOCK('blocker', 100) FROM v1; 4759# CALL p1() so the view is merged. 4760CALL p1(); 4761SELECT RELEASE_LOCK('blocker'); 4762RELEASE_LOCK('blocker') 47631 4764connection con3; 4765SELECT GET_LOCK('blocker', 100); 4766GET_LOCK('blocker', 100) 47671 4768connection default; 4769# Try to CALL p1() again, this time it should block on "blocker". 4770# Sending: 4771CALL p1(); 4772connection con2; 4773# ... then try to drop the view. This should block. 4774# Sending: 4775DROP VIEW v1; 4776connection con3; 4777# Now allow CALL p1() to complete 4778SELECT RELEASE_LOCK('blocker'); 4779RELEASE_LOCK('blocker') 47801 4781connection default; 4782# Reaping: CALL p1() 4783SELECT RELEASE_LOCK('blocker'); 4784RELEASE_LOCK('blocker') 47851 4786connection con2; 4787# Reaping: DROP VIEW v1 4788connection default; 4789DROP PROCEDURE p1; 4790disconnect con2; 4791disconnect con3; 4792# 4793# Bug#12626844: WRONG ERROR MESSAGE WHILE CREATING A VIEW ON A 4794# NON EXISTING DATABASE 4795# 4796DROP DATABASE IF EXISTS nodb; 4797CREATE VIEW nodb.a AS SELECT 1; 4798ERROR 42000: Unknown database 'nodb' 4799# 4800# BUG#14117018 - MYSQL SERVER CREATES INVALID VIEW DEFINITION 4801# BUG#18405221 - SHOW CREATE VIEW OUTPUT INCORRECT 4802# 4803CREATE VIEW v1 AS (SELECT '' FROM DUAL); 4804CREATE VIEW v2 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL 4805(SELECT '' FROM DUAL); 4806CREATE VIEW v3 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL 4807(SELECT '' FROM DUAL) UNION ALL 4808(SELECT '' FROM DUAL); 4809CREATE VIEW v4 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL 4810(SELECT '' AS col2 FROM DUAL) UNION ALL 4811(SELECT '' FROM DUAL); 4812CREATE VIEW v5 AS (SELECT 'buggy' AS col1, 'fix' as col2 FROM DUAL) UNION ALL 4813(SELECT 'buggy' as a, 'fix' as a FROM DUAL); 4814# Name for the column in select1 is set properly with or 4815# without this fix. 4816SHOW CREATE VIEW v1; 4817View Create View character_set_client collation_connection 4818v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select '' AS `Name_exp_1`) latin1 latin1_swedish_ci 4819# Name for the column in select2 is set with this fix. 4820# Without this fix, name would not have set for the 4821# columns in select2. 4822SHOW CREATE VIEW v2; 4823View Create View character_set_client collation_connection 4824v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS (select 'BUG#14117018' AS `col1`) union all (select '' AS `Name_exp_1`) latin1 latin1_swedish_ci 4825# Name for the field item in select2 & select3 is set with this fix. 4826# Without this fix, name would not have set for the 4827# columns in select2 & select3. 4828SHOW CREATE VIEW v3; 4829View Create View character_set_client collation_connection 4830v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS (select 'BUG#14117018' AS `col1`) union all (select '' AS `Name_exp_1`) union all (select '' AS `Name_exp_1`) latin1 latin1_swedish_ci 4831# Name for the field item in select3 is set with this fix. 4832# Without this fix, name would not have set for the 4833# columns in select3. 4834SHOW CREATE VIEW v4; 4835View Create View character_set_client collation_connection 4836v4 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS (select 'BUG#14117018' AS `col1`) union all (select '' AS `col2`) union all (select '' AS `Name_exp_1`) latin1 latin1_swedish_ci 4837DROP VIEW v1, v2, v3, v4, v5; 4838# 4839# BUG#19886430: VIEW CREATION WITH NAMED COLUMNS, OVER UNION, 4840# IS REJECTED 4841# Without the patch, reports an error. 4842CREATE VIEW v1 (fld1, fld2) AS 4843SELECT 1 AS a, 2 AS b 4844UNION ALL 4845SELECT 1 AS a, 1 AS a; 4846# The column names are explicitly specified and not duplicates, hence 4847# succeeds. 4848CREATE VIEW v2 (fld1, fld2) AS 4849SELECT 1 AS a, 2 AS a 4850UNION ALL 4851SELECT 1 AS a, 1 AS a; 4852# The column name in the first SELECT are not duplicates, hence succeeds. 4853CREATE VIEW v3 AS 4854SELECT 1 AS a, 2 AS b 4855UNION ALL 4856SELECT 1 AS a, 1 AS a; 4857# Should report an error, since the explicitly specified column names are 4858# duplicates. 4859CREATE VIEW v4 (fld1, fld1) AS 4860SELECT 1 AS a, 2 AS b 4861UNION ALL 4862SELECT 1 AS a, 1 AS a; 4863ERROR 42S21: Duplicate column name 'fld1' 4864# Should report an error, since duplicate column name is specified in the 4865# First SELECT. 4866CREATE VIEW v4 AS 4867SELECT 1 AS a, 2 AS a 4868UNION ALL 4869SELECT 1 AS a, 1 AS a; 4870ERROR 42S21: Duplicate column name 'a' 4871# Cleanup 4872DROP VIEW v1, v2, v3; 4873# 4874# lp:833600 Wrong result with view + outer join + uncorrelated subquery (non-semijoin) 4875# 4876CREATE TABLE t1 ( a int, b int ); 4877INSERT INTO t1 VALUES (0,0),(0,0); 4878CREATE TABLE t2 ( a int, b int ); 4879INSERT IGNORE INTO t2 VALUES (1,0),(1,0); 4880CREATE TABLE t3 ( b int ); 4881INSERT IGNORE INTO t3 VALUES (0),(0); 4882CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2; 4883SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ; 4884a b a b 4885NULL NULL 1 0 4886NULL NULL 1 0 4887SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ; 4888a b a b 4889NULL NULL 1 0 4890NULL NULL 1 0 4891DROP VIEW v2; 4892DROP TABLE t1, t2, t3; 4893# 4894# BUG#915222: Valgrind complains or crashes with INSERT SELECT 4895# within a trigger that uses a view 4896# 4897CREATE TABLE t1 (a char(1)); 4898CREATE TABLE t2 (d int, e char(1)); 4899INSERT INTO t2 VALUES (13,'z'); 4900CREATE TRIGGER tr AFTER UPDATE ON t2 4901FOR EACH ROW 4902REPLACE INTO t3 4903SELECT f, a AS alias FROM t3, v; 4904CREATE TABLE t3 (f int, g char(8)); 4905CREATE VIEW v AS SELECT a, e FROM t2, t1; 4906UPDATE t2 SET d=7; 4907UPDATE t2 SET d=7; 4908UPDATE t2 SET d=7; 4909UPDATE t2 SET d=7; 4910DROP TRIGGER tr; 4911DROP VIEW v; 4912DROP TABLE t1,t2,t3; 4913# 4914# BUG#972943: Assertion failure with INSERT SELECT within a trigger 4915# that uses derived table and materialized view 4916# 4917CREATE TABLE t1 (a int, b int); 4918INSERT INTO t1 VALUES (1,0), (2,8); 4919CREATE ALGORITHM=TEMPTABLE VIEW v1 4920AS SELECT * FROM t1; 4921CREATE TABLE t2 (c int); 4922CREATE TABLE t3 (d int, e int); 4923CREATE TRIGGER tr BEFORE INSERT ON t2 FOR EACH ROW 4924INSERT INTO t3 4925SELECT t1.* 4926FROM (SELECT * FROM t1 WHERE b IN (SELECT b FROM v1)) AS alias1, t1 4927WHERE t1.a = 3 OR t1.a > 5; 4928INSERT INTO t2 VALUES (1); 4929DROP TRIGGER tr; 4930DROP VIEW v1; 4931DROP TABLE t1,t2,t3; 4932# 4933# LP bug#1007622 Server crashes in handler::increment_statistics on 4934# inserting into a view over a view 4935# 4936flush status; 4937CREATE TABLE t1 (a INT); 4938CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.* FROM t1 AS a1, t1 AS a2; 4939CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1; 4940INSERT INTO v2 (a) VALUES (1) ; 4941select * from t1; 4942a 49431 4944drop view v2,v1; 4945drop table t1; 4946show status like '%view%'; 4947Variable_name Value 4948Com_create_view 2 4949Com_drop_view 1 4950Opened_views 3 4951show status like 'Opened_table%'; 4952Variable_name Value 4953Opened_table_definitions 2 4954Opened_tables 2 4955# 4956# MDEV-486 LP BUG#1010116 Incorrect query results in 4957# view and derived tables 4958# 4959SELECT 4960`Derived1`.`id`, 4961`Derived2`.`Val1` 4962FROM (select 30631 as `id`) AS `Derived1` LEFT OUTER JOIN (SELECT 49632 as `id`, 49641 AS `Val1` 4965FROM (select 30631 as `id`) AS `Derived3`) AS `Derived2` ON `Derived1`.`id` = `Derived2`.`id`; 4966id Val1 496730631 NULL 4968create table t1 ( id int ); 4969insert into t1 values (30631); 4970create table t2 ( id int ); 4971insert into t2 values (30631); 4972create algorithm=MERGE view v2 as select 2 as id, 1 as val1 from t2; 4973select t1.*, v2.* from t1 left join v2 on t1.id = v2.id; 4974id id val1 497530631 NULL NULL 4976drop view v2; 4977drop table t1,t2; 4978create table t1 ( id int ); 4979insert into t1 values (30631); 4980create table t2 ( id int ); 4981insert into t2 values (30631); 4982create algorithm=MERGE view v2 as select 2 as id, id is null as bbb, id as iddqd, 1 as val1 from t2; 4983select t1.*, v2.* from t1 left join v2 on t1.id = v2.id; 4984id id bbb iddqd val1 498530631 NULL NULL NULL NULL 4986drop view v2; 4987drop table t1,t2; 4988# 4989# MDEV-3914: Wrong result (NULLs instead of real values) 4990# with INNER and RIGHT JOIN in a FROM subquery, derived_merge=on 4991# (fix of above MDEV-486 fix) 4992# 4993SET @save_optimizer_switch_MDEV_3914=@@optimizer_switch; 4994SET optimizer_switch = 'derived_merge=on'; 4995CREATE TABLE t1 (a INT) ENGINE=MyISAM; 4996INSERT INTO t1 VALUES (1),(2); 4997CREATE TABLE t2 (b INT) ENGINE=MyISAM; 4998INSERT INTO t2 VALUES (3),(4); 4999CREATE TABLE t3 (c INT) ENGINE=MyISAM; 5000INSERT INTO t3 VALUES (5),(6); 5001SELECT * FROM ( SELECT c FROM ( t1 INNER JOIN t2 ) RIGHT JOIN t3 ON a = c ) AS alias; 5002c 50035 50046 5005SET optimizer_switch = 'derived_merge=off'; 5006SELECT * FROM ( SELECT c FROM ( t1 INNER JOIN t2 ) RIGHT JOIN t3 ON a = c ) AS alias; 5007c 50085 50096 5010SET optimizer_switch=@save_optimizer_switch_MDEV_3914; 5011drop table t1,t2,t3; 5012# 5013# MDEV-589 (LP BUG#1007647) : 5014# Assertion `vcol_table == 0 || vcol_table == table' failed in 5015# fill_record(THD*, List<Item>&, List<Item>&, bool) 5016# 5017CREATE TABLE t1 (f1 INT, f2 INT); 5018CREATE TABLE t2 (f1 INT, f2 INT); 5019CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.f1, a2.f2 FROM t1 AS a1, t1 AS a2; 5020CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1; 5021CREATE ALGORITHM=MERGE VIEW v3 AS SELECT a1.f1, a2.f2 FROM t1 AS a1, t2 AS a2; 5022CREATE ALGORITHM=MERGE VIEW v4 AS SELECT * FROM v3; 5023INSERT INTO v3 (f1, f2) VALUES (1, 2); 5024ERROR HY000: Can not modify more than one base table through a join view 'test.v3' 5025INSERT INTO v1 (f1, f2) VALUES (1, 2); 5026ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 5027INSERT INTO v4 (f1, f2) VALUES (1, 2); 5028ERROR HY000: Can not modify more than one base table through a join view 'test.v4' 5029INSERT INTO v2 (f1, f2) VALUES (1, 2); 5030ERROR HY000: Can not modify more than one base table through a join view 'test.v2' 5031drop view v4,v3,v2,v1; 5032drop table t1,t2; 5033# 5034# MDEV-3799 fix of above bugfix (MDEV-589) 5035# Wrong result (NULLs instead of real values) with RIGHT JOIN 5036# in a FROM subquery and derived_merge=on 5037# 5038CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; 5039INSERT INTO t1 VALUES (4),(6); 5040CREATE TABLE t2 (f2 INT) ENGINE=MyISAM; 5041INSERT INTO t2 VALUES (7),(8); 5042SELECT * FROM ( 5043SELECT * FROM t1 RIGHT JOIN t2 ON f1 = f2 5044) AS alias; 5045f1 f2 5046NULL 7 5047NULL 8 5048SELECT * FROM ( 5049SELECT * FROM t2 LEFT JOIN t1 ON f1 = f2 5050) AS alias; 5051f2 f1 50527 NULL 50538 NULL 5054drop tables t1,t2; 5055# 5056# MDEV-3876 Wrong result (extra rows) with ALL subquery 5057# from a MERGE view (duplicate of MDEV-3873) 5058# 5059CREATE TABLE t1 (a INT NOT NULL) ENGINE=MyISAM; 5060INSERT INTO t1 VALUES (1),(2); 5061CREATE TABLE t2 (b INT NOT NULL) ENGINE=MyISAM; 5062INSERT INTO t2 VALUES (1),(3); 5063CREATE OR REPLACE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2; 5064SELECT a FROM t1 AS alias 5065WHERE a >= ALL ( 5066SELECT b FROM t1 LEFT JOIN v1 ON (a = b) 5067WHERE a = alias.a ); 5068a 50691 5070drop view v1; 5071drop table t1,t2; 5072# 5073# MDEV-4593: p_s: crash in simplify_joins with delete using subselect 5074# from view 5075# 5076create table `t1`(`a` int); 5077create table `t2`(`a` int); 5078create or replace view `v1` as select `a` from `t1`; 5079prepare s from "delete from `t2` order by (select 1 from `v1`)"; 5080execute s; 5081deallocate prepare s; 5082drop view v1; 5083drop tables t1,t2; 5084# 5085# MDEV-5034 (duplicate of MDEV-5107): 5086# Left Join Yields All Nulls Instead of Appropriate Matches 5087# 5088# test #1 5089CREATE TABLE t1 (state VARCHAR(32), INDEX(state)); 5090INSERT INTO t1 VALUES ('Indiana'),('Vermont'); 5091CREATE TABLE t2 (state VARCHAR(32)); 5092INSERT INTO t2 VALUES ('Hawaii'),('Oregon'),('Vermont'); 5093CREATE ALGORITHM=MERGE VIEW v1 AS SELECT t1.* FROM t2, t1; 5094SELECT * FROM t1 AS outer_t1 LEFT JOIN v1 AS joined_t1 5095ON (joined_t1.state = outer_t1.state AND joined_t1.state IN ( SELECT 'Vermont' UNION SELECT 'Florida' ) ); 5096state state 5097Indiana NULL 5098Vermont Vermont 5099Vermont Vermont 5100Vermont Vermont 5101SELECT * FROM t1 AS outer_t1 LEFT JOIN (SELECT t1.* FROM t2, t1) AS joined_t1 ON (joined_t1.state = outer_t1.state AND joined_t1.state IN ( SELECT 'Vermont' UNION SELECT 'Florida' ) ); 5102state state 5103Indiana NULL 5104Vermont Vermont 5105Vermont Vermont 5106Vermont Vermont 5107drop view v1; 5108drop table t1, t2; 5109# test #1 5110CREATE TABLE t1 (a INT, b VARCHAR(1), INDEX(b,a)); 5111INSERT INTO t1 VALUES (4,'p'),(1,'q'),(9,'w'); 5112CREATE TABLE t2 (c VARCHAR(1), INDEX(c)); 5113INSERT INTO t2 VALUES ('q'),('a'); 5114CREATE ALGORITHM=MERGE VIEW v1 AS SELECT t1a.* FROM t1, t1 AS t1a; 5115SELECT * FROM t2 LEFT JOIN v1 ON ( c=b AND a IN ( 1,6 ) ); 5116c a b 5117a NULL NULL 5118q 1 q 5119q 1 q 5120q 1 q 5121CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT t1a.* FROM t1, t1 AS t1a; 5122SELECT * FROM t2 LEFT JOIN v1 ON ( c=b AND a IN ( 1,6 ) ); 5123c a b 5124a NULL NULL 5125q 1 q 5126q 1 q 5127q 1 q 5128drop view v1; 5129drop table t1,t2; 5130# 5131# MDEV-5153: Server crashes in Item_ref::fix_fields on 2nd execution 5132# of PS with LEFT JOIN and MERGE view or SELECT SQ 5133# 5134CREATE TABLE t1 (i1 INT, c1 VARCHAR(6)) ENGINE=MyISAM; 5135INSERT INTO t1 VALUES (1,'foo'),(2,'bar'); 5136CREATE TABLE t2 (c2 VARCHAR(6)) ENGINE=MyISAM; 5137INSERT INTO t2 VALUES ('foobar'),('qux'); 5138CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1 WHERE ( c1 ) IN ( SELECT c2 FROM t2 ) AND i1 <= 2 ; 5139PREPARE stmt FROM 'SELECT * FROM t1 LEFT JOIN v1 ON (v1.i1 = t1.i1)'; 5140EXECUTE stmt; 5141i1 c1 i1 c1 51421 foo NULL NULL 51432 bar NULL NULL 5144EXECUTE stmt; 5145i1 c1 i1 c1 51461 foo NULL NULL 51472 bar NULL NULL 5148drop view v1; 5149CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1 WHERE ( c1, c1 ) IN ( SELECT c2, c2 FROM t2 ) AND i1 <= 2 ; 5150EXECUTE stmt; 5151i1 c1 i1 c1 51521 foo NULL NULL 51532 bar NULL NULL 5154EXECUTE stmt; 5155i1 c1 i1 c1 51561 foo NULL NULL 51572 bar NULL NULL 5158deallocate prepare stmt; 5159drop view v1; 5160drop table t1,t2; 5161create table t1 (a int); 5162insert into t1 values (1),(2); 5163create view v1 (a,r) as select a,rand() from t1; 5164create table t2 select a, r as r1, r as r2, r as r3 from v1; 5165select a, r1 = r2, r2 = r3 from t2; 5166a r1 = r2 r2 = r3 51671 1 1 51682 1 1 5169drop view v1; 5170drop table t1,t2; 5171# 5172# MDEV-5515: 2nd execution of a prepared statement returns wrong results 5173# 5174CREATE TABLE t1 (i1 INT, j1 INT NOT NULL, PRIMARY KEY (i1)); 5175INSERT INTO t1 VALUES (30,300),(40,400); 5176CREATE TABLE t2 (i2 INT); 5177INSERT INTO t2 VALUES (50),(60); 5178CREATE TABLE t3 (c3 VARCHAR(20), i3 INT); 5179INSERT INTO t3 VALUES ('a',10),('b',2); 5180CREATE TABLE t4 (i4 INT); 5181INSERT INTO t4 VALUES (1),(2); 5182DROP VIEW IF EXISTS v1; 5183Warnings: 5184Note 4092 Unknown VIEW: 'test.v1' 5185CREATE VIEW v1 AS select coalesce(j1,i3) AS v1_field1 from t2 join t3 left join t1 on ( i1 = i2 ); 5186CREATE VIEW v2 AS select v1_field1 from t4 join v1; 5187prepare my_stmt from "select v1_field1 from v2"; 5188execute my_stmt; 5189v1_field1 519010 519110 519210 519310 51942 51952 51962 51972 5198execute my_stmt; 5199v1_field1 520010 520110 520210 520310 52042 52052 52062 52072 5208deallocate prepare my_stmt; 5209DROP VIEW v1,v2; 5210DROP TABLE t1,t2,t3,t4; 5211# 5212#MDEV-5717: Server crash with insert statement containing DEFAULT into 5213#view 5214# 5215CREATE TABLE t1 ( 5216`id` int(10) unsigned NOT NULL AUTO_INCREMENT, 5217`test` tinyint(3) unsigned NOT NULL DEFAULT '0', 5218PRIMARY KEY (`id`) 5219); 5220CREATE VIEW v1 AS (select t1.id AS id, t1.test AS test from t1); 5221INSERT INTO v1 SET test = DEFAULT; 5222select * from v1; 5223id test 52241 0 5225drop view v1; 5226drop table t1; 5227# 5228# MDEV-5981: name resolution issues with views and multi-update 5229# in ps-protocol 5230# 5231create table t1 (id1 int primary key, val1 varchar(20)); 5232insert into t1 values (1, 'test1'); 5233create table t2 (id2 int primary key, val2 varchar(20)); 5234insert into t2 values (1, 'test2'); 5235create algorithm=merge view v1 as select id1 as id1v1, val1 as val1v1 from t1; 5236create algorithm=merge view v2 as 5237select t2.id2 as id2v2, t2.val2 as val2v2 5238from t2, v1 5239where t2.id2 = v1.id1v1; 5240prepare stmt1 from "update v2 set val2v2 = 'test19' where 1 = id2v2"; 5241execute stmt1; 5242deallocate prepare stmt1; 5243drop view v1,v2; 5244drop table t1,t2; 5245# ----------------------------------------------------------------- 5246# -- End of 5.3 tests. 5247# ----------------------------------------------------------------- 5248# 5249# MDEV-3874: Server crashes in Item_field::print on a SELECT 5250# from a MERGE view with materialization+semijoin, subquery, ORDER BY 5251# 5252SET @save_optimizer_switch_MDEV_3874=@@optimizer_switch; 5253SET optimizer_switch = 'materialization=on,semijoin=on'; 5254CREATE TABLE t1 (a INT) ENGINE=MyISAM; 5255INSERT INTO t1 VALUES (1),(7); 5256CREATE TABLE t2 (b INT) ENGINE=MyISAM; 5257INSERT INTO t2 VALUES (4),(6); 5258CREATE TABLE t3 (c INT) ENGINE=MyISAM; 5259INSERT INTO t3 VALUES (1),(2); 5260CREATE ALGORITHM=MERGE VIEW v1 AS SELECT 5261( SELECT a FROM t1 WHERE ( 1, 1 ) IN ( 5262SELECT b, c FROM t2, t3 HAVING c > 2 ) ) AS field1, 5263b + c AS field2 5264FROM t2, t3 AS table1 5265GROUP BY field1, field2 ORDER BY field1; 5266Warnings: 5267Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm) 5268SELECT * FROM v1; 5269field1 field2 5270NULL 5 5271NULL 7 5272NULL 6 5273NULL 8 5274drop view v1; 5275drop table t1,t2,t3; 5276SET optimizer_switch=@save_optimizer_switch_MDEV_3874; 5277CREATE TABLE `t1` ( 5278`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 5279`f0` int(11) unsigned NOT NULL DEFAULT '0', 5280`f1` int(11) unsigned NOT NULL DEFAULT '0', 5281PRIMARY KEY (`id`), 5282UNIQUE KEY `id` (`id`) 5283); 5284CREATE TABLE `t2` ( 5285`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 5286`f02` bigint(20) unsigned NOT NULL DEFAULT '0', 5287`f03` int(11) unsigned NOT NULL DEFAULT '0', 5288PRIMARY KEY (`id`), 5289UNIQUE KEY `id` (`id`) 5290); 5291CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `v1` AS 5292SELECT 5293`t1`.`f0` AS `f0`, 5294`t1`.`f1` AS `f1`, 5295`t2`.`f02` AS `f02`, 5296`t2`.`f03` AS `f03` 5297FROM 5298(`t1` LEFT JOIN `t2` ON((`t1`.`id` = `t2`.`f02`))); 5299CREATE FUNCTION `f1`( 5300p0 BIGINT(20) UNSIGNED 5301) 5302RETURNS bigint(20) unsigned 5303DETERMINISTIC 5304CONTAINS SQL 5305SQL SECURITY DEFINER 5306COMMENT '' 5307BEGIN 5308DECLARE k0 INTEGER UNSIGNED DEFAULT 0; 5309DECLARE lResult INTEGER UNSIGNED DEFAULT 0; 5310SET k0 = 0; 5311WHILE k0 < 1 DO 5312SELECT COUNT(*) as `f00` INTO lResult FROM `v1` WHERE `v1`.`f0` = p0; -- BUG 5313SET k0 = k0 + 1; 5314END WHILE; 5315RETURN(k0); 5316END| 5317SELECT `f1`(1); 5318`f1`(1) 53191 5320SELECT `f1`(1); 5321`f1`(1) 53221 5323SELECT `f1`(1); 5324`f1`(1) 53251 5326SELECT `f1`(1); 5327`f1`(1) 53281 5329DROP FUNCTION f1; 5330DROP VIEW v1; 5331DROP TABLE t1, t2; 5332create view v1 as select 1; 5333FOUND 1 /mariadb-version/ in v1.frm 5334drop view v1; 5335# 5336# MDEV-7260: Crash in get_best_combination when executing multi-table 5337# UPDATE with nested views 5338# 5339CREATE TABLE `t1` (`id` bigint(20)); 5340INSERT INTO `t1` VALUES (1),(2); 5341CREATE TABLE `t2` (`id` bigint(20)); 5342CREATE TABLE `t3` (`id` bigint(20), `flag` tinyint(4)); 5343create view v1 as select id from t1; 5344create view v2 as select t2.* from (t2 left join v1 using (id)); 5345update t3 left join v2 using (id) set flag=flag+1; 5346drop view v2, v1; 5347drop table t1, t2, t3; 5348# 5349# MDEV-7207 - ALTER VIEW does not change ALGORITM 5350# 5351create table t1 (a int, b int); 5352create algorithm=temptable view v2 (c) as select b+1 from t1; 5353show create view v2; 5354View Create View character_set_client collation_connection 5355v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 5356alter algorithm=undefined view v2 (c) as select b+1 from t1; 5357show create view v2; 5358View Create View character_set_client collation_connection 5359v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 5360alter algorithm=merge view v2 (c) as select b+1 from t1; 5361show create view v2; 5362View Create View character_set_client collation_connection 5363v2 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 5364drop view v2; 5365drop table t1; 5366# 5367# MDEV-8554: Server crashes in base_list_iterator::next_fast on 1st execution of PS with a multi-table update 5368# 5369CREATE TABLE t1 (a INT) ENGINE=MyISAM; 5370INSERT INTO t1 VALUES (1),(2); 5371CREATE TABLE t2 (b INT) ENGINE=MyISAM; 5372INSERT INTO t2 VALUES (3),(4); 5373CREATE TABLE t3 (c INT) ENGINE=MyISAM; 5374INSERT INTO t3 VALUES (5),(6); 5375CREATE OR REPLACE ALGORITHM=MERGE VIEW v3 AS SELECT * FROM t3; 5376PREPARE stmt FROM 'UPDATE t1, t2 SET a = 1 WHERE a IN ( SELECT 0 FROM t3 )'; 5377UPDATE t1, t2 SET a = 1 WHERE a IN ( SELECT 0 FROM v3 ); 5378EXECUTE stmt; 5379DROP TABLE t1, t2, t3; 5380DROP VIEW v3; 5381# 5382# MDEV-8632: Segmentation fault on INSERT 5383# 5384CREATE TABLE `t1` ( 5385`id` int(10) unsigned NOT NULL, 5386`r` float NOT NULL, 5387PRIMARY KEY (`id`) 5388) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 5389create view v1 as select id, if(r=r,1,2) as d from t1; 5390create view v2 as 5391select id, 5392d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d as p 5393from v1; 5394insert into t1 (id, r) 5395select id,p from 5396( 5397select id, 5398d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d as p 5399from ( 5400select id, if(r=r,1,2) as d 5401from t1 5402) a 5403) b 5404on duplicate key update r=p; 5405insert into t1 (id, r) 5406select id,p from v2 5407on duplicate key update r=p; 5408prepare stmt from "insert into t1 (id, r) select id,p from v2 on duplicate key update r=p"; 5409execute stmt; 5410execute stmt; 5411deallocate prepare stmt; 5412drop view v1,v2; 5413drop table `t1`; 5414create table t1 (a int, b int); 5415create view v1 as select a+b from t1; 5416alter table v1 check partition p1; 5417Table Op Msg_type Msg_text 5418test.v1 check Error 'test.v1' is not of type 'BASE TABLE' 5419test.v1 check status Operation failed 5420drop view v1; 5421drop table t1; 5422# 5423# MDEV-10419: crash in mariadb 10.1.16-MariaDB-1~trusty 5424# 5425CREATE TABLE t1 (c1 CHAR(13)); 5426CREATE TABLE t2 (c2 CHAR(13)); 5427CREATE FUNCTION f() RETURNS INT RETURN 0; 5428CREATE OR REPLACE VIEW v1 AS select f() from t1 where c1 in (select c2 from t2); 5429DROP FUNCTION f; 5430SHOW CREATE VIEW v1; 5431View Create View character_set_client collation_connection 5432v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `f`() AS `f()` from `t1` where `test`.`t1`.`c1` in (select `test`.`t2`.`c2` from `t2`) latin1 latin1_swedish_ci 5433Warnings: 5434Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 5435drop view v1; 5436drop table t1,t2; 5437# 5438# MDEV-12099: usage of mergeable view with LEFT JOIN 5439# that can be converted to INNER JOIN 5440# 5441create table t1 (a int, b int, key(a)) engine=myisam; 5442insert into t1 values 5443(3,20), (7,10), (2,10), (4,30), (8,70), 5444(7,70), (9,100), (9,60), (8,80), (7,60); 5445create table t2 (c int, d int, key (c)) engine=myisam; 5446insert into t2 values 5447(50,100), (20, 200), (10,300), 5448(150,100), (120, 200), (110,300), 5449(250,100), (220, 200), (210,300); 5450create table t3(e int, f int not null, key(e), unique (f)) engine=myisam; 5451insert into t3 values 5452(100, 3), (300, 5), (400, 4), (300,7), 5453(300,2), (600, 13), (800, 15), (700, 14), 5454(600, 23), (800, 25), (700, 24); 5455create view v1 as 5456select * from t2 left join t3 on t3.e=t2.d where t3.f is not null; 5457select * 5458from t1 left join v1 on v1.c=t1.b 5459where t1.a < 5; 5460a b c d e f 54612 10 10 300 300 5 54622 10 10 300 300 7 54632 10 10 300 300 2 54643 20 NULL NULL NULL NULL 54654 30 NULL NULL NULL NULL 5466select * 5467from t1 left join ( t2 left join t3 on t3.e=t2.d ) 5468on t2.c=t1.b and t3.f is not null 5469where t1.a < 5; 5470a b c d e f 54712 10 10 300 300 5 54722 10 10 300 300 7 54732 10 10 300 300 2 54743 20 NULL NULL NULL NULL 54754 30 NULL NULL NULL NULL 5476explain extended 5477select * 5478from t1 left join v1 on v1.c=t1.b 5479where t1.a < 5; 5480id select_type table type possible_keys key key_len ref rows filtered Extra 54811 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 54821 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 54831 SIMPLE t3 ref f,e e 5 test.t2.d 2 100.00 Using where 5484Warnings: 5485Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t3`.`e` = `test`.`t2`.`d` and `test`.`t3`.`f` is not null and `test`.`t1`.`b` is not null and `test`.`t2`.`d` is not null) where `test`.`t1`.`a` < 5 5486explain extended 5487select * 5488from t1 left join ( t2 left join t3 on t3.e=t2.d ) 5489on t2.c=t1.b and t3.f is not null 5490where t1.a < 5; 5491id select_type table type possible_keys key key_len ref rows filtered Extra 54921 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 54931 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 54941 SIMPLE t3 ref f,e e 5 test.t2.d 2 100.00 Using where 5495Warnings: 5496Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t3`.`e` = `test`.`t2`.`d` and `test`.`t3`.`f` is not null and `test`.`t1`.`b` is not null and `test`.`t2`.`d` is not null) where `test`.`t1`.`a` < 5 5497explain extended 5498select * 5499from t1 left join v1 on v1.c=t1.b and v1.f=t1.a 5500where t1.a < 5; 5501id select_type table type possible_keys key key_len ref rows filtered Extra 55021 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 55031 SIMPLE t3 eq_ref f,e f 4 test.t1.a 1 100.00 Using where 55041 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 5505Warnings: 5506Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t3`.`f` = `test`.`t1`.`a` and `test`.`t2`.`d` = `test`.`t3`.`e` and `test`.`t1`.`a` is not null and `test`.`t1`.`a` is not null and `test`.`t1`.`b` is not null) where `test`.`t1`.`a` < 5 5507explain extended 5508select * 5509from t1 left join ( t2 left join t3 on t3.e=t2.d ) 5510on t2.c=t1.b and t3.f=t1.a and t3.f is not null 5511where t1.a < 5; 5512id select_type table type possible_keys key key_len ref rows filtered Extra 55131 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 55141 SIMPLE t3 eq_ref f,e f 4 test.t1.a 1 100.00 Using where 55151 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 5516Warnings: 5517Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`c` = `test`.`t1`.`b` and `test`.`t3`.`f` = `test`.`t1`.`a` and `test`.`t2`.`d` = `test`.`t3`.`e` and `test`.`t1`.`a` is not null and `test`.`t1`.`a` is not null and `test`.`t1`.`b` is not null) where `test`.`t1`.`a` < 5 5518drop view v1; 5519drop table t1,t2,t3; 5520# 5521# MDEV-11240: Server crashes in check_view_single_update or 5522# Assertion `derived->table' failed in mysql_derived_merge_for_insert 5523# 5524CREATE TABLE t3 (a INT); 5525CREATE ALGORITHM = MERGE VIEW v1 AS SELECT t2.a FROM t3 AS t1, t3 AS t2; 5526CREATE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM v1; 5527PREPARE stmt FROM 'REPLACE INTO v2 SELECT a FROM t3'; 5528ERROR HY000: Can not insert into join view 'test.v2' without fields list 5529drop view v1,v2; 5530drop table t3; 5531# 5532# MDEV-14619: VIEW and GROUP_CONCAT 5533# 5534CREATE TABLE t1 (str text); 5535INSERT INTO t1 VALUES ("My"),("SQL"); 5536CREATE VIEW v1 AS SELECT GROUP_CONCAT(str SEPARATOR '\\') FROM t1; 5537SELECT * FROM v1; 5538GROUP_CONCAT(str SEPARATOR '\\') 5539My\SQL 5540SHOW CREATE VIEW v1; 5541View Create View character_set_client collation_connection 5542v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select group_concat(`t1`.`str` separator '\\') AS `GROUP_CONCAT(str SEPARATOR '\\')` from `t1` latin1 latin1_swedish_ci 5543drop view v1; 5544drop table t1; 5545CREATE TABLE IF NOT EXISTS t0 (f0 INT); 5546CREATE TABLE IF NOT EXISTS t1 (f1 INT); 5547CREATE TABLE IF NOT EXISTS t2 (f2 INT); 5548CREATE TABLE IF NOT EXISTS t3 (f3 INT); 5549CREATE TABLE IF NOT EXISTS t4 (f4 INT); 5550CREATE TABLE IF NOT EXISTS t5 (f5 INT); 5551CREATE TABLE IF NOT EXISTS t6 (f6 INT); 5552CREATE TABLE IF NOT EXISTS t7 (f7 INT); 5553CREATE TABLE IF NOT EXISTS t8 (f8 INT); 5554CREATE TABLE IF NOT EXISTS t9 (f9 INT); 5555CREATE TABLE IF NOT EXISTS t10 (f10 INT); 5556CREATE TABLE IF NOT EXISTS t11 (f11 INT); 5557CREATE TABLE IF NOT EXISTS t12 (f12 INT); 5558CREATE TABLE IF NOT EXISTS t13 (f13 INT); 5559CREATE TABLE IF NOT EXISTS t14 (f14 INT); 5560CREATE TABLE IF NOT EXISTS t15 (f15 INT); 5561CREATE TABLE IF NOT EXISTS t16 (f16 INT); 5562CREATE TABLE IF NOT EXISTS t17 (f17 INT); 5563CREATE TABLE IF NOT EXISTS t18 (f18 INT); 5564CREATE TABLE IF NOT EXISTS t19 (f19 INT); 5565CREATE TABLE IF NOT EXISTS t20 (f20 INT); 5566CREATE TABLE IF NOT EXISTS t21 (f21 INT); 5567CREATE TABLE IF NOT EXISTS t22 (f22 INT); 5568CREATE TABLE IF NOT EXISTS t23 (f23 INT); 5569CREATE TABLE IF NOT EXISTS t24 (f24 INT); 5570CREATE TABLE IF NOT EXISTS t25 (f25 INT); 5571CREATE TABLE IF NOT EXISTS t26 (f26 INT); 5572CREATE TABLE IF NOT EXISTS t27 (f27 INT); 5573CREATE TABLE IF NOT EXISTS t28 (f28 INT); 5574CREATE TABLE IF NOT EXISTS t29 (f29 INT); 5575CREATE TABLE IF NOT EXISTS t30 (f30 INT); 5576CREATE TABLE IF NOT EXISTS t31 (f31 INT); 5577CREATE TABLE IF NOT EXISTS t32 (f32 INT); 5578CREATE TABLE IF NOT EXISTS t33 (f33 INT); 5579CREATE TABLE IF NOT EXISTS t34 (f34 INT); 5580CREATE TABLE IF NOT EXISTS t35 (f35 INT); 5581CREATE TABLE IF NOT EXISTS t36 (f36 INT); 5582CREATE TABLE IF NOT EXISTS t37 (f37 INT); 5583CREATE TABLE IF NOT EXISTS t38 (f38 INT); 5584CREATE TABLE IF NOT EXISTS t39 (f39 INT); 5585CREATE TABLE IF NOT EXISTS t40 (f40 INT); 5586CREATE TABLE IF NOT EXISTS t41 (f41 INT); 5587CREATE TABLE IF NOT EXISTS t42 (f42 INT); 5588CREATE TABLE IF NOT EXISTS t43 (f43 INT); 5589CREATE TABLE IF NOT EXISTS t44 (f44 INT); 5590CREATE TABLE IF NOT EXISTS t45 (f45 INT); 5591CREATE TABLE IF NOT EXISTS t46 (f46 INT); 5592CREATE TABLE IF NOT EXISTS t47 (f47 INT); 5593CREATE TABLE IF NOT EXISTS t48 (f48 INT); 5594CREATE TABLE IF NOT EXISTS t49 (f49 INT); 5595CREATE TABLE IF NOT EXISTS t50 (f50 INT); 5596CREATE TABLE IF NOT EXISTS t51 (f51 INT); 5597CREATE TABLE IF NOT EXISTS t52 (f52 INT); 5598CREATE TABLE IF NOT EXISTS t53 (f53 INT); 5599CREATE TABLE IF NOT EXISTS t54 (f54 INT); 5600CREATE TABLE IF NOT EXISTS t55 (f55 INT); 5601CREATE TABLE IF NOT EXISTS t56 (f56 INT); 5602CREATE TABLE IF NOT EXISTS t57 (f57 INT); 5603CREATE TABLE IF NOT EXISTS t58 (f58 INT); 5604CREATE TABLE IF NOT EXISTS t59 (f59 INT); 5605CREATE TABLE IF NOT EXISTS t60 (f60 INT); 5606CREATE OR REPLACE VIEW v60 AS SELECT * FROM t60; 5607EXPLAIN 5608SELECT t0.* 5609FROM t0 5610JOIN t1 5611ON t1.f1 = t0.f0 5612LEFT JOIN t2 5613ON t0.f0 = t2.f2 5614LEFT JOIN t3 5615ON t0.f0 = t3.f3 5616LEFT JOIN t4 5617ON t0.f0 = t4.f4 5618LEFT JOIN t5 5619ON t4.f4 = t5.f5 5620LEFT JOIN t6 5621ON t0.f0 = t6.f6 5622LEFT JOIN t7 5623ON t0.f0 = t7.f7 5624LEFT JOIN t8 5625ON t0.f0 = t8.f8 5626LEFT JOIN t9 5627ON t0.f0 = t9.f9 5628LEFT JOIN t10 5629ON t0.f0 = t10.f10 5630LEFT JOIN t11 5631ON t0.f0 = t11.f11 5632LEFT JOIN t12 5633ON t0.f0 = t12.f12 5634LEFT JOIN t13 5635ON t0.f0 = t13.f13 5636LEFT JOIN t14 5637ON t0.f0 = t14.f14 5638LEFT JOIN t15 5639ON t0.f0 = t15.f15 5640LEFT JOIN t16 5641ON t0.f0 = t16.f16 5642LEFT JOIN t17 5643ON t0.f0 = t17.f17 5644LEFT JOIN t18 5645ON t0.f0 = t18.f18 5646LEFT JOIN t19 5647ON t18.f18 = t19.f19 5648LEFT JOIN t20 5649ON t20.f20 = t19.f19 5650LEFT JOIN t21 5651ON t20.f20 = t21.f21 5652LEFT JOIN t22 5653ON t19.f19 = t22.f22 5654LEFT JOIN t23 5655ON t23.f23 = t0.f0 5656LEFT JOIN t24 5657ON t24.f24 = t23.f23 5658LEFT JOIN t25 5659ON t0.f0 = t25.f25 5660LEFT JOIN t26 5661ON t26.f26 = t0.f0 5662LEFT JOIN t27 5663ON t27.f27 = t0.f0 5664LEFT JOIN t28 5665ON t0.f0 = t28.f28 5666LEFT JOIN t29 5667ON t0.f0 = t29.f29 5668LEFT JOIN t30 5669ON t30.f30 = t0.f0 5670LEFT JOIN t31 5671ON t0.f0 = t31.f31 5672LEFT JOIN t32 5673ON t32.f32 = t31.f31 5674LEFT JOIN t33 5675ON t33.f33 = t0.f0 5676LEFT JOIN t34 5677ON t33.f33 = t34.f34 5678LEFT JOIN t35 5679ON t33.f33 = t35.f35 5680LEFT JOIN t36 5681ON t36.f36 = t0.f0 5682LEFT JOIN t37 5683ON t32.f32 = t37.f37 5684LEFT JOIN t38 5685ON t31.f31 = t38.f38 5686LEFT JOIN t39 5687ON t39.f39 = t0.f0 5688LEFT JOIN t40 5689ON t40.f40 = t39.f39 5690LEFT JOIN t41 5691ON t41.f41 = t0.f0 5692LEFT JOIN t42 5693ON t42.f42 = t41.f41 5694LEFT JOIN t43 5695ON t43.f43 = t41.f41 5696LEFT JOIN t44 5697ON t44.f44 = t0.f0 5698LEFT JOIN t45 5699ON t45.f45 = t0.f0 5700LEFT JOIN t46 5701ON t46.f46 = t0.f0 5702LEFT JOIN t47 5703ON t47.f47 = t0.f0 5704LEFT JOIN t48 5705ON t48.f48 = t0.f0 5706LEFT JOIN t49 5707ON t0.f0 = t49.f49 5708LEFT JOIN t50 5709ON t0.f0 = t50.f50 5710LEFT JOIN t51 5711ON t0.f0 = t51.f51 5712LEFT JOIN t52 5713ON t52.f52 = t0.f0 5714LEFT JOIN t53 5715ON t53.f53 = t0.f0 5716LEFT JOIN t54 5717ON t54.f54 = t0.f0 5718LEFT JOIN t55 5719ON t55.f55 = t0.f0 5720LEFT JOIN t56 5721ON t56.f56 = t0.f0 5722LEFT JOIN t57 5723ON t57.f57 = t0.f0 5724LEFT JOIN t58 5725ON t58.f58 = t57.f57 5726LEFT JOIN t59 5727ON t36.f36 = t59.f59 5728LEFT JOIN v60 5729ON t36.f36 = v60.f60 5730; 5731id select_type table type possible_keys key key_len ref rows Extra 57321 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 57332 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table 5734drop table t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, 5735t10, t11, t12, t13, t14, t15, t16, t17, t18, 5736t19, t20, t21, t22, t23, t24, t25, t26, t27, 5737t28, t29, t30, t31, t32, t33, t34, t35, t36, 5738t37, t38, t39, t40, t41, t42, t43, t44, t45, 5739t46, t47, t48, t49, t50, t51, t52, t53, t54, 5740t55, t56, t57, t58, t59,t60; 5741drop view v60; 5742# 5743# MDEV-15572: view.test, server crash with --big-tables=1 5744# 5745set tmp_memory_table_size=0; 5746CREATE TABLE t1 ( f1 int , f2 int , f3 int , f4 int); 5747CREATE TABLE t2 ( f1 int , f2 int , f3 int , f4 int); 5748CREATE VIEW v1 AS 5749SELECT t2.f1, t1.f2, t2.f3, t2.f4 FROM (t1 JOIN t2); 5750REPLACE INTO v1 (f1, f2, f3, f4) 5751SELECT f1, f2, f3, f4 FROM t1; 5752ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 5753drop view v1; 5754drop table t1, t2; 5755set tmp_memory_table_size=default; 5756# ----------------------------------------------------------------- 5757# -- End of 5.5 tests. 5758# ----------------------------------------------------------------- 5759# some subqueries in SELECT list test 5760create table t1 (a int, b int); 5761create table t2 (a int, b int); 5762insert into t1 values (1,2), (3,4), (3,3), (5,6), (7,8), (9,10); 5763insert into t2 values (1,2), (3,4), (3,3), (5,6), (7,8), (9,10); 5764create algorithm=merge view v1 as select t1.a as a, (select max(b) from t2 where t1.a=t2.a) as c from t1; 5765explain extended 5766select * from v1; 5767id select_type table type possible_keys key key_len ref rows filtered Extra 57681 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 57693 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5770Warnings: 5771Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5772Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>((/* select#3 */ select max(`test`.`t2`.`b`) from `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a`)) AS `c` from `test`.`t1` 5773select * from v1; 5774a c 57751 2 57763 4 57773 4 57785 6 57797 8 57809 10 5781explain extended 5782select * from t2, v1 where t2.a=v1.a; 5783id select_type table type possible_keys key key_len ref rows filtered Extra 57841 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 57851 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 57863 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5787Warnings: 5788Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5789Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>((/* select#3 */ select max(`test`.`t2`.`b`) from `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a`)) AS `c` from `test`.`t2` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`a` 5790select * from t2, v1 where t2.a=v1.a; 5791a b a c 57921 2 1 2 57933 4 3 4 57943 3 3 4 57953 4 3 4 57963 3 3 4 57975 6 5 6 57987 8 7 8 57999 10 9 10 5800explain extended 5801select * from t1, v1 where t1.a=v1.a; 5802id select_type table type possible_keys key key_len ref rows filtered Extra 58031 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 58041 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 58053 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5806Warnings: 5807Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5808Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>((/* select#3 */ select max(`test`.`t2`.`b`) from `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a`)) AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t1`.`a` 5809select * from t1, v1 where t1.a=v1.a; 5810a b a c 58111 2 1 2 58123 4 3 4 58133 3 3 4 58143 4 3 4 58153 3 3 4 58165 6 5 6 58177 8 7 8 58189 10 9 10 5819explain extended 5820select * from t1, v1 where t1.b=v1.c; 5821id select_type table type possible_keys key key_len ref rows filtered Extra 58221 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 58231 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 58243 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5825Warnings: 5826Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5827Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>((/* select#3 */ select max(`test`.`t2`.`b`) from `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a`)) AS `c` from `test`.`t1` join `test`.`t1` where `test`.`t1`.`b` = <expr_cache><`test`.`t1`.`a`>((/* select#3 */ select max(`test`.`t2`.`b`) from `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a`)) 5828select * from t1, v1 where t1.b=v1.c; 5829a b a c 58301 2 1 2 58313 4 3 4 58323 4 3 4 58335 6 5 6 58347 8 7 8 58359 10 9 10 5836explain extended 5837select * from t2, t1, v1 where t1.a=t2.a and t1.a=v1.a; 5838id select_type table type possible_keys key key_len ref rows filtered Extra 58391 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 58401 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 58411 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (incremental, BNL join) 58423 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5843Warnings: 5844Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5845Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>((/* select#3 */ select max(`test`.`t2`.`b`) from `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a`)) AS `c` from `test`.`t2` join `test`.`t1` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a` 5846select * from t2, t1, v1 where t1.a=t2.a and t1.a=v1.a; 5847a b a b a c 58481 2 1 2 1 2 58493 4 3 4 3 4 58503 3 3 4 3 4 58513 4 3 3 3 4 58523 3 3 3 3 4 58533 4 3 4 3 4 58543 3 3 4 3 4 58553 4 3 3 3 4 58563 3 3 3 3 4 58575 6 5 6 5 6 58587 8 7 8 7 8 58599 10 9 10 9 10 5860drop view v1; 5861drop table t1,t2; 5862create table t1 (i int not null); 5863insert into t1 values (1),(2); 5864create table t2 (j int not null); 5865insert into t2 values (11),(12); 5866create algorithm=merge view v3 as select t1.* from t2 left join t1 on (t2.j = t1.i); 5867prepare stmt from 'select count(v3.i) from t1, v3'; 5868execute stmt; 5869count(v3.i) 58700 5871execute stmt; 5872count(v3.i) 58730 5874drop table t1, t2; 5875drop view v3; 5876# 5877# MDEV-8525: mariadb 10.0.20 crashing when data is read by Kodi 5878# media center (http://kodi.tv). 5879# 5880CREATE TABLE `t1` ( 5881`idSong` int(11) NOT NULL AUTO_INCREMENT, 5882`idAlbum` int(11) DEFAULT NULL, 5883`idPath` int(11) DEFAULT NULL, 5884`strArtists` text, 5885`strGenres` text, 5886`strTitle` varchar(512) DEFAULT NULL, 5887`iTrack` int(11) DEFAULT NULL, 5888`iDuration` int(11) DEFAULT NULL, 5889`iYear` int(11) DEFAULT NULL, 5890`dwFileNameCRC` text, 5891`strFileName` text, 5892`strMusicBrainzTrackID` text, 5893`iTimesPlayed` int(11) DEFAULT NULL, 5894`iStartOffset` int(11) DEFAULT NULL, 5895`iEndOffset` int(11) DEFAULT NULL, 5896`idThumb` int(11) DEFAULT NULL, 5897`lastplayed` varchar(20) DEFAULT NULL, 5898`rating` char(1) DEFAULT '0', 5899`comment` text, 5900`mood` text, 5901PRIMARY KEY (`idSong`), 5902UNIQUE KEY `idxSong7` (`idAlbum`,`strMusicBrainzTrackID`(36)), 5903KEY `idxSong` (`strTitle`(255)), 5904KEY `idxSong1` (`iTimesPlayed`), 5905KEY `idxSong2` (`lastplayed`), 5906KEY `idxSong3` (`idAlbum`), 5907KEY `idxSong6` (`idPath`,`strFileName`(255)) 5908) DEFAULT CHARSET=utf8; 5909INSERT INTO `t1` VALUES (1,1,1,'strArtists1','strGenres1','strTitle1',1,100,2000,NULL,'strFileName1','strMusicBrainzTrackID1',0,0,0,NULL,NULL,'0','',''),(2,2,2,'strArtists2','strGenres2','strTitle2',2,200,2001,NULL,'strFileName2','strMusicBrainzTrackID2',0,0,0,NULL,NULL,'0','',''); 5910CREATE TABLE `t2` ( 5911`idAlbum` int(11) NOT NULL AUTO_INCREMENT, 5912`strAlbum` varchar(256) DEFAULT NULL, 5913`strMusicBrainzAlbumID` text, 5914`strArtists` text, 5915`strGenres` text, 5916`iYear` int(11) DEFAULT NULL, 5917`idThumb` int(11) DEFAULT NULL, 5918`bCompilation` int(11) NOT NULL DEFAULT '0', 5919`strMoods` text, 5920`strStyles` text, 5921`strThemes` text, 5922`strReview` text, 5923`strImage` text, 5924`strLabel` text, 5925`strType` text, 5926`iRating` int(11) DEFAULT NULL, 5927`lastScraped` varchar(20) DEFAULT NULL, 5928`dateAdded` varchar(20) DEFAULT NULL, 5929`strReleaseType` text, 5930PRIMARY KEY (`idAlbum`), 5931UNIQUE KEY `idxAlbum_2` (`strMusicBrainzAlbumID`(36)), 5932KEY `idxAlbum` (`strAlbum`(255)), 5933KEY `idxAlbum_1` (`bCompilation`) 5934) DEFAULT CHARSET=utf8; 5935INSERT INTO `t2` VALUES (1,'strAlbum1','strMusicBrainzAlbumID1','strArtists1','strGenres1',2000,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'album'); 5936CREATE TABLE `t3` ( 5937`idArtist` int(11) DEFAULT NULL, 5938`idAlbum` int(11) DEFAULT NULL, 5939`strJoinPhrase` text, 5940`boolFeatured` int(11) DEFAULT NULL, 5941`iOrder` int(11) DEFAULT NULL, 5942`strArtist` text, 5943UNIQUE KEY `idxAlbumArtist_1` (`idAlbum`,`idArtist`), 5944UNIQUE KEY `idxAlbumArtist_2` (`idArtist`,`idAlbum`), 5945KEY `idxAlbumArtist_3` (`boolFeatured`) 5946) DEFAULT CHARSET=utf8; 5947INSERT INTO `t3` VALUES (1,1,'',0,0,'strArtist1'); 5948CREATE TABLE `t4` ( 5949`idArtist` int(11) NOT NULL AUTO_INCREMENT, 5950`strArtist` varchar(256) DEFAULT NULL, 5951`strMusicBrainzArtistID` text, 5952`strBorn` text, 5953`strFormed` text, 5954`strGenres` text, 5955`strMoods` text, 5956`strStyles` text, 5957`strInstruments` text, 5958`strBiography` text, 5959`strDied` text, 5960`strDisbanded` text, 5961`strYearsActive` text, 5962`strImage` text, 5963`strFanart` text, 5964`lastScraped` varchar(20) DEFAULT NULL, 5965`dateAdded` varchar(20) DEFAULT NULL, 5966PRIMARY KEY (`idArtist`), 5967UNIQUE KEY `idxArtist1` (`strMusicBrainzArtistID`(36)), 5968KEY `idxArtist` (`strArtist`(255)) 5969) DEFAULT CHARSET=utf8; 5970INSERT INTO `t4` VALUES (1,'strArtist1','strMusicBrainzArtistID',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); 5971CREATE VIEW `v1` AS select `t2`.`idAlbum` AS `idAlbum`,`t2`.`strAlbum` AS `strAlbum`,`t2`.`strMusicBrainzAlbumID` AS `strMusicBrainzAlbumID`,`t2`.`strArtists` AS `strArtists`,`t2`.`strGenres` AS `strGenres`,`t2`.`iYear` AS `iYear`,`t2`.`strMoods` AS `strMoods`,`t2`.`strStyles` AS `strStyles`,`t2`.`strThemes` AS `strThemes`,`t2`.`strReview` AS `strReview`,`t2`.`strLabel` AS `strLabel`,`t2`.`strType` AS `strType`,`t2`.`strImage` AS `strImage`,`t2`.`iRating` AS `iRating`,`t2`.`bCompilation` AS `bCompilation`,(select min(`t1`.`iTimesPlayed`) from `t1` where (`t1`.`idAlbum` = `t2`.`idAlbum`)) AS `iTimesPlayed`,`t2`.`strReleaseType` AS `strReleaseType` from `t2`; 5972CREATE VIEW `v2` AS select `t3`.`idAlbum` AS `idAlbum`,`t3`.`idArtist` AS `idArtist`,`t4`.`strArtist` AS `strArtist`,`t4`.`strMusicBrainzArtistID` AS `strMusicBrainzArtistID`,`t3`.`boolFeatured` AS `boolFeatured`,`t3`.`strJoinPhrase` AS `strJoinPhrase`,`t3`.`iOrder` AS `iOrder` from (`t3` join `t4` on((`t3`.`idArtist` = `t4`.`idArtist`))); 5973SELECT v1.*,v2.* FROM v1 LEFT JOIN v2 ON v1.idAlbum = v2.idAlbum WHERE v1.idAlbum = 1 ORDER BY v2.iOrder; 5974idAlbum strAlbum strMusicBrainzAlbumID strArtists strGenres iYear strMoods strStyles strThemes strReview strLabel strType strImage iRating bCompilation iTimesPlayed strReleaseType idAlbum idArtist strArtist strMusicBrainzArtistID boolFeatured strJoinPhrase iOrder 59751 strAlbum1 strMusicBrainzAlbumID1 strArtists1 strGenres1 2000 NULL NULL NULL NULL NULL NULL NULL NULL 0 0 album 1 1 strArtist1 strMusicBrainzArtistID 0 0 5976drop view v1,v2; 5977drop table t1,t2,t3,t4; 5978# 5979# MDEV-8913: Derived queries with same column names as final 5980# projection causes issues when using Order By 5981# 5982create table t1 (field int); 5983insert into t1 values (10),(5),(3),(8),(20); 5984SELECT sq.f2 AS f1, sq.f1 AS f2 5985FROM ( SELECT field AS f1, 1 AS f2 FROM t1) AS sq 5986ORDER BY sq.f1; 5987f1 f2 59881 3 59891 5 59901 8 59911 10 59921 20 5993create view v1 as SELECT field AS f1, 1 AS f2 FROM t1; 5994SELECT sq.f2 AS f1, sq.f1 AS f2 5995FROM v1 AS sq 5996ORDER BY sq.f1; 5997f1 f2 59981 3 59991 5 60001 8 60011 10 60021 20 6003drop view v1; 6004create table t2 SELECT field AS f1, 1 AS f2 FROM t1; 6005SELECT 6006sq.f2 AS f1, 6007sq.f1 AS f2 6008FROM t2 AS sq 6009ORDER BY sq.f1; 6010f1 f2 60111 3 60121 5 60131 8 60141 10 60151 20 6016drop table t1, t2; 6017SELECT 1 FROM (SELECT 1 as a) AS b HAVING (SELECT `SOME_GARBAGE`.b.a)=1; 6018ERROR 42S22: Unknown column 'SOME_GARBAGE.b.a' in 'field list' 6019# 6020# MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 6021# FOR UPDATE 6022# 6023CREATE TABLE t1 (a INT); 6024insert into t1 values (1),(2); 6025CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE; 6026SHOW CREATE VIEW v1; 6027View Create View character_set_client collation_connection 6028v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` for update latin1 latin1_swedish_ci 6029select * from v1; 6030a 60311 60322 6033DROP VIEW v1; 6034CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE; 6035SHOW CREATE VIEW v1; 6036View Create View character_set_client collation_connection 6037v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` lock in share mode latin1 latin1_swedish_ci 6038select * from v1; 6039a 60401 60412 6042DROP VIEW v1; 6043DROP TABLE t1; 6044# 6045# MDEV-8642: WHERE Clause not applied on View - Empty result set returned 6046# 6047CREATE TABLE `t1` ( 6048`id` int(20) NOT NULL AUTO_INCREMENT, 6049`use_case` int(11) DEFAULT NULL, 6050`current_deadline` date DEFAULT NULL, 6051`ts_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 6052PRIMARY KEY (`id`), 6053UNIQUE KEY `id_UNIQUE` (`id`) 6054) ENGINE=MyISAM AUTO_INCREMENT=13976 DEFAULT CHARSET=latin1; 6055INSERT INTO `t1` VALUES (1,10,'2015-12-18','2015-08-18 08:38:16'); 6056INSERT INTO `t1` VALUES (2,20,'2015-10-18','2015-08-18 08:43:30'); 6057CREATE VIEW v1 AS SELECT 6058use_case as use_case_id, 6059( 6060SELECT 6061deadline_sub.current_deadline 6062FROM 6063t1 deadline_sub 6064WHERE 6065deadline_sub.use_case = use_case_id 6066AND ts_create = (SELECT 6067MIN(ts_create) 6068FROM 6069t1 startdate_sub 6070WHERE 6071startdate_sub.use_case = use_case_id 6072) 6073) AS InitialDeadline 6074FROM 6075t1; 6076SELECT * FROM v1 where use_case_id = 10; 6077use_case_id InitialDeadline 607810 2015-12-18 6079drop view v1; 6080drop table t1; 6081# 6082# MDEV-12666: CURRENT_ROLE() and DATABASE() does not work in a view 6083# 6084# DATABASE() fails only when the initial view creation features a NULL 6085# default database. 6086# 6087# CREATE, USE and DROP database so that we have no "default" database. 6088# 6089CREATE DATABASE temporary; 6090USE temporary; 6091DROP DATABASE temporary; 6092SELECT DATABASE(); 6093DATABASE() 6094NULL 6095CREATE VIEW test.v_no_db AS SELECT DATABASE() = 'temporary_two'; 6096SHOW CREATE VIEW test.v_no_db; 6097View Create View character_set_client collation_connection 6098v_no_db CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `test`.`v_no_db` AS select database() = 'temporary_two' AS `DATABASE() = 'temporary_two'` latin1 latin1_swedish_ci 6099PREPARE prepared_no_database FROM "SELECT DATABASE() = 'temporary_two'"; 6100# 6101# All statements should return NULL 6102# 6103EXECUTE prepared_no_database; 6104DATABASE() = 'temporary_two' 6105NULL 6106SELECT DATABASE() = 'temporary_two'; 6107DATABASE() = 'temporary_two' 6108NULL 6109SELECT * FROM test.v_no_db; 6110DATABASE() = 'temporary_two' 6111NULL 6112CREATE DATABASE temporary_two; 6113USE temporary_two; 6114CREATE VIEW test.v_with_db AS SELECT DATABASE() = 'temporary_two'; 6115PREPARE prepared_with_database FROM "SELECT DATABASE() = 'temporary_two'"; 6116# 6117# All statements should return 1; 6118# 6119SELECT DATABASE() = 'temporary_two'; 6120DATABASE() = 'temporary_two' 61211 6122SELECT * FROM test.v_no_db; 6123DATABASE() = 'temporary_two' 61241 6125SELECT * FROM test.v_with_db; 6126DATABASE() = 'temporary_two' 61271 6128EXECUTE prepared_with_database; 6129DATABASE() = 'temporary_two' 61301 6131# 6132# Prepared statements maintain default database to be the same 6133# during on creation so this should return NULL still. 6134# See MySQL bug #25843 6135# 6136EXECUTE prepared_no_database; 6137DATABASE() = 'temporary_two' 6138NULL 6139DROP DATABASE temporary_two; 6140DROP VIEW test.v_no_db; 6141DROP VIEW test.v_with_db; 6142USE test; 6143# ----------------------------------------------------------------- 6144# -- End of 10.0 tests. 6145# ----------------------------------------------------------------- 6146SET optimizer_switch=@save_optimizer_switch; 6147# 6148# Start of 10.1 tests 6149# 6150# 6151# MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin 6152# 6153CREATE TABLE t1 (a varchar(10) character set cp1251 collate cp1251_ukrainian_ci, KEY (a)) ; 6154INSERT INTO t1 VALUES ('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'),('MM'),('`1'); 6155CREATE VIEW v1 AS SELECT * FROM t1; 6156SELECT * FROM t1 WHERE a <> 0 AND a = ' 1'; 6157a 6158Warnings: 6159Warning 1292 Truncated incorrect DOUBLE value: '`1' 6160SELECT * FROM v1 WHERE a <> 0 AND a = ' 1'; 6161a 6162Warnings: 6163Warning 1292 Truncated incorrect DOUBLE value: '`1' 6164DROP VIEW v1; 6165DROP TABLE t1; 6166CREATE TABLE t1 (a ENUM('5','6')); 6167INSERT INTO t1 VALUES ('5'),('6'); 6168CREATE VIEW v1 AS SELECT * FROM t1; 6169SELECT * FROM t1 WHERE a='5' AND a<2; 6170a 61715 6172SELECT * FROM v1 WHERE a='5' AND a<2; 6173a 61745 6175DROP VIEW v1; 6176DROP TABLE t1; 6177# 6178# MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number2 6179# 6180CREATE TABLE t1 (a varchar(10) character set cp1251 collate cp1251_ukrainian_ci, KEY (a)); 6181INSERT INTO t1 VALUES ('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'),('MM'),('`1'); 6182CREATE VIEW v1 AS SELECT * FROM t1; 6183SELECT * FROM t1 WHERE a <> 0 AND a = ' 1'; 6184a 6185Warnings: 6186Warning 1292 Truncated incorrect DOUBLE value: '`1' 6187SELECT * FROM v1 WHERE a <> 0 AND a = ' 1'; 6188a 6189Warnings: 6190Warning 1292 Truncated incorrect DOUBLE value: '`1' 6191DROP VIEW v1; 6192DROP TABLE t1; 6193CREATE TABLE t1 (a ENUM('5','6')); 6194INSERT INTO t1 VALUES ('5'),('6'); 6195CREATE VIEW v1 AS SELECT * FROM t1; 6196SELECT * FROM t1 WHERE a='5' AND a<2; 6197a 61985 6199SELECT * FROM v1 WHERE a='5' AND a<2; 6200a 62015 6202DROP VIEW v1; 6203DROP TABLE t1; 6204# 6205# MDEV-8742 Wrong result for SELECT..WHERE view_latin1_swedish_ci_field='a' COLLATE latin1_bin 6206# 6207CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1); 6208INSERT INTO t1 VALUES ('a'),('A'); 6209CREATE VIEW v1 AS SELECT * FROM t1 WHERE a='a'; 6210SELECT * FROM v1 WHERE a=_latin1'a' COLLATE latin1_bin; 6211a 6212a 6213DROP VIEW v1; 6214DROP TABLE t1; 6215# 6216# MDEV-9701: CREATE VIEW with GROUP BY or ORDER BY and constant 6217# produces invalid definition 6218# 6219CREATE TABLE t1 ( i INT ); 6220INSERT INTO t1 VALUES (1),(2); 6221CREATE VIEW v1 AS 6222SELECT 3 AS three, COUNT(*) FROM t1 GROUP BY three; 6223show create view v1; 6224View Create View character_set_client collation_connection 6225v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 3 AS `three`,count(0) AS `COUNT(*)` from `t1` group by '' latin1 latin1_swedish_ci 6226SELECT * FROM v1; 6227three COUNT(*) 62283 2 6229drop view v1; 6230drop table t1; 6231# 6232# MDEV-12819: order by ordering expression changed to empty string 6233# when creatin view with union 6234# 6235create table t1 (t1col1 int, t1col2 int,t1col3 int ); 6236create table t2 (t2col1 int, t2col2 int, t2col3 int); 6237create view v1 as 6238select t1col1,t1col2,t1col3 from t1 6239union all 6240select t2col1,t2col2,t2col3 from t2 6241order by 2,3; 6242show create view v1; 6243View Create View character_set_client collation_connection 6244v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`t1col1` AS `t1col1`,`t1`.`t1col2` AS `t1col2`,`t1`.`t1col3` AS `t1col3` from `t1` union all select `t2`.`t2col1` AS `t2col1`,`t2`.`t2col2` AS `t2col2`,`t2`.`t2col3` AS `t2col3` from `t2` order by 2,3 latin1 latin1_swedish_ci 6245select * from v1; 6246t1col1 t1col2 t1col3 6247drop view v1; 6248drop table t1,t2; 6249# 6250# End of 10.1 tests 6251# 6252# 6253# Start of 10.2 tests 6254# 6255# Checking that SHOW CREATE VIEW preserve parentheses 6256CREATE TABLE t1 (a INT); 6257INSERT INTO t1 VALUES (10),(20),(30); 6258CREATE VIEW v1 AS SELECT 1 AS a UNION SELECT a FROM t1; 6259SHOW CREATE VIEW v1; 6260View Create View character_set_client collation_connection 6261v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `a` union select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci 6262SELECT * FROM v1; 6263a 62641 626510 626620 626730 6268DROP VIEW v1; 6269CREATE VIEW v1 AS SELECT 1 AS a UNION SELECT a FROM t1 LIMIT 1; 6270SHOW CREATE VIEW v1; 6271View Create View character_set_client collation_connection 6272v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `a` union select `t1`.`a` AS `a` from `t1` limit 1 latin1 latin1_swedish_ci 6273SELECT * FROM v1; 6274a 62751 6276DROP VIEW v1; 6277CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1); 6278SHOW CREATE VIEW v1; 6279View Create View character_set_client collation_connection 6280v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `a` union (select `t1`.`a` AS `a` from `t1`) latin1 latin1_swedish_ci 6281SELECT * FROM v1; 6282a 62831 628410 628520 628630 6287DROP VIEW v1; 6288CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1 LIMIT 1); 6289SHOW CREATE VIEW v1; 6290View Create View character_set_client collation_connection 6291v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `a` union (select `t1`.`a` AS `a` from `t1` limit 1) latin1 latin1_swedish_ci 6292SELECT * FROM v1; 6293a 62941 629510 6296DROP VIEW v1; 6297CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1) LIMIT 1; 6298SHOW CREATE VIEW v1; 6299View Create View character_set_client collation_connection 6300v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `a` union (select `t1`.`a` AS `a` from `t1`) limit 1 latin1 latin1_swedish_ci 6301SELECT * FROM v1; 6302a 63031 6304DROP VIEW v1; 6305DROP TABLE t1; 6306# 6307# MDEV-9408 CREATE TABLE SELECT MAX(int_column) creates different columns for table vs view 6308# 6309CREATE TABLE t1 ( 6310id int(11) NOT NULL PRIMARY KEY, 6311country varchar(32), 6312code int(11) default NULL 6313); 6314INSERT INTO t1 VALUES (1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); 6315CREATE VIEW v1 AS SELECT * FROM t1; 6316CREATE TABLE t2 AS 6317SELECT code, COUNT(DISTINCT country), MAX(id) FROM t1 GROUP BY code ORDER BY MAX(id); 6318SHOW CREATE TABLE t2; 6319Table Create Table 6320t2 CREATE TABLE `t2` ( 6321 `code` int(11) DEFAULT NULL, 6322 `COUNT(DISTINCT country)` bigint(21) NOT NULL, 6323 `MAX(id)` int(11) 6324) ENGINE=MyISAM DEFAULT CHARSET=latin1 6325CREATE TABLE t3 AS 6326SELECT code, COUNT(DISTINCT country), MAX(id) FROM v1 GROUP BY code ORDER BY MAX(id); 6327SHOW CREATE TABLE t3; 6328Table Create Table 6329t3 CREATE TABLE `t3` ( 6330 `code` int(11) DEFAULT NULL, 6331 `COUNT(DISTINCT country)` bigint(21) NOT NULL, 6332 `MAX(id)` int(11) DEFAULT NULL 6333) ENGINE=MyISAM DEFAULT CHARSET=latin1 6334DROP VIEW v1; 6335DROP TABLE t1,t2,t3; 6336# 6337# MDEV-3944: Allow derived tables in VIEWS 6338# 6339create table t1 (s1 int); 6340insert into t1 values (1),(2),(3); 6341CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1>1) AS x; 6342CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1<3) AS x; 6343select * from v1; 6344s1 63452 63463 6347select * from v2; 6348s1 63491 63502 6351select * from v1 natural join v2; 6352s1 63532 6354select * from v1 natural join t1; 6355s1 63562 63573 6358select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; 6359s1 63602 6361select * from v1 left join v2 on (v1.s1=v2.s1); 6362s1 s1 63632 2 63643 NULL 6365select * from v1 left join t1 on (v1.s1=t1.s1); 6366s1 s1 63672 2 63683 3 6369select * from t1 left join v2 on (t1.s1=v2.s1); 6370s1 s1 63711 1 63722 2 63733 NULL 6374select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); 6375s1 s1 63762 2 63773 NULL 6378select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); 6379s1 s1 63802 2 63813 NULL 6382drop view v1,v2; 6383CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6384< 100) as xx WHERE s1>1) AS x; 6385CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6386> -100) as xx WHERE s1<3) AS x; 6387insert into t1 values (200),(-200); 6388select * from t1; 6389s1 6390-200 63911 63922 6393200 63943 6395select * from v1; 6396s1 63972 63983 6399select * from v2; 6400s1 64011 64022 6403select * from v1 natural join v2; 6404s1 64052 6406select * from v1 natural join t1; 6407s1 64082 64093 6410select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; 6411s1 64122 6413select * from v1 left join v2 on (v1.s1=v2.s1); 6414s1 s1 64152 2 64163 NULL 6417select * from v1 left join t1 on (v1.s1=t1.s1); 6418s1 s1 64192 2 64203 3 6421select * from t1 left join v2 on (t1.s1=v2.s1); 6422s1 s1 6423-200 NULL 64241 1 64252 2 6426200 NULL 64273 NULL 6428select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); 6429s1 s1 64302 2 64313 NULL 6432select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); 6433s1 s1 64342 2 6435200 NULL 64363 NULL 6437drop view v1,v2; 6438CREATE algorithm=temptable VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6439< 100) as xx WHERE s1>1) AS x; 6440CREATE algorithm=temptable VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6441> -100) as xx WHERE s1<3) AS x; 6442select * from t1; 6443s1 6444-200 64451 64462 6447200 64483 6449select * from v1; 6450s1 64512 64523 6453select * from v2; 6454s1 64551 64562 6457select * from v1 natural join v2; 6458s1 64592 6460select * from v1 natural join t1; 6461s1 64622 64633 6464select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; 6465s1 64662 6467select * from v1 left join v2 on (v1.s1=v2.s1); 6468s1 s1 64692 2 64703 NULL 6471select * from v1 left join t1 on (v1.s1=t1.s1); 6472s1 s1 64732 2 64743 3 6475select * from t1 left join v2 on (t1.s1=v2.s1); 6476s1 s1 6477-200 NULL 64781 1 64792 2 6480200 NULL 64813 NULL 6482select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); 6483s1 s1 64842 2 64853 NULL 6486select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); 6487s1 s1 64882 2 6489200 NULL 64903 NULL 6491drop view v1,v2; 6492CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6493< 100) as xx WHERE s1>1) AS x; 6494insert into v1 values (-300); 6495ERROR HY000: The target table v1 of the INSERT is not insertable-into 6496update v1 set s1=s1+1; 6497ERROR HY000: The target table v1 of the UPDATE is not updatable 6498drop view v1; 6499CREATE VIEW v1 AS SELECT s1,s2 FROM (SELECT s1 as s2 FROM t1 WHERE s1 < 6500100) x, t1 WHERE t1.s1=x.s2; 6501select * from v1; 6502s1 s2 65031 1 65042 2 65053 3 6506-200 -200 6507insert into v1 (s1) values (-300); 6508update v1 set s1=s1+1; 6509select * from v1; 6510s1 s2 65112 2 65123 3 65134 4 6514-199 -199 6515-299 -299 6516select * from t1; 6517s1 65182 65193 65204 6521200 6522-199 6523-299 6524insert into v1(s2) values (-300); 6525ERROR HY000: The target table v1 of the INSERT is not insertable-into 6526update v1 set s2=s2+1; 6527ERROR HY000: The target table v1 of the UPDATE is not updatable 6528drop view v1; 6529CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1 6530< 100) AS x; 6531insert into v1 values (-300); 6532ERROR HY000: The target table v1 of the INSERT is not insertable-into 6533update v1 set s1=s1+1; 6534ERROR HY000: The target table v1 of the UPDATE is not updatable 6535drop view v1; 6536CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6537< 100) as xx WHERE s1>1) AS x; 6538insert into v1 values (-300); 6539ERROR HY000: The target table v1 of the INSERT is not insertable-into 6540update v1 set s1=s1+1; 6541ERROR HY000: The target table v1 of the UPDATE is not updatable 6542create view v2 as select * from v1; 6543insert into v2 values (-300); 6544ERROR HY000: The target table v2 of the INSERT is not insertable-into 6545update v2 set s1=s1+1; 6546ERROR HY000: The target table v2 of the UPDATE is not updatable 6547drop view v1, v2; 6548drop table t1; 6549# 6550# MDEV-9671:Wrong result upon select from a view with a FROM subquery 6551# 6552CREATE TABLE t1 (i INT); 6553INSERT INTO t1 VALUES (3),(2); 6554CREATE TABLE t2 (j INT); 6555INSERT INTO t2 VALUES (8),(3),(3); 6556CREATE TABLE t3 (k INT); 6557INSERT INTO t3 VALUES (1),(8); 6558CREATE VIEW v1 AS SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); 6559show create view v1; 6560View Create View character_set_client collation_connection 6561v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`i` AS `i`,`alias1`.`j` AS `j` from (`test`.`t1` left join (select `test`.`t2`.`j` AS `j` from (`test`.`t2` join `test`.`t3` on(`test`.`t3`.`k` = `test`.`t2`.`j`))) `alias1` on(`test`.`t1`.`i` = `alias1`.`j`)) latin1 latin1_swedish_ci 6562SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); 6563i j 65643 NULL 65652 NULL 6566SELECT * FROM v1; 6567i j 65683 NULL 65692 NULL 6570DROP VIEW v1; 6571DROP TABLE t1, t2, t3; 6572# 6573# MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 6574# FOR UPDATE 6575# 6576CREATE TABLE t1 (a INT); 6577insert into t1 values (1),(2); 6578CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE; 6579SHOW CREATE VIEW v1; 6580View Create View character_set_client collation_connection 6581v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` for update latin1 latin1_swedish_ci 6582select * from v1; 6583a 65841 65852 6586DROP VIEW v1; 6587CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE; 6588SHOW CREATE VIEW v1; 6589View Create View character_set_client collation_connection 6590v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` lock in share mode latin1 latin1_swedish_ci 6591select * from v1; 6592a 65931 65942 6595DROP VIEW v1; 6596DROP TABLE t1; 6597# 6598# MDEV-10724:Assertion `vcol_table == 0 || vcol_table == table' 6599# failed in fill_record(THD*, TABLE*, List<Item>&, List<Item>&, 6600# bool, bool) 6601# 6602CREATE TABLE t1 (f1 INT); 6603CREATE TABLE t2 (f2 INT); 6604CREATE TABLE t3 (f3 INT); 6605CREATE ALGORITHM = MERGE VIEW v AS SELECT f1, f3 FROM t1, 6606( SELECT f3 FROM t2, t3 ) AS sq; 6607INSERT INTO v (f1, f3) VALUES (1,1), (2,2); 6608ERROR HY000: Can not modify more than one base table through a join view 'test.v' 6609drop view v; 6610drop tables t1,t2,t3; 6611# 6612# MDEV-10704: Assertion `field->field->table == table_arg' 6613# failed in fill_record(THD*, TABLE*, List<Item>&, List<Item>&, 6614# bool, bool) 6615# 6616CREATE TABLE t1 (i INT); 6617CREATE TABLE t2 (j INT); 6618CREATE TABLE t3 (k INT); 6619CREATE ALGORITHM = MERGE VIEW v AS SELECT j AS f1, k AS f2 FROM ( SELECT j FROM t1, t2 ) sq, t3; 6620REPLACE INTO v (f1,f2) VALUES (1,1); 6621ERROR HY000: Can not modify more than one base table through a join view 'test.v' 6622drop view v; 6623drop table t1,t2,t3; 6624# 6625# MDEV-12379: Server crashes in TABLE_LIST::is_with_table on 6626# SHOW CREATE VIEW 6627# 6628CREATE TABLE t (i INT); 6629CREATE VIEW v AS SELECT * FROM ( SELECT * FROM t ) sq; 6630DROP TABLE IF EXISTS t; 6631SHOW CREATE VIEW v; 6632View Create View character_set_client collation_connection 6633v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `sq`.`i` AS `i` from (select `test`.`t`.`i` AS `i` from `test`.`t`) `sq` latin1 latin1_swedish_ci 6634Warnings: 6635Warning 1356 View 'test.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 6636DROP VIEW v; 6637# 6638# MDEV-13439: Database permissions are not enough to run a subquery 6639# with GROUP BY within a view 6640# 6641create database test_db; 6642use test_db; 6643create table t (i int); 6644create user foo@localhost; 6645grant all on test_db.* to foo@localhost; 6646connect con1,localhost,foo,,; 6647use test_db; 6648create view v as select * from (select i from t group by i) sq; 6649select * from v; 6650i 6651disconnect con1; 6652connection default; 6653use test; 6654drop database test_db; 6655drop user foo@localhost; 6656# 6657# MDEV-13523: Group By in a View, called within a Stored Routine 6658# causes Error Code 1356 when a non-root user runs the routine for 6659# a second time 6660# 6661CREATE DATABASE bugTest; 6662USE bugTest; 6663CREATE TABLE `procViewTable` (`id` int(10), `someText` varchar(50) NOT NULL); 6664insert into `procViewTable` values (1,'Test'), (2,'Test 2'); 6665CREATE USER 'procView'@'%'; 6666GRANT ALL PRIVILEGES ON `bugTest`.* TO 'procView'@'%'; 6667CREATE DEFINER=`procView`@`%` VIEW `procViewSimple` AS ( 6668select * from ( 6669select `id` from `bugTest`.`procViewTable` 6670 ) `innerQuery` 6671 group by `innerQuery`.`id` 6672); 6673connect con1,localhost,procView,,; 6674use bugTest; 6675prepare stmt from "SELECT * FROM procViewSimple"; 6676execute stmt; 6677id 66781 66792 6680execute stmt; 6681id 66821 66832 6684disconnect con1; 6685connection default; 6686drop user procView; 6687drop view procViewSimple; 6688drop table procViewTable; 6689use test; 6690drop database bugTest; 6691# 6692# MDEV-13436: PREPARE doesn't work as expected & throws errors but 6693# MySQL is working fine 6694# 6695create table t1 (a int); 6696insert into t1 values (1),(2); 6697SET @sql_query = " 6698 CREATE VIEW v1 AS 6699 SELECT * FROM ( 6700 SELECT CASE WHEN 1 IN (SELECT a from t1 where a < 2) THEN TRUE END AS testcase 6701 ) testalias 6702"; 6703PREPARE stmt FROM @sql_query; 6704EXECUTE stmt; 6705DEALLOCATE PREPARE stmt; 6706show create view v1; 6707View Create View character_set_client collation_connection 6708v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `testalias`.`testcase` AS `testcase` from (select case when 1 in (select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`a` < 2) then 1 end AS `testcase`) `testalias` latin1 latin1_swedish_ci 6709SELECT * FROM v1; 6710testcase 67111 6712drop view v1; 6713drop table t1; 6714# 6715# MDEV-18502: Server crash in find_field_in_tables upon 2nd execution of SP which causes ER_WRONG_GROUP_FIELD 6716# 6717CREATE TABLE t1 (id INT, f VARCHAR(1)); 6718CREATE VIEW v1 AS SELECT * FROM t1; 6719INSERT INTO t1 VALUES (1,'a'),(2,'b'); 6720CREATE PROCEDURE sp() SELECT f AS f1, MAX(id) AS f2 FROM v1 GROUP BY f1, f2 ORDER BY f1; 6721CALL sp; 6722ERROR 42000: Can't group on 'f2' 6723CALL sp; 6724ERROR 42000: Can't group on 'f2' 6725DROP PROCEDURE sp; 6726DROP VIEW v1; 6727DROP TABLE t1; 6728# 6729# MDEV-24314: create view with derived table without default database 6730# 6731drop database test; 6732create database db1; 6733create table db1.t1 (a int); 6734insert into db1.t1 values (3),(7),(1); 6735create view db1.v1 as select * from (select * from db1.t1) t; 6736show create view db1.v1; 6737View Create View character_set_client collation_connection 6738v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `db1`.`v1` AS select `t`.`a` AS `a` from (select `db1`.`t1`.`a` AS `a` from `db1`.`t1`) `t` latin1 latin1_swedish_ci 6739select * from db1.v1; 6740a 67413 67427 67431 6744drop view db1.v1; 6745prepare stmt from " 6746create view db1.v1 as select * from (select * from db1.t1) t; 6747"; 6748execute stmt; 6749deallocate prepare stmt; 6750show create view db1.v1; 6751View Create View character_set_client collation_connection 6752v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `db1`.`v1` AS select `t`.`a` AS `a` from (select `db1`.`t1`.`a` AS `a` from `db1`.`t1`) `t` latin1 latin1_swedish_ci 6753select * from db1.v1; 6754a 67553 67567 67571 6758drop view db1.v1; 6759drop table db1.t1; 6760drop database db1; 6761create database test; 6762use test; 6763# 6764# MDEV-16940: update of multi-table view returning error used in SP 6765# 6766CREATE TABLE t1 (a INT) ENGINE=MyISAM; 6767INSERT INTO t1 VALUES (1), (2); 6768CREATE TABLE t2 (b INT) ENGINE=MyISAM; 6769INSERT INTO t2 VALUES (2), (3); 6770CREATE VIEW v1 AS SELECT a, b FROM t1,t2; 6771CREATE PROCEDURE sp1() UPDATE v1 SET a = 8, b = 9; 6772CALL sp1; 6773ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 6774CALL sp1; 6775ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 6776DROP PROCEDURE sp1; 6777DROP VIEW v1; 6778DROP TABLE t1, t2; 6779# 6780# MDEV-23291: SUM column from a derived table returns invalid values 6781# 6782CREATE TABLE t1(a INT, b INT); 6783INSERT INTO t1 VALUES (1,1), (2,2); 6784CREATE view v1 AS 6785SELECT a as x, (select x) as y, (select y) as z FROM t1; 6786SELECT sum(z) FROM (SELECT a as x, (select x) as y, (select y) as z FROM t1) q; 6787sum(z) 67883 6789SELECT sum(z) FROM v1; 6790sum(z) 67913 6792DROP TABLE t1; 6793DROP VIEW v1; 6794# 6795# MDEV-26299: Some views force server (and mysqldump) to generate 6796# invalid SQL for their definitions 6797# 6798create view v1 as 6799select * from 6800(select 6801"12345678901234567890123456789012345678901234567890123456789012345") as t1; 6802drop view v1; 6803CREATE VIEW v1 AS select `t1`.`12345678901234567890123456789012345678901234567890123456789012345` AS `Name_exp_1` from (select '12345678901234567890123456789012345678901234567890123456789012345') `t1`; 6804drop view v1; 6805# 6806# MDEV-25631: view with outer reference in select used 6807# as argument of set function 6808# 6809create table t1 (c int); 6810insert into t1 values (1); 6811create view v1 as select c from t1 where (select t1.c from t1 t) = 1; 6812select * from (select sum((select * from v1)) as r) dt; 6813r 68141 6815with cte as (select c from t1 where (select t1.c from t1 t) = 1) 6816select * from (select sum((select * from cte)) as r) dt1 6817union 6818select * from (select sum((select * from cte)) as r) dt2; 6819r 68201 6821drop view v1; 6822drop table t1; 6823# 6824# End of 10.2 tests 6825# 6826# 6827# Start of 10.3 tests 6828# 6829# 6830# MDEV-13197 Parser refactoring for CREATE VIEW,TRIGGER,SP,UDF,EVENT 6831# 6832ALTER VIEW IF NOT EXISTS v1 AS SELECT 1; 6833ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF NOT EXISTS v1 AS SELECT 1' at line 1 6834# 6835# MDEV-18605: Loss of column aliases by using view and group 6836# 6837CREATE TABLE t1 (id int, foo int); 6838CREATE VIEW v1 AS SELECT id, IFNULL(foo,'') AS foo FROM t1; 6839INSERT INTO t1 (id, foo) VALUES (1,1),(2,2); 6840SELECT v.id, v.foo AS bar FROM v1 v 6841WHERE id = 2; 6842id bar 68432 2 6844SELECT v.id, v.foo AS bar FROM v1 v 6845GROUP BY v.id; 6846id bar 68471 1 68482 2 6849SELECT v.id, v.foo AS bar FROM v1 v 6850WHERE id = 2 6851GROUP BY v.id; 6852id bar 68532 2 6854Drop View v1; 6855Drop table t1; 6856# 6857# End of 10.3 tests 6858# 6859# 6860# MDEV-25206: view specification contains unknown column reference 6861# 6862CREATE TABLE t1 (a int); 6863INSERT INTO t1 VALUES (1),(2); 6864CREATE TABLE t2 (b int); 6865INSERT INTO t2 VALUES (2),(3); 6866CREATE TABLE t3 (c int); 6867CREATE VIEW v1 AS SELECT * FROM t1 JOIN t2 ON t1.x > t2.b; 6868ERROR 42S22: Unknown column 't1.x' in 'on clause' 6869INSERT INTO t3 SELECT * FROM t1 JOIN t2 ON t1.x > t2.b; 6870ERROR 42S22: Unknown column 't1.x' in 'on clause' 6871CREATE TABLE t4 AS SELECT * FROM t1 JOIN t2 ON t1.x > t2.b; 6872ERROR 42S22: Unknown column 't1.x' in 'on clause' 6873DROP TABLE t1,t2,t3; 6874# End of 10.4 tests 6875