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 HY000: 'test.t1' is not of type 'VIEW' 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 HY000: 'test.t1' is not of type 'VIEW' 2852SHOW TABLES; 2853Tables_in_test 2854t1 2855DROP TABLE t1; 2856DROP VIEW IF EXISTS v1; 2857set GLOBAL sql_mode=""; 2858set LOCAL sql_mode=""; 2859CREATE DATABASE bug21261DB; 2860USE bug21261DB; 2861connect root,localhost,root,,bug21261DB; 2862connection root; 2863CREATE TABLE t1 (x INT); 2864CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1; 2865GRANT INSERT, UPDATE ON v1 TO 'user21261'@'localhost'; 2866GRANT INSERT, UPDATE ON t1 TO 'user21261'@'localhost'; 2867CREATE TABLE t2 (y INT); 2868GRANT SELECT ON t2 TO 'user21261'@'localhost'; 2869connect user21261, localhost, user21261,, bug21261DB; 2870connection user21261; 2871INSERT INTO v1 (x) VALUES (5); 2872UPDATE v1 SET x=1; 2873connection root; 2874GRANT SELECT ON v1 TO 'user21261'@'localhost'; 2875GRANT SELECT ON t1 TO 'user21261'@'localhost'; 2876connection user21261; 2877UPDATE v1,t2 SET x=1 WHERE x=y; 2878connection root; 2879SELECT * FROM t1; 2880x 28811 2882REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user21261'@'localhost'; 2883DROP USER 'user21261'@'localhost'; 2884DROP VIEW v1; 2885DROP TABLE t1; 2886DROP DATABASE bug21261DB; 2887connection default; 2888USE test; 2889disconnect root; 2890disconnect user21261; 2891set GLOBAL sql_mode=default; 2892set LOCAL sql_mode=default; 2893create table t1 (f1 datetime); 2894create view v1 as select * from t1 where f1 between now() and now() + interval 1 minute; 2895show create view v1; 2896View Create View character_set_client collation_connection 2897v1 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 2898drop view v1; 2899drop table t1; 2900DROP TABLE IF EXISTS t1; 2901DROP VIEW IF EXISTS v1; 2902DROP VIEW IF EXISTS v2; 2903CREATE TABLE t1(a INT, b INT); 2904CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost 2905VIEW v1 AS SELECT a FROM t1; 2906ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345...' is too long for user name (should be no longer than 80) 2907CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY 2908VIEW v2 AS SELECT b FROM t1; 2909ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) 2910DROP TABLE t1; 2911DROP FUNCTION IF EXISTS f1; 2912DROP FUNCTION IF EXISTS f2; 2913DROP VIEW IF EXISTS v1, v2; 2914DROP TABLE IF EXISTS t1; 2915CREATE TABLE t1 (i INT); 2916CREATE VIEW v1 AS SELECT * FROM t1; 2917CREATE FUNCTION f1() RETURNS INT 2918BEGIN 2919INSERT INTO v1 VALUES (0); 2920RETURN 0; 2921END | 2922SELECT f1(); 2923f1() 29240 2925CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1; 2926CREATE FUNCTION f2() RETURNS INT 2927BEGIN 2928INSERT INTO v2 VALUES (0); 2929RETURN 0; 2930END | 2931SELECT f2(); 2932ERROR HY000: The target table v2 of the INSERT is not insertable-into 2933DROP FUNCTION f1; 2934DROP FUNCTION f2; 2935DROP VIEW v1, v2; 2936DROP TABLE t1; 2937CREATE TABLE t1 (s1 int); 2938CREATE VIEW v1 AS SELECT * FROM t1; 2939EXPLAIN SELECT * FROM t1; 2940id select_type table type possible_keys key key_len ref rows Extra 29411 SIMPLE t1 system NULL NULL NULL NULL 0 Const row not found 2942EXPLAIN SELECT * FROM v1; 2943id select_type table type possible_keys key key_len ref rows Extra 29441 SIMPLE t1 system NULL NULL NULL NULL 0 Const row not found 2945INSERT INTO t1 VALUES (1), (3), (2); 2946EXPLAIN SELECT * FROM t1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1); 2947id select_type table type possible_keys key key_len ref rows Extra 29481 PRIMARY t ALL NULL NULL NULL NULL 3 Using where 29492 SUBQUERY t1 ALL NULL NULL NULL NULL 3 2950EXPLAIN SELECT * FROM v1 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 t1 ALL NULL NULL NULL NULL 3 Using where 29532 SUBQUERY t1 ALL NULL NULL NULL NULL 3 2954DROP VIEW v1; 2955DROP TABLE t1; 2956create table t1 (s1 int); 2957create view v1 as select s1 as a, s1 as b from t1; 2958insert into v1 values (1,1); 2959ERROR HY000: The target table v1 of the INSERT is not insertable-into 2960update v1 set a = 5; 2961drop view v1; 2962drop table t1; 2963CREATE TABLE t1(pk int PRIMARY KEY); 2964CREATE TABLE t2(pk int PRIMARY KEY, fk int, ver int, org int); 2965CREATE ALGORITHM=MERGE VIEW v1 AS 2966SELECT t1.* 2967FROM t1 JOIN t2 2968ON t2.fk = t1.pk AND 2969t2.ver = (SELECT MAX(t.ver) FROM t2 t WHERE t.org = t2.org); 2970SHOW WARNINGS; 2971Level Code Message 2972SHOW CREATE VIEW v1; 2973View Create View character_set_client collation_connection 2974v1 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 2975DROP VIEW v1; 2976DROP TABLE t1, t2; 2977DROP FUNCTION IF EXISTS f1; 2978DROP VIEW IF EXISTS v1; 2979DROP TABLE IF EXISTS t1; 2980CREATE TABLE t1 (i INT); 2981INSERT INTO t1 VALUES (1); 2982CREATE VIEW v1 AS SELECT MAX(i) FROM t1; 2983CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW 2984SET NEW.i = (SELECT * FROM v1) + 1; 2985INSERT INTO t1 VALUES (1); 2986CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1); 2987UPDATE t1 SET i= f1(); 2988DROP FUNCTION f1; 2989DROP VIEW v1; 2990DROP TABLE t1; 2991CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL); 2992CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION; 2993INSERT INTO v1 (val) VALUES (2); 2994INSERT INTO v1 (val) VALUES (4); 2995INSERT INTO v1 (val) VALUES (6); 2996ERROR 44000: CHECK OPTION failed `test`.`v1` 2997UPDATE v1 SET val=6 WHERE id=2; 2998ERROR 44000: CHECK OPTION failed `test`.`v1` 2999DROP VIEW v1; 3000DROP TABLE t1; 3001DROP VIEW IF EXISTS v1, v2; 3002DROP TABLE IF EXISTS t1; 3003CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT); 3004CREATE VIEW v1 AS SELECT j FROM t1; 3005CREATE VIEW v2 AS SELECT * FROM t1; 3006INSERT INTO t1 (j) VALUES (1); 3007SELECT LAST_INSERT_ID(); 3008LAST_INSERT_ID() 30091 3010INSERT INTO v1 (j) VALUES (2); 3011# LAST_INSERT_ID() should not change. 3012SELECT LAST_INSERT_ID(); 3013LAST_INSERT_ID() 30141 3015INSERT INTO v2 (j) VALUES (3); 3016# LAST_INSERT_ID() should be updated. 3017SELECT LAST_INSERT_ID(); 3018LAST_INSERT_ID() 30193 3020INSERT INTO v1 (j) SELECT j FROM t1; 3021# LAST_INSERT_ID() should not change. 3022SELECT LAST_INSERT_ID(); 3023LAST_INSERT_ID() 30243 3025SELECT * FROM t1; 3026i j 30271 1 30282 2 30293 3 30304 1 30315 2 30326 3 3033DROP VIEW v1, v2; 3034DROP TABLE t1; 3035CREATE VIEW v AS SELECT !0 * 5 AS x FROM DUAL; 3036SHOW CREATE VIEW v; 3037View Create View character_set_client collation_connection 3038v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select !0 * 5 AS `x` latin1 latin1_swedish_ci 3039SELECT !0 * 5 AS x FROM DUAL; 3040x 30415 3042SELECT * FROM v; 3043x 30445 3045DROP VIEW v; 3046DROP VIEW IF EXISTS v1; 3047CREATE VIEW v1 AS SELECT 'The\ZEnd'; 3048SELECT * FROM v1; 3049TheEnd 3050TheEnd 3051SHOW CREATE VIEW v1; 3052View Create View character_set_client collation_connection 3053v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 'The\ZEnd' AS `TheEnd` latin1 latin1_swedish_ci 3054DROP VIEW v1; 3055CREATE TABLE t1 (mydate DATETIME); 3056INSERT INTO t1 VALUES 3057('2007-01-01'), ('2007-01-02'), ('2007-01-30'), ('2007-01-31'); 3058CREATE VIEW v1 AS SELECT mydate from t1; 3059SELECT * FROM t1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31'; 3060mydate 30612007-01-01 00:00:00 30622007-01-02 00:00:00 30632007-01-30 00:00:00 30642007-01-31 00:00:00 3065SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31'; 3066mydate 30672007-01-01 00:00:00 30682007-01-02 00:00:00 30692007-01-30 00:00:00 30702007-01-31 00:00:00 3071DROP VIEW v1; 3072DROP TABLE t1; 3073CREATE TABLE t1 (a int); 3074CREATE TABLE t2 (b int); 3075INSERT INTO t1 VALUES (1), (2); 3076INSERT INTO t2 VALUES (1), (2); 3077CREATE VIEW v1 AS 3078SELECT t2.b FROM t1,t2 WHERE t1.a = t2.b WITH CHECK OPTION; 3079SELECT * FROM v1; 3080b 30811 30822 3083UPDATE v1 SET b=3; 3084ERROR 44000: CHECK OPTION failed `test`.`v1` 3085SELECT * FROM v1; 3086b 30871 30882 3089SELECT * FROM t1; 3090a 30911 30922 3093SELECT * FROM t2; 3094b 30951 30962 3097DROP VIEW v1; 3098DROP TABLE t1,t2; 3099create table t1(f1 int, f2 int); 3100insert into t1 values(1,2),(1,3),(1,1),(2,3),(2,1),(2,2); 3101select * from t1; 3102f1 f2 31031 2 31041 3 31051 1 31062 3 31072 1 31082 2 3109create view v1 as select * from t1 order by f2; 3110select * from v1; 3111f1 f2 31121 1 31132 1 31141 2 31152 2 31161 3 31172 3 3118explain extended select * from v1; 3119id select_type table type possible_keys key key_len ref rows filtered Extra 31201 SIMPLE t1 ALL NULL NULL NULL NULL 6 100.00 Using filesort 3121Warnings: 3122Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f2` 3123select * from v1 order by f1; 3124f1 f2 31251 2 31261 3 31271 1 31282 3 31292 1 31302 2 3131explain extended select * from v1 order by f1; 3132id select_type table type possible_keys key key_len ref rows filtered Extra 31331 SIMPLE t1 ALL NULL NULL NULL NULL 6 100.00 Using filesort 3134Warnings: 3135Note 1926 View 'test'.'v1' ORDER BY clause ignored because there is other ORDER BY clause already 3136Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f1` 3137drop view v1; 3138drop table t1; 3139CREATE TABLE t1 ( 3140id int(11) NOT NULL PRIMARY KEY, 3141country varchar(32), 3142code int(11) default NULL 3143); 3144INSERT INTO t1 VALUES 3145(1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); 3146CREATE VIEW v1 AS SELECT * FROM t1; 3147SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id); 3148code COUNT(DISTINCT country) 3149200 1 3150100 2 3151SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id); 3152code COUNT(DISTINCT country) 3153200 1 3154100 2 3155DROP VIEW v1; 3156DROP TABLE t1; 3157DROP VIEW IF EXISTS v1; 3158SELECT * FROM (SELECT 1) AS t into @w; 3159Warnings: 3160Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 3161CREATE VIEW v1 AS SELECT * FROM (SELECT 1) AS t into @w; 3162ERROR 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 3163# Previously the following would fail. 3164SELECT * FROM (SELECT 1) AS t into @w; 3165Warnings: 3166Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 3167drop view if exists view_24532_a; 3168drop view if exists view_24532_b; 3169drop table if exists table_24532; 3170create table table_24532 ( 3171a int, 3172b bigint, 3173c int(4), 3174d bigint(48) 3175); 3176create view view_24532_a as 3177select 3178a IS TRUE, 3179a IS NOT TRUE, 3180a IS FALSE, 3181a IS NOT FALSE, 3182a IS UNKNOWN, 3183a IS NOT UNKNOWN, 3184a is NULL, 3185a IS NOT NULL, 3186ISNULL(a), 3187b IS TRUE, 3188b IS NOT TRUE, 3189b IS FALSE, 3190b IS NOT FALSE, 3191b IS UNKNOWN, 3192b IS NOT UNKNOWN, 3193b is NULL, 3194b IS NOT NULL, 3195ISNULL(b), 3196c IS TRUE, 3197c IS NOT TRUE, 3198c IS FALSE, 3199c IS NOT FALSE, 3200c IS UNKNOWN, 3201c IS NOT UNKNOWN, 3202c is NULL, 3203c IS NOT NULL, 3204ISNULL(c), 3205d IS TRUE, 3206d IS NOT TRUE, 3207d IS FALSE, 3208d IS NOT FALSE, 3209d IS UNKNOWN, 3210d IS NOT UNKNOWN, 3211d is NULL, 3212d IS NOT NULL, 3213ISNULL(d) 3214from table_24532; 3215describe view_24532_a; 3216Field Type Null Key Default Extra 3217a IS TRUE int(1) NO 0 3218a IS NOT TRUE int(1) NO 0 3219a IS FALSE int(1) NO 0 3220a IS NOT FALSE int(1) NO 0 3221a IS UNKNOWN int(1) NO 0 3222a IS NOT UNKNOWN int(1) NO 0 3223a is NULL int(1) NO 0 3224a IS NOT NULL int(1) NO 0 3225ISNULL(a) int(1) NO 0 3226b IS TRUE int(1) NO 0 3227b IS NOT TRUE int(1) NO 0 3228b IS FALSE int(1) NO 0 3229b IS NOT FALSE int(1) NO 0 3230b IS UNKNOWN int(1) NO 0 3231b IS NOT UNKNOWN int(1) NO 0 3232b is NULL int(1) NO 0 3233b IS NOT NULL int(1) NO 0 3234ISNULL(b) int(1) NO 0 3235c IS TRUE int(1) NO 0 3236c IS NOT TRUE int(1) NO 0 3237c IS FALSE int(1) NO 0 3238c IS NOT FALSE int(1) NO 0 3239c IS UNKNOWN int(1) NO 0 3240c IS NOT UNKNOWN int(1) NO 0 3241c is NULL int(1) NO 0 3242c IS NOT NULL int(1) NO 0 3243ISNULL(c) int(1) NO 0 3244d IS TRUE int(1) NO 0 3245d IS NOT TRUE int(1) NO 0 3246d IS FALSE int(1) NO 0 3247d IS NOT FALSE int(1) NO 0 3248d IS UNKNOWN int(1) NO 0 3249d IS NOT UNKNOWN int(1) NO 0 3250d is NULL int(1) NO 0 3251d IS NOT NULL int(1) NO 0 3252ISNULL(d) int(1) NO 0 3253create view view_24532_b as 3254select 3255a IS TRUE, 3256if(ifnull(a, 0), 1, 0) as old_istrue, 3257a IS NOT TRUE, 3258if(ifnull(a, 0), 0, 1) as old_isnottrue, 3259a IS FALSE, 3260if(ifnull(a, 1), 0, 1) as old_isfalse, 3261a IS NOT FALSE, 3262if(ifnull(a, 1), 1, 0) as old_isnotfalse 3263from table_24532; 3264describe view_24532_b; 3265Field Type Null Key Default Extra 3266a IS TRUE int(1) NO 0 3267old_istrue int(1) NO 0 3268a IS NOT TRUE int(1) NO 0 3269old_isnottrue int(1) NO 0 3270a IS FALSE int(1) NO 0 3271old_isfalse int(1) NO 0 3272a IS NOT FALSE int(1) NO 0 3273old_isnotfalse int(1) NO 0 3274show create view view_24532_b; 3275View Create View character_set_client collation_connection 3276view_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 3277insert into table_24532 values (0, 0, 0, 0); 3278select * from view_24532_b; 3279a IS TRUE old_istrue a IS NOT TRUE old_isnottrue a IS FALSE old_isfalse a IS NOT FALSE old_isnotfalse 32800 0 1 1 1 1 0 0 3281update table_24532 set a=1; 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 32841 1 0 0 0 0 1 1 3285update table_24532 set a=NULL; 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 32880 0 1 1 0 0 1 1 3289drop view view_24532_a; 3290drop view view_24532_b; 3291drop table table_24532; 3292CREATE TABLE t1 ( 3293lid int NOT NULL PRIMARY KEY, 3294name char(10) NOT NULL 3295); 3296INSERT INTO t1 (lid, name) VALUES 3297(1, 'YES'), (2, 'NO'); 3298CREATE TABLE t2 ( 3299id int NOT NULL PRIMARY KEY, 3300gid int NOT NULL, 3301lid int NOT NULL, 3302dt date 3303); 3304INSERT INTO t2 (id, gid, lid, dt) VALUES 3305(1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'), 3306(3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02'); 3307SELECT DISTINCT t2.gid AS lgid, 3308(SELECT t1.name FROM t1, t2 3309WHERE t1.lid = t2.lid AND t2.gid = lgid 3310ORDER BY t2.dt DESC LIMIT 1 3311) as clid 3312FROM t2; 3313lgid clid 33141 NO 33152 YES 3316CREATE VIEW v1 AS 3317SELECT DISTINCT t2.gid AS lgid, 3318(SELECT t1.name FROM t1, t2 3319WHERE t1.lid = t2.lid AND t2.gid = lgid 3320ORDER BY t2.dt DESC LIMIT 1 3321) as clid 3322FROM t2; 3323SELECT * FROM v1; 3324lgid clid 33251 NO 33262 YES 3327DROP VIEW v1; 3328DROP table t1,t2; 3329CREATE TABLE t1 (a INT); 3330INSERT INTO t1 VALUES (1),(2),(3); 3331CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a; 3332SELECT * FROM t1 UNION SELECT * FROM v1; 3333a 33341 33352 33363 3337EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1; 3338id select_type table type possible_keys key key_len ref rows Extra 33391 PRIMARY t1 ALL NULL NULL NULL NULL 3 33402 UNION t1 ALL NULL NULL NULL NULL 3 3341NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 3342SELECT * FROM v1 UNION SELECT * FROM t1; 3343a 33441 33452 33463 3347EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1; 3348id select_type table type possible_keys key key_len ref rows Extra 33491 PRIMARY t1 ALL NULL NULL NULL NULL 3 33502 UNION t1 ALL NULL NULL NULL NULL 3 3351NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 3352SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; 3353a 33541 33552 33563 3357EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; 3358id select_type table type possible_keys key key_len ref rows Extra 33591 PRIMARY t1 ALL NULL NULL NULL NULL 3 33602 UNION t1 ALL NULL NULL NULL NULL 3 3361NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL Using filesort 3362DROP VIEW v1; 3363DROP TABLE t1; 3364CREATE VIEW v1 AS SELECT CAST( 1.23456789 AS DECIMAL( 7,5 ) ) AS col; 3365SELECT * FROM v1; 3366col 33671.23457 3368DESCRIBE v1; 3369Field Type Null Key Default Extra 3370col decimal(7,5) NO 0.00000 3371DROP VIEW v1; 3372CREATE VIEW v1 AS SELECT CAST(1.23456789 AS DECIMAL(8,0)) AS col; 3373SHOW CREATE VIEW v1; 3374View Create View character_set_client collation_connection 3375v1 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 3376DROP VIEW v1; 3377CREATE TABLE t1 (a INT); 3378CREATE TABLE t2 (b INT, c INT DEFAULT 0); 3379INSERT INTO t1 (a) VALUES (1), (2); 3380INSERT INTO t2 (b) VALUES (1), (2); 3381CREATE VIEW v1 AS SELECT t2.b,t2.c FROM t1, t2 3382WHERE t1.a=t2.b AND t2.b < 3 WITH CHECK OPTION; 3383SELECT * FROM v1; 3384b c 33851 0 33862 0 3387UPDATE v1 SET c=1 WHERE b=1; 3388SELECT * FROM v1; 3389b c 33901 1 33912 0 3392DROP VIEW v1; 3393DROP TABLE t1,t2; 3394CREATE TABLE t1 (id int); 3395CREATE TABLE t2 (id int, c int DEFAULT 0); 3396INSERT INTO t1 (id) VALUES (1); 3397INSERT INTO t2 (id) VALUES (1); 3398CREATE VIEW v1 AS 3399SELECT t2.c FROM t1, t2 3400WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; 3401UPDATE v1 SET c=1; 3402DROP VIEW v1; 3403DROP TABLE t1,t2; 3404CREATE TABLE t1 (a1 INT, c INT DEFAULT 0); 3405CREATE TABLE t2 (a2 INT); 3406CREATE TABLE t3 (a3 INT); 3407CREATE TABLE t4 (a4 INT); 3408INSERT INTO t1 (a1) VALUES (1),(2); 3409INSERT INTO t2 (a2) VALUES (1),(2); 3410INSERT INTO t3 (a3) VALUES (1),(2); 3411INSERT INTO t4 (a4) VALUES (1),(2); 3412CREATE VIEW v1 AS 3413SELECT t1.a1, t1.c FROM t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3 3414WITH CHECK OPTION; 3415SELECT * FROM v1; 3416a1 c 34171 0 34182 0 3419UPDATE v1 SET c=3; 3420ERROR 44000: CHECK OPTION failed `test`.`v1` 3421PREPARE t FROM 'UPDATE v1 SET c=3'; 3422EXECUTE t; 3423ERROR 44000: CHECK OPTION failed `test`.`v1` 3424EXECUTE t; 3425ERROR 44000: CHECK OPTION failed `test`.`v1` 3426INSERT INTO v1(a1, c) VALUES (3, 3); 3427ERROR 44000: CHECK OPTION failed `test`.`v1` 3428UPDATE v1 SET c=1 WHERE a1=1; 3429SELECT * FROM v1; 3430a1 c 34311 1 34322 0 3433SELECT * FROM t1; 3434a1 c 34351 1 34362 0 3437CREATE VIEW v2 AS SELECT t1.a1, t1.c 3438FROM (t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3) 3439JOIN (t3 JOIN t4 ON t3.a3=t4.a4) 3440ON t2.a2=t3.a3 WITH CHECK OPTION; 3441SELECT * FROM v2; 3442a1 c 34431 1 34442 0 3445UPDATE v2 SET c=3; 3446ERROR 44000: CHECK OPTION failed `test`.`v2` 3447PREPARE t FROM 'UPDATE v2 SET c=3'; 3448EXECUTE t; 3449ERROR 44000: CHECK OPTION failed `test`.`v2` 3450EXECUTE t; 3451ERROR 44000: CHECK OPTION failed `test`.`v2` 3452INSERT INTO v2(a1, c) VALUES (3, 3); 3453ERROR 44000: CHECK OPTION failed `test`.`v2` 3454UPDATE v2 SET c=2 WHERE a1=1; 3455SELECT * FROM v2; 3456a1 c 34571 2 34582 0 3459SELECT * FROM t1; 3460a1 c 34611 2 34622 0 3463DROP VIEW v1,v2; 3464DROP TABLE t1,t2,t3,t4; 3465CREATE TABLE t1 (a int, b int); 3466INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2); 3467CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1; 3468SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; 3469b SUM(a) 34703 4 3471EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; 3472id select_type table type possible_keys key key_len ref rows Extra 34731 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where 3474SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; 3475a SUM(b) 34761 6 34772 3 3478EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; 3479id select_type table type possible_keys key key_len ref rows Extra 34801 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where; Using temporary; Using filesort 3481SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; 3482a SUM(b) 34831 10 3484EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; 3485id select_type table type possible_keys key key_len ref rows Extra 34861 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where 3487DROP VIEW v1; 3488DROP TABLE t1; 3489CREATE TABLE t1 ( 3490person_id int NOT NULL PRIMARY KEY, 3491username varchar(40) default NULL, 3492status_flg char(1) NOT NULL default 'A' 3493); 3494CREATE TABLE t2 ( 3495person_role_id int NOT NULL auto_increment PRIMARY KEY, 3496role_id int NOT NULL, 3497person_id int NOT NULL, 3498INDEX idx_person_id (person_id), 3499INDEX idx_role_id (role_id) 3500); 3501CREATE TABLE t3 ( 3502role_id int NOT NULL auto_increment PRIMARY KEY, 3503role_name varchar(100) default NULL, 3504app_name varchar(40) NOT NULL, 3505INDEX idx_app_name(app_name) 3506); 3507CREATE VIEW v1 AS 3508SELECT profile.person_id AS person_id 3509FROM t1 profile, t2 userrole, t3 role 3510WHERE userrole.person_id = profile.person_id AND 3511role.role_id = userrole.role_id AND 3512profile.status_flg = 'A' 3513 ORDER BY profile.person_id,role.app_name,role.role_name; 3514INSERT INTO t1 VALUES 3515(6,'Sw','A'), (-1136332546,'ols','e'), (0,' *\n','0'), 3516(-717462680,'ENTS Ta','0'), (-904346964,'ndard SQL\n','0'); 3517INSERT INTO t2 VALUES 3518(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); 3519INSERT INTO t3 VALUES 3520(1,'NUCANS_APP_USER','NUCANSAPP'),(2,'NUCANS_TRGAPP_USER','NUCANSAPP'), 3521(3,'IA_INTAKE_COORDINATOR','IACANS'),(4,'IA_SCREENER','IACANS'), 3522(5,'IA_SUPERVISOR','IACANS'),(6,'IA_READONLY','IACANS'), 3523(7,'SOC_USER','SOCCANS'),(8,'CAYIT_USER','CAYITCANS'), 3524(9,'RTOS_DCFSPOS_SUPERVISOR','RTOS'); 3525EXPLAIN SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6; 3526id select_type table type possible_keys key key_len ref rows Extra 35271 SIMPLE profile const PRIMARY PRIMARY 4 const 1 Using temporary; Using filesort 35281 SIMPLE userrole ref idx_person_id,idx_role_id idx_person_id 4 const 2 35291 SIMPLE role eq_ref PRIMARY PRIMARY 4 test.userrole.role_id 1 3530SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6; 3531a b 35326 6 35336 6 3534DROP VIEW v1; 3535DROP TABLE t1,t2,t3; 3536create table t1 (i int); 3537insert into t1 values (1), (2), (1), (3), (2), (4); 3538create view v1 as select distinct i from t1; 3539select * from v1; 3540i 35411 35422 35433 35444 3545select table_name, is_updatable from information_schema.views 3546where table_name = 'v1'; 3547table_name is_updatable 3548v1 NO 3549drop view v1; 3550drop table t1; 3551CREATE TABLE t1 (a INT); 3552INSERT INTO t1 VALUES (1),(2); 3553CREATE VIEW v1 AS SELECT * FROM t1; 3554SELECT * FROM v1 USE KEY(non_existant); 3555ERROR 42000: Key 'non_existant' doesn't exist in table 'v1' 3556SELECT * FROM v1 FORCE KEY(non_existant); 3557ERROR 42000: Key 'non_existant' doesn't exist in table 'v1' 3558SELECT * FROM v1 IGNORE KEY(non_existant); 3559ERROR 42000: Key 'non_existant' doesn't exist in table 'v1' 3560DROP VIEW v1; 3561DROP TABLE t1; 3562CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL DEFAULT 0, 3563PRIMARY KEY(a), KEY (b)); 3564INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(); 3565CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a; 3566SHOW CREATE VIEW v1; 3567View Create View character_set_client collation_connection 3568v1 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 3569EXPLAIN SELECT * FROM v1; 3570id select_type table type possible_keys key key_len ref rows Extra 35711 SIMPLE t1 index NULL PRIMARY 4 NULL 15 3572CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a; 3573SHOW CREATE VIEW v2; 3574View Create View character_set_client collation_connection 3575v2 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 3576EXPLAIN SELECT * FROM v2; 3577id select_type table type possible_keys key key_len ref rows Extra 35781 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort 3579CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a; 3580SHOW CREATE VIEW v3; 3581View Create View character_set_client collation_connection 3582v3 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 3583EXPLAIN SELECT * FROM v3; 3584id select_type table type possible_keys key key_len ref rows Extra 35851 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using filesort 3586DROP VIEW v1; 3587DROP VIEW v2; 3588DROP VIEW v3; 3589DROP TABLE t1; 3590# 3591# Bug#29477 Not all fields of the target table were checked to have 3592# a default value when inserting into a view. 3593# 3594create table t1(f1 int, f2 int not null); 3595create view v1 as select f1 from t1; 3596insert ignore into v1 values(1); 3597Warnings: 3598Warning 1423 Field of view 'test.v1' underlying table doesn't have a default value 3599set @old_mode=@@sql_mode; 3600set @@sql_mode=traditional; 3601insert into v1 values(1); 3602ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value 3603set @@sql_mode=@old_mode; 3604drop view v1; 3605drop table t1; 3606create table t1 (a int, key(a)); 3607create table t2 (c int); 3608create view v1 as select a b from t1; 3609create view v2 as select 1 a from t2, v1 where c in 3610(select 1 from t1 where b = a); 3611insert into t1 values (1), (1); 3612insert into t2 values (1), (1); 3613prepare stmt from "select * from v2 where a = 1"; 3614execute stmt; 3615a 36161 36171 36181 36191 3620drop view v1, v2; 3621drop table t1, t2; 3622CREATE TABLE t1 (a INT); 3623CREATE VIEW v1 AS SELECT p.a AS a FROM t1 p, t1 q; 3624INSERT INTO t1 VALUES (1), (1); 3625SELECT MAX(a), COUNT(DISTINCT a) FROM v1 GROUP BY a; 3626MAX(a) COUNT(DISTINCT a) 36271 1 3628DROP VIEW v1; 3629DROP TABLE t1; 3630# ----------------------------------------------------------------- 3631# -- Bug#34337 Server crash when Altering a view using a table name. 3632# ----------------------------------------------------------------- 3633 3634DROP TABLE IF EXISTS t1; 3635 3636CREATE TABLE t1(c1 INT); 3637 3638SELECT * FROM t1; 3639c1 3640ALTER ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW t1 (c2) AS SELECT (1); 3641ERROR HY000: 'test.t1' is not of type 'VIEW' 3642 3643DROP TABLE t1; 3644 3645# -- End of test case for Bug#34337. 3646 3647# ----------------------------------------------------------------- 3648# -- Bug#35193 VIEW query is rewritten without "FROM DUAL", 3649# -- causing syntax error 3650# ----------------------------------------------------------------- 3651 3652CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE 1; 3653 3654SELECT * FROM v1; 36551 36561 3657SHOW CREATE TABLE v1; 3658View Create View character_set_client collation_connection 3659v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1` from DUAL where 1 latin1 latin1_swedish_ci 3660 3661DROP VIEW v1; 3662 3663# -- End of test case for Bug#35193. 3664 3665CREATE VIEW v1 AS SELECT 1; 3666DROP VIEW v1; 3667CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, INDEX (c2)); 3668INSERT INTO t1 VALUES (1,1), (2,2), (3,3); 3669SELECT * FROM t1 USE INDEX (PRIMARY) WHERE c1=2; 3670c1 c2 36712 2 3672SELECT * FROM t1 USE INDEX (c2) WHERE c2=2; 3673c1 c2 36742 2 3675CREATE VIEW v1 AS SELECT c1, c2 FROM t1; 3676SHOW INDEX FROM v1; 3677Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 3678SELECT * FROM v1 USE INDEX (PRIMARY) WHERE c1=2; 3679ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1' 3680SELECT * FROM v1 FORCE INDEX (PRIMARY) WHERE c1=2; 3681ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1' 3682SELECT * FROM v1 IGNORE INDEX (PRIMARY) WHERE c1=2; 3683ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1' 3684SELECT * FROM v1 USE INDEX (c2) WHERE c2=2; 3685ERROR 42000: Key 'c2' doesn't exist in table 'v1' 3686SELECT * FROM v1 FORCE INDEX (c2) WHERE c2=2; 3687ERROR 42000: Key 'c2' doesn't exist in table 'v1' 3688SELECT * FROM v1 IGNORE INDEX (c2) WHERE c2=2; 3689ERROR 42000: Key 'c2' doesn't exist in table 'v1' 3690DROP VIEW v1; 3691DROP TABLE t1; 3692# 3693# Bug #45806 crash when replacing into a view with a join! 3694# 3695CREATE TABLE t1(a INT UNIQUE); 3696CREATE VIEW v1 AS SELECT t1.a FROM t1, t1 AS a; 3697INSERT INTO t1 VALUES (1), (2); 3698REPLACE INTO v1(a) SELECT 1 FROM t1,t1 AS c; 3699SELECT * FROM v1; 3700a 37011 37022 37031 37042 3705REPLACE INTO v1(a) SELECT 3 FROM t1,t1 AS c; 3706SELECT * FROM v1; 3707a 37081 37092 37103 37111 37122 37133 37141 37152 37163 3717DELETE FROM t1 WHERE a=3; 3718INSERT INTO v1(a) SELECT 1 FROM t1,t1 AS c 3719ON DUPLICATE KEY UPDATE `v1`.`a`= 1; 3720SELECT * FROM v1; 3721a 37221 37232 37241 37252 3726CREATE VIEW v2 AS SELECT t1.a FROM t1, v1 AS a; 3727REPLACE INTO v2(a) SELECT 1 FROM t1,t1 AS c; 3728SELECT * FROM v2 order by 1; 3729a 37301 37311 37321 37331 37342 37352 37362 37372 3738REPLACE INTO v2(a) SELECT 3 FROM t1,t1 AS c; 3739SELECT * FROM v2 order by 1; 3740a 37411 37421 37431 37441 37451 37461 37471 37481 37491 37502 37512 37522 37532 37542 37552 37562 37572 37582 37593 37603 37613 37623 37633 37643 37653 37663 37673 3768INSERT INTO v2(a) SELECT 1 FROM t1,t1 AS c 3769ON DUPLICATE KEY UPDATE `v2`.`a`= 1; 3770SELECT * FROM v2 order by 1; 3771a 37721 37731 37741 37751 37761 37771 37781 37791 37801 37812 37822 37832 37842 37852 37862 37872 37882 37892 37903 37913 37923 37933 37943 37953 37963 37973 37983 3799DROP VIEW v1; 3800DROP VIEW v2; 3801DROP TABLE t1; 3802# -- End of test case for Bug#45806 3803# ----------------------------------------------------------------- 3804# -- Bug#40825: Error 1356 while selecting from a view 3805# -- with a "HAVING" clause though query works 3806# ----------------------------------------------------------------- 3807 3808CREATE TABLE t1 (c INT); 3809 3810CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias; 3811SHOW CREATE VIEW v1; 3812View Create View character_set_client collation_connection 3813v1 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 3814SELECT * FROM v1; 3815view_column 3816 3817DROP VIEW v1; 3818DROP TABLE t1; 3819 3820# -- End of test case for Bug#40825 3821 3822# ----------------------------------------------------------------- 3823# -- End of 5.0 tests. 3824# ----------------------------------------------------------------- 3825DROP DATABASE IF EXISTS `d-1`; 3826CREATE DATABASE `d-1`; 3827USE `d-1`; 3828CREATE TABLE `t-1` (c1 INT); 3829CREATE VIEW `v-1` AS SELECT c1 FROM `t-1`; 3830SHOW TABLES; 3831Tables_in_d-1 3832t-1 3833v-1 3834RENAME TABLE `t-1` TO `t-2`; 3835RENAME TABLE `v-1` TO `v-2`; 3836SHOW TABLES; 3837Tables_in_d-1 3838t-2 3839v-2 3840DROP TABLE `t-2`; 3841DROP VIEW `v-2`; 3842DROP DATABASE `d-1`; 3843USE test; 3844 3845# 3846# Bug#26676 VIEW using old table schema in a session. 3847# 3848 3849DROP VIEW IF EXISTS v1; 3850DROP TABLE IF EXISTS t1; 3851CREATE TABLE t1(c1 INT, c2 INT); 3852INSERT INTO t1 VALUES (1, 2), (3, 4); 3853 3854SELECT * FROM t1; 3855c1 c2 38561 2 38573 4 3858 3859CREATE VIEW v1 AS SELECT * FROM t1; 3860 3861SELECT * FROM v1; 3862c1 c2 38631 2 38643 4 3865 3866ALTER TABLE t1 ADD COLUMN c3 INT AFTER c2; 3867 3868SELECT * FROM t1; 3869c1 c2 c3 38701 2 NULL 38713 4 NULL 3872 3873SELECT * FROM v1; 3874c1 c2 38751 2 38763 4 3877 3878SHOW CREATE VIEW v1; 3879View Create View character_set_client collation_connection 3880v1 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 3881 3882DROP VIEW v1; 3883DROP TABLE t1; 3884 3885# End of test case for Bug#26676. 3886 3887# ----------------------------------------------------------------- 3888# -- Bug#32538 View definition picks up character set, but not collation 3889# ----------------------------------------------------------------- 3890 3891DROP VIEW IF EXISTS v1; 3892 3893SET collation_connection = latin1_general_ci; 3894CREATE VIEW v1 AS SELECT _latin1 'text1' AS c1, 'text2' AS c2; 3895 3896SELECT COLLATION(c1), COLLATION(c2) FROM v1; 3897COLLATION(c1) COLLATION(c2) 3898latin1_swedish_ci latin1_general_ci 3899 3900SHOW CREATE VIEW v1; 3901View Create View character_set_client collation_connection 3902v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select _latin1'text1' AS `c1`,'text2' AS `c2` latin1 latin1_general_ci 3903 3904SELECT * FROM v1 WHERE c1 = 'text1'; 3905ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin1_general_ci,COERCIBLE) for operation '=' 3906 3907SELECT * FROM v1 WHERE c2 = 'text2'; 3908c1 c2 3909text1 text2 3910 3911use test; 3912SET names latin1; 3913 3914SELECT COLLATION(c1), COLLATION(c2) FROM v1; 3915COLLATION(c1) COLLATION(c2) 3916latin1_swedish_ci latin1_general_ci 3917 3918SELECT * FROM v1 WHERE c1 = 'text1'; 3919c1 c2 3920text1 text2 3921 3922SELECT * FROM v1 WHERE c2 = 'text2'; 3923ERROR HY000: Illegal mix of collations (latin1_general_ci,COERCIBLE) and (latin1_swedish_ci,COERCIBLE) for operation '=' 3924 3925DROP VIEW v1; 3926 3927# -- End of test case for Bug#32538. 3928 3929drop view if exists a; 3930drop procedure if exists p; 3931create procedure p() 3932begin 3933declare continue handler for sqlexception begin end; 3934create view a as select 1; 3935end| 3936call p(); 3937call p(); 3938drop view a; 3939drop procedure p; 3940# 3941# Bug #44860: ALTER TABLE on view crashes server 3942# 3943CREATE TABLE t1 (a INT); 3944CREATE VIEW v1 AS SELECT a FROM t1; 3945ALTER TABLE v1; 3946ERROR HY000: 'test.v1' is not of type 'BASE TABLE' 3947DROP VIEW v1; 3948DROP TABLE t1; 3949# 3950# Bug#48449: hang on show create view after upgrading when 3951# view contains function of view 3952# 3953DROP VIEW IF EXISTS v1,v2; 3954DROP TABLE IF EXISTS t1,t2; 3955DROP FUNCTION IF EXISTS f1; 3956CREATE TABLE t1 (a INT); 3957CREATE TABLE t2 (a INT); 3958CREATE FUNCTION f1() RETURNS INT 3959BEGIN 3960SELECT a FROM v2 INTO @a; 3961RETURN @a; 3962END// 3963Warnings: 3964Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead 3965# Trigger pre-locking when opening v2. 3966CREATE VIEW v1 AS SELECT f1() FROM t1; 3967SHOW CREATE VIEW v1; 3968View Create View character_set_client collation_connection 3969v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `f1`() AS `f1()` from `t1` latin1 latin1_swedish_ci 3970Warnings: 3971Note 1599 View `test`.`v2` has no creation context 3972DROP VIEW v1,v2; 3973DROP TABLE t1,t2; 3974DROP FUNCTION f1; 3975CREATE TABLE t1(f1 INT); 3976INSERT INTO t1 VALUES (); 3977CREATE VIEW v1 AS SELECT 1 FROM t1 WHERE 3978ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE f1 >= ANY ( SELECT '1' ))); 3979DROP VIEW v1; 3980DROP TABLE t1; 3981# 3982# Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817 3983# 3984CREATE TABLE t1 (a CHAR(1) CHARSET latin1, b CHAR(1) CHARSET utf8); 3985CREATE VIEW v1 AS SELECT 1 from t1 3986WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1')); 3987DROP VIEW v1; 3988DROP TABLE t1; 3989# 3990# Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846 3991# 3992CREATE TABLE t1(a int); 3993CREATE VIEW v1 AS SELECT 1 FROM t1 GROUP BY 3994SUBSTRING(1 FROM (SELECT 3 FROM t1 WHERE a >= ANY(SELECT 1))); 3995DROP VIEW v1; 3996DROP TABLE t1; 3997# 3998# Bug#57352 valgrind warnings when creating view 3999# 4000CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f; 4001DROP VIEW v1; 4002# 4003# Bug 11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY 4004# 4005CREATE TABLE t1 (a INT); 4006CREATE VIEW v1 AS SELECT s.* FROM t1 s, t1 b HAVING a; 4007SELECT * FROM v1; 4008a 4009DROP VIEW v1; 4010DROP TABLE t1; 4011# 4012# LP BUG#777809 (a retrograded condition for view ON) 4013# 4014CREATE TABLE t1 ( f1 int NOT NULL , f6 int NOT NULL ) ; 4015INSERT IGNORE INTO t1 VALUES (20, 2); 4016CREATE TABLE t2 ( f3 int NOT NULL ) ; 4017INSERT IGNORE INTO t2 VALUES (7); 4018CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2; 4019PREPARE prep_stmt FROM 'SELECT t1.f6 FROM t1 RIGHT JOIN v2 ON v2.f3 WHERE t1.f1 != 0'; 4020EXECUTE prep_stmt; 4021f6 40222 4023EXECUTE prep_stmt; 4024f6 40252 4026drop view v2; 4027drop table t1,t2; 4028# ----------------------------------------------------------------- 4029# -- End of 5.1 tests. 4030# ----------------------------------------------------------------- 4031# 4032# Bug #794005: crash in st_table::mark_virtual_columns_for_write 4033# 4034CREATE TABLE t1 (a int); 4035insert into t1 values (1); 4036CREATE TABLE t2 (a int); 4037insert into t2 values (1); 4038CREATE VIEW v2 AS SELECT * FROM t2; 4039CREATE VIEW v1 AS SELECT * FROM v2; 4040CREATE VIEW v3 AS SELECT t2.a,v1.a as b FROM t2,v1 where t2.a=v1.a; 4041CREATE OR REPLACE ALGORITHM = TEMPTABLE VIEW v2 AS SELECT * FROM t1; 4042UPDATE v1 SET a = 10; 4043ERROR HY000: The target table v1 of the UPDATE is not updatable 4044REPLACE v1 SET a = 10; 4045ERROR HY000: The target table v1 of the INSERT is not insertable-into 4046INSERT into v1 values (20); 4047ERROR HY000: The target table v1 of the INSERT is not insertable-into 4048DELETE from v1; 4049ERROR HY000: The target table v1 of the DELETE is not updatable 4050UPDATE v3 SET b= 10; 4051ERROR HY000: The target table v3 of the UPDATE is not updatable 4052REPLACE v3 SET b= 10; 4053ERROR HY000: The target table v3 of the INSERT is not insertable-into 4054INSERT into v3(b) values (20); 4055ERROR HY000: The target table v3 of the INSERT is not insertable-into 4056DELETE from v3 where b=20; 4057ERROR HY000: Can not delete from join view 'test.v3' 4058DELETE from v3 where a=20; 4059ERROR HY000: Can not delete from join view 'test.v3' 4060DELETE v1 from v1,t1 where v1.a=t1.a; 4061ERROR HY000: The target table v1 of the DELETE is not updatable 4062UPDATE v3 SET a = 10; 4063REPLACE v3 SET a = 11; 4064INSERT INTO v3(a) values (20); 4065select * from t1; 4066a 40671 4068select * from t2; 4069a 407010 407111 407220 4073CREATE OR REPLACE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM t2; 4074DELETE from v1 where a=11; 4075DELETE v1 from v1,t1 where v1.a=t1.a; 4076select * from t1; 4077a 40781 4079select * from t2; 4080a 408110 408220 4083DROP VIEW v1,v2,v3; 4084DROP TABLE t1,t2; 4085# 4086# MDEV-6251: SIGSEGV in query optimizer (in set_check_materialized 4087# with MERGE view) 4088# 4089CREATE TABLE t1 (a1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4090CREATE TABLE t2 (b1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4091CREATE TABLE t3 (c1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4092CREATE TABLE t4 (d1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4093CREATE TABLE t5 (e1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4094CREATE TABLE t6 (f1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); 4095CREATE OR REPLACE view v1 AS 4096SELECT 1 4097FROM t1 a_alias_1 4098LEFT 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 4099LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4100LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4101LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4102LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4103LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4104; 4105SELECT 1 4106FROM (( SELECT 1 4107FROM t1 a_alias_1 4108LEFT 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 4109LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4110LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4111LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4112LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4113LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4114) t1) 4115LEFT OUTER JOIN (( SELECT 1 4116FROM t1 a_alias_1 4117LEFT 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 4118LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4119LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4120LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4121LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4122LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4123) t2) ON 1=1 4124LEFT OUTER JOIN (( SELECT 1 4125FROM t1 a_alias_1 4126LEFT 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 4127LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4128LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4129LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4130LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4131LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4132) t3) ON 1=1 4133LEFT OUTER JOIN (( SELECT 1 4134FROM t1 a_alias_1 4135LEFT 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 4136LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4137LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4138LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4139LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4140LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4141) t4) ON 1=1 4142LEFT OUTER JOIN (( SELECT 1 4143FROM t1 a_alias_1 4144LEFT 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 4145LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4146LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4147LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4148LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4149LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4150) t5) ON 1=1 4151LEFT OUTER JOIN (( SELECT 1 4152FROM t1 a_alias_1 4153LEFT 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 4154LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4155LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4156LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4157LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4158LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4159) t6) ON 1=1 4160LEFT OUTER JOIN (( SELECT 1 4161FROM t1 a_alias_1 4162LEFT 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 4163LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4164LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4165LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4166LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4167LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4168) t7) ON 1=1 4169LEFT OUTER JOIN (( SELECT 1 4170FROM t1 a_alias_1 4171LEFT 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 4172LEFT JOIN t3 c_alias_1 ON c_alias_1.c1 = a_alias_1.a1 4173LEFT JOIN t4 d_alias_1 ON d_alias_1.d1 = a_alias_1.a1 4174LEFT JOIN t3 c_alias_2 ON c_alias_2.c1 = a_alias_1.a1 4175LEFT JOIN t5 e_alias_1 ON e_alias_1.e1 = a_alias_1.a1 4176LEFT JOIN t6 f_alias_1 ON f_alias_1.f1 = a_alias_1.a1 4177) t8) ON 1=1 4178; 41791 4180SELECT 1 4181FROM (v1 t1) 4182LEFT OUTER JOIN (v1 t2) ON 1=1 4183LEFT OUTER JOIN (v1 t3) ON 1=1 4184LEFT OUTER JOIN (v1 t4) ON 1=1 4185LEFT OUTER JOIN (v1 t5) ON 1=1 4186LEFT OUTER JOIN (v1 t6) ON 1=1 4187LEFT OUTER JOIN (v1 t7) ON 1=1 4188LEFT OUTER JOIN (v1 t8) ON 1=1 4189; 41901 4191drop view v1; 4192drop table t1,t2,t3,t4,t5,t6; 4193# ----------------------------------------------------------------- 4194# -- End of 5.2 tests. 4195# ----------------------------------------------------------------- 4196# 4197# Bug #59696 Optimizer does not use equalities for conditions over view 4198# 4199CREATE TABLE t1 (a int NOT NULL); 4200INSERT INTO t1 VALUES 4201(9), (2), (8), (1), (3), (4), (2), (5), 4202(9), (2), (8), (1), (3), (4), (2), (5); 4203CREATE TABLE t2 (pk int PRIMARY KEY, c int NOT NULL); 4204INSERT INTO t2 VALUES 4205(9,90), (16, 160), (11,110), (1,10), (18,180), (2,20), 4206(14,140), (15, 150), (12,120), (3,30), (17,170), (19,190); 4207EXPLAIN EXTENDED 4208SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8; 4209id select_type table type possible_keys key key_len ref rows filtered Extra 42101 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where 42111 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 4212Warnings: 4213Note 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 4214FLUSH STATUS; 4215SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8; 4216a c 42179 90 42189 90 4219SHOW STATUS LIKE 'Handler_read_%'; 4220Variable_name Value 4221Handler_read_first 0 4222Handler_read_key 1 4223Handler_read_last 0 4224Handler_read_next 0 4225Handler_read_prev 0 4226Handler_read_retry 0 4227Handler_read_rnd 0 4228Handler_read_rnd_deleted 0 4229Handler_read_rnd_next 17 4230CREATE VIEW v AS SELECT * FROM t2; 4231EXPLAIN EXTENDED 4232SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8; 4233id select_type table type possible_keys key key_len ref rows filtered Extra 42341 SIMPLE t1 ALL NULL NULL NULL NULL 16 100.00 Using where 42351 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 4236Warnings: 4237Note 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 4238FLUSH STATUS; 4239SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8; 4240a c 42419 90 42429 90 4243SHOW STATUS LIKE 'Handler_read_%'; 4244Variable_name Value 4245Handler_read_first 0 4246Handler_read_key 1 4247Handler_read_last 0 4248Handler_read_next 0 4249Handler_read_prev 0 4250Handler_read_retry 0 4251Handler_read_rnd 0 4252Handler_read_rnd_deleted 0 4253Handler_read_rnd_next 17 4254DROP VIEW v; 4255DROP TABLE t1, t2; 4256# 4257# Bug#702403: crash with multiple equalities and a view 4258# 4259CREATE TABLE t1 (a int); 4260INSERT INTO t1 VALUES (10); 4261CREATE TABLE t2 (pk int PRIMARY KEY, b int, INDEX idx (b)); 4262INSERT INTO t2 VALUES (1,2), (3,4); 4263CREATE TABLE t3 (pk int PRIMARY KEY, b int, INDEX idx (b)); 4264INSERT INTO t3 VALUES (1,2), (3,4); 4265CREATE VIEW v1 AS SELECT * FROM t1; 4266EXPLAIN 4267SELECT * FROM v1, t2, t3 4268WHERE t3.pk = v1.a AND t2.b = 1 AND t2.b = t3.pk AND v1.a BETWEEN 2 AND 5; 4269id select_type table type possible_keys key key_len ref rows Extra 42701 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 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; 4273a pk b pk b 4274DROP VIEW v1; 4275DROP TABLE t1, t2, t3; 4276# 4277# Bug#717577: substitution for best field in a query over a view and 4278# with OR in the WHERE condition 4279# 4280create table t1 (a int, b int); 4281insert into t1 values (2,4), (1,3); 4282create table t2 (c int); 4283insert into t2 values (6), (4), (1), (3), (8), (3), (4), (2); 4284select * from t1,t2 where t2.c=t1.a and t2.c < 3 or t2.c=t1.b and t2.c >=4; 4285a b c 42862 4 4 42871 3 1 42882 4 4 42892 4 2 4290explain extended 4291select * from t1,t2 where t2.c=t1.a and t2.c < 3 or t2.c=t1.b and t2.c >=4; 4292id select_type table type possible_keys key key_len ref rows filtered Extra 42931 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 42941 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4295Warnings: 4296Note 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 4297create view v1 as select * from t2; 4298select * from t1,v1 where v1.c=t1.a and v1.c < 3 or v1.c=t1.b and v1.c >=4; 4299a b c 43002 4 4 43011 3 1 43022 4 4 43032 4 2 4304explain extended 4305select * from t1,v1 where v1.c=t1.a and v1.c < 3 or v1.c=t1.b and v1.c >=4; 4306id select_type table type possible_keys key key_len ref rows filtered Extra 43071 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 43081 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4309Warnings: 4310Note 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 4311create view v2 as select * from v1; 4312select * from t1,v2 where v2.c=t1.a and v2.c < 3 or v2.c=t1.b and v2.c >=4; 4313a b c 43142 4 4 43151 3 1 43162 4 4 43172 4 2 4318explain extended 4319select * from t1,v2 where v2.c=t1.a and v2.c < 3 or v2.c=t1.b and v2.c >=4; 4320id select_type table type possible_keys key key_len ref rows filtered Extra 43211 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 43221 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4323Warnings: 4324Note 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 4325create view v3 as select * from t1; 4326select * from v3,v2 where v2.c=v3.a and v2.c < 3 or v2.c=v3.b and v2.c >=4; 4327a b c 43282 4 4 43291 3 1 43302 4 4 43312 4 2 4332explain extended 4333select * from v3,v2 where v2.c=v3.a and v2.c < 3 or v2.c=v3.b and v2.c >=4; 4334id select_type table type possible_keys key key_len ref rows filtered Extra 43351 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where 43361 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (flat, BNL join) 4337Warnings: 4338Note 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 4339drop view v1,v2,v3; 4340drop table t1,t2; 4341# 4342# Bug#724942: substitution of the constant into a view field 4343# 4344CREATE TABLE t1 (a int); 4345INSERT INTO t1 VALUES (2), (9), (9), (6), (5), (4), (7); 4346CREATE VIEW v1 AS SELECT * FROM t1; 4347SELECT * FROM v1 WHERE a > -1 OR a > 6 AND a = 3; 4348a 43492 43509 43519 43526 43535 43544 43557 4356EXPLAIN EXTENDED 4357SELECT * FROM v1 WHERE a > -1 OR a > 6 AND a = 3; 4358id select_type table type possible_keys key key_len ref rows filtered Extra 43591 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where 4360Warnings: 4361Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > -1 4362SELECT * FROM v1 WHERE a > -1 OR a AND a = 0; 4363a 43642 43659 43669 43676 43685 43694 43707 4371EXPLAIN EXTENDED 4372SELECT * FROM v1 WHERE a > -1 OR a AND a = 0; 4373id select_type table type possible_keys key key_len ref rows filtered Extra 43741 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where 4375Warnings: 4376Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > -1 4377CREATE VIEW v2 AS SELECT * FROM v1; 4378SELECT * FROM v2 WHERE a > -1 OR a AND a = 0; 4379a 43802 43819 43829 43836 43845 43854 43867 4387EXPLAIN EXTENDED 4388SELECT * FROM v2 WHERE a > -1 OR a AND a = 0; 4389id select_type table type possible_keys key key_len ref rows filtered Extra 43901 SIMPLE t1 ALL NULL NULL NULL NULL 7 100.00 Using where 4391Warnings: 4392Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > -1 4393DROP VIEW v1,v2; 4394DROP TABLE t1; 4395CREATE TABLE t1 (a varchar(10), KEY (a)) ; 4396INSERT INTO t1 VALUES 4397('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'), ('MM'), 4398('AA'), ('DD'), ('CC'), ('GG'); 4399CREATE VIEW v1 AS SELECT * FROM t1; 4400# t1 and v1 should return the same result set 4401SELECT * FROM v1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4402a 4403KK 4404MM 4405ZZ 4406ZZ 4407SELECT * FROM t1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4408a 4409KK 4410MM 4411ZZ 4412ZZ 4413# t1 and v1 should propagate constants in the same way 4414EXPLAIN EXTENDED 4415SELECT * FROM v1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4416id select_type table type possible_keys key key_len ref rows filtered Extra 44171 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4418Warnings: 4419Note 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 4420EXPLAIN EXTENDED 4421SELECT * FROM t1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV'; 4422id select_type table type possible_keys key key_len ref rows filtered Extra 44231 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4424Warnings: 4425Note 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 4426# t1 and v1 should return the same result set 4427SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV'; 4428a 4429KK 4430MM 4431ZZ 4432ZZ 4433SELECT * FROM t1 WHERE a > 'JJ' OR a AND a = 'VV'; 4434a 4435KK 4436MM 4437ZZ 4438ZZ 4439# t1 and v1 should propagate constants in the same way 4440EXPLAIN EXTENDED 4441SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV'; 4442id select_type table type possible_keys key key_len ref rows filtered Extra 44431 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4444Warnings: 4445Note 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 4446EXPLAIN EXTENDED 4447SELECT * FROM t1 WHERE a > 'JJ' OR a AND a = 'VV'; 4448id select_type table type possible_keys key key_len ref rows filtered Extra 44491 SIMPLE t1 range a a 13 NULL 4 100.00 Using where; Using index 4450Warnings: 4451Note 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 4452DROP VIEW v1; 4453DROP TABLE t1; 4454# 4455# Bug#777745: crash with equality propagation 4456# over view fields 4457# 4458CREATE TABLE t1 (a int NOT NULL ) ; 4459INSERT INTO t1 VALUES (2), (1); 4460CREATE TABLE t2 (a int NOT NULL , b int NOT NULL) ; 4461INSERT INTO t2 VALUES (2,20),(2,30); 4462CREATE VIEW v2 AS SELECT * FROM t2; 4463EXPLAIN 4464SELECT * FROM t1,v2 4465WHERE v2.a = t1.a AND v2.a = 2 AND v2.a IS NULL AND t1.a != 0; 4466id select_type table type possible_keys key key_len ref rows Extra 44671 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 4468SELECT * FROM t1,v2 4469WHERE v2.a = t1.a AND v2.a = 2 AND v2.a IS NULL AND t1.a != 0; 4470a a b 4471EXPLAIN 4472SELECT * FROM t1,v2 4473WHERE v2.a = t1.a AND v2.a = 2 AND v2.a+1 > 2 AND t1.a != 0; 4474id select_type table type possible_keys key key_len ref rows Extra 44751 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where 44761 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 4477SELECT * FROM t1,v2 4478WHERE v2.a = t1.a AND v2.a = 2 AND v2.a+1 > 2 AND t1.a != 0; 4479a a b 44802 2 20 44812 2 30 4482DROP VIEW v2; 4483DROP TABLE t1,t2; 4484# 4485# Bug#794038: crash with INSERT/UPDATE/DELETE 4486# over a non-updatable view 4487# 4488CREATE TABLE t1 (a int); 4489CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT * FROM t1; 4490CREATE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM v1; 4491CREATE ALGORITHM = TEMPTABLE VIEW v3 AS SELECT * FROM v2; 4492INSERT INTO v3 VALUES (1); 4493ERROR HY000: The target table v3 of the INSERT is not insertable-into 4494UPDATE v3 SET a=0; 4495ERROR HY000: The target table v3 of the UPDATE is not updatable 4496DELETE FROM v3; 4497ERROR HY000: The target table v3 of the DELETE is not updatable 4498DROP VIEW v1,v2,v3; 4499DROP TABLE t1; 4500# 4501# Bug#798621: crash with a view string field equal 4502# to a constant 4503# 4504CREATE TABLE t1 (a varchar(32), b int) ; 4505INSERT INTO t1 VALUES ('j', NULL), ('c', 8), ('c', 1); 4506CREATE VIEW v1 AS SELECT * FROM t1; 4507CREATE TABLE t2 (a varchar(32)) ; 4508INSERT INTO t2 VALUES ('j'), ('c'); 4509SELECT * FROM v1 LEFT JOIN t2 ON t2.a = v1.a 4510WHERE v1.b = 1 OR v1.a = 'a' AND LENGTH(v1.a) >= v1.b; 4511a b a 4512c 1 c 4513EXPLAIN EXTENDED 4514SELECT * FROM v1 LEFT JOIN t2 ON t2.a = v1.a 4515WHERE v1.b = 1 OR v1.a = 'a' AND LENGTH(v1.a) >= v1.b; 4516id select_type table type possible_keys key key_len ref rows filtered Extra 45171 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where 45181 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where 4519Warnings: 4520Note 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` 4521DROP VIEW v1; 4522DROP TABLE t1,t2; 4523# Bug#798625: duplicate of the previous one, but without crash 4524CREATE TABLE t1 (f1 int NOT NULL, f2 int, f3 int, f4 varchar(32), f5 int) ; 4525INSERT INTO t1 VALUES (20,5,2,'r', 0); 4526CREATE VIEW v1 AS SELECT * FROM t1; 4527SELECT v1.f4 FROM v1 4528WHERE f1<>0 OR f2<>0 AND f4='v' AND (f2<>0 OR f3<>0 AND f5<>0 OR f4 LIKE '%b%'); 4529f4 4530r 4531EXPLAIN EXTENDED 4532SELECT v1.f4 FROM v1 4533WHERE f1<>0 OR f2<>0 AND f4='v' AND (f2<>0 OR f3<>0 AND f5<>0 OR f4 LIKE '%b%'); 4534id select_type table type possible_keys key key_len ref rows filtered Extra 45351 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 4536Warnings: 4537Note 1003 select 'r' AS `f4` from dual where 1 4538DROP VIEW v1; 4539DROP TABLE t1; 4540# 4541# Bug#798576: abort on a GROUP BY query over a view with left join 4542# that can be converted to inner join 4543# 4544CREATE TABLE t1 (a int NOT NULL , b int NOT NULL) ; 4545INSERT INTO t1 VALUES (214,0), (6,6), (6,0), (7,0); 4546CREATE TABLE t2 (b int) ; 4547INSERT INTO t2 VALUES (88), (78), (6); 4548CREATE ALGORITHM=MERGE VIEW v1 AS 4549SELECT t1.a, t2.b FROM (t2 LEFT JOIN t1 ON t2.b > t1.a) WHERE t1.b <= 0; 4550SELECT * FROM v1; 4551a b 45526 88 45536 78 45547 88 45557 78 4556SELECT a, MIN(b) FROM v1 GROUP BY a; 4557a MIN(b) 45586 78 45597 78 4560DROP VIEW v1; 4561DROP TABLE t1,t2; 4562# 4563# LP bug #793386: unexpected 'Duplicate column name ''' error 4564# at the second execution of a PS using a view 4565# 4566CREATE TABLE t1 (f1 int, f2 int, f3 int, f4 int); 4567CREATE VIEW v1 AS 4568SELECT t.f1, t.f2, s.f3, s.f4 FROM t1 t, t1 s 4569WHERE t.f4 >= s.f2 AND s.f3 < 0; 4570PREPARE stmt1 FROM 4571"SELECT s.f1 AS f1, s.f2 AS f2, s.f3 AS f3, t.f4 AS f4 4572 FROM v1 AS t LEFT JOIN v1 AS s ON t.f4=s.f4 WHERE t.f2 <> 1225"; 4573EXECUTE stmt1; 4574f1 f2 f3 f4 4575EXECUTE stmt1; 4576f1 f2 f3 f4 4577DEALLOCATE PREPARE stmt1; 4578DROP VIEW v1; 4579DROP TABLE t1; 4580# 4581# LP BUG#806071 (2 views with ORDER BY) 4582# 4583CREATE TABLE t1 (f1 int); 4584INSERT INTO t1 VALUES (1),(1); 4585CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT f1 FROM t1; 4586CREATE ALGORITHM=MERGE VIEW v2 AS SELECT f1 FROM v1 ORDER BY f1; 4587SELECT * FROM v2 AS a1, v2 AS a2; 4588f1 f1 45891 1 45901 1 45911 1 45921 1 4593EXPLAIN EXTENDED SELECT * FROM v2 AS a1, v2 AS a2; 4594id select_type table type possible_keys key key_len ref rows filtered Extra 45951 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort 45961 PRIMARY <derived5> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join) 45975 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 45983 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 4599Warnings: 4600Note 1926 View 'test'.'v2' ORDER BY clause ignored because there is other ORDER BY clause already 4601Note 1003 /* select#1 */ select `v1`.`f1` AS `f1`,`v1`.`f1` AS `f1` from `test`.`v1` join `test`.`v1` order by `v1`.`f1` 4602DROP VIEW v1, v2; 4603DROP TABLE t1; 4604# 4605# LP bug #823189: dependent subquery with RIGHT JOIN 4606# referencing view in WHERE 4607# 4608CREATE TABLE t1 (a varchar(32)); 4609INSERT INTO t1 VALUES ('y'), ('w'); 4610CREATE TABLE t2 (a int); 4611INSERT INTO t2 VALUES (10); 4612CREATE TABLE t3 (a varchar(32), b int); 4613CREATE TABLE t4 (a varchar(32)); 4614INSERT INTO t4 VALUES ('y'), ('w'); 4615CREATE VIEW v1 AS SELECT * FROM t1; 4616EXPLAIN EXTENDED 4617SELECT * FROM t1, t2 4618WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4619WHERE t4.a >= t1.a); 4620id select_type table type possible_keys key key_len ref rows filtered Extra 46211 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 46221 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where 46232 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 0.00 Const row not found 46242 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 4625Warnings: 4626Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 4627Note 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)))) 4628SELECT * FROM t1, t2 4629WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4630WHERE t4.a >= t1.a); 4631a a 4632EXPLAIN EXTENDED 4633SELECT * FROM v1, t2 4634WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4635WHERE t4.a >= v1.a); 4636id select_type table type possible_keys key key_len ref rows filtered Extra 46371 PRIMARY t2 system NULL NULL NULL NULL 1 100.00 46381 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where 46392 DEPENDENT SUBQUERY t3 system NULL NULL NULL NULL 0 0.00 Const row not found 46402 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 4641Warnings: 4642Note 1276 Field or reference 'v1.a' of SELECT #2 was resolved in SELECT #1 4643Note 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)))) 4644SELECT * FROM v1, t2 4645WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a) 4646WHERE t4.a >= v1.a); 4647a a 4648DROP VIEW v1; 4649DROP TABLE t1,t2,t3,t4; 4650# 4651# LP bug #823237: dependent subquery with LEFT JOIN 4652# referencing view in WHERE 4653# (duplicate of LP bug #823189) 4654# 4655CREATE TABLE t1 (a int); 4656CREATE TABLE t2 ( b int, d int, e int); 4657INSERT INTO t2 VALUES (7,8,0); 4658CREATE TABLE t3 ( c int); 4659INSERT INTO t3 VALUES (0); 4660CREATE TABLE t4 (a int, b int, c int); 4661INSERT INTO t4 VALUES (93,1,0), (95,NULL,0); 4662CREATE VIEW v4 AS SELECT * FROM t4; 4663EXPLAIN EXTENDED 4664SELECT * FROM t3 , t4 4665WHERE t4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4666WHERE t2.b > t4.b); 4667id select_type table type possible_keys key key_len ref rows filtered Extra 46681 PRIMARY t3 system NULL NULL NULL NULL 1 100.00 46691 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 46702 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 100.00 46712 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 Const row not found 4672Warnings: 4673Note 1276 Field or reference 'test.t4.b' of SELECT #2 was resolved in SELECT #1 4674Note 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`)) 4675SELECT * FROM t3 , t4 4676WHERE t4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4677WHERE t2.b > t4.b); 4678c a b c 46790 93 1 0 4680EXPLAIN EXTENDED 4681SELECT * FROM t3, v4 4682WHERE v4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4683WHERE t2.b > v4.b); 4684id select_type table type possible_keys key key_len ref rows filtered Extra 46851 PRIMARY t3 system NULL NULL NULL NULL 1 100.00 46861 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using where 46872 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 100.00 46882 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 Const row not found 4689Warnings: 4690Note 1276 Field or reference 'v4.b' of SELECT #2 was resolved in SELECT #1 4691Note 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`)) 4692SELECT * FROM t3, v4 4693WHERE v4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d ) 4694WHERE t2.b > v4.b); 4695c a b c 46960 93 1 0 4697DROP VIEW v4; 4698DROP TABLE t1,t2,t3,t4; 4699drop table if exists t_9801; 4700drop view if exists v_9801; 4701create table t_9801 (s1 int); 4702create view v_9801 as 4703select sum(s1) from t_9801 with check option; 4704ERROR HY000: CHECK OPTION on non-updatable view `test`.`v_9801` 4705create view v_9801 as 4706select sum(s1) from t_9801 group by s1 with check option; 4707ERROR HY000: CHECK OPTION on non-updatable view `test`.`v_9801` 4708create view v_9801 as 4709select sum(s1) from t_9801 group by s1 with rollup with check option; 4710ERROR HY000: CHECK OPTION on non-updatable view `test`.`v_9801` 4711drop table t_9801; 4712# 4713# Bug #47335 assert in get_table_share 4714# 4715DROP TABLE IF EXISTS t1; 4716DROP VIEW IF EXISTS v1; 4717CREATE TEMPORARY TABLE t1 (id INT); 4718ALTER VIEW t1 AS SELECT 1 AS f1; 4719ERROR 42S02: Table 'test.t1' doesn't exist 4720DROP TABLE t1; 4721CREATE VIEW v1 AS SELECT 1 AS f1; 4722CREATE TEMPORARY TABLE v1 (id INT); 4723ALTER VIEW v1 AS SELECT 2 AS f1; 4724DROP TABLE v1; 4725SELECT * FROM v1; 4726f1 47272 4728DROP VIEW v1; 4729# 4730# Bug #47635 assert in start_waiting_global_read_lock 4731# during CREATE VIEW 4732# 4733DROP TABLE IF EXISTS t1, t2; 4734DROP VIEW IF EXISTS t2; 4735CREATE TABLE t1 (f1 integer); 4736CREATE TEMPORARY TABLE IF NOT EXISTS t1 (f1 integer); 4737CREATE TEMPORARY TABLE t2 (f1 integer); 4738DROP TABLE t1; 4739FLUSH TABLES WITH READ LOCK; 4740CREATE VIEW t2 AS SELECT * FROM t1; 4741ERROR HY000: Can't execute the query because you have a conflicting read lock 4742UNLOCK TABLES; 4743DROP TABLE t1, t2; 4744# 4745# Bug#48315 Metadata lock is not taken for merged views that 4746# use an INFORMATION_SCHEMA table 4747# 4748DROP VIEW IF EXISTS v1; 4749DROP PROCEDURE IF EXISTS p1; 4750connect con2, localhost, root; 4751connect con3, localhost, root; 4752connection default; 4753CREATE VIEW v1 AS SELECT schema_name FROM information_schema.schemata; 4754CREATE PROCEDURE p1() SELECT COUNT(*), GET_LOCK('blocker', 100) FROM v1; 4755# CALL p1() so the view is merged. 4756CALL p1(); 4757SELECT RELEASE_LOCK('blocker'); 4758RELEASE_LOCK('blocker') 47591 4760connection con3; 4761SELECT GET_LOCK('blocker', 100); 4762GET_LOCK('blocker', 100) 47631 4764connection default; 4765# Try to CALL p1() again, this time it should block on "blocker". 4766# Sending: 4767CALL p1(); 4768connection con2; 4769# ... then try to drop the view. This should block. 4770# Sending: 4771DROP VIEW v1; 4772connection con3; 4773# Now allow CALL p1() to complete 4774SELECT RELEASE_LOCK('blocker'); 4775RELEASE_LOCK('blocker') 47761 4777connection default; 4778# Reaping: CALL p1() 4779SELECT RELEASE_LOCK('blocker'); 4780RELEASE_LOCK('blocker') 47811 4782connection con2; 4783# Reaping: DROP VIEW v1 4784connection default; 4785DROP PROCEDURE p1; 4786disconnect con2; 4787disconnect con3; 4788# 4789# Bug#12626844: WRONG ERROR MESSAGE WHILE CREATING A VIEW ON A 4790# NON EXISTING DATABASE 4791# 4792DROP DATABASE IF EXISTS nodb; 4793CREATE VIEW nodb.a AS SELECT 1; 4794ERROR 42000: Unknown database 'nodb' 4795# 4796# BUG#14117018 - MYSQL SERVER CREATES INVALID VIEW DEFINITION 4797# BUG#18405221 - SHOW CREATE VIEW OUTPUT INCORRECT 4798# 4799CREATE VIEW v1 AS (SELECT '' FROM DUAL); 4800CREATE VIEW v2 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL 4801(SELECT '' FROM DUAL); 4802CREATE VIEW v3 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL 4803(SELECT '' FROM DUAL) UNION ALL 4804(SELECT '' FROM DUAL); 4805CREATE VIEW v4 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL 4806(SELECT '' AS col2 FROM DUAL) UNION ALL 4807(SELECT '' FROM DUAL); 4808CREATE VIEW v5 AS (SELECT 'buggy' AS col1, 'fix' as col2 FROM DUAL) UNION ALL 4809(SELECT 'buggy' as a, 'fix' as a FROM DUAL); 4810# Name for the column in select1 is set properly with or 4811# without this fix. 4812SHOW CREATE VIEW v1; 4813View Create View character_set_client collation_connection 4814v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select '' AS `Name_exp_1`) latin1 latin1_swedish_ci 4815# Name for the column in select2 is set with this fix. 4816# Without this fix, name would not have set for the 4817# columns in select2. 4818SHOW CREATE VIEW v2; 4819View Create View character_set_client collation_connection 4820v2 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 4821# Name for the field item in select2 & select3 is set with this fix. 4822# Without this fix, name would not have set for the 4823# columns in select2 & select3. 4824SHOW CREATE VIEW v3; 4825View Create View character_set_client collation_connection 4826v3 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 4827# Name for the field item in select3 is set with this fix. 4828# Without this fix, name would not have set for the 4829# columns in select3. 4830SHOW CREATE VIEW v4; 4831View Create View character_set_client collation_connection 4832v4 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 4833DROP VIEW v1, v2, v3, v4, v5; 4834# 4835# BUG#19886430: VIEW CREATION WITH NAMED COLUMNS, OVER UNION, 4836# IS REJECTED 4837# Without the patch, reports an error. 4838CREATE VIEW v1 (fld1, fld2) AS 4839SELECT 1 AS a, 2 AS b 4840UNION ALL 4841SELECT 1 AS a, 1 AS a; 4842# The column names are explicitly specified and not duplicates, hence 4843# succeeds. 4844CREATE VIEW v2 (fld1, fld2) AS 4845SELECT 1 AS a, 2 AS a 4846UNION ALL 4847SELECT 1 AS a, 1 AS a; 4848# The column name in the first SELECT are not duplicates, hence succeeds. 4849CREATE VIEW v3 AS 4850SELECT 1 AS a, 2 AS b 4851UNION ALL 4852SELECT 1 AS a, 1 AS a; 4853# Should report an error, since the explicitly specified column names are 4854# duplicates. 4855CREATE VIEW v4 (fld1, fld1) AS 4856SELECT 1 AS a, 2 AS b 4857UNION ALL 4858SELECT 1 AS a, 1 AS a; 4859ERROR 42S21: Duplicate column name 'fld1' 4860# Should report an error, since duplicate column name is specified in the 4861# First SELECT. 4862CREATE VIEW v4 AS 4863SELECT 1 AS a, 2 AS a 4864UNION ALL 4865SELECT 1 AS a, 1 AS a; 4866ERROR 42S21: Duplicate column name 'a' 4867# Cleanup 4868DROP VIEW v1, v2, v3; 4869# 4870# lp:833600 Wrong result with view + outer join + uncorrelated subquery (non-semijoin) 4871# 4872CREATE TABLE t1 ( a int, b int ); 4873INSERT INTO t1 VALUES (0,0),(0,0); 4874CREATE TABLE t2 ( a int, b int ); 4875INSERT IGNORE INTO t2 VALUES (1,0),(1,0); 4876CREATE TABLE t3 ( b int ); 4877INSERT IGNORE INTO t3 VALUES (0),(0); 4878CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2; 4879SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ; 4880a b a b 4881NULL NULL 1 0 4882NULL NULL 1 0 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 4887DROP VIEW v2; 4888DROP TABLE t1, t2, t3; 4889# 4890# BUG#915222: Valgrind complains or crashes with INSERT SELECT 4891# within a trigger that uses a view 4892# 4893CREATE TABLE t1 (a char(1)); 4894CREATE TABLE t2 (d int, e char(1)); 4895INSERT INTO t2 VALUES (13,'z'); 4896CREATE TRIGGER tr AFTER UPDATE ON t2 4897FOR EACH ROW 4898REPLACE INTO t3 4899SELECT f, a AS alias FROM t3, v; 4900CREATE TABLE t3 (f int, g char(8)); 4901CREATE VIEW v AS SELECT a, e FROM t2, t1; 4902UPDATE t2 SET d=7; 4903UPDATE t2 SET d=7; 4904UPDATE t2 SET d=7; 4905UPDATE t2 SET d=7; 4906DROP TRIGGER tr; 4907DROP VIEW v; 4908DROP TABLE t1,t2,t3; 4909# 4910# BUG#972943: Assertion failure with INSERT SELECT within a trigger 4911# that uses derived table and materialized view 4912# 4913CREATE TABLE t1 (a int, b int); 4914INSERT INTO t1 VALUES (1,0), (2,8); 4915CREATE ALGORITHM=TEMPTABLE VIEW v1 4916AS SELECT * FROM t1; 4917CREATE TABLE t2 (c int); 4918CREATE TABLE t3 (d int, e int); 4919CREATE TRIGGER tr BEFORE INSERT ON t2 FOR EACH ROW 4920INSERT INTO t3 4921SELECT t1.* 4922FROM (SELECT * FROM t1 WHERE b IN (SELECT b FROM v1)) AS alias1, t1 4923WHERE t1.a = 3 OR t1.a > 5; 4924INSERT INTO t2 VALUES (1); 4925DROP TRIGGER tr; 4926DROP VIEW v1; 4927DROP TABLE t1,t2,t3; 4928# 4929# LP bug#1007622 Server crashes in handler::increment_statistics on 4930# inserting into a view over a view 4931# 4932flush status; 4933CREATE TABLE t1 (a INT); 4934CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.* FROM t1 AS a1, t1 AS a2; 4935CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1; 4936INSERT INTO v2 (a) VALUES (1) ; 4937select * from t1; 4938a 49391 4940drop view v2,v1; 4941drop table t1; 4942show status like '%view%'; 4943Variable_name Value 4944Com_create_view 2 4945Com_drop_view 1 4946Opened_views 3 4947show status like 'Opened_table%'; 4948Variable_name Value 4949Opened_table_definitions 2 4950Opened_tables 2 4951# 4952# MDEV-486 LP BUG#1010116 Incorrect query results in 4953# view and derived tables 4954# 4955SELECT 4956`Derived1`.`id`, 4957`Derived2`.`Val1` 4958FROM (select 30631 as `id`) AS `Derived1` LEFT OUTER JOIN (SELECT 49592 as `id`, 49601 AS `Val1` 4961FROM (select 30631 as `id`) AS `Derived3`) AS `Derived2` ON `Derived1`.`id` = `Derived2`.`id`; 4962id Val1 496330631 NULL 4964create table t1 ( id int ); 4965insert into t1 values (30631); 4966create table t2 ( id int ); 4967insert into t2 values (30631); 4968create algorithm=MERGE view v2 as select 2 as id, 1 as val1 from t2; 4969select t1.*, v2.* from t1 left join v2 on t1.id = v2.id; 4970id id val1 497130631 NULL NULL 4972drop view v2; 4973drop table t1,t2; 4974create table t1 ( id int ); 4975insert into t1 values (30631); 4976create table t2 ( id int ); 4977insert into t2 values (30631); 4978create algorithm=MERGE view v2 as select 2 as id, id is null as bbb, id as iddqd, 1 as val1 from t2; 4979select t1.*, v2.* from t1 left join v2 on t1.id = v2.id; 4980id id bbb iddqd val1 498130631 NULL NULL NULL NULL 4982drop view v2; 4983drop table t1,t2; 4984# 4985# MDEV-3914: Wrong result (NULLs instead of real values) 4986# with INNER and RIGHT JOIN in a FROM subquery, derived_merge=on 4987# (fix of above MDEV-486 fix) 4988# 4989SET @save_optimizer_switch_MDEV_3914=@@optimizer_switch; 4990SET optimizer_switch = 'derived_merge=on'; 4991CREATE TABLE t1 (a INT) ENGINE=MyISAM; 4992INSERT INTO t1 VALUES (1),(2); 4993CREATE TABLE t2 (b INT) ENGINE=MyISAM; 4994INSERT INTO t2 VALUES (3),(4); 4995CREATE TABLE t3 (c INT) ENGINE=MyISAM; 4996INSERT INTO t3 VALUES (5),(6); 4997SELECT * FROM ( SELECT c FROM ( t1 INNER JOIN t2 ) RIGHT JOIN t3 ON a = c ) AS alias; 4998c 49995 50006 5001SET optimizer_switch = 'derived_merge=off'; 5002SELECT * FROM ( SELECT c FROM ( t1 INNER JOIN t2 ) RIGHT JOIN t3 ON a = c ) AS alias; 5003c 50045 50056 5006SET optimizer_switch=@save_optimizer_switch_MDEV_3914; 5007drop table t1,t2,t3; 5008# 5009# MDEV-589 (LP BUG#1007647) : 5010# Assertion `vcol_table == 0 || vcol_table == table' failed in 5011# fill_record(THD*, List<Item>&, List<Item>&, bool) 5012# 5013CREATE TABLE t1 (f1 INT, f2 INT); 5014CREATE TABLE t2 (f1 INT, f2 INT); 5015CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.f1, a2.f2 FROM t1 AS a1, t1 AS a2; 5016CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1; 5017CREATE ALGORITHM=MERGE VIEW v3 AS SELECT a1.f1, a2.f2 FROM t1 AS a1, t2 AS a2; 5018CREATE ALGORITHM=MERGE VIEW v4 AS SELECT * FROM v3; 5019INSERT INTO v3 (f1, f2) VALUES (1, 2); 5020ERROR HY000: Can not modify more than one base table through a join view 'test.v3' 5021INSERT INTO v1 (f1, f2) VALUES (1, 2); 5022ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 5023INSERT INTO v4 (f1, f2) VALUES (1, 2); 5024ERROR HY000: Can not modify more than one base table through a join view 'test.v4' 5025INSERT INTO v2 (f1, f2) VALUES (1, 2); 5026ERROR HY000: Can not modify more than one base table through a join view 'test.v2' 5027drop view v4,v3,v2,v1; 5028drop table t1,t2; 5029# 5030# MDEV-3799 fix of above bugfix (MDEV-589) 5031# Wrong result (NULLs instead of real values) with RIGHT JOIN 5032# in a FROM subquery and derived_merge=on 5033# 5034CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; 5035INSERT INTO t1 VALUES (4),(6); 5036CREATE TABLE t2 (f2 INT) ENGINE=MyISAM; 5037INSERT INTO t2 VALUES (7),(8); 5038SELECT * FROM ( 5039SELECT * FROM t1 RIGHT JOIN t2 ON f1 = f2 5040) AS alias; 5041f1 f2 5042NULL 7 5043NULL 8 5044SELECT * FROM ( 5045SELECT * FROM t2 LEFT JOIN t1 ON f1 = f2 5046) AS alias; 5047f2 f1 50487 NULL 50498 NULL 5050drop tables t1,t2; 5051# 5052# MDEV-3876 Wrong result (extra rows) with ALL subquery 5053# from a MERGE view (duplicate of MDEV-3873) 5054# 5055CREATE TABLE t1 (a INT NOT NULL) ENGINE=MyISAM; 5056INSERT INTO t1 VALUES (1),(2); 5057CREATE TABLE t2 (b INT NOT NULL) ENGINE=MyISAM; 5058INSERT INTO t2 VALUES (1),(3); 5059CREATE OR REPLACE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2; 5060SELECT a FROM t1 AS alias 5061WHERE a >= ALL ( 5062SELECT b FROM t1 LEFT JOIN v1 ON (a = b) 5063WHERE a = alias.a ); 5064a 50651 5066drop view v1; 5067drop table t1,t2; 5068# 5069# MDEV-4593: p_s: crash in simplify_joins with delete using subselect 5070# from view 5071# 5072create table `t1`(`a` int); 5073create table `t2`(`a` int); 5074create or replace view `v1` as select `a` from `t1`; 5075prepare s from "delete from `t2` order by (select 1 from `v1`)"; 5076execute s; 5077deallocate prepare s; 5078drop view v1; 5079drop tables t1,t2; 5080# 5081# MDEV-5034 (duplicate of MDEV-5107): 5082# Left Join Yields All Nulls Instead of Appropriate Matches 5083# 5084# test #1 5085CREATE TABLE t1 (state VARCHAR(32), INDEX(state)); 5086INSERT INTO t1 VALUES ('Indiana'),('Vermont'); 5087CREATE TABLE t2 (state VARCHAR(32)); 5088INSERT INTO t2 VALUES ('Hawaii'),('Oregon'),('Vermont'); 5089CREATE ALGORITHM=MERGE VIEW v1 AS SELECT t1.* FROM t2, t1; 5090SELECT * FROM t1 AS outer_t1 LEFT JOIN v1 AS joined_t1 5091ON (joined_t1.state = outer_t1.state AND joined_t1.state IN ( SELECT 'Vermont' UNION SELECT 'Florida' ) ); 5092state state 5093Indiana NULL 5094Vermont Vermont 5095Vermont Vermont 5096Vermont Vermont 5097SELECT * 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' ) ); 5098state state 5099Indiana NULL 5100Vermont Vermont 5101Vermont Vermont 5102Vermont Vermont 5103drop view v1; 5104drop table t1, t2; 5105# test #1 5106CREATE TABLE t1 (a INT, b VARCHAR(1), INDEX(b,a)); 5107INSERT INTO t1 VALUES (4,'p'),(1,'q'),(9,'w'); 5108CREATE TABLE t2 (c VARCHAR(1), INDEX(c)); 5109INSERT INTO t2 VALUES ('q'),('a'); 5110CREATE ALGORITHM=MERGE VIEW v1 AS SELECT t1a.* FROM t1, t1 AS t1a; 5111SELECT * FROM t2 LEFT JOIN v1 ON ( c=b AND a IN ( 1,6 ) ); 5112c a b 5113a NULL NULL 5114q 1 q 5115q 1 q 5116q 1 q 5117CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT t1a.* FROM t1, t1 AS t1a; 5118SELECT * FROM t2 LEFT JOIN v1 ON ( c=b AND a IN ( 1,6 ) ); 5119c a b 5120a NULL NULL 5121q 1 q 5122q 1 q 5123q 1 q 5124drop view v1; 5125drop table t1,t2; 5126# 5127# MDEV-5153: Server crashes in Item_ref::fix_fields on 2nd execution 5128# of PS with LEFT JOIN and MERGE view or SELECT SQ 5129# 5130CREATE TABLE t1 (i1 INT, c1 VARCHAR(6)) ENGINE=MyISAM; 5131INSERT INTO t1 VALUES (1,'foo'),(2,'bar'); 5132CREATE TABLE t2 (c2 VARCHAR(6)) ENGINE=MyISAM; 5133INSERT INTO t2 VALUES ('foobar'),('qux'); 5134CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1 WHERE ( c1 ) IN ( SELECT c2 FROM t2 ) AND i1 <= 2 ; 5135PREPARE stmt FROM 'SELECT * FROM t1 LEFT JOIN v1 ON (v1.i1 = t1.i1)'; 5136EXECUTE stmt; 5137i1 c1 i1 c1 51381 foo NULL NULL 51392 bar NULL NULL 5140EXECUTE stmt; 5141i1 c1 i1 c1 51421 foo NULL NULL 51432 bar NULL NULL 5144drop view v1; 5145CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1 WHERE ( c1, c1 ) IN ( SELECT c2, c2 FROM t2 ) AND i1 <= 2 ; 5146EXECUTE stmt; 5147i1 c1 i1 c1 51481 foo NULL NULL 51492 bar NULL NULL 5150EXECUTE stmt; 5151i1 c1 i1 c1 51521 foo NULL NULL 51532 bar NULL NULL 5154deallocate prepare stmt; 5155drop view v1; 5156drop table t1,t2; 5157create table t1 (a int); 5158insert into t1 values (1),(2); 5159create view v1 (a,r) as select a,rand() from t1; 5160create table t2 select a, r as r1, r as r2, r as r3 from v1; 5161select a, r1 = r2, r2 = r3 from t2; 5162a r1 = r2 r2 = r3 51631 1 1 51642 1 1 5165drop view v1; 5166drop table t1,t2; 5167# 5168# MDEV-5515: 2nd execution of a prepared statement returns wrong results 5169# 5170CREATE TABLE t1 (i1 INT, j1 INT NOT NULL, PRIMARY KEY (i1)); 5171INSERT INTO t1 VALUES (30,300),(40,400); 5172CREATE TABLE t2 (i2 INT); 5173INSERT INTO t2 VALUES (50),(60); 5174CREATE TABLE t3 (c3 VARCHAR(20), i3 INT); 5175INSERT INTO t3 VALUES ('a',10),('b',2); 5176CREATE TABLE t4 (i4 INT); 5177INSERT INTO t4 VALUES (1),(2); 5178DROP VIEW IF EXISTS v1; 5179Warnings: 5180Note 4092 Unknown VIEW: 'test.v1' 5181CREATE VIEW v1 AS select coalesce(j1,i3) AS v1_field1 from t2 join t3 left join t1 on ( i1 = i2 ); 5182CREATE VIEW v2 AS select v1_field1 from t4 join v1; 5183prepare my_stmt from "select v1_field1 from v2"; 5184execute my_stmt; 5185v1_field1 518610 518710 518810 518910 51902 51912 51922 51932 5194execute my_stmt; 5195v1_field1 519610 519710 519810 519910 52002 52012 52022 52032 5204deallocate prepare my_stmt; 5205DROP VIEW v1,v2; 5206DROP TABLE t1,t2,t3,t4; 5207# 5208#MDEV-5717: Server crash with insert statement containing DEFAULT into 5209#view 5210# 5211CREATE TABLE t1 ( 5212`id` int(10) unsigned NOT NULL AUTO_INCREMENT, 5213`test` tinyint(3) unsigned NOT NULL DEFAULT '0', 5214PRIMARY KEY (`id`) 5215); 5216CREATE VIEW v1 AS (select t1.id AS id, t1.test AS test from t1); 5217INSERT INTO v1 SET test = DEFAULT; 5218select * from v1; 5219id test 52201 0 5221drop view v1; 5222drop table t1; 5223# 5224# MDEV-5981: name resolution issues with views and multi-update 5225# in ps-protocol 5226# 5227create table t1 (id1 int primary key, val1 varchar(20)); 5228insert into t1 values (1, 'test1'); 5229create table t2 (id2 int primary key, val2 varchar(20)); 5230insert into t2 values (1, 'test2'); 5231create algorithm=merge view v1 as select id1 as id1v1, val1 as val1v1 from t1; 5232create algorithm=merge view v2 as 5233select t2.id2 as id2v2, t2.val2 as val2v2 5234from t2, v1 5235where t2.id2 = v1.id1v1; 5236prepare stmt1 from "update v2 set val2v2 = 'test19' where 1 = id2v2"; 5237execute stmt1; 5238deallocate prepare stmt1; 5239drop view v1,v2; 5240drop table t1,t2; 5241# ----------------------------------------------------------------- 5242# -- End of 5.3 tests. 5243# ----------------------------------------------------------------- 5244# 5245# MDEV-3874: Server crashes in Item_field::print on a SELECT 5246# from a MERGE view with materialization+semijoin, subquery, ORDER BY 5247# 5248SET @save_optimizer_switch_MDEV_3874=@@optimizer_switch; 5249SET optimizer_switch = 'materialization=on,semijoin=on'; 5250CREATE TABLE t1 (a INT) ENGINE=MyISAM; 5251INSERT INTO t1 VALUES (1),(7); 5252CREATE TABLE t2 (b INT) ENGINE=MyISAM; 5253INSERT INTO t2 VALUES (4),(6); 5254CREATE TABLE t3 (c INT) ENGINE=MyISAM; 5255INSERT INTO t3 VALUES (1),(2); 5256CREATE ALGORITHM=MERGE VIEW v1 AS SELECT 5257( SELECT a FROM t1 WHERE ( 1, 1 ) IN ( 5258SELECT b, c FROM t2, t3 HAVING c > 2 ) ) AS field1, 5259b + c AS field2 5260FROM t2, t3 AS table1 5261GROUP BY field1, field2 ORDER BY field1; 5262Warnings: 5263Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm) 5264SELECT * FROM v1; 5265field1 field2 5266NULL 5 5267NULL 7 5268NULL 6 5269NULL 8 5270drop view v1; 5271drop table t1,t2,t3; 5272SET optimizer_switch=@save_optimizer_switch_MDEV_3874; 5273CREATE TABLE `t1` ( 5274`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 5275`f0` int(11) unsigned NOT NULL DEFAULT '0', 5276`f1` int(11) unsigned NOT NULL DEFAULT '0', 5277PRIMARY KEY (`id`), 5278UNIQUE KEY `id` (`id`) 5279); 5280CREATE TABLE `t2` ( 5281`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 5282`f02` bigint(20) unsigned NOT NULL DEFAULT '0', 5283`f03` int(11) unsigned NOT NULL DEFAULT '0', 5284PRIMARY KEY (`id`), 5285UNIQUE KEY `id` (`id`) 5286); 5287CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `v1` AS 5288SELECT 5289`t1`.`f0` AS `f0`, 5290`t1`.`f1` AS `f1`, 5291`t2`.`f02` AS `f02`, 5292`t2`.`f03` AS `f03` 5293FROM 5294(`t1` LEFT JOIN `t2` ON((`t1`.`id` = `t2`.`f02`))); 5295CREATE FUNCTION `f1`( 5296p0 BIGINT(20) UNSIGNED 5297) 5298RETURNS bigint(20) unsigned 5299DETERMINISTIC 5300CONTAINS SQL 5301SQL SECURITY DEFINER 5302COMMENT '' 5303BEGIN 5304DECLARE k0 INTEGER UNSIGNED DEFAULT 0; 5305DECLARE lResult INTEGER UNSIGNED DEFAULT 0; 5306SET k0 = 0; 5307WHILE k0 < 1 DO 5308SELECT COUNT(*) as `f00` INTO lResult FROM `v1` WHERE `v1`.`f0` = p0; -- BUG 5309SET k0 = k0 + 1; 5310END WHILE; 5311RETURN(k0); 5312END| 5313SELECT `f1`(1); 5314`f1`(1) 53151 5316SELECT `f1`(1); 5317`f1`(1) 53181 5319SELECT `f1`(1); 5320`f1`(1) 53211 5322SELECT `f1`(1); 5323`f1`(1) 53241 5325DROP FUNCTION f1; 5326DROP VIEW v1; 5327DROP TABLE t1, t2; 5328create view v1 as select 1; 5329FOUND 1 /mariadb-version/ in v1.frm 5330drop view v1; 5331# 5332# MDEV-7260: Crash in get_best_combination when executing multi-table 5333# UPDATE with nested views 5334# 5335CREATE TABLE `t1` (`id` bigint(20)); 5336INSERT INTO `t1` VALUES (1),(2); 5337CREATE TABLE `t2` (`id` bigint(20)); 5338CREATE TABLE `t3` (`id` bigint(20), `flag` tinyint(4)); 5339create view v1 as select id from t1; 5340create view v2 as select t2.* from (t2 left join v1 using (id)); 5341update t3 left join v2 using (id) set flag=flag+1; 5342drop view v2, v1; 5343drop table t1, t2, t3; 5344# 5345# MDEV-7207 - ALTER VIEW does not change ALGORITM 5346# 5347create table t1 (a int, b int); 5348create algorithm=temptable view v2 (c) as select b+1 from t1; 5349show create view v2; 5350View Create View character_set_client collation_connection 5351v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 5352alter algorithm=undefined view v2 (c) as select b+1 from t1; 5353show create view v2; 5354View Create View character_set_client collation_connection 5355v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 5356alter algorithm=merge view v2 (c) as select b+1 from t1; 5357show create view v2; 5358View Create View character_set_client collation_connection 5359v2 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`b` + 1 AS `c` from `t1` latin1 latin1_swedish_ci 5360drop view v2; 5361drop table t1; 5362# 5363# MDEV-8554: Server crashes in base_list_iterator::next_fast on 1st execution of PS with a multi-table update 5364# 5365CREATE TABLE t1 (a INT) ENGINE=MyISAM; 5366INSERT INTO t1 VALUES (1),(2); 5367CREATE TABLE t2 (b INT) ENGINE=MyISAM; 5368INSERT INTO t2 VALUES (3),(4); 5369CREATE TABLE t3 (c INT) ENGINE=MyISAM; 5370INSERT INTO t3 VALUES (5),(6); 5371CREATE OR REPLACE ALGORITHM=MERGE VIEW v3 AS SELECT * FROM t3; 5372PREPARE stmt FROM 'UPDATE t1, t2 SET a = 1 WHERE a IN ( SELECT 0 FROM t3 )'; 5373UPDATE t1, t2 SET a = 1 WHERE a IN ( SELECT 0 FROM v3 ); 5374EXECUTE stmt; 5375DROP TABLE t1, t2, t3; 5376DROP VIEW v3; 5377# 5378# MDEV-8632: Segmentation fault on INSERT 5379# 5380CREATE TABLE `t1` ( 5381`id` int(10) unsigned NOT NULL, 5382`r` float NOT NULL, 5383PRIMARY KEY (`id`) 5384) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 5385create view v1 as select id, if(r=r,1,2) as d from t1; 5386create view v2 as 5387select id, 5388d+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 5389from v1; 5390insert into t1 (id, r) 5391select id,p from 5392( 5393select id, 5394d+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 5395from ( 5396select id, if(r=r,1,2) as d 5397from t1 5398) a 5399) b 5400on duplicate key update r=p; 5401insert into t1 (id, r) 5402select id,p from v2 5403on duplicate key update r=p; 5404prepare stmt from "insert into t1 (id, r) select id,p from v2 on duplicate key update r=p"; 5405execute stmt; 5406execute stmt; 5407deallocate prepare stmt; 5408drop view v1,v2; 5409drop table `t1`; 5410create table t1 (a int, b int); 5411create view v1 as select a+b from t1; 5412alter table v1 check partition p1; 5413Table Op Msg_type Msg_text 5414test.v1 check Error 'test.v1' is not of type 'BASE TABLE' 5415test.v1 check status Operation failed 5416drop view v1; 5417drop table t1; 5418# 5419# MDEV-10419: crash in mariadb 10.1.16-MariaDB-1~trusty 5420# 5421CREATE TABLE t1 (c1 CHAR(13)); 5422CREATE TABLE t2 (c2 CHAR(13)); 5423CREATE FUNCTION f() RETURNS INT RETURN 0; 5424CREATE OR REPLACE VIEW v1 AS select f() from t1 where c1 in (select c2 from t2); 5425DROP FUNCTION f; 5426SHOW CREATE VIEW v1; 5427View Create View character_set_client collation_connection 5428v1 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 5429Warnings: 5430Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 5431drop view v1; 5432drop table t1,t2; 5433# 5434# MDEV-12099: usage of mergeable view with LEFT JOIN 5435# that can be converted to INNER JOIN 5436# 5437create table t1 (a int, b int, key(a)) engine=myisam; 5438insert into t1 values 5439(3,20), (7,10), (2,10), (4,30), (8,70), 5440(7,70), (9,100), (9,60), (8,80), (7,60); 5441create table t2 (c int, d int, key (c)) engine=myisam; 5442insert into t2 values 5443(50,100), (20, 200), (10,300), 5444(150,100), (120, 200), (110,300), 5445(250,100), (220, 200), (210,300); 5446create table t3(e int, f int not null, key(e), unique (f)) engine=myisam; 5447insert into t3 values 5448(100, 3), (300, 5), (400, 4), (300,7), 5449(300,2), (600, 13), (800, 15), (700, 14), 5450(600, 23), (800, 25), (700, 24); 5451create view v1 as 5452select * from t2 left join t3 on t3.e=t2.d where t3.f is not null; 5453select * 5454from t1 left join v1 on v1.c=t1.b 5455where t1.a < 5; 5456a b c d e f 54572 10 10 300 300 5 54582 10 10 300 300 7 54592 10 10 300 300 2 54603 20 NULL NULL NULL NULL 54614 30 NULL NULL NULL NULL 5462select * 5463from t1 left join ( t2 left join t3 on t3.e=t2.d ) 5464on t2.c=t1.b and t3.f is not null 5465where t1.a < 5; 5466a b c d e f 54672 10 10 300 300 5 54682 10 10 300 300 7 54692 10 10 300 300 2 54703 20 NULL NULL NULL NULL 54714 30 NULL NULL NULL NULL 5472explain extended 5473select * 5474from t1 left join v1 on v1.c=t1.b 5475where t1.a < 5; 5476id select_type table type possible_keys key key_len ref rows filtered Extra 54771 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 54781 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 54791 SIMPLE t3 ref f,e e 5 test.t2.d 2 100.00 Using where 5480Warnings: 5481Note 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 5482explain extended 5483select * 5484from t1 left join ( t2 left join t3 on t3.e=t2.d ) 5485on t2.c=t1.b and t3.f is not null 5486where t1.a < 5; 5487id select_type table type possible_keys key key_len ref rows filtered Extra 54881 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 54891 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 54901 SIMPLE t3 ref f,e e 5 test.t2.d 2 100.00 Using where 5491Warnings: 5492Note 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 5493explain extended 5494select * 5495from t1 left join v1 on v1.c=t1.b and v1.f=t1.a 5496where t1.a < 5; 5497id select_type table type possible_keys key key_len ref rows filtered Extra 54981 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 54991 SIMPLE t3 eq_ref f,e f 4 test.t1.a 1 100.00 Using where 55001 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 5501Warnings: 5502Note 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 5503explain extended 5504select * 5505from t1 left join ( t2 left join t3 on t3.e=t2.d ) 5506on t2.c=t1.b and t3.f=t1.a and t3.f is not null 5507where t1.a < 5; 5508id select_type table type possible_keys key key_len ref rows filtered Extra 55091 SIMPLE t1 range a a 5 NULL 3 100.00 Using index condition 55101 SIMPLE t3 eq_ref f,e f 4 test.t1.a 1 100.00 Using where 55111 SIMPLE t2 ref c c 5 test.t1.b 2 100.00 Using where 5512Warnings: 5513Note 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 5514drop view v1; 5515drop table t1,t2,t3; 5516# 5517# MDEV-11240: Server crashes in check_view_single_update or 5518# Assertion `derived->table' failed in mysql_derived_merge_for_insert 5519# 5520CREATE TABLE t3 (a INT); 5521CREATE ALGORITHM = MERGE VIEW v1 AS SELECT t2.a FROM t3 AS t1, t3 AS t2; 5522CREATE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM v1; 5523PREPARE stmt FROM 'REPLACE INTO v2 SELECT a FROM t3'; 5524ERROR HY000: Can not insert into join view 'test.v2' without fields list 5525drop view v1,v2; 5526drop table t3; 5527# 5528# MDEV-14619: VIEW and GROUP_CONCAT 5529# 5530CREATE TABLE t1 (str text); 5531INSERT INTO t1 VALUES ("My"),("SQL"); 5532CREATE VIEW v1 AS SELECT GROUP_CONCAT(str SEPARATOR '\\') FROM t1; 5533SELECT * FROM v1; 5534GROUP_CONCAT(str SEPARATOR '\\') 5535My\SQL 5536SHOW CREATE VIEW v1; 5537View Create View character_set_client collation_connection 5538v1 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 5539drop view v1; 5540drop table t1; 5541CREATE TABLE IF NOT EXISTS t0 (f0 INT); 5542CREATE TABLE IF NOT EXISTS t1 (f1 INT); 5543CREATE TABLE IF NOT EXISTS t2 (f2 INT); 5544CREATE TABLE IF NOT EXISTS t3 (f3 INT); 5545CREATE TABLE IF NOT EXISTS t4 (f4 INT); 5546CREATE TABLE IF NOT EXISTS t5 (f5 INT); 5547CREATE TABLE IF NOT EXISTS t6 (f6 INT); 5548CREATE TABLE IF NOT EXISTS t7 (f7 INT); 5549CREATE TABLE IF NOT EXISTS t8 (f8 INT); 5550CREATE TABLE IF NOT EXISTS t9 (f9 INT); 5551CREATE TABLE IF NOT EXISTS t10 (f10 INT); 5552CREATE TABLE IF NOT EXISTS t11 (f11 INT); 5553CREATE TABLE IF NOT EXISTS t12 (f12 INT); 5554CREATE TABLE IF NOT EXISTS t13 (f13 INT); 5555CREATE TABLE IF NOT EXISTS t14 (f14 INT); 5556CREATE TABLE IF NOT EXISTS t15 (f15 INT); 5557CREATE TABLE IF NOT EXISTS t16 (f16 INT); 5558CREATE TABLE IF NOT EXISTS t17 (f17 INT); 5559CREATE TABLE IF NOT EXISTS t18 (f18 INT); 5560CREATE TABLE IF NOT EXISTS t19 (f19 INT); 5561CREATE TABLE IF NOT EXISTS t20 (f20 INT); 5562CREATE TABLE IF NOT EXISTS t21 (f21 INT); 5563CREATE TABLE IF NOT EXISTS t22 (f22 INT); 5564CREATE TABLE IF NOT EXISTS t23 (f23 INT); 5565CREATE TABLE IF NOT EXISTS t24 (f24 INT); 5566CREATE TABLE IF NOT EXISTS t25 (f25 INT); 5567CREATE TABLE IF NOT EXISTS t26 (f26 INT); 5568CREATE TABLE IF NOT EXISTS t27 (f27 INT); 5569CREATE TABLE IF NOT EXISTS t28 (f28 INT); 5570CREATE TABLE IF NOT EXISTS t29 (f29 INT); 5571CREATE TABLE IF NOT EXISTS t30 (f30 INT); 5572CREATE TABLE IF NOT EXISTS t31 (f31 INT); 5573CREATE TABLE IF NOT EXISTS t32 (f32 INT); 5574CREATE TABLE IF NOT EXISTS t33 (f33 INT); 5575CREATE TABLE IF NOT EXISTS t34 (f34 INT); 5576CREATE TABLE IF NOT EXISTS t35 (f35 INT); 5577CREATE TABLE IF NOT EXISTS t36 (f36 INT); 5578CREATE TABLE IF NOT EXISTS t37 (f37 INT); 5579CREATE TABLE IF NOT EXISTS t38 (f38 INT); 5580CREATE TABLE IF NOT EXISTS t39 (f39 INT); 5581CREATE TABLE IF NOT EXISTS t40 (f40 INT); 5582CREATE TABLE IF NOT EXISTS t41 (f41 INT); 5583CREATE TABLE IF NOT EXISTS t42 (f42 INT); 5584CREATE TABLE IF NOT EXISTS t43 (f43 INT); 5585CREATE TABLE IF NOT EXISTS t44 (f44 INT); 5586CREATE TABLE IF NOT EXISTS t45 (f45 INT); 5587CREATE TABLE IF NOT EXISTS t46 (f46 INT); 5588CREATE TABLE IF NOT EXISTS t47 (f47 INT); 5589CREATE TABLE IF NOT EXISTS t48 (f48 INT); 5590CREATE TABLE IF NOT EXISTS t49 (f49 INT); 5591CREATE TABLE IF NOT EXISTS t50 (f50 INT); 5592CREATE TABLE IF NOT EXISTS t51 (f51 INT); 5593CREATE TABLE IF NOT EXISTS t52 (f52 INT); 5594CREATE TABLE IF NOT EXISTS t53 (f53 INT); 5595CREATE TABLE IF NOT EXISTS t54 (f54 INT); 5596CREATE TABLE IF NOT EXISTS t55 (f55 INT); 5597CREATE TABLE IF NOT EXISTS t56 (f56 INT); 5598CREATE TABLE IF NOT EXISTS t57 (f57 INT); 5599CREATE TABLE IF NOT EXISTS t58 (f58 INT); 5600CREATE TABLE IF NOT EXISTS t59 (f59 INT); 5601CREATE TABLE IF NOT EXISTS t60 (f60 INT); 5602CREATE OR REPLACE VIEW v60 AS SELECT * FROM t60; 5603EXPLAIN 5604SELECT t0.* 5605FROM t0 5606JOIN t1 5607ON t1.f1 = t0.f0 5608LEFT JOIN t2 5609ON t0.f0 = t2.f2 5610LEFT JOIN t3 5611ON t0.f0 = t3.f3 5612LEFT JOIN t4 5613ON t0.f0 = t4.f4 5614LEFT JOIN t5 5615ON t4.f4 = t5.f5 5616LEFT JOIN t6 5617ON t0.f0 = t6.f6 5618LEFT JOIN t7 5619ON t0.f0 = t7.f7 5620LEFT JOIN t8 5621ON t0.f0 = t8.f8 5622LEFT JOIN t9 5623ON t0.f0 = t9.f9 5624LEFT JOIN t10 5625ON t0.f0 = t10.f10 5626LEFT JOIN t11 5627ON t0.f0 = t11.f11 5628LEFT JOIN t12 5629ON t0.f0 = t12.f12 5630LEFT JOIN t13 5631ON t0.f0 = t13.f13 5632LEFT JOIN t14 5633ON t0.f0 = t14.f14 5634LEFT JOIN t15 5635ON t0.f0 = t15.f15 5636LEFT JOIN t16 5637ON t0.f0 = t16.f16 5638LEFT JOIN t17 5639ON t0.f0 = t17.f17 5640LEFT JOIN t18 5641ON t0.f0 = t18.f18 5642LEFT JOIN t19 5643ON t18.f18 = t19.f19 5644LEFT JOIN t20 5645ON t20.f20 = t19.f19 5646LEFT JOIN t21 5647ON t20.f20 = t21.f21 5648LEFT JOIN t22 5649ON t19.f19 = t22.f22 5650LEFT JOIN t23 5651ON t23.f23 = t0.f0 5652LEFT JOIN t24 5653ON t24.f24 = t23.f23 5654LEFT JOIN t25 5655ON t0.f0 = t25.f25 5656LEFT JOIN t26 5657ON t26.f26 = t0.f0 5658LEFT JOIN t27 5659ON t27.f27 = t0.f0 5660LEFT JOIN t28 5661ON t0.f0 = t28.f28 5662LEFT JOIN t29 5663ON t0.f0 = t29.f29 5664LEFT JOIN t30 5665ON t30.f30 = t0.f0 5666LEFT JOIN t31 5667ON t0.f0 = t31.f31 5668LEFT JOIN t32 5669ON t32.f32 = t31.f31 5670LEFT JOIN t33 5671ON t33.f33 = t0.f0 5672LEFT JOIN t34 5673ON t33.f33 = t34.f34 5674LEFT JOIN t35 5675ON t33.f33 = t35.f35 5676LEFT JOIN t36 5677ON t36.f36 = t0.f0 5678LEFT JOIN t37 5679ON t32.f32 = t37.f37 5680LEFT JOIN t38 5681ON t31.f31 = t38.f38 5682LEFT JOIN t39 5683ON t39.f39 = t0.f0 5684LEFT JOIN t40 5685ON t40.f40 = t39.f39 5686LEFT JOIN t41 5687ON t41.f41 = t0.f0 5688LEFT JOIN t42 5689ON t42.f42 = t41.f41 5690LEFT JOIN t43 5691ON t43.f43 = t41.f41 5692LEFT JOIN t44 5693ON t44.f44 = t0.f0 5694LEFT JOIN t45 5695ON t45.f45 = t0.f0 5696LEFT JOIN t46 5697ON t46.f46 = t0.f0 5698LEFT JOIN t47 5699ON t47.f47 = t0.f0 5700LEFT JOIN t48 5701ON t48.f48 = t0.f0 5702LEFT JOIN t49 5703ON t0.f0 = t49.f49 5704LEFT JOIN t50 5705ON t0.f0 = t50.f50 5706LEFT JOIN t51 5707ON t0.f0 = t51.f51 5708LEFT JOIN t52 5709ON t52.f52 = t0.f0 5710LEFT JOIN t53 5711ON t53.f53 = t0.f0 5712LEFT JOIN t54 5713ON t54.f54 = t0.f0 5714LEFT JOIN t55 5715ON t55.f55 = t0.f0 5716LEFT JOIN t56 5717ON t56.f56 = t0.f0 5718LEFT JOIN t57 5719ON t57.f57 = t0.f0 5720LEFT JOIN t58 5721ON t58.f58 = t57.f57 5722LEFT JOIN t59 5723ON t36.f36 = t59.f59 5724LEFT JOIN v60 5725ON t36.f36 = v60.f60 5726; 5727id select_type table type possible_keys key key_len ref rows Extra 57281 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 57292 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table 5730drop table t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, 5731t10, t11, t12, t13, t14, t15, t16, t17, t18, 5732t19, t20, t21, t22, t23, t24, t25, t26, t27, 5733t28, t29, t30, t31, t32, t33, t34, t35, t36, 5734t37, t38, t39, t40, t41, t42, t43, t44, t45, 5735t46, t47, t48, t49, t50, t51, t52, t53, t54, 5736t55, t56, t57, t58, t59,t60; 5737drop view v60; 5738# 5739# MDEV-15572: view.test, server crash with --big-tables=1 5740# 5741set @save_big_tables=@@big_tables; 5742set big_tables=ON; 5743CREATE TABLE t1 ( f1 int , f2 int , f3 int , f4 int); 5744CREATE TABLE t2 ( f1 int , f2 int , f3 int , f4 int); 5745CREATE VIEW v1 AS 5746SELECT t2.f1, t1.f2, t2.f3, t2.f4 FROM (t1 JOIN t2); 5747REPLACE INTO v1 (f1, f2, f3, f4) 5748SELECT f1, f2, f3, f4 FROM t1; 5749ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 5750drop view v1; 5751drop table t1, t2; 5752set big_tables=@save_big_tables; 5753# ----------------------------------------------------------------- 5754# -- End of 5.5 tests. 5755# ----------------------------------------------------------------- 5756# some subqueries in SELECT list test 5757create table t1 (a int, b int); 5758create table t2 (a int, b int); 5759insert into t1 values (1,2), (3,4), (3,3), (5,6), (7,8), (9,10); 5760insert into t2 values (1,2), (3,4), (3,3), (5,6), (7,8), (9,10); 5761create algorithm=merge view v1 as select t1.a as a, (select max(b) from t2 where t1.a=t2.a) as c from t1; 5762explain extended 5763select * from v1; 5764id select_type table type possible_keys key key_len ref rows filtered Extra 57651 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 57663 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5767Warnings: 5768Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5769Note 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` 5770select * from v1; 5771a c 57721 2 57733 4 57743 4 57755 6 57767 8 57779 10 5778explain extended 5779select * from t2, v1 where t2.a=v1.a; 5780id select_type table type possible_keys key key_len ref rows filtered Extra 57811 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 57821 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 57833 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5784Warnings: 5785Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5786Note 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` 5787select * from t2, v1 where t2.a=v1.a; 5788a b a c 57891 2 1 2 57903 4 3 4 57913 3 3 4 57923 4 3 4 57933 3 3 4 57945 6 5 6 57957 8 7 8 57969 10 9 10 5797explain extended 5798select * from t1, v1 where t1.a=v1.a; 5799id select_type table type possible_keys key key_len ref rows filtered Extra 58001 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 58011 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 58023 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5803Warnings: 5804Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5805Note 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` 5806select * from t1, v1 where t1.a=v1.a; 5807a b a c 58081 2 1 2 58093 4 3 4 58103 3 3 4 58113 4 3 4 58123 3 3 4 58135 6 5 6 58147 8 7 8 58159 10 9 10 5816explain extended 5817select * from t1, v1 where t1.b=v1.c; 5818id select_type table type possible_keys key key_len ref rows filtered Extra 58191 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 58201 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 58213 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5822Warnings: 5823Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5824Note 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`)) 5825select * from t1, v1 where t1.b=v1.c; 5826a b a c 58271 2 1 2 58283 4 3 4 58293 4 3 4 58305 6 5 6 58317 8 7 8 58329 10 9 10 5833explain extended 5834select * from t2, t1, v1 where t1.a=t2.a and t1.a=v1.a; 5835id select_type table type possible_keys key key_len ref rows filtered Extra 58361 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 58371 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) 58381 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (incremental, BNL join) 58393 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where 5840Warnings: 5841Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2 5842Note 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` 5843select * from t2, t1, v1 where t1.a=t2.a and t1.a=v1.a; 5844a b a b a c 58451 2 1 2 1 2 58463 4 3 4 3 4 58473 3 3 4 3 4 58483 4 3 3 3 4 58493 3 3 3 3 4 58503 4 3 4 3 4 58513 3 3 4 3 4 58523 4 3 3 3 4 58533 3 3 3 3 4 58545 6 5 6 5 6 58557 8 7 8 7 8 58569 10 9 10 9 10 5857drop view v1; 5858drop table t1,t2; 5859create table t1 (i int not null); 5860insert into t1 values (1),(2); 5861create table t2 (j int not null); 5862insert into t2 values (11),(12); 5863create algorithm=merge view v3 as select t1.* from t2 left join t1 on (t2.j = t1.i); 5864prepare stmt from 'select count(v3.i) from t1, v3'; 5865execute stmt; 5866count(v3.i) 58670 5868execute stmt; 5869count(v3.i) 58700 5871drop table t1, t2; 5872drop view v3; 5873# 5874# MDEV-8525: mariadb 10.0.20 crashing when data is read by Kodi 5875# media center (http://kodi.tv). 5876# 5877CREATE TABLE `t1` ( 5878`idSong` int(11) NOT NULL AUTO_INCREMENT, 5879`idAlbum` int(11) DEFAULT NULL, 5880`idPath` int(11) DEFAULT NULL, 5881`strArtists` text, 5882`strGenres` text, 5883`strTitle` varchar(512) DEFAULT NULL, 5884`iTrack` int(11) DEFAULT NULL, 5885`iDuration` int(11) DEFAULT NULL, 5886`iYear` int(11) DEFAULT NULL, 5887`dwFileNameCRC` text, 5888`strFileName` text, 5889`strMusicBrainzTrackID` text, 5890`iTimesPlayed` int(11) DEFAULT NULL, 5891`iStartOffset` int(11) DEFAULT NULL, 5892`iEndOffset` int(11) DEFAULT NULL, 5893`idThumb` int(11) DEFAULT NULL, 5894`lastplayed` varchar(20) DEFAULT NULL, 5895`rating` char(1) DEFAULT '0', 5896`comment` text, 5897`mood` text, 5898PRIMARY KEY (`idSong`), 5899UNIQUE KEY `idxSong7` (`idAlbum`,`strMusicBrainzTrackID`(36)), 5900KEY `idxSong` (`strTitle`(255)), 5901KEY `idxSong1` (`iTimesPlayed`), 5902KEY `idxSong2` (`lastplayed`), 5903KEY `idxSong3` (`idAlbum`), 5904KEY `idxSong6` (`idPath`,`strFileName`(255)) 5905) DEFAULT CHARSET=utf8; 5906INSERT 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','',''); 5907CREATE TABLE `t2` ( 5908`idAlbum` int(11) NOT NULL AUTO_INCREMENT, 5909`strAlbum` varchar(256) DEFAULT NULL, 5910`strMusicBrainzAlbumID` text, 5911`strArtists` text, 5912`strGenres` text, 5913`iYear` int(11) DEFAULT NULL, 5914`idThumb` int(11) DEFAULT NULL, 5915`bCompilation` int(11) NOT NULL DEFAULT '0', 5916`strMoods` text, 5917`strStyles` text, 5918`strThemes` text, 5919`strReview` text, 5920`strImage` text, 5921`strLabel` text, 5922`strType` text, 5923`iRating` int(11) DEFAULT NULL, 5924`lastScraped` varchar(20) DEFAULT NULL, 5925`dateAdded` varchar(20) DEFAULT NULL, 5926`strReleaseType` text, 5927PRIMARY KEY (`idAlbum`), 5928UNIQUE KEY `idxAlbum_2` (`strMusicBrainzAlbumID`(36)), 5929KEY `idxAlbum` (`strAlbum`(255)), 5930KEY `idxAlbum_1` (`bCompilation`) 5931) DEFAULT CHARSET=utf8; 5932INSERT INTO `t2` VALUES (1,'strAlbum1','strMusicBrainzAlbumID1','strArtists1','strGenres1',2000,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'album'); 5933CREATE TABLE `t3` ( 5934`idArtist` int(11) DEFAULT NULL, 5935`idAlbum` int(11) DEFAULT NULL, 5936`strJoinPhrase` text, 5937`boolFeatured` int(11) DEFAULT NULL, 5938`iOrder` int(11) DEFAULT NULL, 5939`strArtist` text, 5940UNIQUE KEY `idxAlbumArtist_1` (`idAlbum`,`idArtist`), 5941UNIQUE KEY `idxAlbumArtist_2` (`idArtist`,`idAlbum`), 5942KEY `idxAlbumArtist_3` (`boolFeatured`) 5943) DEFAULT CHARSET=utf8; 5944INSERT INTO `t3` VALUES (1,1,'',0,0,'strArtist1'); 5945CREATE TABLE `t4` ( 5946`idArtist` int(11) NOT NULL AUTO_INCREMENT, 5947`strArtist` varchar(256) DEFAULT NULL, 5948`strMusicBrainzArtistID` text, 5949`strBorn` text, 5950`strFormed` text, 5951`strGenres` text, 5952`strMoods` text, 5953`strStyles` text, 5954`strInstruments` text, 5955`strBiography` text, 5956`strDied` text, 5957`strDisbanded` text, 5958`strYearsActive` text, 5959`strImage` text, 5960`strFanart` text, 5961`lastScraped` varchar(20) DEFAULT NULL, 5962`dateAdded` varchar(20) DEFAULT NULL, 5963PRIMARY KEY (`idArtist`), 5964UNIQUE KEY `idxArtist1` (`strMusicBrainzArtistID`(36)), 5965KEY `idxArtist` (`strArtist`(255)) 5966) DEFAULT CHARSET=utf8; 5967INSERT INTO `t4` VALUES (1,'strArtist1','strMusicBrainzArtistID',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); 5968CREATE 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`; 5969CREATE 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`))); 5970SELECT v1.*,v2.* FROM v1 LEFT JOIN v2 ON v1.idAlbum = v2.idAlbum WHERE v1.idAlbum = 1 ORDER BY v2.iOrder; 5971idAlbum strAlbum strMusicBrainzAlbumID strArtists strGenres iYear strMoods strStyles strThemes strReview strLabel strType strImage iRating bCompilation iTimesPlayed strReleaseType idAlbum idArtist strArtist strMusicBrainzArtistID boolFeatured strJoinPhrase iOrder 59721 strAlbum1 strMusicBrainzAlbumID1 strArtists1 strGenres1 2000 NULL NULL NULL NULL NULL NULL NULL NULL 0 0 album 1 1 strArtist1 strMusicBrainzArtistID 0 0 5973drop view v1,v2; 5974drop table t1,t2,t3,t4; 5975# 5976# MDEV-8913: Derived queries with same column names as final 5977# projection causes issues when using Order By 5978# 5979create table t1 (field int); 5980insert into t1 values (10),(5),(3),(8),(20); 5981SELECT sq.f2 AS f1, sq.f1 AS f2 5982FROM ( SELECT field AS f1, 1 AS f2 FROM t1) AS sq 5983ORDER BY sq.f1; 5984f1 f2 59851 3 59861 5 59871 8 59881 10 59891 20 5990create view v1 as SELECT field AS f1, 1 AS f2 FROM t1; 5991SELECT sq.f2 AS f1, sq.f1 AS f2 5992FROM v1 AS sq 5993ORDER BY sq.f1; 5994f1 f2 59951 3 59961 5 59971 8 59981 10 59991 20 6000drop view v1; 6001create table t2 SELECT field AS f1, 1 AS f2 FROM t1; 6002SELECT 6003sq.f2 AS f1, 6004sq.f1 AS f2 6005FROM t2 AS sq 6006ORDER BY sq.f1; 6007f1 f2 60081 3 60091 5 60101 8 60111 10 60121 20 6013drop table t1, t2; 6014SELECT 1 FROM (SELECT 1 as a) AS b HAVING (SELECT `SOME_GARBAGE`.b.a)=1; 6015ERROR 42S22: Unknown column 'SOME_GARBAGE.b.a' in 'field list' 6016# 6017# MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 6018# FOR UPDATE 6019# 6020CREATE TABLE t1 (a INT); 6021insert into t1 values (1),(2); 6022CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE; 6023SHOW CREATE VIEW v1; 6024View Create View character_set_client collation_connection 6025v1 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 6026select * from v1; 6027a 60281 60292 6030DROP VIEW v1; 6031CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE; 6032SHOW CREATE VIEW v1; 6033View Create View character_set_client collation_connection 6034v1 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 6035select * from v1; 6036a 60371 60382 6039DROP VIEW v1; 6040DROP TABLE t1; 6041# 6042# MDEV-8642: WHERE Clause not applied on View - Empty result set returned 6043# 6044CREATE TABLE `t1` ( 6045`id` int(20) NOT NULL AUTO_INCREMENT, 6046`use_case` int(11) DEFAULT NULL, 6047`current_deadline` date DEFAULT NULL, 6048`ts_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 6049PRIMARY KEY (`id`), 6050UNIQUE KEY `id_UNIQUE` (`id`) 6051) ENGINE=MyISAM AUTO_INCREMENT=13976 DEFAULT CHARSET=latin1; 6052INSERT INTO `t1` VALUES (1,10,'2015-12-18','2015-08-18 08:38:16'); 6053INSERT INTO `t1` VALUES (2,20,'2015-10-18','2015-08-18 08:43:30'); 6054CREATE VIEW v1 AS SELECT 6055use_case as use_case_id, 6056( 6057SELECT 6058deadline_sub.current_deadline 6059FROM 6060t1 deadline_sub 6061WHERE 6062deadline_sub.use_case = use_case_id 6063AND ts_create = (SELECT 6064MIN(ts_create) 6065FROM 6066t1 startdate_sub 6067WHERE 6068startdate_sub.use_case = use_case_id 6069) 6070) AS InitialDeadline 6071FROM 6072t1; 6073SELECT * FROM v1 where use_case_id = 10; 6074use_case_id InitialDeadline 607510 2015-12-18 6076drop view v1; 6077drop table t1; 6078# 6079# MDEV-12666: CURRENT_ROLE() and DATABASE() does not work in a view 6080# 6081# DATABASE() fails only when the initial view creation features a NULL 6082# default database. 6083# 6084# CREATE, USE and DROP database so that we have no "default" database. 6085# 6086CREATE DATABASE temporary; 6087USE temporary; 6088DROP DATABASE temporary; 6089SELECT DATABASE(); 6090DATABASE() 6091NULL 6092CREATE VIEW test.v_no_db AS SELECT DATABASE() = 'temporary_two'; 6093SHOW CREATE VIEW test.v_no_db; 6094View Create View character_set_client collation_connection 6095v_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 6096PREPARE prepared_no_database FROM "SELECT DATABASE() = 'temporary_two'"; 6097# 6098# All statements should return NULL 6099# 6100EXECUTE prepared_no_database; 6101DATABASE() = 'temporary_two' 6102NULL 6103SELECT DATABASE() = 'temporary_two'; 6104DATABASE() = 'temporary_two' 6105NULL 6106SELECT * FROM test.v_no_db; 6107DATABASE() = 'temporary_two' 6108NULL 6109CREATE DATABASE temporary_two; 6110USE temporary_two; 6111CREATE VIEW test.v_with_db AS SELECT DATABASE() = 'temporary_two'; 6112PREPARE prepared_with_database FROM "SELECT DATABASE() = 'temporary_two'"; 6113# 6114# All statements should return 1; 6115# 6116SELECT DATABASE() = 'temporary_two'; 6117DATABASE() = 'temporary_two' 61181 6119SELECT * FROM test.v_no_db; 6120DATABASE() = 'temporary_two' 61211 6122SELECT * FROM test.v_with_db; 6123DATABASE() = 'temporary_two' 61241 6125EXECUTE prepared_with_database; 6126DATABASE() = 'temporary_two' 61271 6128# 6129# Prepared statements maintain default database to be the same 6130# during on creation so this should return NULL still. 6131# See MySQL bug #25843 6132# 6133EXECUTE prepared_no_database; 6134DATABASE() = 'temporary_two' 6135NULL 6136DROP DATABASE temporary_two; 6137DROP VIEW test.v_no_db; 6138DROP VIEW test.v_with_db; 6139USE test; 6140# ----------------------------------------------------------------- 6141# -- End of 10.0 tests. 6142# ----------------------------------------------------------------- 6143SET optimizer_switch=@save_optimizer_switch; 6144# 6145# Start of 10.1 tests 6146# 6147# 6148# MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin 6149# 6150CREATE TABLE t1 (a varchar(10) character set cp1251 collate cp1251_ukrainian_ci, KEY (a)) ; 6151INSERT INTO t1 VALUES ('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'),('MM'),('`1'); 6152CREATE VIEW v1 AS SELECT * FROM t1; 6153SELECT * FROM t1 WHERE a <> 0 AND a = ' 1'; 6154a 6155Warnings: 6156Warning 1292 Truncated incorrect DOUBLE value: '`1' 6157SELECT * FROM v1 WHERE a <> 0 AND a = ' 1'; 6158a 6159Warnings: 6160Warning 1292 Truncated incorrect DOUBLE value: '`1' 6161DROP VIEW v1; 6162DROP TABLE t1; 6163CREATE TABLE t1 (a ENUM('5','6')); 6164INSERT INTO t1 VALUES ('5'),('6'); 6165CREATE VIEW v1 AS SELECT * FROM t1; 6166SELECT * FROM t1 WHERE a='5' AND a<2; 6167a 61685 6169SELECT * FROM v1 WHERE a='5' AND a<2; 6170a 61715 6172DROP VIEW v1; 6173DROP TABLE t1; 6174# 6175# MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number2 6176# 6177CREATE TABLE t1 (a varchar(10) character set cp1251 collate cp1251_ukrainian_ci, KEY (a)); 6178INSERT INTO t1 VALUES ('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'),('MM'),('`1'); 6179CREATE VIEW v1 AS SELECT * FROM t1; 6180SELECT * FROM t1 WHERE a <> 0 AND a = ' 1'; 6181a 6182Warnings: 6183Warning 1292 Truncated incorrect DOUBLE value: '`1' 6184SELECT * FROM v1 WHERE a <> 0 AND a = ' 1'; 6185a 6186Warnings: 6187Warning 1292 Truncated incorrect DOUBLE value: '`1' 6188DROP VIEW v1; 6189DROP TABLE t1; 6190CREATE TABLE t1 (a ENUM('5','6')); 6191INSERT INTO t1 VALUES ('5'),('6'); 6192CREATE VIEW v1 AS SELECT * FROM t1; 6193SELECT * FROM t1 WHERE a='5' AND a<2; 6194a 61955 6196SELECT * FROM v1 WHERE a='5' AND a<2; 6197a 61985 6199DROP VIEW v1; 6200DROP TABLE t1; 6201# 6202# MDEV-8742 Wrong result for SELECT..WHERE view_latin1_swedish_ci_field='a' COLLATE latin1_bin 6203# 6204CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET latin1); 6205INSERT INTO t1 VALUES ('a'),('A'); 6206CREATE VIEW v1 AS SELECT * FROM t1 WHERE a='a'; 6207SELECT * FROM v1 WHERE a=_latin1'a' COLLATE latin1_bin; 6208a 6209a 6210DROP VIEW v1; 6211DROP TABLE t1; 6212# 6213# MDEV-9701: CREATE VIEW with GROUP BY or ORDER BY and constant 6214# produces invalid definition 6215# 6216CREATE TABLE t1 ( i INT ); 6217INSERT INTO t1 VALUES (1),(2); 6218CREATE VIEW v1 AS 6219SELECT 3 AS three, COUNT(*) FROM t1 GROUP BY three; 6220show create view v1; 6221View Create View character_set_client collation_connection 6222v1 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 6223SELECT * FROM v1; 6224three COUNT(*) 62253 2 6226drop view v1; 6227drop table t1; 6228# 6229# MDEV-12819: order by ordering expression changed to empty string 6230# when creatin view with union 6231# 6232create table t1 (t1col1 int, t1col2 int,t1col3 int ); 6233create table t2 (t2col1 int, t2col2 int, t2col3 int); 6234create view v1 as 6235select t1col1,t1col2,t1col3 from t1 6236union all 6237select t2col1,t2col2,t2col3 from t2 6238order by 2,3; 6239show create view v1; 6240View Create View character_set_client collation_connection 6241v1 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 6242select * from v1; 6243t1col1 t1col2 t1col3 6244drop view v1; 6245drop table t1,t2; 6246# 6247# End of 10.1 tests 6248# 6249# 6250# Start of 10.2 tests 6251# 6252# Checking that SHOW CREATE VIEW preserve parentheses 6253CREATE TABLE t1 (a INT); 6254INSERT INTO t1 VALUES (10),(20),(30); 6255CREATE VIEW v1 AS SELECT 1 AS a UNION SELECT a FROM t1; 6256SHOW CREATE VIEW v1; 6257View Create View character_set_client collation_connection 6258v1 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 6259SELECT * FROM v1; 6260a 62611 626210 626320 626430 6265DROP VIEW v1; 6266CREATE VIEW v1 AS SELECT 1 AS a UNION SELECT a FROM t1 LIMIT 1; 6267SHOW CREATE VIEW v1; 6268View Create View character_set_client collation_connection 6269v1 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 6270SELECT * FROM v1; 6271a 62721 6273DROP VIEW v1; 6274CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1); 6275SHOW CREATE VIEW v1; 6276View Create View character_set_client collation_connection 6277v1 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 6278SELECT * FROM v1; 6279a 62801 628110 628220 628330 6284DROP VIEW v1; 6285CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1 LIMIT 1); 6286SHOW CREATE VIEW v1; 6287View Create View character_set_client collation_connection 6288v1 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 6289SELECT * FROM v1; 6290a 62911 629210 6293DROP VIEW v1; 6294CREATE VIEW v1 AS SELECT 1 AS a UNION (SELECT a FROM t1) LIMIT 1; 6295SHOW CREATE VIEW v1; 6296View Create View character_set_client collation_connection 6297v1 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 6298SELECT * FROM v1; 6299a 63001 6301DROP VIEW v1; 6302DROP TABLE t1; 6303# 6304# MDEV-9408 CREATE TABLE SELECT MAX(int_column) creates different columns for table vs view 6305# 6306CREATE TABLE t1 ( 6307id int(11) NOT NULL PRIMARY KEY, 6308country varchar(32), 6309code int(11) default NULL 6310); 6311INSERT INTO t1 VALUES (1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); 6312CREATE VIEW v1 AS SELECT * FROM t1; 6313CREATE TABLE t2 AS 6314SELECT code, COUNT(DISTINCT country), MAX(id) FROM t1 GROUP BY code ORDER BY MAX(id); 6315SHOW CREATE TABLE t2; 6316Table Create Table 6317t2 CREATE TABLE `t2` ( 6318 `code` int(11) DEFAULT NULL, 6319 `COUNT(DISTINCT country)` bigint(21) NOT NULL, 6320 `MAX(id)` int(11) 6321) ENGINE=MyISAM DEFAULT CHARSET=latin1 6322CREATE TABLE t3 AS 6323SELECT code, COUNT(DISTINCT country), MAX(id) FROM v1 GROUP BY code ORDER BY MAX(id); 6324SHOW CREATE TABLE t3; 6325Table Create Table 6326t3 CREATE TABLE `t3` ( 6327 `code` int(11) DEFAULT NULL, 6328 `COUNT(DISTINCT country)` bigint(21) NOT NULL, 6329 `MAX(id)` int(11) DEFAULT NULL 6330) ENGINE=MyISAM DEFAULT CHARSET=latin1 6331DROP VIEW v1; 6332DROP TABLE t1,t2,t3; 6333# 6334# MDEV-3944: Allow derived tables in VIEWS 6335# 6336create table t1 (s1 int); 6337insert into t1 values (1),(2),(3); 6338CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1>1) AS x; 6339CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1<3) AS x; 6340select * from v1; 6341s1 63422 63433 6344select * from v2; 6345s1 63461 63472 6348select * from v1 natural join v2; 6349s1 63502 6351select * from v1 natural join t1; 6352s1 63532 63543 6355select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; 6356s1 63572 6358select * from v1 left join v2 on (v1.s1=v2.s1); 6359s1 s1 63602 2 63613 NULL 6362select * from v1 left join t1 on (v1.s1=t1.s1); 6363s1 s1 63642 2 63653 3 6366select * from t1 left join v2 on (t1.s1=v2.s1); 6367s1 s1 63681 1 63692 2 63703 NULL 6371select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); 6372s1 s1 63732 2 63743 NULL 6375select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); 6376s1 s1 63772 2 63783 NULL 6379drop view v1,v2; 6380CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6381< 100) as xx WHERE s1>1) AS x; 6382CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6383> -100) as xx WHERE s1<3) AS x; 6384insert into t1 values (200),(-200); 6385select * from t1; 6386s1 6387-200 63881 63892 6390200 63913 6392select * from v1; 6393s1 63942 63953 6396select * from v2; 6397s1 63981 63992 6400select * from v1 natural join v2; 6401s1 64022 6403select * from v1 natural join t1; 6404s1 64052 64063 6407select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; 6408s1 64092 6410select * from v1 left join v2 on (v1.s1=v2.s1); 6411s1 s1 64122 2 64133 NULL 6414select * from v1 left join t1 on (v1.s1=t1.s1); 6415s1 s1 64162 2 64173 3 6418select * from t1 left join v2 on (t1.s1=v2.s1); 6419s1 s1 6420-200 NULL 64211 1 64222 2 6423200 NULL 64243 NULL 6425select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); 6426s1 s1 64272 2 64283 NULL 6429select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); 6430s1 s1 64312 2 6432200 NULL 64333 NULL 6434drop view v1,v2; 6435CREATE algorithm=temptable VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6436< 100) as xx WHERE s1>1) AS x; 6437CREATE algorithm=temptable VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6438> -100) as xx WHERE s1<3) AS x; 6439select * from t1; 6440s1 6441-200 64421 64432 6444200 64453 6446select * from v1; 6447s1 64482 64493 6450select * from v2; 6451s1 64521 64532 6454select * from v1 natural join v2; 6455s1 64562 6457select * from v1 natural join t1; 6458s1 64592 64603 6461select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x; 6462s1 64632 6464select * from v1 left join v2 on (v1.s1=v2.s1); 6465s1 s1 64662 2 64673 NULL 6468select * from v1 left join t1 on (v1.s1=t1.s1); 6469s1 s1 64702 2 64713 3 6472select * from t1 left join v2 on (t1.s1=v2.s1); 6473s1 s1 6474-200 NULL 64751 1 64762 2 6477200 NULL 64783 NULL 6479select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1); 6480s1 s1 64812 2 64823 NULL 6483select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1); 6484s1 s1 64852 2 6486200 NULL 64873 NULL 6488drop view v1,v2; 6489CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6490< 100) as xx WHERE s1>1) AS x; 6491insert into v1 values (-300); 6492ERROR HY000: The target table v1 of the INSERT is not insertable-into 6493update v1 set s1=s1+1; 6494ERROR HY000: The target table v1 of the UPDATE is not updatable 6495drop view v1; 6496CREATE VIEW v1 AS SELECT s1,s2 FROM (SELECT s1 as s2 FROM t1 WHERE s1 < 6497100) x, t1 WHERE t1.s1=x.s2; 6498select * from v1; 6499s1 s2 65001 1 65012 2 65023 3 6503-200 -200 6504insert into v1 (s1) values (-300); 6505update v1 set s1=s1+1; 6506select * from v1; 6507s1 s2 65082 2 65093 3 65104 4 6511-199 -199 6512-299 -299 6513select * from t1; 6514s1 65152 65163 65174 6518200 6519-199 6520-299 6521insert into v1(s2) values (-300); 6522ERROR HY000: The target table v1 of the INSERT is not insertable-into 6523update v1 set s2=s2+1; 6524ERROR HY000: The target table v1 of the UPDATE is not updatable 6525drop view v1; 6526CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1 6527< 100) AS x; 6528insert into v1 values (-300); 6529ERROR HY000: The target table v1 of the INSERT is not insertable-into 6530update v1 set s1=s1+1; 6531ERROR HY000: The target table v1 of the UPDATE is not updatable 6532drop view v1; 6533CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1 6534< 100) as xx WHERE s1>1) AS x; 6535insert into v1 values (-300); 6536ERROR HY000: The target table v1 of the INSERT is not insertable-into 6537update v1 set s1=s1+1; 6538ERROR HY000: The target table v1 of the UPDATE is not updatable 6539create view v2 as select * from v1; 6540insert into v2 values (-300); 6541ERROR HY000: The target table v2 of the INSERT is not insertable-into 6542update v2 set s1=s1+1; 6543ERROR HY000: The target table v2 of the UPDATE is not updatable 6544drop view v1, v2; 6545drop table t1; 6546# 6547# MDEV-9671:Wrong result upon select from a view with a FROM subquery 6548# 6549CREATE TABLE t1 (i INT); 6550INSERT INTO t1 VALUES (3),(2); 6551CREATE TABLE t2 (j INT); 6552INSERT INTO t2 VALUES (8),(3),(3); 6553CREATE TABLE t3 (k INT); 6554INSERT INTO t3 VALUES (1),(8); 6555CREATE VIEW v1 AS SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); 6556show create view v1; 6557View Create View character_set_client collation_connection 6558v1 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 6559SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j ); 6560i j 65613 NULL 65622 NULL 6563SELECT * FROM v1; 6564i j 65653 NULL 65662 NULL 6567DROP VIEW v1; 6568DROP TABLE t1, t2, t3; 6569# 6570# MDEV-10035: DBUG_ASSERT on CREATE VIEW v1 AS SELECT * FROM t1 6571# FOR UPDATE 6572# 6573CREATE TABLE t1 (a INT); 6574insert into t1 values (1),(2); 6575CREATE VIEW v1 AS SELECT * FROM t1 FOR UPDATE; 6576SHOW CREATE VIEW v1; 6577View Create View character_set_client collation_connection 6578v1 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 6579select * from v1; 6580a 65811 65822 6583DROP VIEW v1; 6584CREATE VIEW v1 AS SELECT * FROM t1 LOCK IN SHARE MODE; 6585SHOW CREATE VIEW v1; 6586View Create View character_set_client collation_connection 6587v1 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 6588select * from v1; 6589a 65901 65912 6592DROP VIEW v1; 6593DROP TABLE t1; 6594# 6595# MDEV-10724:Assertion `vcol_table == 0 || vcol_table == table' 6596# failed in fill_record(THD*, TABLE*, List<Item>&, List<Item>&, 6597# bool, bool) 6598# 6599CREATE TABLE t1 (f1 INT); 6600CREATE TABLE t2 (f2 INT); 6601CREATE TABLE t3 (f3 INT); 6602CREATE ALGORITHM = MERGE VIEW v AS SELECT f1, f3 FROM t1, 6603( SELECT f3 FROM t2, t3 ) AS sq; 6604INSERT INTO v (f1, f3) VALUES (1,1), (2,2); 6605ERROR HY000: Can not modify more than one base table through a join view 'test.v' 6606drop view v; 6607drop tables t1,t2,t3; 6608# 6609# MDEV-10704: Assertion `field->field->table == table_arg' 6610# failed in fill_record(THD*, TABLE*, List<Item>&, List<Item>&, 6611# bool, bool) 6612# 6613CREATE TABLE t1 (i INT); 6614CREATE TABLE t2 (j INT); 6615CREATE TABLE t3 (k INT); 6616CREATE ALGORITHM = MERGE VIEW v AS SELECT j AS f1, k AS f2 FROM ( SELECT j FROM t1, t2 ) sq, t3; 6617REPLACE INTO v (f1,f2) VALUES (1,1); 6618ERROR HY000: Can not modify more than one base table through a join view 'test.v' 6619drop view v; 6620drop table t1,t2,t3; 6621# 6622# MDEV-12379: Server crashes in TABLE_LIST::is_with_table on 6623# SHOW CREATE VIEW 6624# 6625CREATE TABLE t (i INT); 6626CREATE VIEW v AS SELECT * FROM ( SELECT * FROM t ) sq; 6627DROP TABLE IF EXISTS t; 6628SHOW CREATE VIEW v; 6629View Create View character_set_client collation_connection 6630v 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 6631Warnings: 6632Warning 1356 View 'test.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them 6633DROP VIEW v; 6634# 6635# MDEV-13439: Database permissions are not enough to run a subquery 6636# with GROUP BY within a view 6637# 6638create database test_db; 6639use test_db; 6640create table t (i int); 6641create user foo@localhost; 6642grant all on test_db.* to foo@localhost; 6643connect con1,localhost,foo,,; 6644use test_db; 6645create view v as select * from (select i from t group by i) sq; 6646select * from v; 6647i 6648disconnect con1; 6649connection default; 6650use test; 6651drop database test_db; 6652drop user foo@localhost; 6653# 6654# MDEV-13523: Group By in a View, called within a Stored Routine 6655# causes Error Code 1356 when a non-root user runs the routine for 6656# a second time 6657# 6658CREATE DATABASE bugTest; 6659USE bugTest; 6660CREATE TABLE `procViewTable` (`id` int(10), `someText` varchar(50) NOT NULL); 6661insert into `procViewTable` values (1,'Test'), (2,'Test 2'); 6662CREATE USER 'procView'@'%'; 6663GRANT ALL PRIVILEGES ON `bugTest`.* TO 'procView'@'%'; 6664CREATE DEFINER=`procView`@`%` VIEW `procViewSimple` AS ( 6665select * from ( 6666select `id` from `bugTest`.`procViewTable` 6667 ) `innerQuery` 6668 group by `innerQuery`.`id` 6669); 6670connect con1,localhost,procView,,; 6671use bugTest; 6672prepare stmt from "SELECT * FROM procViewSimple"; 6673execute stmt; 6674id 66751 66762 6677execute stmt; 6678id 66791 66802 6681disconnect con1; 6682connection default; 6683drop user procView; 6684drop view procViewSimple; 6685drop table procViewTable; 6686use test; 6687drop database bugTest; 6688# 6689# MDEV-13436: PREPARE doesn't work as expected & throws errors but 6690# MySQL is working fine 6691# 6692create table t1 (a int); 6693insert into t1 values (1),(2); 6694SET @sql_query = " 6695 CREATE VIEW v1 AS 6696 SELECT * FROM ( 6697 SELECT CASE WHEN 1 IN (SELECT a from t1 where a < 2) THEN TRUE END AS testcase 6698 ) testalias 6699"; 6700PREPARE stmt FROM @sql_query; 6701EXECUTE stmt; 6702DEALLOCATE PREPARE stmt; 6703show create view v1; 6704View Create View character_set_client collation_connection 6705v1 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 6706SELECT * FROM v1; 6707testcase 67081 6709drop view v1; 6710drop table t1; 6711# 6712# MDEV-18502: Server crash in find_field_in_tables upon 2nd execution of SP which causes ER_WRONG_GROUP_FIELD 6713# 6714CREATE TABLE t1 (id INT, f VARCHAR(1)); 6715CREATE VIEW v1 AS SELECT * FROM t1; 6716INSERT INTO t1 VALUES (1,'a'),(2,'b'); 6717CREATE PROCEDURE sp() SELECT f AS f1, MAX(id) AS f2 FROM v1 GROUP BY f1, f2 ORDER BY f1; 6718CALL sp; 6719ERROR 42000: Can't group on 'f2' 6720CALL sp; 6721ERROR 42000: Can't group on 'f2' 6722DROP PROCEDURE sp; 6723DROP VIEW v1; 6724DROP TABLE t1; 6725# 6726# MDEV-24314: create view with derived table without default database 6727# 6728drop database test; 6729create database db1; 6730create table db1.t1 (a int); 6731insert into db1.t1 values (3),(7),(1); 6732create view db1.v1 as select * from (select * from db1.t1) t; 6733show create view db1.v1; 6734View Create View character_set_client collation_connection 6735v1 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 6736select * from db1.v1; 6737a 67383 67397 67401 6741drop view db1.v1; 6742prepare stmt from " 6743create view db1.v1 as select * from (select * from db1.t1) t; 6744"; 6745execute stmt; 6746deallocate prepare stmt; 6747show create view db1.v1; 6748View Create View character_set_client collation_connection 6749v1 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 6750select * from db1.v1; 6751a 67523 67537 67541 6755drop view db1.v1; 6756drop table db1.t1; 6757drop database db1; 6758create database test; 6759use test; 6760# 6761# MDEV-16940: update of multi-table view returning error used in SP 6762# 6763CREATE TABLE t1 (a INT) ENGINE=MyISAM; 6764INSERT INTO t1 VALUES (1), (2); 6765CREATE TABLE t2 (b INT) ENGINE=MyISAM; 6766INSERT INTO t2 VALUES (2), (3); 6767CREATE VIEW v1 AS SELECT a, b FROM t1,t2; 6768CREATE PROCEDURE sp1() UPDATE v1 SET a = 8, b = 9; 6769CALL sp1; 6770ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 6771CALL sp1; 6772ERROR HY000: Can not modify more than one base table through a join view 'test.v1' 6773DROP PROCEDURE sp1; 6774DROP VIEW v1; 6775DROP TABLE t1, t2; 6776# 6777# MDEV-23291: SUM column from a derived table returns invalid values 6778# 6779CREATE TABLE t1(a INT, b INT); 6780INSERT INTO t1 VALUES (1,1), (2,2); 6781CREATE view v1 AS 6782SELECT a as x, (select x) as y, (select y) as z FROM t1; 6783SELECT sum(z) FROM (SELECT a as x, (select x) as y, (select y) as z FROM t1) q; 6784sum(z) 67853 6786SELECT sum(z) FROM v1; 6787sum(z) 67883 6789DROP TABLE t1; 6790DROP VIEW v1; 6791# 6792# MDEV-26299: Some views force server (and mysqldump) to generate 6793# invalid SQL for their definitions 6794# 6795create view v1 as 6796select * from 6797(select 6798"12345678901234567890123456789012345678901234567890123456789012345") as t1; 6799drop view v1; 6800CREATE VIEW v1 AS select `t1`.`12345678901234567890123456789012345678901234567890123456789012345` AS `Name_exp_1` from (select '12345678901234567890123456789012345678901234567890123456789012345') `t1`; 6801drop view v1; 6802# 6803# MDEV-25631: view with outer reference in select used 6804# as argument of set function 6805# 6806create table t1 (c int); 6807insert into t1 values (1); 6808create view v1 as select c from t1 where (select t1.c from t1 t) = 1; 6809select * from (select sum((select * from v1)) as r) dt; 6810r 68111 6812with cte as (select c from t1 where (select t1.c from t1 t) = 1) 6813select * from (select sum((select * from cte)) as r) dt1 6814union 6815select * from (select sum((select * from cte)) as r) dt2; 6816r 68171 6818drop view v1; 6819drop table t1; 6820# 6821# End of 10.2 tests 6822# 6823# 6824# Start of 10.3 tests 6825# 6826# 6827# MDEV-13197 Parser refactoring for CREATE VIEW,TRIGGER,SP,UDF,EVENT 6828# 6829ALTER VIEW IF NOT EXISTS v1 AS SELECT 1; 6830ERROR 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 6831# 6832# MDEV-18605: Loss of column aliases by using view and group 6833# 6834CREATE TABLE t1 (id int, foo int); 6835CREATE VIEW v1 AS SELECT id, IFNULL(foo,'') AS foo FROM t1; 6836INSERT INTO t1 (id, foo) VALUES (1,1),(2,2); 6837SELECT v.id, v.foo AS bar FROM v1 v 6838WHERE id = 2; 6839id bar 68402 2 6841SELECT v.id, v.foo AS bar FROM v1 v 6842GROUP BY v.id; 6843id bar 68441 1 68452 2 6846SELECT v.id, v.foo AS bar FROM v1 v 6847WHERE id = 2 6848GROUP BY v.id; 6849id bar 68502 2 6851Drop View v1; 6852Drop table t1; 6853# 6854# End of 10.3 tests 6855# 6856# 6857# MDEV-25206: view specification contains unknown column reference 6858# 6859CREATE TABLE t1 (a int); 6860INSERT INTO t1 VALUES (1),(2); 6861CREATE TABLE t2 (b int); 6862INSERT INTO t2 VALUES (2),(3); 6863CREATE TABLE t3 (c int); 6864CREATE VIEW v1 AS SELECT * FROM t1 JOIN t2 ON t1.x > t2.b; 6865ERROR 42S22: Unknown column 't1.x' in 'on clause' 6866INSERT INTO t3 SELECT * FROM t1 JOIN t2 ON t1.x > t2.b; 6867ERROR 42S22: Unknown column 't1.x' in 'on clause' 6868CREATE TABLE t4 AS SELECT * FROM t1 JOIN t2 ON t1.x > t2.b; 6869ERROR 42S22: Unknown column 't1.x' in 'on clause' 6870DROP TABLE t1,t2,t3; 6871# End of 10.4 tests 6872