1drop table if exists t1,t2,t3,t4,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
2drop view if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6;
3drop database if exists mysqltest;
4use test;
5create view v1 (c,d) as select a,b from t1;
6ERROR 42S02: Table 'test.t1' doesn't exist
7create temporary table t1 (a int, b int);
8create view v1 (c) as select b+1 from t1;
9ERROR HY000: View's SELECT refers to a temporary table 't1'
10drop table t1;
11create table t1 (a int, b int);
12insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
13create view v1 (c,d) as select a,b+@@global.max_user_connections from t1;
14ERROR HY000: View's SELECT contains a variable or parameter
15create view v1 (c,d) as select a,b from t1
16where a = @@global.max_user_connections;
17ERROR HY000: View's SELECT contains a variable or parameter
18CREATE VIEW v1 AS SELECT @a=1 FROM DUAL;
19ERROR HY000: View's SELECT contains a variable or parameter
20CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE @a>1;
21ERROR HY000: View's SELECT contains a variable or parameter
22CREATE VIEW v1 AS SELECT (@a:= 1) AS one FROM DUAL;
23ERROR HY000: View's SELECT contains a variable or parameter
24CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE (@a:= 1);
25ERROR HY000: View's SELECT contains a variable or parameter
26create view v1 (c) as select b+1 from t1;
27select c from v1;
28c
293
304
315
326
3311
34select is_updatable from information_schema.views where table_name='v1';
35is_updatable
36NO
37create temporary table t1 (a int, b int);
38select * from t1;
39a	b
40select c from v1;
41c
423
434
445
456
4611
47show create table v1;
48View	Create View	character_set_client	collation_connection
49v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (`t1`.`b` + 1) AS `c` from `t1`	latin1	latin1_swedish_ci
50show create view v1;
51View	Create View	character_set_client	collation_connection
52v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (`t1`.`b` + 1) AS `c` from `t1`	latin1	latin1_swedish_ci
53show create view t1;
54ERROR HY000: 'test.t1' is not VIEW
55drop table t1;
56select a from v1;
57ERROR 42S22: Unknown column 'a' in 'field list'
58select v1.a from v1;
59ERROR 42S22: Unknown column 'v1.a' in 'field list'
60select b from v1;
61ERROR 42S22: Unknown column 'b' in 'field list'
62select v1.b from v1;
63ERROR 42S22: Unknown column 'v1.b' in 'field list'
64explain extended select c from v1;
65id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
661	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
67Warnings:
68Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
69Note	1003	/* select#1 */ select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1`
70create algorithm=temptable view v2 (c) as select b+1 from t1;
71show create view v2;
72View	Create View	character_set_client	collation_connection
73v2	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select (`t1`.`b` + 1) AS `c` from `t1`	latin1	latin1_swedish_ci
74select c from v2;
75c
763
774
785
796
8011
81explain extended select c from v2;
82id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
831	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
842	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
85Warnings:
86Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
87Note	1003	/* select#1 */ select `v2`.`c` AS `c` from `test`.`v2`
88create view v3 (c) as select a+1 from v1;
89ERROR 42S22: Unknown column 'a' in 'field list'
90create view v3 (c) as select b+1 from v1;
91ERROR 42S22: Unknown column 'b' in 'field list'
92create view v3 (c) as select c+1 from v1;
93select c from v3;
94c
954
965
976
987
9912
100explain extended select c from v3;
101id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1021	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
103Warnings:
104Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
105Note	1003	/* select#1 */ select ((`test`.`t1`.`b` + 1) + 1) AS `c` from `test`.`t1`
106create algorithm=temptable view v4 (c) as select c+1 from v2;
107select c from v4;
108c
1094
1105
1116
1127
11312
114explain extended select c from v4;
115id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1161	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
1172	DERIVED	<derived3>	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
1183	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
119Warnings:
120Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
121Note	1003	/* select#1 */ select `v4`.`c` AS `c` from `test`.`v4`
122create view v5 (c) as select c+1 from v2;
123select c from v5;
124c
1254
1265
1276
1287
12912
130explain extended select c from v5;
131id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1321	PRIMARY	<derived3>	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
1333	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
134Warnings:
135Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
136Note	1003	/* select#1 */ select (`v2`.`c` + 1) AS `c` from `test`.`v2`
137create algorithm=temptable view v6 (c) as select c+1 from v1;
138select c from v6;
139c
1404
1415
1426
1437
14412
145explain extended select c from v6;
146id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1471	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
1482	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	100.00	NULL
149Warnings:
150Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
151Note	1003	/* select#1 */ select `v6`.`c` AS `c` from `test`.`v6`
152show tables;
153Tables_in_test
154t1
155v1
156v2
157v3
158v4
159v5
160v6
161show full tables;
162Tables_in_test	Table_type
163t1	BASE TABLE
164v1	VIEW
165v2	VIEW
166v3	VIEW
167v4	VIEW
168v5	VIEW
169v6	VIEW
170show table status;
171Name	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
172t1	MyISAM	10	Fixed	5	9	45	#	1024	0	NULL	#	#	NULL	latin1_swedish_ci	NULL
173v1	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	NULL	NULL	#	#	NULL	NULL	NULL	NULL	VIEW
174v2	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	NULL	NULL	#	#	NULL	NULL	NULL	NULL	VIEW
175v3	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	NULL	NULL	#	#	NULL	NULL	NULL	NULL	VIEW
176v4	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	NULL	NULL	#	#	NULL	NULL	NULL	NULL	VIEW
177v5	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	NULL	NULL	#	#	NULL	NULL	NULL	NULL	VIEW
178v6	NULL	NULL	NULL	NULL	NULL	NULL	#	NULL	NULL	NULL	#	#	NULL	NULL	NULL	NULL	VIEW
179drop view v1,v2,v3,v4,v5,v6;
180create view v1 (c,d,e,f) as select a,b,
181a in (select a+2 from t1), a = all (select a from t1) from t1;
182create view v2 as select c, d from v1;
183select * from v1;
184c	d	e	f
1851	2	0	0
1861	3	0	0
1872	4	0	0
1882	5	0	0
1893	10	1	0
190select * from v2;
191c	d
1921	2
1931	3
1942	4
1952	5
1963	10
197create 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;
198ERROR 42S01: Table 'v1' already exists
199create 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;
200drop view v2;
201alter view v2 as select c, d from v1;
202ERROR 42S02: Table 'test.v2' doesn't exist
203create or replace view v2 as select c, d from v1;
204alter view v1 (c,d) as select a,max(b) from t1 group by a;
205select * from v1;
206c	d
2071	3
2082	5
2093	10
210select * from v2;
211c	d
2121	3
2132	5
2143	10
215drop view v100;
216ERROR 42S02: Unknown table 'test.v100'
217drop view t1;
218ERROR HY000: 'test.t1' is not VIEW
219drop table v1;
220ERROR 42S02: Unknown table 'test.v1'
221drop view v1,v2;
222drop table t1;
223create table t1 (a int);
224insert into t1 values (1), (2), (3);
225create view v1 (a) as select a+1 from t1;
226create view v2 (a) as select a-1 from t1;
227select * from t1 natural left join v1;
228a
2291
2302
2313
232select * from v2 natural left join t1;
233a
2340
2351
2362
237select * from v2 natural left join v1;
238a
2390
2401
2412
242drop view v1, v2;
243drop table t1;
244create table t1 (a int);
245insert into t1 values (1), (2), (3), (1), (2), (3);
246create view v1 as select distinct a from t1;
247select * from v1;
248a
2491
2502
2513
252explain select * from v1;
253id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
2541	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
2552	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using temporary
256Warnings:
257Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
258select * from t1;
259a
2601
2612
2623
2631
2642
2653
266drop view v1;
267drop table t1;
268create table t1 (a int);
269create view v1 as select distinct a from t1 WITH CHECK OPTION;
270ERROR HY000: CHECK OPTION on non-updatable view 'test.v1'
271create view v1 as select a from t1 WITH CHECK OPTION;
272create view v2 as select a from t1 WITH CASCADED CHECK OPTION;
273create view v3 as select a from t1 WITH LOCAL CHECK OPTION;
274drop view v3 RESTRICT;
275drop view v2 CASCADE;
276drop view v1;
277drop table t1;
278create table t1 (a int, b int);
279insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
280create view v1 (c) as select b+1 from t1;
281select test.c from v1 test;
282c
2833
2844
2855
2866
28711
288create algorithm=temptable view v2 (c) as select b+1 from t1;
289select test.c from v2 test;
290c
2913
2924
2935
2946
29511
296select test1.* from v1 test1, v2 test2 where test1.c=test2.c;
297c
2983
2994
3005
3016
30211
303select test2.* from v1 test1, v2 test2 where test1.c=test2.c;
304c
3053
3064
3075
3086
30911
310drop table t1;
311drop view v1,v2;
312create table t1 (a int);
313insert into t1 values (1), (2), (3), (4);
314create view v1 as select a+1 from t1 order by 1 desc limit 2;
315select * from v1;
316a+1
3175
3184
319explain select * from v1;
320id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3211	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
3222	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using filesort
323Warnings:
324Note	1003	/* select#1 */ select `v1`.`a+1` AS `a+1` from `test`.`v1`
325drop view v1;
326drop table t1;
327create table t1 (a int);
328insert into t1 values (1), (2), (3), (4);
329create view v1 as select a+1 from t1;
330create table t2 select * from v1;
331show columns from t2;
332Field	Type	Null	Key	Default	Extra
333a+1	bigint(12)	YES		NULL
334select * from t2;
335a+1
3362
3373
3384
3395
340drop view v1;
341drop table t1,t2;
342create table t1 (a int, b int, primary key(a));
343insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10);
344create view v1 (a,c) as select a, b+1 from t1;
345create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
346select is_updatable from information_schema.views where table_name='v2';
347is_updatable
348NO
349select is_updatable from information_schema.views where table_name='v1';
350is_updatable
351YES
352update v1 set c=a+c;
353ERROR HY000: Column 'c' is not updatable
354update v2 set a=a+c;
355ERROR HY000: The target table v2 of the UPDATE is not updatable
356update v1 set a=a+c;
357select * from v1;
358a	c
35913	3
36024	4
36135	5
36246	6
36361	11
364select * from t1;
365a	b
36613	2
36724	3
36835	4
36946	5
37061	10
371drop table t1;
372drop view v1,v2;
373create table t1 (a int, b int, primary key(a));
374insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10);
375create table t2 (x int);
376insert into t2 values (10), (20);
377create view v1 (a,c) as select a, b+1 from t1;
378create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
379update t2,v1 set v1.c=v1.a+v1.c where t2.x=v1.a;
380ERROR HY000: Column 'c' is not updatable
381update t2,v2 set v2.a=v2.a+c where t2.x=v2.a;
382ERROR HY000: The target table v2 of the UPDATE is not updatable
383update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.a;
384select * from v1;
385a	c
38613	3
38724	4
38830	5
38940	6
39050	11
391select * from t1;
392a	b
39313	2
39424	3
39530	4
39640	5
39750	10
398drop table t1,t2;
399drop view v1,v2;
400create table t1 (a int, b int, primary key(b));
401insert into t1 values (1,20), (2,30), (3,40), (4,50), (5,100);
402create view v1 (c) as select b from t1 where a<3;
403select * from v1;
404c
40520
40630
407explain extended select * from v1;
408id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
4091	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	5	33.33	Using where
410Warnings:
411Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
412Note	1003	/* select#1 */ select `test`.`t1`.`b` AS `c` from `test`.`t1` where (`test`.`t1`.`a` < 3)
413update v1 set c=c+1;
414select * from t1;
415a	b
4161	21
4172	31
4183	40
4194	50
4205	100
421create view v2 (c) as select b from t1 where a>=3;
422select * from v1, v2;
423c	c
42421	40
42531	40
42621	50
42731	50
42821	100
42931	100
430drop view v1, v2;
431drop table t1;
432create table t1 (a int, b int, primary key(a));
433insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10);
434create view v1 (a,c) as select a, b+1 from t1;
435create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
436delete from v2 where c < 4;
437ERROR HY000: The target table v2 of the DELETE is not updatable
438delete from v1 where c < 4;
439select * from v1;
440a	c
4412	4
4423	5
4434	6
4445	11
445select * from t1;
446a	b
4472	3
4483	4
4494	5
4505	10
451drop table t1;
452drop view v1,v2;
453create table t1 (a int, b int, primary key(a));
454insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10);
455create table t2 (x int);
456insert into t2 values (1), (2), (3), (4);
457create view v1 (a,c) as select a, b+1 from t1;
458create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
459delete v2 from t2,v2 where t2.x=v2.a;
460ERROR HY000: The target table v2 of the DELETE is not updatable
461delete v1 from t2,v1 where t2.x=v1.a;
462select * from v1;
463a	c
4645	11
465select * from t1;
466a	b
4675	10
468drop table t1,t2;
469drop view v1,v2;
470create table t1 (a int, b int, c int, primary key(a,b));
471insert into t1 values (10,2,-1), (20,3,-2), (30,4,-3), (40,5,-4), (50,10,-5);
472create view v1 (x,y) as select a, b from t1;
473create view v2 (x,y) as select a, c from t1;
474set updatable_views_with_limit=NO;
475update v1 set x=x+1;
476update v2 set x=x+1;
477update v1 set x=x+1 limit 1;
478update v2 set x=x+1 limit 1;
479ERROR HY000: The target table v2 of the UPDATE is not updatable
480delete from v2 limit 1;
481ERROR HY000: The target table v2 of the DELETE is not updatable
482set updatable_views_with_limit=YES;
483update v1 set x=x+1 limit 1;
484update v2 set x=x+1 limit 1;
485Warnings:
486Note	1355	View being updated does not have complete key of underlying table in it
487set updatable_views_with_limit=DEFAULT;
488show variables like "updatable_views_with_limit";
489Variable_name	Value
490updatable_views_with_limit	YES
491select * from t1;
492a	b	c
49315	2	-1
49422	3	-2
49532	4	-3
49642	5	-4
49752	10	-5
498drop table t1;
499drop view v1,v2;
500create table t1 (a int, b int, c int, primary key(a,b));
501insert into t1 values (10,2,-1), (20,3,-2);
502create view v1 (x,y,z) as select c, b, a from t1;
503create view v2 (x,y) as select b, a from t1;
504create view v3 (x,y,z) as select b, a, b from t1;
505create view v4 (x,y,z) as select c+1, b, a from t1;
506create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1;
507insert into v3 values (-60,4,30);
508ERROR HY000: The target table v3 of the INSERT is not insertable-into
509insert into v4 values (-60,4,30);
510ERROR HY000: Column 'x' is not updatable
511insert into v5 values (-60,4,30);
512ERROR HY000: The target table v5 of the INSERT is not insertable-into
513insert into v1 values (-60,4,30);
514insert into v1 (z,y,x) values (50,6,-100);
515insert into v2 values (5,40);
516select * from t1;
517a	b	c
51810	2	-1
51920	3	-2
52030	4	-60
52150	6	-100
52240	5	NULL
523drop table t1;
524drop view v1,v2,v3,v4,v5;
525create table t1 (a int, b int, c int, primary key(a,b));
526insert into t1 values (10,2,-1), (20,3,-2);
527create table t2 (a int, b int, c int, primary key(a,b));
528insert into t2 values (30,4,-60);
529create view v1 (x,y,z) as select c, b, a from t1;
530create view v2 (x,y) as select b, a from t1;
531create view v3 (x,y,z) as select b, a, b from t1;
532create view v4 (x,y,z) as select c+1, b, a from t1;
533create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1;
534insert into v3 select c, b, a from t2;
535ERROR HY000: The target table v3 of the INSERT is not insertable-into
536insert into v4 select c, b, a from t2;
537ERROR HY000: Column 'x' is not updatable
538insert into v5 select c, b, a from t2;
539ERROR HY000: The target table v5 of the INSERT is not insertable-into
540insert into v1 select c, b, a from t2;
541insert into v1 (z,y,x) select a+20,b+2,-100 from t2;
542insert into v2 select b+1, a+10 from t2;
543select * from t1;
544a	b	c
54510	2	-1
54620	3	-2
54730	4	-60
54850	6	-100
54940	5	NULL
550drop table t1, t2;
551drop view v1,v2,v3,v4,v5;
552create table t1 (a int, primary key(a));
553insert into t1 values (1), (2), (3);
554create view v1 (x) as select a from t1 where a > 1;
555select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);
556a	x
5571	NULL
5582	2
5593	3
560drop table t1;
561drop view v1;
562create table t1 (a int, primary key(a));
563insert into t1 values (1), (2), (3), (200);
564create view v1 (x) as select a from t1 where a > 1;
565create view v2 (y) as select x from v1 where x < 100;
566select * from v2;
567y
5682
5693
570drop table t1;
571drop view v1,v2;
572create table t1 (a int, primary key(a));
573insert into t1 values (1), (2), (3), (200);
574create ALGORITHM=TEMPTABLE view v1 (x) as select a from t1;
575create view v2 (y) as select x from v1;
576update v2 set y=10 where y=2;
577ERROR HY000: The target table v2 of the UPDATE is not updatable
578drop table t1;
579drop view v1,v2;
580create table t1 (a int not null auto_increment, b int not null, primary key(a), unique(b));
581create view v1 (x) as select b from t1;
582insert into v1 values (1);
583select last_insert_id();
584last_insert_id()
5850
586insert into t1 (b) values (2);
587select last_insert_id();
588last_insert_id()
5892
590select * from t1;
591a	b
5921	1
5932	2
594drop view v1;
595drop table t1;
596set sql_mode='ansi';
597Warnings:
598Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
599create table t1 ("a*b" int);
600create view v1 as select "a*b" from t1;
601show create view v1;
602View	Create View	character_set_client	collation_connection
603v1	CREATE VIEW "v1" AS select "t1"."a*b" AS "a*b" from "t1"	latin1	latin1_swedish_ci
604drop view v1;
605drop table t1;
606set sql_mode=default;
607create table t1 (t_column int);
608create view v1 as select 'a';
609select * from v1, t1;
610a	t_column
611drop view v1;
612drop table t1;
613create table `t1a``b` (col1 char(2));
614create view v1 as select * from `t1a``b`;
615select * from v1;
616col1
617describe v1;
618Field	Type	Null	Key	Default	Extra
619col1	char(2)	YES		NULL
620drop view v1;
621drop table `t1a``b`;
622SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
623Warnings:
624Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
625create table t1 (col1 char(5),col2 char(5));
626create view v1 as select * from t1;
627drop table t1;
628create table t1 (col1 char(5),newcol2 char(5));
629insert into v1 values('a','aa');
630ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
631drop table t1;
632select * from v1;
633ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
634drop view v1;
635SET sql_mode = default;
636create view v1 (a,a) as select 'a','a';
637ERROR 42S21: Duplicate column name 'a'
638create table t1 (col1 int,col2 char(22));
639insert into t1 values(5,'Hello, world of views');
640create view v1 as select * from t1;
641create view v2 as select * from v1;
642update v2 set col2='Hello, view world';
643select is_updatable from information_schema.views where table_schema != 'sys';
644is_updatable
645YES
646YES
647select * from t1;
648col1	col2
6495	Hello, view world
650drop view v2, v1;
651drop table t1;
652create table t1 (a int, b int);
653create view v1 as select a, sum(b) from t1 group by a;
654select b from v1 use index (some_index) where b=1;
655ERROR 42000: Key 'some_index' doesn't exist in table 'v1'
656drop view v1;
657drop table t1;
658create table t1 (col1 char(5),col2 char(5));
659create view v1 (col1,col2) as select col1,col2 from t1;
660insert into v1 values('s1','p1'),('s1','p2'),('s1','p3'),('s1','p4'),('s2','p1'),('s3','p2'),('s4','p4');
661select distinct first.col2 from t1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1);
662col2
663p1
664p2
665p4
666select distinct first.col2 from v1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1);
667col2
668p1
669p2
670p4
671drop view v1;
672drop table t1;
673create table t1 (a int);
674create view v1 as select a from t1;
675insert into t1 values (1);
676SET @v0 = '2';
677PREPARE stmt FROM 'UPDATE v1 SET a = ?';
678EXECUTE stmt USING @v0;
679DEALLOCATE PREPARE stmt;
680SET @v0 = '3';
681PREPARE stmt FROM 'insert into v1 values (?)';
682EXECUTE stmt USING @v0;
683DEALLOCATE PREPARE stmt;
684SET @v0 = '4';
685PREPARE stmt FROM 'insert into v1 (a) values (?)';
686EXECUTE stmt USING @v0;
687DEALLOCATE PREPARE stmt;
688select * from t1;
689a
6902
6913
6924
693drop view v1;
694drop table t1;
695CREATE VIEW v02 AS SELECT * FROM DUAL;
696ERROR HY000: No tables used
697SHOW TABLES;
698Tables_in_test
699CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2);
700select * from v1;
701EXISTS (SELECT 1 UNION SELECT 2)
7021
703drop view v1;
704create table t1 (col1 int,col2 char(22));
705create view v1 as select * from t1;
706create index i1 on v1 (col1);
707ERROR HY000: 'test.v1' is not BASE TABLE
708drop view v1;
709drop table t1;
710CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version();
711SHOW CREATE VIEW v1;
712View	Create View	character_set_client	collation_connection
713v1	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
714drop view v1;
715create table t1 (s1 int);
716create table t2 (s2 int);
717insert into t1 values (1), (2);
718insert into t2 values (2), (3);
719create view v1 as select * from t1,t2 union all select * from t1,t2;
720select * from v1;
721s1	s2
7221	2
7232	2
7241	3
7252	3
7261	2
7272	2
7281	3
7292	3
730drop view v1;
731drop tables t1, t2;
732create table t1 (col1 int);
733insert into t1 values (1);
734create view v1 as select count(*) from t1;
735insert into t1 values (null);
736select * from v1;
737count(*)
7382
739drop view v1;
740drop table t1;
741create table t1 (a int);
742create table t2 (a int);
743create view v1 as select a from t1;
744create view v2 as select a from t2 where a in (select a from v1);
745show create view v2;
746View	Create View	character_set_client	collation_connection
747v2	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
748drop view v2, v1;
749drop table t1, t2;
750CREATE VIEW `v 1` AS select 5 AS `5`;
751show create view `v 1`;
752View	Create View	character_set_client	collation_connection
753v 1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v 1` AS select 5 AS `5`	latin1	latin1_swedish_ci
754drop view `v 1`;
755create database mysqltest;
756create table mysqltest.t1 (a int, b int);
757create view mysqltest.v1 as select a from mysqltest.t1;
758alter view mysqltest.v1 as select b from mysqltest.t1;
759alter view mysqltest.v1 as select a from mysqltest.t1;
760drop database mysqltest;
761CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2));
762insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer');
763select * from t1 WHERE match (c2) against ('Beer');
764c1	c2
7651	real Beer
7667	almost real Beer
767CREATE VIEW v1 AS SELECT  * from t1 WHERE match (c2) against ('Beer');
768select * from v1;
769c1	c2
7701	real Beer
7717	almost real Beer
772drop view v1;
773drop table t1;
774create table t1 (a int);
775insert into t1 values (1),(1),(2),(2),(3),(3);
776create view v1 as select a from t1;
777select distinct a from v1;
778a
7791
7802
7813
782select distinct a from v1 limit 2;
783a
7841
7852
786select distinct a from t1 limit 2;
787a
7881
7892
790prepare stmt1 from "select distinct a from v1 limit 2";
791execute stmt1;
792a
7931
7942
795execute stmt1;
796a
7971
7982
799deallocate prepare stmt1;
800drop view v1;
801drop table t1;
802create table t1 (tg_column bigint);
803create view v1 as select count(tg_column) as vg_column from t1;
804select avg(vg_column) from v1;
805avg(vg_column)
8060.0000
807drop view v1;
808drop table t1;
809create table t1 (col1 bigint not null, primary key (col1));
810create table t2 (col1 bigint not null, key (col1));
811create view v1 as select * from t1;
812create view v2 as select * from t2;
813insert into v1 values (1);
814insert into v2 values (1);
815create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1;
816select * from v3;
817a	b
8181	1
819show create view v3;
820View	Create View	character_set_client	collation_connection
821v3	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
822drop view v3, v2, v1;
823drop table t2, t1;
824create function `f``1` () returns int return 5;
825create view v1 as select test.`f``1` ();
826show create view v1;
827View	Create View	character_set_client	collation_connection
828v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`f``1`() AS `test.``f````1`` ()`	latin1	latin1_swedish_ci
829select * from v1;
830test.`f``1` ()
8315
832drop view v1;
833drop function `f``1`;
834create function a() returns int return 5;
835create view v1 as select a();
836select * from v1;
837a()
8385
839drop view v1;
840drop function a;
841create table t2 (col1 char collate latin1_german2_ci);
842create view v2 as select col1 collate latin1_german1_ci from t2;
843show create view v2;
844View	Create View	character_set_client	collation_connection
845v2	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
846show create view v2;
847View	Create View	character_set_client	collation_connection
848v2	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
849drop view v2;
850drop table t2;
851create table t1 (a int);
852insert into t1 values (1), (2);
853create view v1 as select 5 from t1 order by 1;
854select * from v1;
8555
8565
8575
858drop view v1;
859drop table t1;
860create function x1 () returns int return 5;
861create table t1 (s1 int);
862create view v1 as select x1() from t1;
863drop function x1;
864select * from v1;
865ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
866show table status;
867Name	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
868t1	MyISAM	10	Fixed	0	0	0	#	1024	0	NULL	#	#	NULL	latin1_swedish_ci	NULL
869v1	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
870Warnings:
871Warning	1356	View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
872drop view v1;
873drop table t1;
874create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1;
875show create view v1;
876View	Create View	character_set_client	collation_connection
877v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 99999999999999999999999999999999999999999999999999999 AS `col1`	latin1	latin1_swedish_ci
878drop view v1;
879SET @old_cs_client = @@character_set_client;
880SET @old_cs_results = @@character_set_results;
881SET @old_cs_connection = @@character_set_connection;
882set names utf8;
883create table tü (cü char);
884create view vü as select cü from tü;
885insert into vü values ('ü');
886select * from vü;
887888ü
889drop view vü;
890drop table tü;
891SET character_set_client = @old_cs_client;
892SET character_set_results = @old_cs_results;
893SET character_set_connection = @old_cs_connection;
894create table t1 (a int, b int);
895insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
896create view v1(c) as select a+1 from t1 where b >= 4;
897select c from v1 where exists (select * from t1 where a=2 and b=c);
898c
8994
900drop view v1;
901drop table t1;
902create view v1 as select cast(1 as char(3));
903show create view v1;
904View	Create View	character_set_client	collation_connection
905v1	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
906select * from v1;
907cast(1 as char(3))
9081
909drop view v1;
910create table t1 (a int);
911create view v1 as select a from t1;
912create view v3 as select a from t1;
913create database mysqltest;
914rename table v1 to mysqltest.v1;
915ERROR HY000: Changing schema from 'test' to 'mysqltest' is not allowed.
916rename table v1 to v2;
917rename table v3 to v1, v2 to t1;
918ERROR 42S01: Table 't1' already exists
919drop table t1;
920drop view v2,v3;
921drop database mysqltest;
922create view v1 as select 'a',1;
923create view v2 as select * from v1 union all select * from v1;
924create view v3 as select * from v2 where 1 = (select `1` from v2);
925create view v4 as select * from v3;
926select * from v4;
927ERROR 21000: Subquery returns more than 1 row
928drop view v4, v3, v2, v1;
929create view v1 as select 5 into @w;
930ERROR HY000: View's SELECT contains a 'INTO' clause
931create view v1 as select 5 into outfile 'ttt';
932ERROR HY000: View's SELECT contains a 'INTO' clause
933create table t1 (a int);
934create view v1 as select a from t1 procedure analyse();
935ERROR HY000: View's SELECT contains a 'PROCEDURE' clause
936create view v1 as select 1 from (select 1) as d1;
937drop view v1;
938drop table t1;
939create table t1 (s1 int, primary key (s1));
940create view v1 as select * from t1;
941insert into v1 values (1) on duplicate key update s1 = 7;
942insert into v1 values (1) on duplicate key update s1 = 7;
943select * from t1;
944s1
9457
946drop view v1;
947drop table t1;
948create table t1 (col1 int);
949create table t2 (col1 int);
950create table t3 (col1 datetime not null);
951create view v1 as select * from t1;
952create view v2 as select * from v1;
953create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
954update v2 set col1 = (select max(col1) from v1);
955ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v2'.
956update v2 set col1 = (select max(col1) from t1);
957ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v2'.
958update v2 set col1 = (select max(col1) from v2);
959ERROR HY000: You can't specify target table 'v2' for update in FROM clause
960update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
961ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v2'.
962update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
963ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't1'.
964update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
965ERROR HY000: You can't specify target table 'v1' for update in FROM clause
966update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
967ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'.
968update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
969ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'.
970update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
971ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't2'.
972update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
973ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v2'.
974update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
975ERROR HY000: You can't specify target table 't1' for update in FROM clause
976update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
977ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v1'.
978update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
979ERROR HY000: You can't specify target table 't2' for update in FROM clause
980update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
981ERROR HY000: You can't specify target table 't2' for update in FROM clause
982update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
983ERROR HY000: You can't specify target table 't2' for update in FROM clause
984update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
985ERROR HY000: You can't specify target table 'v2' for update in FROM clause
986update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
987ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't1'.
988update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
989ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v1'.
990update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
991ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'.
992update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
993ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'.
994update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
995ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 't2'.
996update v3 set v3.col1 = (select max(col1) from v1);
997ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 'v3'.
998update v3 set v3.col1 = (select max(col1) from t1);
999ERROR HY000: The definition of table 'v3' prevents operation UPDATE on table 'v3'.
1000update v3 set v3.col1 = (select max(col1) from v2);
1001ERROR HY000: The definition of table 'v2' prevents operation UPDATE on table 'v3'.
1002update v3 set v3.col1 = (select max(col1) from v3);
1003ERROR HY000: You can't specify target table 'v3' for update in FROM clause
1004delete from v2 where col1 = (select max(col1) from v1);
1005ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v2'.
1006delete from v2 where col1 = (select max(col1) from t1);
1007ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v2'.
1008delete from v2 where col1 = (select max(col1) from v2);
1009ERROR HY000: You can't specify target table 'v2' for update in FROM clause
1010delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1;
1011ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v2'.
1012delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1;
1013ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 't1'.
1014delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1;
1015ERROR HY000: You can't specify target table 'v1' for update in FROM clause
1016delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1;
1017ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v2'.
1018delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1;
1019ERROR HY000: You can't specify target table 't1' for update in FROM clause
1020delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1;
1021ERROR HY000: The definition of table 'v1' prevents operation DELETE on table 'v1'.
1022delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1;
1023ERROR HY000: You can't specify target table 'v2' for update in FROM clause
1024delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1;
1025ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 't1'.
1026delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1;
1027ERROR HY000: The definition of table 'v2' prevents operation DELETE on table 'v1'.
1028insert into v2 values ((select max(col1) from v1));
1029ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v2'.
1030insert into t1 values ((select max(col1) from v1));
1031ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 't1'.
1032insert into v2 values ((select max(col1) from v1));
1033ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v2'.
1034insert into v2 values ((select max(col1) from t1));
1035ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v2'.
1036insert into t1 values ((select max(col1) from t1));
1037ERROR HY000: You can't specify target table 't1' for update in FROM clause
1038insert into v2 values ((select max(col1) from t1));
1039ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v2'.
1040insert into v2 values ((select max(col1) from v2));
1041ERROR HY000: You can't specify target table 'v2' for update in FROM clause
1042insert into t1 values ((select max(col1) from v2));
1043ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 't1'.
1044insert into v2 values ((select max(col1) from v2));
1045ERROR HY000: You can't specify target table 'v2' for update in FROM clause
1046insert into v3 (col1) values ((select max(col1) from v1));
1047ERROR HY000: The definition of table 'v1' prevents operation INSERT on table 'v3'.
1048insert into v3 (col1) values ((select max(col1) from t1));
1049ERROR HY000: The definition of table 'v3' prevents operation INSERT on table 'v3'.
1050insert into v3 (col1) values ((select max(col1) from v2));
1051ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3'.
1052insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2));
1053ERROR HY000: The definition of table 'v2' prevents operation INSERT on table 'v3'.
1054insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
1055insert into t3 values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
1056ERROR 23000: Column 'col1' cannot be null
1057create algorithm=temptable view v4 as select * from t1;
1058insert into t1 values (1),(2),(3);
1059insert into t1 (col1) values ((select max(col1) from v4));
1060select * from t1;
1061col1
1062NULL
10631
10642
10653
10663
1067drop view v4,v3,v2,v1;
1068drop table t1,t2,t3;
1069create table t1 (s1 int);
1070create view v1 as select * from t1;
1071handler v1 open as xx;
1072ERROR HY000: 'test.v1' is not BASE TABLE
1073drop view v1;
1074drop table t1;
1075create table t1(a int);
1076insert into t1 values (0), (1), (2), (3);
1077create table t2 (a int);
1078insert into t2 select a from t1 where a > 1;
1079create view v1 as select a from t1 where a > 1;
1080select * from t1 left join (t2 as t, v1) on v1.a=t1.a;
1081a	a	a
10820	NULL	NULL
10831	NULL	NULL
10842	2	2
10852	3	2
10863	2	3
10873	3	3
1088select * from t1 left join (t2 as t, t2) on t2.a=t1.a;
1089a	a	a
10900	NULL	NULL
10911	NULL	NULL
10922	2	2
10932	3	2
10943	2	3
10953	3	3
1096drop view v1;
1097drop table t1, t2;
1098create table t1 (s1 char);
1099create view v1 as select s1 collate latin1_german1_ci as s1 from t1;
1100insert into v1 values ('a');
1101select * from v1;
1102s1
1103a
1104update v1 set s1='b';
1105select * from v1;
1106s1
1107b
1108update v1,t1 set v1.s1='c' where t1.s1=v1.s1;
1109select * from v1;
1110s1
1111c
1112prepare stmt1 from "update v1,t1 set v1.s1=? where t1.s1=v1.s1";
1113set @arg='d';
1114execute stmt1 using @arg;
1115select * from v1;
1116s1
1117d
1118set @arg='e';
1119execute stmt1 using @arg;
1120select * from v1;
1121s1
1122e
1123deallocate prepare stmt1;
1124drop view v1;
1125drop table t1;
1126create table t1 (a int);
1127create table t2 (a int);
1128create view v1 as select * from t1;
1129lock tables t1 read, v1 read;
1130select * from v1;
1131a
1132select * from t2;
1133ERROR HY000: Table 't2' was not locked with LOCK TABLES
1134unlock tables;
1135drop view v1;
1136drop table t1, t2;
1137create table t1 (a int);
1138create view v1 as select * from t1 where a < 2 with check option;
1139insert into v1 values(1);
1140insert into v1 values(3);
1141ERROR HY000: CHECK OPTION failed 'test.v1'
1142insert ignore into v1 values (2),(3),(0);
1143Warnings:
1144Warning	1369	CHECK OPTION failed 'test.v1'
1145Warning	1369	CHECK OPTION failed 'test.v1'
1146select * from t1;
1147a
11481
11490
1150delete from t1;
1151insert into v1 SELECT 1;
1152insert into v1 SELECT 3;
1153ERROR HY000: CHECK OPTION failed 'test.v1'
1154create table t2 (a int);
1155insert into t2 values (2),(3),(0);
1156insert ignore into v1 SELECT a from t2;
1157Warnings:
1158Warning	1369	CHECK OPTION failed 'test.v1'
1159Warning	1369	CHECK OPTION failed 'test.v1'
1160select * from t1 order by a desc;
1161a
11621
11630
1164update v1 set a=-1 where a=0;
1165update v1 set a=2 where a=1;
1166ERROR HY000: CHECK OPTION failed 'test.v1'
1167select * from t1 order by a desc;
1168a
11691
1170-1
1171update v1 set a=0 where a=0;
1172insert into t2 values (1);
1173update v1,t2 set v1.a=v1.a-1 where v1.a=t2.a;
1174select * from t1 order by a desc;
1175a
11760
1177-1
1178update v1 set a=a+1;
1179update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a;
1180Warnings:
1181Warning	1369	CHECK OPTION failed 'test.v1'
1182select * from t1;
1183a
11841
11851
1186drop view v1;
1187drop table t1, t2;
1188create table t1 (a int);
1189create view v1 as select * from t1 where a < 2 with check option;
1190create view v2 as select * from v1 where a > 0 with local check option;
1191create view v3 as select * from v1 where a > 0 with cascaded check option;
1192insert into v2 values (1);
1193insert into v3 values (1);
1194insert into v2 values (0);
1195ERROR HY000: CHECK OPTION failed 'test.v2'
1196insert into v3 values (0);
1197ERROR HY000: CHECK OPTION failed 'test.v3'
1198insert into v2 values (2);
1199ERROR HY000: CHECK OPTION failed 'test.v2'
1200insert into v3 values (2);
1201ERROR HY000: CHECK OPTION failed 'test.v3'
1202select * from t1;
1203a
12041
12051
1206drop view v3,v2,v1;
1207drop table t1;
1208create table t1 (a int, primary key (a));
1209create view v1 as select * from t1 where a < 2 with check option;
1210insert into v1 values (1) on duplicate key update a=2;
1211insert into v1 values (1) on duplicate key update a=2;
1212ERROR HY000: CHECK OPTION failed 'test.v1'
1213insert ignore into v1 values (1) on duplicate key update a=2;
1214Warnings:
1215Warning	1369	CHECK OPTION failed 'test.v1'
1216select * from t1;
1217a
12181
1219drop view v1;
1220drop table t1;
1221create table t1 (s1 int);
1222create view v1 as select * from t1;
1223create view v2 as select * from v1;
1224alter view v1 as select * from v2;
1225ERROR 42S02: Table 'test.v1' doesn't exist
1226alter view v1 as select * from v1;
1227ERROR 42S02: Table 'test.v1' doesn't exist
1228create or replace view v1 as select * from v2;
1229ERROR 42S02: Table 'test.v1' doesn't exist
1230create or replace view v1 as select * from v1;
1231ERROR 42S02: Table 'test.v1' doesn't exist
1232drop view v2,v1;
1233drop table t1;
1234create table t1 (a int);
1235create view v1 as select * from t1;
1236show create view v1;
1237View	Create View	character_set_client	collation_connection
1238v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	latin1	latin1_swedish_ci
1239alter algorithm=undefined view v1 as select * from t1 with check option;
1240show create view v1;
1241View	Create View	character_set_client	collation_connection
1242v1	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
1243alter algorithm=merge view v1 as select * from t1 with cascaded check option;
1244show create view v1;
1245View	Create View	character_set_client	collation_connection
1246v1	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
1247alter algorithm=temptable view v1 as select * from t1;
1248show create view v1;
1249View	Create View	character_set_client	collation_connection
1250v1	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	latin1	latin1_swedish_ci
1251drop view v1;
1252drop table t1;
1253create table t1 (s1 int);
1254create table t2 (s1 int);
1255create view v2 as select * from t2 where s1 in (select s1 from t1);
1256insert into v2 values (5);
1257insert into t1 values (5);
1258select * from v2;
1259s1
12605
1261update v2 set s1 = 0;
1262select * from v2;
1263s1
1264select * from t2;
1265s1
12660
1267alter view v2 as select * from t2 where s1 in (select s1 from t1) with check option;
1268insert into v2 values (5);
1269update v2 set s1 = 1;
1270ERROR HY000: CHECK OPTION failed 'test.v2'
1271insert into t1 values (1);
1272update v2 set s1 = 1;
1273select * from v2;
1274s1
12751
1276select * from t2;
1277s1
12780
12791
1280prepare stmt1 from "select * from v2;";
1281execute stmt1;
1282s1
12831
1284insert into t1 values (0);
1285execute stmt1;
1286s1
12871
12880
1289deallocate prepare stmt1;
1290drop view v2;
1291drop table t1, t2;
1292create table t1 (t time);
1293create view v1 as select substring_index(t,':',2) as t from t1;
1294insert into t1 (t) values ('12:24:10');
1295select substring_index(t,':',2) from t1;
1296substring_index(t,':',2)
129712:24
1298select substring_index(t,':',2) from v1;
1299substring_index(t,':',2)
130012:24
1301drop view v1;
1302drop table t1;
1303create table t1 (s1 tinyint);
1304create view v1 as select * from t1 where s1 <> 0 with local check option;
1305create view v2 as select * from v1 with cascaded check option;
1306insert into v2 values (0);
1307ERROR HY000: CHECK OPTION failed 'test.v2'
1308drop view v2, v1;
1309drop table t1;
1310create table t1 (s1 int);
1311create view v1 as select * from t1 where s1 < 5 with check option;
1312insert ignore into v1 values (6);
1313Warnings:
1314Warning	1369	CHECK OPTION failed 'test.v1'
1315insert ignore into v1 values (6),(3);
1316Warnings:
1317Warning	1369	CHECK OPTION failed 'test.v1'
1318select * from t1;
1319s1
13203
1321drop view v1;
1322drop table t1;
1323SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
1324Warnings:
1325Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
1326create table t1 (s1 tinyint);
1327create trigger t1_bi before insert on t1 for each row set new.s1 = 500;
1328create view v1 as select * from t1 where s1 <> 127 with check option;
1329insert into v1 values (0);
1330ERROR HY000: CHECK OPTION failed 'test.v1'
1331select * from v1;
1332s1
1333select * from t1;
1334s1
1335drop trigger t1_bi;
1336drop view v1;
1337drop table t1;
1338SET sql_mode = default;
1339create table t1 (s1 tinyint);
1340create view v1 as select * from t1 where s1 <> 0;
1341create view v2 as select * from v1 where s1 <> 1 with cascaded check option;
1342insert into v2 values (0);
1343ERROR HY000: CHECK OPTION failed 'test.v2'
1344select * from v2;
1345s1
1346select * from t1;
1347s1
1348drop view v2, v1;
1349drop table t1;
1350create table t1 (a int, b char(10));
1351create view v1 as select * from t1 where a != 0 with check option;
1352load data infile '../../std_data/loaddata3.dat' into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
1353ERROR HY000: CHECK OPTION failed 'test.v1'
1354select * from t1;
1355a	b
13561	row 1
13572	row 2
1358select * from v1;
1359a	b
13601	row 1
13612	row 2
1362delete from t1;
1363load data infile '../../std_data/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
1364Warnings:
1365Warning	1366	Incorrect integer value: 'error      ' for column 'a' at row 3
1366Warning	1369	CHECK OPTION failed 'test.v1'
1367Warning	1366	Incorrect integer value: 'wrong end  ' for column 'a' at row 4
1368Warning	1369	CHECK OPTION failed 'test.v1'
1369select * from t1 order by a,b;
1370a	b
13711	row 1
13722	row 2
13733	row 3
1374select * from v1 order by a,b;
1375a	b
13761	row 1
13772	row 2
13783	row 3
1379drop view v1;
1380drop table t1;
1381create table t1 (a text, b text);
1382create view v1 as select * from t1 where a <> 'Field A' with check option;
1383load data infile '../../std_data/loaddata2.dat' into table v1 fields terminated by ',' enclosed by '''';
1384ERROR HY000: CHECK OPTION failed 'test.v1'
1385select concat('|',a,'|'), concat('|',b,'|') from t1;
1386concat('|',a,'|')	concat('|',b,'|')
1387select concat('|',a,'|'), concat('|',b,'|') from v1;
1388concat('|',a,'|')	concat('|',b,'|')
1389delete from t1;
1390load data infile '../../std_data/loaddata2.dat' ignore into table v1 fields terminated by ',' enclosed by '''';
1391Warnings:
1392Warning	1369	CHECK OPTION failed 'test.v1'
1393Warning	1261	Row 2 doesn't contain data for all columns
1394select concat('|',a,'|'), concat('|',b,'|') from t1;
1395concat('|',a,'|')	concat('|',b,'|')
1396|Field 1|	|Field 2'
1397Field 3,'Field 4|
1398|Field 5' ,'Field 6|	NULL
1399|Field 6|	| 'Field 7'|
1400select concat('|',a,'|'), concat('|',b,'|') from v1;
1401concat('|',a,'|')	concat('|',b,'|')
1402|Field 1|	|Field 2'
1403Field 3,'Field 4|
1404|Field 5' ,'Field 6|	NULL
1405|Field 6|	| 'Field 7'|
1406drop view v1;
1407drop table t1;
1408create table t1 (s1 smallint);
1409create view v1 as select * from t1 where 20 < (select (s1) from t1);
1410insert into v1 values (30);
1411ERROR HY000: The target table v1 of the INSERT is not insertable-into
1412create view v2 as select * from t1;
1413create view v3 as select * from t1 where 20 < (select (s1) from v2);
1414insert into v3 values (30);
1415ERROR HY000: The target table v3 of the INSERT is not insertable-into
1416create view v4 as select * from v2 where 20 < (select (s1) from t1);
1417insert into v4 values (30);
1418ERROR HY000: The target table v4 of the INSERT is not insertable-into
1419drop view v4, v3, v2, v1;
1420drop table t1;
1421create table t1 (a int);
1422create view v1 as select * from t1;
1423check table t1,v1;
1424Table	Op	Msg_type	Msg_text
1425test.t1	check	status	OK
1426test.v1	check	status	OK
1427check table v1,t1;
1428Table	Op	Msg_type	Msg_text
1429test.v1	check	status	OK
1430test.t1	check	status	OK
1431drop table t1;
1432check table v1;
1433Table	Op	Msg_type	Msg_text
1434test.v1	check	Error	Table 'test.t1' doesn't exist
1435test.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
1436test.v1	check	error	Corrupt
1437drop view v1;
1438create table t1 (a int);
1439create table t2 (a int);
1440create table t3 (a int);
1441insert into t1 values (1), (2), (3);
1442insert into t2 values (1), (3);
1443insert into t3 values (1), (2), (4);
1444create view v3 (a,b) as select t1.a as a, t2.a as b from t1 left join t2 on (t1.a=t2.a);
1445select * from t3 left join v3 on (t3.a = v3.a);
1446a	a	b
14471	1	1
14482	2	NULL
14494	NULL	NULL
1450explain extended select * from t3 left join v3 on (t3.a = v3.a);
1451id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14521	SIMPLE	t3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
14531	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (Block Nested Loop)
14541	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
1455Warnings:
1456Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
1457Note	1003	/* select#1 */ 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
1458create view v1 (a) as select a from t1;
1459create view v2 (a) as select a from t2;
1460create view v4 (a,b) as select v1.a as a, v2.a as b from v1 left join v2 on (v1.a=v2.a);
1461select * from t3 left join v4 on (t3.a = v4.a);
1462a	a	b
14631	1	1
14642	2	NULL
14654	NULL	NULL
1466explain extended select * from t3 left join v4 on (t3.a = v4.a);
1467id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
14681	SIMPLE	t3	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
14691	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (Block Nested Loop)
14701	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (Block Nested Loop)
1471Warnings:
1472Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
1473Note	1003	/* select#1 */ 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`.`t1`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`a` = `test`.`t3`.`a`)))) on((`test`.`t1`.`a` = `test`.`t3`.`a`)) where 1
1474prepare stmt1 from "select * from t3 left join v4 on (t3.a = v4.a);";
1475execute stmt1;
1476a	a	b
14771	1	1
14782	2	NULL
14794	NULL	NULL
1480execute stmt1;
1481a	a	b
14821	1	1
14832	2	NULL
14844	NULL	NULL
1485deallocate prepare stmt1;
1486drop view v4,v3,v2,v1;
1487drop tables t1,t2,t3;
1488create table t1 (a int, primary key (a), b int);
1489create table t2 (a int, primary key (a));
1490insert into t1 values (1,100), (2,200);
1491insert into t2 values (1), (3);
1492create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2;
1493update v3 set a= 10 where a=1;
1494select * from t1;
1495a	b
149610	100
14972	200
1498select * from t2;
1499a
15001
15013
1502create view v2 (a,b) as select t1.b as a, t2.a as b from t1, t2;
1503set updatable_views_with_limit=NO;
1504update v2 set a= 10 where a=200 limit 1;
1505Got one of the listed errors
1506set updatable_views_with_limit=DEFAULT;
1507select * from v3;
1508a	b
15092	1
151010	1
15112	3
151210	3
1513select * from v2;
1514a	b
1515100	1
1516200	1
1517100	3
1518200	3
1519set @a= 10;
1520set @b= 100;
1521prepare stmt1 from "update v3 set a= ? where a=?";
1522execute stmt1 using @a,@b;
1523select * from v3;
1524a	b
15252	1
152610	1
15272	3
152810	3
1529set @a= 300;
1530set @b= 10;
1531execute stmt1 using @a,@b;
1532select * from v3;
1533a	b
15342	1
1535300	1
15362	3
1537300	3
1538deallocate prepare stmt1;
1539drop view v3,v2;
1540drop tables t1,t2;
1541create table t1 (a int, primary key (a), b int);
1542create table t2 (a int, primary key (a), b int);
1543insert into t2 values (1000, 2000);
1544create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2;
1545insert into v3 values (1,2);
1546ERROR HY000: Can not insert into join view 'test.v3' without fields list
1547insert into v3 select * from t2;
1548ERROR HY000: Can not insert into join view 'test.v3' without fields list
1549insert into v3(a,b) values (1,2);
1550ERROR HY000: Can not modify more than one base table through a join view 'test.v3'
1551insert into v3(a,b) select * from t2;
1552ERROR HY000: Can not modify more than one base table through a join view 'test.v3'
1553insert into v3(a) values (1);
1554insert into v3(b) values (10);
1555insert into v3(a) select a from t2;
1556insert into v3(b) select b from t2;
1557Warnings:
1558Warning	1048	Column 'a' cannot be null
1559insert into v3(a) values (1) on duplicate key update a=a+10000+VALUES(a);
1560select * from t1;
1561a	b
156210002	NULL
156310	NULL
15641000	NULL
1565select * from t2;
1566a	b
15671000	2000
156810	NULL
15692000	NULL
15700	NULL
1571delete from v3;
1572ERROR HY000: Can not delete from join view 'test.v3'
1573delete v3,t1 from v3,t1;
1574ERROR HY000: Can not delete from join view 'test.v3'
1575delete t1,v3 from t1,v3;
1576ERROR HY000: Can not delete from join view 'test.v3'
1577delete from t1;
1578prepare stmt1 from "insert into v3(a) values (?);";
1579set @a= 100;
1580execute stmt1 using @a;
1581set @a= 300;
1582execute stmt1 using @a;
1583deallocate prepare stmt1;
1584prepare stmt1 from "insert into v3(a) select ?;";
1585set @a= 101;
1586execute stmt1 using @a;
1587set @a= 301;
1588execute stmt1 using @a;
1589deallocate prepare stmt1;
1590select * from v3;
1591a	b
1592100	0
1593101	0
1594300	0
1595301	0
1596100	10
1597101	10
1598300	10
1599301	10
1600100	1000
1601101	1000
1602300	1000
1603301	1000
1604100	2000
1605101	2000
1606300	2000
1607301	2000
1608drop view v3;
1609drop tables t1,t2;
1610create table t1(f1 int);
1611create view v1 as select f1 from t1;
1612select * from v1 where F1 = 1;
1613f1
1614drop view v1;
1615drop table t1;
1616create table t1(c1 int);
1617create table t2(c2 int);
1618insert into t1 values (1),(2),(3);
1619insert into t2 values (1);
1620SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2);
1621c1
16221
1623SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1);
1624c1
16251
1626create view v1 as SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2);
1627create view v2 as SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1);
1628select * from v1;
1629c1
16301
1631select * from v2;
1632c1
16331
1634select * from (select c1 from v2) X;
1635c1
16361
1637drop view v2, v1;
1638drop table t1, t2;
1639CREATE TABLE t1 (C1 INT, C2 INT);
1640CREATE TABLE t2 (C2 INT);
1641CREATE VIEW v1 AS SELECT C2 FROM t2;
1642CREATE VIEW v2 AS SELECT C1 FROM t1 LEFT OUTER JOIN v1 USING (C2);
1643SELECT * FROM v2;
1644C1
1645drop view v2, v1;
1646drop table t1, t2;
1647create table t1 (col1 char(5),col2 int,col3 int);
1648insert into t1 values ('one',10,25), ('two',10,50), ('two',10,50), ('one',20,25), ('one',30,25);
1649create view v1 as select * from t1;
1650select col1,group_concat(col2,col3) from t1 group by col1;
1651col1	group_concat(col2,col3)
1652one	1025,2025,3025
1653two	1050,1050
1654select col1,group_concat(col2,col3) from v1 group by col1;
1655col1	group_concat(col2,col3)
1656one	1025,2025,3025
1657two	1050,1050
1658drop view v1;
1659drop table t1;
1660create table t1 (s1 int, s2 char);
1661create view v1 as select s1, s2 from t1;
1662select s2 from v1 vq1 where 2 = (select count(*) from v1 vq2 having vq1.s2 = vq2.s2);
1663ERROR 42S22: Unknown column 'vq2.s2' in 'having clause'
1664select s2 from v1 vq1 where 2 = (select count(*) aa from v1 vq2 having vq1.s2 = aa);
1665s2
1666drop view v1;
1667drop table t1;
1668CREATE TABLE t1 (a1 int);
1669CREATE TABLE t2 (a2 int);
1670INSERT INTO t1 VALUES (1), (2), (3), (4);
1671INSERT INTO t2 VALUES (1), (2), (3);
1672CREATE VIEW v1(a,b) AS SELECT a1,a2 FROM t1 JOIN t2 ON a1=a2 WHERE a1>1;
1673SELECT * FROM v1;
1674a	b
16752	2
16763	3
1677CREATE TABLE t3 SELECT * FROM v1;
1678SELECT * FROM t3;
1679a	b
16802	2
16813	3
1682DROP VIEW v1;
1683DROP TABLE t1,t2,t3;
1684create table t1 (a int);
1685create table t2 like t1;
1686create table t3 like t1;
1687create view v1 as select t1.a x, t2.a y from t1 join t2 where t1.a=t2.a;
1688insert into t3 select x from v1;
1689insert into t2 select x from v1;
1690drop view v1;
1691drop table t1,t2,t3;
1692CREATE TABLE t1 (col1 int PRIMARY KEY, col2 varchar(10));
1693INSERT INTO t1 VALUES(1,'trudy');
1694INSERT INTO t1 VALUES(2,'peter');
1695INSERT INTO t1 VALUES(3,'sanja');
1696INSERT INTO t1 VALUES(4,'monty');
1697INSERT INTO t1 VALUES(5,'david');
1698INSERT INTO t1 VALUES(6,'kent');
1699INSERT INTO t1 VALUES(7,'carsten');
1700INSERT INTO t1 VALUES(8,'ranger');
1701INSERT INTO t1 VALUES(10,'matt');
1702CREATE TABLE t2 (col1 int, col2 int, col3 char(1));
1703INSERT INTO t2 VALUES (1,1,'y');
1704INSERT INTO t2 VALUES (1,2,'y');
1705INSERT INTO t2 VALUES (2,1,'n');
1706INSERT INTO t2 VALUES (3,1,'n');
1707INSERT INTO t2 VALUES (4,1,'y');
1708INSERT INTO t2 VALUES (4,2,'n');
1709INSERT INTO t2 VALUES (4,3,'n');
1710INSERT INTO t2 VALUES (6,1,'n');
1711INSERT INTO t2 VALUES (8,1,'y');
1712CREATE VIEW v1 AS SELECT * FROM t1;
1713SELECT a.col1,a.col2,b.col2,b.col3
1714FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1
1715WHERE b.col2 IS NULL OR
1716b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
1717col1	col2	col2	col3
17181	trudy	2	y
171910	matt	NULL	NULL
17202	peter	1	n
17213	sanja	1	n
17224	monty	3	n
17235	david	NULL	NULL
17246	kent	1	n
17257	carsten	NULL	NULL
17268	ranger	1	y
1727SELECT a.col1,a.col2,b.col2,b.col3
1728FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1
1729WHERE b.col2 IS NULL OR
1730b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
1731col1	col2	col2	col3
17321	trudy	2	y
173310	matt	NULL	NULL
17342	peter	1	n
17353	sanja	1	n
17364	monty	3	n
17375	david	NULL	NULL
17386	kent	1	n
17397	carsten	NULL	NULL
17408	ranger	1	y
1741CREATE VIEW v2 AS SELECT * FROM t2;
1742SELECT a.col1,a.col2,b.col2,b.col3
1743FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
1744WHERE b.col2 IS NULL OR
1745b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
1746col1	col2	col2	col3
17471	trudy	2	y
174810	matt	NULL	NULL
17492	peter	1	n
17503	sanja	1	n
17514	monty	3	n
17525	david	NULL	NULL
17536	kent	1	n
17547	carsten	NULL	NULL
17558	ranger	1	y
1756SELECT a.col1,a.col2,b.col2,b.col3
1757FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
1758WHERE a.col1 IN (1,5,9) AND
1759(b.col2 IS NULL OR
1760b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1));
1761col1	col2	col2	col3
17621	trudy	2	y
17635	david	NULL	NULL
1764CREATE VIEW v3 AS SELECT * FROM t1 WHERE col1 IN (1,5,9);
1765SELECT a.col1,a.col2,b.col2,b.col3
1766FROM v2 b RIGHT JOIN v3 a ON a.col1=b.col1
1767WHERE b.col2 IS NULL OR
1768b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
1769col1	col2	col2	col3
17701	trudy	2	y
17715	david	NULL	NULL
1772DROP VIEW v1,v2,v3;
1773DROP TABLE t1,t2;
1774create table t1 as select 1 A union select 2 union select 3;
1775create table t2 as select * from t1;
1776create view v1 as select * from t1 where a in (select * from t2);
1777select * from v1 A, v1 B where A.a = B.a;
1778A	A
17791	1
17802	2
17813	3
1782create table t3 as select a a,a b from t2;
1783create view v2 as select * from t3 where
1784a in (select * from t1) or b in (select * from t2);
1785select * from v2 A, v2 B where A.a = B.b;
1786a	b	a	b
17871	1	1	1
17882	2	2	2
17893	3	3	3
1790drop view v1, v2;
1791drop table t1, t2, t3;
1792CREATE TABLE t1 (a int);
1793CREATE TABLE t2 (b int);
1794INSERT INTO t1 VALUES (1), (2), (3), (4);
1795INSERT INTO t2 VALUES (4), (2);
1796CREATE VIEW v1 AS SELECT * FROM t1,t2 WHERE t1.a=t2.b;
1797SELECT * FROM v1;
1798a	b
17992	2
18004	4
1801CREATE VIEW v2 AS SELECT * FROM v1;
1802SELECT * FROM v2;
1803a	b
18042	2
18054	4
1806DROP VIEW v2,v1;
1807DROP TABLE t1, t2;
1808create table t1 (a int);
1809create view v1 as select sum(a) from t1 group by a;
1810create procedure p1()
1811begin
1812select * from v1;
1813end//
1814call p1();
1815sum(a)
1816call p1();
1817sum(a)
1818drop procedure p1;
1819drop view v1;
1820drop table t1;
1821CREATE TABLE t1(a char(2) primary key, b char(2));
1822CREATE TABLE t2(a char(2), b char(2), index i(a));
1823INSERT INTO t1 VALUES ('a','1'), ('b','2');
1824INSERT INTO t2 VALUES ('a','5'), ('a','6'), ('b','5'), ('b','6');
1825CREATE VIEW v1 AS
1826SELECT t1.b as c, t2.b as d FROM t1,t2 WHERE t1.a=t2.a;
1827SELECT d, c FROM v1 ORDER BY d,c;
1828d	c
18295	1
18305	2
18316	1
18326	2
1833DROP VIEW v1;
1834DROP TABLE t1, t2;
1835create table t1 (s1 int);
1836create view  v1 as select sum(distinct s1) from t1;
1837select * from v1;
1838sum(distinct s1)
1839NULL
1840drop view v1;
1841create view  v1 as select avg(distinct s1) from t1;
1842select * from v1;
1843avg(distinct s1)
1844NULL
1845drop view v1;
1846drop table t1;
1847create view v1 as select cast(1 as decimal);
1848select * from v1;
1849cast(1 as decimal)
18501
1851drop view v1;
1852create table t1(f1 int);
1853create table t2(f2 int);
1854insert into t1 values(1),(2),(3);
1855insert into t2 values(1),(2),(3);
1856create view v1 as select * from t1,t2 where f1=f2;
1857create table t3 (f1 int, f2 int);
1858insert into t3 select * from v1 order by 1;
1859select * from t3;
1860f1	f2
18611	1
18622	2
18633	3
1864drop view v1;
1865drop table t1,t2,t3;
1866create view v1 as select '\\','\\shazam';
1867select * from v1;
1868\	\shazam
1869\	\shazam
1870drop view v1;
1871create view v1 as select '\'','\shazam';
1872select * from v1;
1873'	shazam
1874'	shazam
1875drop view v1;
1876create view v1 as select 'k','K';
1877select * from v1;
1878k	My_exp_K
1879k	K
1880drop view v1;
1881create table t1 (s1 int);
1882create view v1 as select s1, 's1' from t1;
1883select * from v1;
1884s1	My_exp_s1
1885drop view v1;
1886create view v1 as select 's1', s1 from t1;
1887select * from v1;
1888My_exp_s1	s1
1889drop view v1;
1890create view v1 as select 's1', s1, 1 as My_exp_s1 from t1;
1891select * from v1;
1892My_exp_1_s1	s1	My_exp_s1
1893drop view v1;
1894create view v1 as select 1 as My_exp_s1, 's1', s1  from t1;
1895select * from v1;
1896My_exp_s1	My_exp_1_s1	s1
1897drop view v1;
1898create view v1 as select 1 as s1, 's1', 's1' from t1;
1899select * from v1;
1900s1	My_exp_s1	My_exp_1_s1
1901drop view v1;
1902create view v1 as select 's1', 's1', 1 as s1 from t1;
1903select * from v1;
1904My_exp_1_s1	My_exp_s1	s1
1905drop view v1;
1906create view v1 as select s1, 's1', 's1' from t1;
1907select * from v1;
1908s1	My_exp_s1	My_exp_1_s1
1909drop view v1;
1910create view v1 as select 's1', 's1', s1 from t1;
1911select * from v1;
1912My_exp_1_s1	My_exp_s1	s1
1913drop view v1;
1914create view v1 as select 1 as s1, 's1', s1 from t1;
1915ERROR 42S21: Duplicate column name 's1'
1916create view v1 as select 's1', s1, 1 as s1 from t1;
1917ERROR 42S21: Duplicate column name 's1'
1918drop table t1;
1919create view v1(k, K) as select 1,2;
1920ERROR 42S21: Duplicate column name 'K'
1921create view v1 as SELECT TIME_FORMAT(SEC_TO_TIME(3600),'%H:%i') as t;
1922select * from v1;
1923t
192401:00
1925drop view v1;
1926create table t1 (a timestamp default now());
1927create table t2 (b timestamp default now());
1928create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now();
1929SHOW CREATE VIEW v1;
1930View	Create View	character_set_client	collation_connection
1931v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t2`.`b` AS `b`,(`t1`.`a` < now()) AS `t1.a < now()` from (`t1` join `t2`) where (`t1`.`a` < now())	latin1	latin1_swedish_ci
1932drop view v1;
1933drop table t1, t2;
1934CREATE TABLE t1 ( a varchar(50) );
1935CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER();
1936SHOW CREATE VIEW v1;
1937View	Create View	character_set_client	collation_connection
1938v1	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
1939DROP VIEW v1;
1940CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION();
1941SHOW CREATE VIEW v1;
1942View	Create View	character_set_client	collation_connection
1943v1	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
1944DROP VIEW v1;
1945CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE();
1946SHOW CREATE VIEW v1;
1947View	Create View	character_set_client	collation_connection
1948v1	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
1949DROP VIEW v1;
1950DROP TABLE t1;
1951CREATE TABLE t1 (col1 time);
1952CREATE TABLE t2 (col1 time);
1953CREATE VIEW v1 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
1954CREATE VIEW v2 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
1955CREATE VIEW v3 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
1956CREATE VIEW v4 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
1957CREATE VIEW v5 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
1958CREATE VIEW v6 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
1959DROP TABLE t1;
1960CHECK TABLE v1, v2, v3, v4, v5, v6;
1961Table	Op	Msg_type	Msg_text
1962test.v1	check	Error	Table 'test.t1' doesn't exist
1963test.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
1964test.v1	check	error	Corrupt
1965test.v2	check	status	OK
1966test.v3	check	Error	Table 'test.t1' doesn't exist
1967test.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
1968test.v3	check	error	Corrupt
1969test.v4	check	status	OK
1970test.v5	check	Error	Table 'test.t1' doesn't exist
1971test.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
1972test.v5	check	error	Corrupt
1973test.v6	check	status	OK
1974drop view v1, v2, v3, v4, v5, v6;
1975drop table t2;
1976drop function if exists f1;
1977drop function if exists f2;
1978CREATE TABLE t1 (col1 time);
1979CREATE TABLE t2 (col1 time);
1980CREATE TABLE t3 (col1 time);
1981create function f1 () returns int return (select max(col1) from t1);
1982create function f2 () returns int return (select max(col1) from t2);
1983CREATE VIEW v1 AS SELECT f1() FROM t3;
1984CREATE VIEW v2 AS SELECT f2() FROM t3;
1985CREATE VIEW v3 AS SELECT f1() FROM t3;
1986CREATE VIEW v4 AS SELECT f2() FROM t3;
1987CREATE VIEW v5 AS SELECT f1() FROM t3;
1988CREATE VIEW v6 AS SELECT f2() FROM t3;
1989drop function f1;
1990CHECK TABLE v1, v2, v3, v4, v5, v6;
1991Table	Op	Msg_type	Msg_text
1992test.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
1993test.v1	check	status	Operation failed
1994test.v2	check	status	OK
1995test.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
1996test.v3	check	status	Operation failed
1997test.v4	check	status	OK
1998test.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
1999test.v5	check	status	Operation failed
2000test.v6	check	status	OK
2001create function f1 () returns int return (select max(col1) from t1);
2002DROP TABLE t1;
2003CHECK TABLE v1, v2, v3, v4, v5, v6;
2004Table	Op	Msg_type	Msg_text
2005test.v1	check	status	OK
2006test.v2	check	status	OK
2007test.v3	check	status	OK
2008test.v4	check	status	OK
2009test.v5	check	status	OK
2010test.v6	check	status	OK
2011drop function f1;
2012drop function f2;
2013drop view v1, v2, v3, v4, v5, v6;
2014drop table t2,t3;
2015create table t1 (f1 date);
2016insert into t1 values ('2005-01-01'),('2005-02-02');
2017create view v1 as select * from t1;
2018select * from v1 where f1='2005.02.02';
2019f1
20202005-02-02
2021select * from v1 where '2005.02.02'=f1;
2022f1
20232005-02-02
2024drop view v1;
2025drop table t1;
2026CREATE VIEW v1 AS SELECT ENCRYPT("dhgdhgd");
2027Warnings:
2028Warning	1287	'ENCRYPT' is deprecated and will be removed in a future release. Please use AES_ENCRYPT instead
2029SELECT * FROM v1;
2030drop view v1;
2031CREATE VIEW v1 AS SELECT SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1);
2032SELECT * FROM v1;
2033SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1)
2034dkjhgd
2035drop view v1;
2036create table t1 (f59 int, f60 int, f61 int);
2037insert into t1 values (19,41,32);
2038create view v1 as select f59, f60 from t1 where f59 in
2039(select f59 from t1);
2040update v1 set f60=2345;
2041ERROR HY000: The target table v1 of the UPDATE is not updatable
2042update t1 set f60=(select max(f60) from v1);
2043ERROR HY000: The definition of table 'v1' prevents operation UPDATE on table 't1'.
2044drop view v1;
2045drop table t1;
2046create table t1 (s1 int);
2047create view v1 as select var_samp(s1) from t1;
2048show create view v1;
2049View	Create View	character_set_client	collation_connection
2050v1	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
2051drop view v1;
2052drop table t1;
2053CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL);
2054CREATE VIEW v1 (vcol1) AS SELECT col1 FROM t1;
2055CREATE VIEW v2 (vcol1) AS SELECT col1 FROM t1 WHERE col2 > 2;
2056INSERT INTO t1 (col1) VALUES(12);
2057ERROR HY000: Field 'col2' doesn't have a default value
2058INSERT INTO v1 (vcol1) VALUES(12);
2059ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value
2060INSERT INTO v2 (vcol1) VALUES(12);
2061ERROR HY000: Field of view 'test.v2' underlying table doesn't have a default value
2062drop view v2,v1;
2063drop table t1;
2064create table t1 (f1 int);
2065insert into t1 values (1);
2066create view v1 as select f1 from t1;
2067select f1 as alias from v1;
2068alias
20691
2070drop view v1;
2071drop table t1;
2072CREATE TABLE t1 (s1 int, s2 int);
2073INSERT  INTO t1 VALUES (1,2);
2074CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1;
2075SELECT * FROM v1;
2076s1	s2
20772	1
2078CREATE PROCEDURE p1 () SELECT * FROM v1;
2079CALL p1();
2080s1	s2
20812	1
2082ALTER VIEW v1 AS SELECT s1 AS s1, s2 AS s2 FROM t1;
2083CALL p1();
2084s1	s2
20851	2
2086DROP VIEW v1;
2087CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1;
2088CALL p1();
2089s1	s2
20902	1
2091DROP PROCEDURE p1;
2092DROP VIEW v1;
2093DROP TABLE t1;
2094create table t1 (f1 int, f2 int);
2095create view v1 as select f1 as f3, f2 as f1 from t1;
2096insert into t1 values (1,3),(2,1),(3,2);
2097select * from v1 order by f1;
2098f3	f1
20992	1
21003	2
21011	3
2102drop view v1;
2103drop table t1;
2104CREATE TABLE t1 (f1 char);
2105INSERT INTO t1 VALUES ('A');
2106CREATE VIEW  v1 AS SELECT * FROM t1;
2107INSERT INTO t1 VALUES('B');
2108SELECT * FROM v1;
2109f1
2110A
2111B
2112SELECT * FROM t1;
2113f1
2114A
2115B
2116DROP VIEW v1;
2117DROP TABLE t1;
2118CREATE TABLE t1 ( bug_table_seq   INTEGER NOT NULL);
2119CREATE OR REPLACE VIEW v1 AS SELECT * from t1;
2120DROP PROCEDURE IF EXISTS p1;
2121Warnings:
2122Note	1305	PROCEDURE test.p1 does not exist
2123CREATE PROCEDURE p1 ( )
2124BEGIN
2125DO (SELECT  @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1);
2126INSERT INTO t1 VALUES (1);
2127END //
2128CALL p1();
2129DROP PROCEDURE p1;
2130DROP VIEW v1;
2131DROP TABLE t1;
2132create table t1(f1 datetime);
2133insert into t1 values('2005.01.01 12:0:0');
2134create view v1 as select f1, subtime(f1, '1:1:1') as sb from t1;
2135select * from v1;
2136f1	sb
21372005-01-01 12:00:00	2005-01-01 10:58:59
2138drop view v1;
2139drop table t1;
2140CREATE TABLE t1 (
2141aid int PRIMARY KEY,
2142fn varchar(20) NOT NULL,
2143ln varchar(20) NOT NULL
2144);
2145CREATE TABLE t2 (
2146aid int NOT NULL,
2147pid int NOT NULL
2148);
2149INSERT INTO t1 VALUES(1,'a','b'), (2,'c','d');
2150INSERT INTO t2 values (1,1), (2,1), (2,2);
2151CREATE VIEW v1 AS SELECT t1.*,t2.pid FROM t1,t2 WHERE t1.aid = t2.aid;
2152SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM t1,t2
2153WHERE t1.aid = t2.aid GROUP BY pid;
2154pid	GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1)
21551	a b,c d
21562	c d
2157SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM v1 GROUP BY pid;
2158pid	GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1)
21591	a b,c d
21602	c d
2161DROP VIEW v1;
2162DROP TABLE t1,t2;
2163CREATE TABLE t1 (id int PRIMARY KEY, f varchar(255));
2164CREATE VIEW v1 AS SELECT id, f FROM t1 WHERE id <= 2;
2165INSERT INTO t1 VALUES (2, 'foo2');
2166INSERT INTO t1 VALUES (1, 'foo1');
2167SELECT * FROM v1;
2168id	f
21691	foo1
21702	foo2
2171SELECT * FROM v1;
2172id	f
21731	foo1
21742	foo2
2175DROP VIEW v1;
2176DROP TABLE t1;
2177CREATE TABLE t1 (pk int PRIMARY KEY, b int);
2178CREATE TABLE t2 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
2179CREATE TABLE t3 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
2180CREATE TABLE t4 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
2181CREATE TABLE t5 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
2182CREATE VIEW v1 AS
2183SELECT t1.pk as a FROM t1,t2,t3,t4,t5
2184WHERE t1.b IS NULL AND
2185t1.pk=t2.fk AND t2.pk=t3.fk AND t3.pk=t4.fk AND t4.pk=t5.fk;
2186SELECT a FROM v1;
2187a
2188DROP VIEW v1;
2189DROP TABLE t1,t2,t3,t4,t5;
2190create view v1 as select timestampdiff(day,'1997-01-01 00:00:00','1997-01-02 00:00:00') as f1;
2191select * from v1;
2192f1
21931
2194drop view v1;
2195create table t1(a int);
2196create procedure p1() create view v1 as select * from t1;
2197drop table t1;
2198call p1();
2199ERROR 42S02: Table 'test.t1' doesn't exist
2200call p1();
2201ERROR 42S02: Table 'test.t1' doesn't exist
2202drop procedure p1;
2203create table t1 (f1 int);
2204create table t2 (f1 int);
2205insert into t1 values (1);
2206insert into t2 values (2);
2207create view v1 as select * from t1 union select * from t2 union all select * from t2;
2208select * from v1;
2209f1
22101
22112
22122
2213drop view v1;
2214drop table t1,t2;
2215CREATE TEMPORARY TABLE t1 (a int);
2216CREATE FUNCTION f1 () RETURNS int RETURN (SELECT COUNT(*) FROM t1);
2217CREATE VIEW v1 AS SELECT f1();
2218ERROR HY000: View's SELECT refers to a temporary table 't1'
2219DROP FUNCTION f1;
2220DROP TABLE t1;
2221DROP TABLE IF EXISTS t1;
2222DROP VIEW  IF EXISTS v1;
2223CREATE TABLE t1 (f4 CHAR(5));
2224CREATE VIEW v1 AS SELECT * FROM t1;
2225DESCRIBE v1;
2226Field	Type	Null	Key	Default	Extra
2227f4	char(5)	YES		NULL
2228ALTER TABLE t1 CHANGE COLUMN f4 f4x CHAR(5);
2229DESCRIBE v1;
2230ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
2231DROP TABLE t1;
2232DROP VIEW v1;
2233create table t1 (f1 char);
2234create view v1 as select strcmp(f1,'a') from t1;
2235select * from v1;
2236strcmp(f1,'a')
2237drop view v1;
2238drop table t1;
2239create table t1 (f1 int, f2 int,f3 int);
2240insert into t1 values (1,10,20),(2,0,0);
2241create view v1 as select * from t1;
2242select if(sum(f1)>1,f2,f3) from v1 group by f1;
2243if(sum(f1)>1,f2,f3)
224420
22450
2246drop view v1;
2247drop table t1;
2248create table t1 (
2249r_object_id char(16) NOT NULL,
2250group_name varchar(32) NOT NULL
2251) engine = InnoDB;
2252create table t2 (
2253r_object_id char(16) NOT NULL,
2254i_position int(11) NOT NULL,
2255users_names varchar(32) default NULL
2256) Engine = InnoDB;
2257create view v1 as select r_object_id, group_name from t1;
2258create view v2 as select r_object_id, i_position, users_names from t2;
2259create unique index r_object_id on t1(r_object_id);
2260create index group_name on t1(group_name);
2261create unique index r_object_id_i_position on t2(r_object_id,i_position);
2262create index users_names on t2(users_names);
2263insert into t1 values('120001a080000542','tstgroup1');
2264insert into t2 values('120001a080000542',-1, 'guser01');
2265insert into t2 values('120001a080000542',-2, 'guser02');
2266select v1.r_object_id, v2.users_names from v1, v2
2267where (v1.group_name='tstgroup1') and v2.r_object_id=v1.r_object_id
2268order by users_names;
2269r_object_id	users_names
2270120001a080000542	guser01
2271120001a080000542	guser02
2272drop view v1, v2;
2273drop table t1, t2;
2274create table t1 (s1 int);
2275create view abc as select * from t1 as abc;
2276drop table t1;
2277drop view abc;
2278create table t1(f1 char(1));
2279create view v1 as select * from t1;
2280select * from (select f1 as f2 from v1) v where v.f2='a';
2281f2
2282drop view v1;
2283drop table t1;
2284create view v1 as SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
2285select * from v1;
2286CONVERT_TZ('2004-01-01 12:00:00','GMT','MET')
2287NULL
2288drop view v1;
2289CREATE TABLE t1 (date DATE NOT NULL);
2290INSERT INTO  t1 VALUES ('2005-09-06');
2291CREATE VIEW v1 AS SELECT DAYNAME(date) FROM t1;
2292SHOW CREATE VIEW v1;
2293View	Create View	character_set_client	collation_connection
2294v1	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
2295CREATE VIEW v2 AS SELECT DAYOFWEEK(date) FROM t1;
2296SHOW CREATE VIEW v2;
2297View	Create View	character_set_client	collation_connection
2298v2	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
2299CREATE VIEW v3 AS SELECT WEEKDAY(date) FROM t1;
2300SHOW CREATE VIEW v3;
2301View	Create View	character_set_client	collation_connection
2302v3	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
2303SELECT DAYNAME('2005-09-06');
2304DAYNAME('2005-09-06')
2305Tuesday
2306SELECT DAYNAME(date) FROM t1;
2307DAYNAME(date)
2308Tuesday
2309SELECT * FROM v1;
2310DAYNAME(date)
2311Tuesday
2312SELECT DAYOFWEEK('2005-09-06');
2313DAYOFWEEK('2005-09-06')
23143
2315SELECT DAYOFWEEK(date) FROM t1;
2316DAYOFWEEK(date)
23173
2318SELECT * FROM v2;
2319DAYOFWEEK(date)
23203
2321SELECT WEEKDAY('2005-09-06');
2322WEEKDAY('2005-09-06')
23231
2324SELECT WEEKDAY(date) FROM t1;
2325WEEKDAY(date)
23261
2327SELECT * FROM v3;
2328WEEKDAY(date)
23291
2330DROP TABLE t1;
2331DROP VIEW  v1, v2, v3;
2332CREATE TABLE t1 ( a int, b int );
2333INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
2334CREATE VIEW v1 AS SELECT a,b FROM t1;
2335SELECT t1.a FROM t1 GROUP BY t1.a HAVING a > 1;
2336a
23372
23383
2339SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1;
2340a
23412
23423
2343DROP VIEW v1;
2344DROP TABLE t1;
2345CREATE TABLE t1 ( a int, b int );
2346INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
2347CREATE VIEW v1 AS SELECT a,b FROM t1;
2348SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1;
2349a
23502
23513
2352SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1;
2353a
23542
23553
2356SELECT t_1.a FROM t1 AS t_1 GROUP BY t_1.a HAVING t_1.a IN (1,2,3);
2357a
23581
23592
23603
2361SELECT v_1.a FROM v1 AS v_1 GROUP BY v_1.a HAVING v_1.a IN (1,2,3);
2362a
23631
23642
23653
2366DROP VIEW v1;
2367DROP TABLE t1;
2368CREATE TABLE t1 (a INT, b INT, INDEX(a,b));
2369CREATE TABLE t2 LIKE t1;
2370CREATE TABLE t3 (a INT);
2371INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
2372INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
2373INSERT INTO t3 VALUES (1),(2),(3);
2374CREATE VIEW v1 AS SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b;
2375CREATE VIEW v2 AS SELECT t3.* FROM t1,t3 WHERE t1.a=t3.a;
2376EXPLAIN SELECT t1.* FROM t1 JOIN t2 WHERE t1.a=t2.a AND t1.b=t2.b AND t1.a=1;
2377id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23781	SIMPLE	t1	NULL	ref	a	a	5	const	1	100.00	Using where; Using index
23791	SIMPLE	t2	NULL	ref	a	a	10	const,test.t1.b	1	100.00	Using index
2380Warnings:
2381Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t1`.`a` = 1) and (`test`.`t2`.`a` = 1))
2382EXPLAIN SELECT * FROM v1 WHERE a=1;
2383id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23841	SIMPLE	t1	NULL	ref	a	a	5	const	1	100.00	Using where; Using index
23851	SIMPLE	t2	NULL	ref	a	a	10	const,test.t1.b	1	100.00	Using index
2386Warnings:
2387Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t1`.`a` = 1) and (`test`.`t2`.`a` = 1))
2388EXPLAIN SELECT * FROM v2 WHERE a=1;
2389id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
23901	SIMPLE	t1	NULL	ref	a	a	5	const	1	100.00	Using index
23911	SIMPLE	t3	NULL	ALL	NULL	NULL	NULL	NULL	3	33.33	Using where; Using join buffer (Block Nested Loop)
2392Warnings:
2393Note	1003	/* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t1` join `test`.`t3` where ((`test`.`t1`.`a` = 1) and (`test`.`t3`.`a` = 1))
2394DROP VIEW v1,v2;
2395DROP TABLE t1,t2,t3;
2396create table t1 (f1 int);
2397create view v1 as select t1.f1 as '123
2398456' from t1;
2399select * from v1;
2400123
2401456
2402drop view v1;
2403drop table t1;
2404create table t1 (f1 int, f2 int);
2405insert into t1 values(1,1),(1,2),(1,3);
2406create view v1 as select f1 ,group_concat(f2 order by f2 asc) from t1 group by f1;
2407create view v2 as select f1 ,group_concat(f2 order by f2 desc) from t1 group by f1;
2408select * from v1;
2409f1	group_concat(f2 order by f2 asc)
24101	1,2,3
2411select * from v2;
2412f1	group_concat(f2 order by f2 desc)
24131	3,2,1
2414drop view v1,v2;
2415drop table t1;
2416create table t1 (x int, y int);
2417create table t2 (x int, y int, z int);
2418create table t3 (x int, y int, z int);
2419create table t4 (x int, y int, z int);
2420create view v1 as
2421select t1.x
2422from (
2423(t1 join t2 on ((t1.y = t2.y)))
2424join
2425(t3 left join t4 on (t3.y = t4.y) and (t3.z = t4.z))
2426);
2427prepare stmt1 from "select count(*) from v1 where x = ?";
2428set @parm1=1;
2429execute stmt1 using @parm1;
2430count(*)
24310
2432execute stmt1 using @parm1;
2433count(*)
24340
2435drop view v1;
2436drop table t1,t2,t3,t4;
2437CREATE TABLE t1(id INT);
2438CREATE VIEW v1 AS SELECT id FROM t1;
2439OPTIMIZE TABLE v1;
2440Table	Op	Msg_type	Msg_text
2441test.v1	optimize	Error	'test.v1' is not BASE TABLE
2442test.v1	optimize	status	Operation failed
2443ANALYZE TABLE v1;
2444Table	Op	Msg_type	Msg_text
2445test.v1	analyze	Error	'test.v1' is not BASE TABLE
2446test.v1	analyze	status	Operation failed
2447REPAIR TABLE v1;
2448Table	Op	Msg_type	Msg_text
2449test.v1	repair	Error	'test.v1' is not BASE TABLE
2450test.v1	repair	status	Operation failed
2451DROP TABLE t1;
2452OPTIMIZE TABLE v1;
2453Table	Op	Msg_type	Msg_text
2454test.v1	optimize	Error	'test.v1' is not BASE TABLE
2455test.v1	optimize	status	Operation failed
2456ANALYZE TABLE v1;
2457Table	Op	Msg_type	Msg_text
2458test.v1	analyze	Error	'test.v1' is not BASE TABLE
2459test.v1	analyze	status	Operation failed
2460REPAIR TABLE v1;
2461Table	Op	Msg_type	Msg_text
2462test.v1	repair	Error	'test.v1' is not BASE TABLE
2463test.v1	repair	status	Operation failed
2464DROP VIEW v1;
2465create definer = current_user() sql security invoker view v1 as select 1;
2466show create view v1;
2467View	Create View	character_set_client	collation_connection
2468v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1`	latin1	latin1_swedish_ci
2469drop view v1;
2470create definer = current_user sql security invoker view v1 as select 1;
2471show create view v1;
2472View	Create View	character_set_client	collation_connection
2473v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1`	latin1	latin1_swedish_ci
2474drop view v1;
2475create table t1 (id INT, primary key(id));
2476insert into t1 values (1),(2);
2477create view v1 as select * from t1;
2478explain select id from v1 order by id;
2479id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
24801	SIMPLE	t1	NULL	index	NULL	PRIMARY	4	NULL	2	100.00	Using index
2481Warnings:
2482Note	1003	/* select#1 */ select `test`.`t1`.`id` AS `id` from `test`.`t1` order by `test`.`t1`.`id`
2483drop view v1;
2484drop table t1;
2485create table t1(f1 int, f2 int);
2486insert into t1 values (null, 10), (null,2);
2487select f1, sum(f2) from t1 group by f1;
2488f1	sum(f2)
2489NULL	12
2490create view v1 as select * from t1;
2491select f1, sum(f2) from v1 group by f1;
2492f1	sum(f2)
2493NULL	12
2494drop view v1;
2495drop table t1;
2496drop procedure if exists p1;
2497create procedure p1 () deterministic
2498begin
2499create view v1 as select 1;
2500end;
2501//
2502call p1();
2503show create view v1;
2504View	Create View	character_set_client	collation_connection
2505v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1`	latin1	latin1_swedish_ci
2506drop view v1;
2507drop procedure p1;
2508CREATE VIEW v1 AS SELECT 42 AS Meaning;
2509DROP FUNCTION IF EXISTS f1;
2510CREATE FUNCTION f1() RETURNS INTEGER
2511BEGIN
2512DECLARE retn INTEGER;
2513SELECT Meaning FROM v1 INTO retn;
2514RETURN retn;
2515END
2516//
2517CREATE VIEW v2 AS SELECT f1();
2518select * from v2;
2519f1()
252042
2521drop view v2,v1;
2522drop function f1;
2523create table t1 (id numeric, warehouse_id numeric);
2524create view v1 as select id from t1;
2525create view v2 as
2526select t1.warehouse_id, v1.id as receipt_id
2527from t1, v1 where t1.id = v1.id;
2528insert into t1 (id, warehouse_id) values(3, 2);
2529insert into t1 (id, warehouse_id) values(4, 2);
2530insert into t1 (id, warehouse_id) values(5, 1);
2531select v2.receipt_id as alias1, v2.receipt_id as alias2 from v2
2532order by v2.receipt_id;
2533alias1	alias2
25343	3
25354	4
25365	5
2537drop view v2, v1;
2538drop table t1;
2539CREATE TABLE t1 (a int PRIMARY KEY, b int);
2540INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10);
2541CREATE VIEW v1 AS SELECT * FROM t1;
2542SELECT MAX(a) FROM t1;
2543MAX(a)
25445
2545SELECT MAX(a) FROM v1;
2546MAX(a)
25475
2548EXPLAIN SELECT MAX(a) FROM t1;
2549id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25501	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
2551Warnings:
2552Note	1003	/* select#1 */ select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1`
2553EXPLAIN SELECT MAX(a) FROM v1;
2554id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25551	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
2556Warnings:
2557Note	1003	/* select#1 */ select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1`
2558SELECT MIN(a) FROM t1;
2559MIN(a)
25600
2561SELECT MIN(a) FROM v1;
2562MIN(a)
25630
2564EXPLAIN SELECT MIN(a) FROM t1;
2565id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25661	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
2567Warnings:
2568Note	1003	/* select#1 */ select min(`test`.`t1`.`a`) AS `MIN(a)` from `test`.`t1`
2569EXPLAIN SELECT MIN(a) FROM v1;
2570id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
25711	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
2572Warnings:
2573Note	1003	/* select#1 */ select min(`test`.`t1`.`a`) AS `MIN(a)` from `test`.`t1`
2574DROP VIEW v1;
2575DROP TABLE t1;
2576CREATE TABLE t1 (x varchar(10));
2577INSERT INTO t1 VALUES (null), ('foo'), ('bar'), (null);
2578CREATE VIEW v1 AS SELECT * FROM t1;
2579SELECT IF(x IS NULL, 'blank', 'not blank') FROM v1 GROUP BY x;
2580IF(x IS NULL, 'blank', 'not blank')
2581blank
2582not blank
2583not blank
2584SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM t1 GROUP BY x;
2585x
2586blank
2587not blank
2588not blank
2589Warnings:
2590Warning	1052	Column 'x' in group statement is ambiguous
2591SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1;
2592x
2593blank
2594not blank
2595not blank
2596blank
2597SELECT IF(x IS NULL, 'blank', 'not blank') AS y FROM v1 GROUP BY y;
2598y
2599blank
2600not blank
2601SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x;
2602x
2603blank
2604not blank
2605not blank
2606Warnings:
2607Warning	1052	Column 'x' in group statement is ambiguous
2608DROP VIEW v1;
2609DROP TABLE t1;
2610drop table if exists t1;
2611drop view if exists v1;
2612create table t1 (id int);
2613create view v1 as select * from t1;
2614drop table t1;
2615show create view v1;
2616drop view v1;
2617//
2618View	Create View	character_set_client	collation_connection
2619v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`id` AS `id` from `t1`	latin1	latin1_swedish_ci
2620create table t1(f1 int, f2 int);
2621create view v1 as select ta.f1 as a, tb.f1 as b from t1 ta, t1 tb where ta.f1=tb
2622.f1 and ta.f2=tb.f2;
2623insert into t1 values(1,1),(2,2);
2624create view v2 as select * from v1 where a > 1 with local check option;
2625select * from v2;
2626a	b
26272	2
2628update v2 set b=3 where a=2;
2629select * from v2;
2630a	b
26313	3
2632drop view v2, v1;
2633drop table t1;
2634CREATE TABLE t1 (a int);
2635INSERT INTO t1 VALUES (1), (2);
2636CREATE VIEW v1 AS SELECT SQRT(a) my_sqrt FROM t1;
2637SELECT my_sqrt FROM v1 ORDER BY my_sqrt;
2638my_sqrt
26391
26401.4142135623730951
2641DROP VIEW v1;
2642DROP TABLE t1;
2643CREATE TABLE t1 (id int PRIMARY KEY);
2644CREATE TABLE t2 (id int PRIMARY KEY);
2645INSERT INTO t1 VALUES (1), (3);
2646INSERT INTO t2 VALUES (1), (2), (3);
2647CREATE VIEW v2 AS SELECT * FROM t2;
2648SELECT COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id=t2.id;
2649COUNT(*)
26502
2651SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id;
2652id	id
26531	1
26543	3
2655SELECT COUNT(*) FROM t1 LEFT JOIN v2 ON t1.id=v2.id;
2656COUNT(*)
26572
2658DROP VIEW v2;
2659DROP TABLE t1, t2;
2660CREATE TABLE t1 (id int NOT NULL PRIMARY KEY,
2661td date DEFAULT NULL, KEY idx(td));
2662INSERT INTO t1 VALUES
2663(1, '2005-01-01'), (2, '2005-01-02'), (3, '2005-01-02'),
2664(4, '2005-01-03'), (5, '2005-01-04'), (6, '2005-01-05'),
2665(7, '2005-01-05'), (8, '2005-01-05'), (9, '2005-01-06');
2666CREATE VIEW v1 AS SELECT * FROM t1;
2667SELECT * FROM t1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE);
2668id	td
26692	2005-01-02
26703	2005-01-02
26714	2005-01-03
26725	2005-01-04
2673SELECT * FROM v1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE);
2674id	td
26752	2005-01-02
26763	2005-01-02
26774	2005-01-03
26785	2005-01-04
2679DROP VIEW v1;
2680DROP TABLE t1;
2681create table t1 (a int);
2682create view v1 as select * from t1;
2683create view v2 as select * from v1;
2684drop table t1;
2685rename table v2 to t1;
2686select * from v1;
2687ERROR HY000: `test`.`v1` contains view recursion
2688drop view t1, v1;
2689create table t1 (a int);
2690create function f1() returns int
2691begin
2692declare mx int;
2693select max(a) from t1 into mx;
2694return mx;
2695end//
2696create view v1 as select f1() as a;
2697create view v2 as select * from v1;
2698drop table t1;
2699rename table v2 to t1;
2700select * from v1;
2701ERROR HY000: Recursive stored functions and triggers are not allowed.
2702drop function f1;
2703drop view t1, v1;
2704create table t1 (dt datetime);
2705insert into t1 values (20040101000000), (20050101000000), (20060101000000);
2706create view v1 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from t1;
2707select * from v1;
2708ldt
27092004-01-01 03:00:00
27102005-01-01 03:00:00
27112006-01-01 03:00:00
2712drop view v1;
2713create view v1 as select * from t1 where convert_tz(dt, 'UTC', 'Europe/Moscow') >= 20050101000000;
2714select * from v1;
2715dt
27162005-01-01 00:00:00
27172006-01-01 00:00:00
2718create view v2 as select * from v1 where dt < 20060101000000;
2719select * from v2;
2720dt
27212005-01-01 00:00:00
2722drop view v2;
2723create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1;
2724select * from v2;
2725ldt
27262005-01-01 03:00:00
27272006-01-01 03:00:00
2728drop view v1, v2;
2729drop table t1;
2730CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, d datetime);
2731CREATE VIEW v1 AS
2732SELECT id, date(d) + INTERVAL TIME_TO_SEC(d) SECOND AS t, COUNT(*)
2733FROM t1 GROUP BY id, t;
2734SHOW CREATE VIEW v1;
2735View	Create View	character_set_client	collation_connection
2736v1	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`,`t`	latin1	latin1_swedish_ci
2737SELECT * FROM v1;
2738id	t	COUNT(*)
2739DROP VIEW v1;
2740DROP TABLE t1;
2741CREATE TABLE t1 (i INT, j BIGINT);
2742INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
2743CREATE VIEW v1 AS SELECT MIN(j) AS j FROM t1;
2744CREATE VIEW v2 AS SELECT MIN(i) FROM t1 WHERE j = ( SELECT * FROM v1 );
2745SELECT * FROM v2;
2746MIN(i)
27471
2748DROP VIEW v2, v1;
2749DROP TABLE t1;
2750CREATE TABLE t1(
2751fName varchar(25) NOT NULL,
2752lName varchar(25) NOT NULL,
2753DOB date NOT NULL,
2754test_date date NOT NULL,
2755uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY);
2756INSERT INTO t1(fName, lName, DOB, test_date) VALUES
2757('Hank', 'Hill', '1964-09-29', '2007-01-01'),
2758('Tom', 'Adams', '1908-02-14', '2007-01-01'),
2759('Homer', 'Simpson', '1968-03-05', '2007-01-01');
2760CREATE VIEW v1 AS
2761SELECT (year(test_date)-year(DOB)) AS Age
2762FROM t1 HAVING Age < 75;
2763SHOW CREATE VIEW v1;
2764View	Create View	character_set_client	collation_connection
2765v1	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
2766SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75;
2767Age
276843
276939
2770SELECT * FROM v1;
2771Age
277243
277339
2774DROP VIEW v1;
2775DROP TABLE t1;
2776CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a char(6) DEFAULT 'xxx');
2777INSERT INTO t1(id) VALUES (1), (2), (3), (4);
2778INSERT INTO t1 VALUES (5,'yyy'), (6,'yyy');
2779SELECT * FROM t1;
2780id	a
27811	xxx
27822	xxx
27833	xxx
27844	xxx
27855	yyy
27866	yyy
2787CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a;
2788SELECT * FROM v1;
2789a	m
2790xxx	1
2791yyy	5
2792CREATE TABLE t2 SELECT * FROM v1;
2793INSERT INTO t2(m) VALUES (0);
2794SELECT * FROM t2;
2795a	m
2796xxx	1
2797yyy	5
2798xxx	0
2799DROP VIEW v1;
2800DROP TABLE t1,t2;
2801CREATE TABLE t1 (id int PRIMARY KEY, e ENUM('a','b') NOT NULL DEFAULT 'b');
2802INSERT INTO t1(id) VALUES (1), (2), (3);
2803INSERT INTO t1 VALUES (4,'a');
2804SELECT * FROM t1;
2805id	e
28061	b
28072	b
28083	b
28094	a
2810CREATE VIEW v1(m, e) AS SELECT MIN(id), e FROM t1 GROUP BY e;
2811CREATE TABLE t2 SELECT * FROM v1;
2812SELECT * FROM t2;
2813m	e
28144	a
28151	b
2816DROP VIEW v1;
2817DROP TABLE t1,t2;
2818CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL);
2819CREATE VIEW v1 AS SELECT a, b FROM t1;
2820INSERT IGNORE INTO v1 (b) VALUES (2);
2821Warnings:
2822Warning	1423	Field of view 'test.v1' underlying table doesn't have a default value
2823SET SQL_MODE = STRICT_ALL_TABLES;
2824Warnings:
2825Warning	3135	'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2826Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
2827INSERT INTO v1 (b) VALUES (4);
2828ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value
2829SET SQL_MODE = '';
2830SELECT * FROM t1;
2831a	b
28320	2
2833DROP VIEW v1;
2834DROP TABLE t1;
2835CREATE TABLE t1 (firstname text, surname text);
2836INSERT INTO t1 VALUES
2837("Bart","Simpson"),("Milhouse","van Houten"),("Montgomery","Burns");
2838CREATE VIEW v1 AS SELECT CONCAT(firstname," ",surname) AS name FROM t1;
2839SELECT CONCAT(LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," ")),
2840LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," "))) AS f1
2841FROM v1;
2842f1
2843BartBart
2844Milhouse vanMilhouse van
2845MontgomeryMontgomery
2846DROP VIEW v1;
2847DROP TABLE t1;
2848CREATE TABLE t1 (i int, j int);
2849CREATE VIEW v1 AS SELECT COALESCE(i,j) FROM t1;
2850DESCRIBE v1;
2851Field	Type	Null	Key	Default	Extra
2852COALESCE(i,j)	bigint(11)	YES		NULL
2853CREATE TABLE t2 SELECT COALESCE(i,j) FROM t1;
2854DESCRIBE t2;
2855Field	Type	Null	Key	Default	Extra
2856COALESCE(i,j)	int(11)	YES		NULL
2857DROP VIEW v1;
2858DROP TABLE t1,t2;
2859CREATE TABLE t1 (s varchar(10));
2860INSERT INTO t1 VALUES ('yadda'), ('yady');
2861SELECT TRIM(BOTH 'y' FROM s) FROM t1;
2862TRIM(BOTH 'y' FROM s)
2863adda
2864ad
2865CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1;
2866SELECT * FROM v1;
2867TRIM(BOTH 'y' FROM s)
2868adda
2869ad
2870DROP VIEW v1;
2871SELECT TRIM(LEADING 'y' FROM s) FROM t1;
2872TRIM(LEADING 'y' FROM s)
2873adda
2874ady
2875CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1;
2876SELECT * FROM v1;
2877TRIM(LEADING 'y' FROM s)
2878adda
2879ady
2880DROP VIEW v1;
2881SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
2882TRIM(TRAILING 'y' FROM s)
2883yadda
2884yad
2885CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
2886SELECT * FROM v1;
2887TRIM(TRAILING 'y' FROM s)
2888yadda
2889yad
2890DROP VIEW v1;
2891DROP TABLE t1;
2892CREATE TABLE t1 (x INT, y INT);
2893CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
2894SHOW CREATE VIEW v1;
2895View	Create View	character_set_client	collation_connection
2896v1	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY INVOKER VIEW `v1` AS select `t1`.`x` AS `x` from `t1`	latin1	latin1_swedish_ci
2897ALTER VIEW v1 AS SELECT x, y FROM t1;
2898SHOW CREATE VIEW v1;
2899View	Create View	character_set_client	collation_connection
2900v1	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
2901DROP VIEW v1;
2902DROP TABLE t1;
2903CREATE TABLE t1 (s1 char);
2904INSERT INTO t1 VALUES ('Z');
2905CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1;
2906CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1;
2907INSERT INTO v1 (col) VALUES ('b');
2908INSERT INTO v2 (col) VALUES ('c');
2909SELECT s1 FROM t1;
2910s1
2911Z
2912b
2913c
2914DROP VIEW v1, v2;
2915DROP TABLE t1;
2916CREATE TABLE t1 (id INT);
2917CREATE VIEW v1 AS SELECT id FROM t1;
2918SHOW TABLES;
2919Tables_in_test
2920t1
2921v1
2922DROP VIEW v2,v1;
2923ERROR 42S02: Unknown table 'test.v2'
2924SHOW TABLES;
2925Tables_in_test
2926t1
2927CREATE VIEW v1 AS SELECT id FROM t1;
2928DROP VIEW t1,v1;
2929ERROR HY000: 'test.t1' is not VIEW
2930SHOW TABLES;
2931Tables_in_test
2932t1
2933DROP TABLE t1;
2934DROP VIEW IF EXISTS v1;
2935CREATE DATABASE bug21261DB;
2936USE bug21261DB;
2937CREATE TABLE t1 (x INT);
2938CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
2939CREATE USER 'user21261'@'localhost';
2940GRANT INSERT, UPDATE ON v1 TO 'user21261'@'localhost';
2941GRANT INSERT, UPDATE ON t1 TO 'user21261'@'localhost';
2942CREATE TABLE t2 (y INT);
2943GRANT SELECT ON t2 TO 'user21261'@'localhost';
2944INSERT INTO v1 (x) VALUES (5);
2945UPDATE v1 SET x=1;
2946GRANT SELECT ON v1 TO 'user21261'@'localhost';
2947GRANT SELECT ON t1 TO 'user21261'@'localhost';
2948UPDATE v1,t2 SET x=1 WHERE x=y;
2949SELECT * FROM t1;
2950x
29511
2952REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user21261'@'localhost';
2953DROP USER 'user21261'@'localhost';
2954DROP VIEW v1;
2955DROP TABLE t1;
2956DROP DATABASE bug21261DB;
2957USE test;
2958create table t1 (f1 datetime);
2959create view v1 as select * from t1 where f1 between now() and now() + interval 1 minute;
2960show create view v1;
2961View	Create View	character_set_client	collation_connection
2962v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f1` AS `f1` from `t1` where (`t1`.`f1` between now() and (now() + interval 1 minute))	latin1	latin1_swedish_ci
2963drop view v1;
2964drop table t1;
2965DROP TABLE IF EXISTS t1;
2966DROP VIEW IF EXISTS v1;
2967DROP VIEW IF EXISTS v2;
2968CREATE TABLE t1(a INT, b INT);
2969CREATE DEFINER=1234567890abcdefGHIKL1234567890abcdefGHIKL@localhost
2970VIEW v1 AS SELECT a FROM t1;
2971ERROR HY000: String '1234567890abcdefGHIKL1234567890abcdefGHIKL' is too long for user name (should be no longer than 32)
2972CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY
2973VIEW v2 AS SELECT b FROM t1;
2974ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60)
2975DROP TABLE t1;
2976DROP FUNCTION IF EXISTS f1;
2977DROP FUNCTION IF EXISTS f2;
2978DROP VIEW IF EXISTS v1, v2;
2979DROP TABLE IF EXISTS t1;
2980CREATE TABLE t1 (i INT);
2981CREATE VIEW v1 AS SELECT * FROM t1;
2982CREATE FUNCTION f1() RETURNS INT
2983BEGIN
2984INSERT INTO v1 VALUES (0);
2985RETURN 0;
2986END |
2987SELECT f1();
2988f1()
29890
2990CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1;
2991CREATE FUNCTION f2() RETURNS INT
2992BEGIN
2993INSERT INTO v2 VALUES (0);
2994RETURN 0;
2995END |
2996SELECT f2();
2997ERROR HY000: The target table v2 of the INSERT is not insertable-into
2998DROP FUNCTION f1;
2999DROP FUNCTION f2;
3000DROP VIEW v1, v2;
3001DROP TABLE t1;
3002CREATE TABLE t1 (s1 int);
3003CREATE VIEW v1 AS SELECT * FROM t1;
3004EXPLAIN SELECT * FROM t1;
3005id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30061	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
3007Warnings:
3008Note	1003	/* select#1 */ select NULL AS `s1` from `test`.`t1`
3009EXPLAIN SELECT * FROM v1;
3010id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30111	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
3012Warnings:
3013Note	1003	/* select#1 */ select NULL AS `s1` from `test`.`t1`
3014INSERT INTO t1 VALUES (1), (3), (2);
3015EXPLAIN SELECT * FROM t1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1);
3016id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30171	PRIMARY	t	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
30182	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
3019Warnings:
3020Note	1003	/* select#1 */ select `test`.`t`.`s1` AS `s1` from `test`.`t1` `t` where ((`test`.`t`.`s1` + 1) < (/* select#2 */ select max(`test`.`t1`.`s1`) from `test`.`t1`))
3021EXPLAIN SELECT * FROM v1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1);
3022id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
30231	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
30242	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
3025Warnings:
3026Note	1003	/* select#1 */ select `test`.`t1`.`s1` AS `s1` from `test`.`t1` where ((`test`.`t1`.`s1` + 1) < (/* select#2 */ select max(`test`.`t1`.`s1`) from `test`.`t1`))
3027DROP VIEW v1;
3028DROP TABLE t1;
3029create table t1 (s1 int);
3030create view v1 as select s1 as a, s1 as b from t1;
3031insert into v1 values (1,1);
3032ERROR HY000: The target table v1 of the INSERT is not insertable-into
3033update v1 set a = 5;
3034drop view v1;
3035drop table t1;
3036CREATE TABLE t1(pk int PRIMARY KEY);
3037CREATE TABLE t2(pk int PRIMARY KEY, fk int, ver int, org int);
3038CREATE ALGORITHM=MERGE VIEW v1 AS
3039SELECT t1.*
3040FROM t1 JOIN t2
3041ON t2.fk = t1.pk AND
3042t2.ver = (SELECT MAX(t.ver) FROM t2 t WHERE t.org = t2.org);
3043SHOW WARNINGS;
3044Level	Code	Message
3045SHOW CREATE VIEW v1;
3046View	Create View	character_set_client	collation_connection
3047v1	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
3048DROP VIEW v1;
3049DROP TABLE t1, t2;
3050DROP FUNCTION IF EXISTS f1;
3051DROP VIEW IF EXISTS v1;
3052DROP TABLE IF EXISTS t1;
3053CREATE TABLE t1 (i INT);
3054INSERT INTO t1 VALUES (1);
3055CREATE VIEW v1 AS SELECT MAX(i) FROM t1;
3056CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
3057SET NEW.i = (SELECT * FROM v1) + 1;
3058INSERT INTO t1 VALUES (1);
3059CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1);
3060UPDATE t1 SET i= f1();
3061DROP FUNCTION f1;
3062DROP VIEW v1;
3063DROP TABLE t1;
3064CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL);
3065CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION;
3066INSERT INTO v1 (val) VALUES (2);
3067INSERT INTO v1 (val) VALUES (4);
3068INSERT INTO v1 (val) VALUES (6);
3069ERROR HY000: CHECK OPTION failed 'test.v1'
3070UPDATE v1 SET val=6 WHERE id=2;
3071ERROR HY000: CHECK OPTION failed 'test.v1'
3072DROP VIEW v1;
3073DROP TABLE t1;
3074DROP VIEW IF EXISTS v1, v2;
3075DROP TABLE IF EXISTS t1;
3076CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT);
3077CREATE VIEW v1 AS SELECT j FROM t1;
3078CREATE VIEW v2 AS SELECT * FROM t1;
3079INSERT INTO t1 (j) VALUES (1);
3080SELECT LAST_INSERT_ID();
3081LAST_INSERT_ID()
30821
3083INSERT INTO v1 (j) VALUES (2);
3084# LAST_INSERT_ID() should not change.
3085SELECT LAST_INSERT_ID();
3086LAST_INSERT_ID()
30871
3088INSERT INTO v2 (j) VALUES (3);
3089# LAST_INSERT_ID() should be updated.
3090SELECT LAST_INSERT_ID();
3091LAST_INSERT_ID()
30923
3093INSERT INTO v1 (j) SELECT j FROM t1;
3094# LAST_INSERT_ID() should not change.
3095SELECT LAST_INSERT_ID();
3096LAST_INSERT_ID()
30973
3098SELECT * FROM t1;
3099i	j
31001	1
31012	2
31023	3
31034	1
31045	2
31056	3
3106DROP VIEW v1, v2;
3107DROP TABLE t1;
3108CREATE VIEW v AS SELECT !0 * 5 AS x FROM DUAL;
3109SHOW CREATE VIEW v;
3110View	Create View	character_set_client	collation_connection
3111v	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select ((not(0)) * 5) AS `x`	latin1	latin1_swedish_ci
3112SELECT !0 * 5 AS x FROM DUAL;
3113x
31145
3115SELECT * FROM v;
3116x
31175
3118DROP VIEW v;
3119DROP VIEW IF EXISTS v1;
3120CREATE VIEW v1 AS SELECT 'The\ZEnd';
3121SELECT * FROM v1;
3122TheEnd
3123TheEnd
3124SHOW CREATE VIEW v1;
3125View	Create View	character_set_client	collation_connection
3126v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 'The\ZEnd' AS `TheEnd`	latin1	latin1_swedish_ci
3127DROP VIEW v1;
3128CREATE TABLE t1 (mydate DATETIME);
3129INSERT INTO t1 VALUES
3130('2007-01-01'), ('2007-01-02'), ('2007-01-30'), ('2007-01-31');
3131CREATE VIEW v1 AS SELECT mydate from t1;
3132SELECT * FROM t1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
3133mydate
31342007-01-01 00:00:00
31352007-01-02 00:00:00
31362007-01-30 00:00:00
31372007-01-31 00:00:00
3138SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
3139mydate
31402007-01-01 00:00:00
31412007-01-02 00:00:00
31422007-01-30 00:00:00
31432007-01-31 00:00:00
3144DROP VIEW v1;
3145DROP TABLE t1;
3146CREATE TABLE t1 (a int);
3147CREATE TABLE t2 (b int);
3148INSERT INTO t1 VALUES (1), (2);
3149INSERT INTO t2 VALUES (1), (2);
3150CREATE VIEW v1 AS
3151SELECT t2.b FROM t1,t2 WHERE t1.a = t2.b WITH CHECK OPTION;
3152SELECT * FROM v1;
3153b
31541
31552
3156UPDATE v1 SET b=3;
3157ERROR HY000: CHECK OPTION failed 'test.v1'
3158SELECT * FROM v1;
3159b
31601
31612
3162SELECT * FROM t1;
3163a
31641
31652
3166SELECT * FROM t2;
3167b
31681
31692
3170DROP VIEW v1;
3171DROP TABLE t1,t2;
3172create table t1(f1 int, f2 int);
3173insert into t1 values(1,2),(1,3),(1,1),(2,3),(2,1),(2,2);
3174select * from t1;
3175f1	f2
31761	2
31771	3
31781	1
31792	3
31802	1
31812	2
3182create view v1 as select * from t1 order by f2;
3183select * from v1;
3184f1	f2
31851	1
31862	1
31871	2
31882	2
31891	3
31902	3
3191explain extended select * from v1;
3192id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
31931	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using filesort
3194Warnings:
3195Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
3196Note	1003	/* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f2`
3197select * from v1 order by f1;
3198f1	f2
31991	2
32001	3
32011	1
32022	3
32032	1
32042	2
3205explain extended select * from v1 order by f1;
3206id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
32071	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using filesort
3208Warnings:
3209Warning	1681	'EXTENDED' is deprecated and will be removed in a future release.
3210Note	1003	/* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f1`
3211drop view v1;
3212drop table t1;
3213CREATE TABLE t1 (
3214id int(11) NOT NULL PRIMARY KEY,
3215country varchar(32),
3216code int(11) default NULL
3217);
3218INSERT INTO t1 VALUES
3219(1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100);
3220CREATE VIEW v1 AS SELECT * FROM t1;
3221SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id);
3222code	COUNT(DISTINCT country)
3223200	1
3224100	2
3225SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id);
3226code	COUNT(DISTINCT country)
3227200	1
3228100	2
3229DROP VIEW v1;
3230DROP TABLE t1;
3231DROP VIEW IF EXISTS v1;
3232SELECT * FROM (SELECT 1) AS t;
32331
32341
3235CREATE VIEW v1 AS SELECT * FROM (SELECT 1) AS t;
3236DROP VIEW v1;
3237# Previously the following would fail.
3238SELECT * FROM (SELECT 1) AS t;
32391
32401
3241drop view if exists view_24532_a;
3242drop view if exists view_24532_b;
3243drop table if exists table_24532;
3244create table table_24532 (
3245a int,
3246b bigint,
3247c int(4),
3248d bigint(48)
3249);
3250create view view_24532_a as
3251select
3252a IS TRUE,
3253a IS NOT TRUE,
3254a IS FALSE,
3255a IS NOT FALSE,
3256a IS UNKNOWN,
3257a IS NOT UNKNOWN,
3258a is NULL,
3259a IS NOT NULL,
3260ISNULL(a),
3261b IS TRUE,
3262b IS NOT TRUE,
3263b IS FALSE,
3264b IS NOT FALSE,
3265b IS UNKNOWN,
3266b IS NOT UNKNOWN,
3267b is NULL,
3268b IS NOT NULL,
3269ISNULL(b),
3270c IS TRUE,
3271c IS NOT TRUE,
3272c IS FALSE,
3273c IS NOT FALSE,
3274c IS UNKNOWN,
3275c IS NOT UNKNOWN,
3276c is NULL,
3277c IS NOT NULL,
3278ISNULL(c),
3279d IS TRUE,
3280d IS NOT TRUE,
3281d IS FALSE,
3282d IS NOT FALSE,
3283d IS UNKNOWN,
3284d IS NOT UNKNOWN,
3285d is NULL,
3286d IS NOT NULL,
3287ISNULL(d)
3288from table_24532;
3289describe view_24532_a;
3290Field	Type	Null	Key	Default	Extra
3291a IS TRUE	int(1)	NO		0
3292a IS NOT TRUE	int(1)	NO		0
3293a IS FALSE	int(1)	NO		0
3294a IS NOT FALSE	int(1)	NO		0
3295a IS UNKNOWN	int(1)	NO		0
3296a IS NOT UNKNOWN	int(1)	NO		0
3297a is NULL	int(1)	NO		0
3298a IS NOT NULL	int(1)	NO		0
3299ISNULL(a)	int(1)	NO		0
3300b IS TRUE	int(1)	NO		0
3301b IS NOT TRUE	int(1)	NO		0
3302b IS FALSE	int(1)	NO		0
3303b IS NOT FALSE	int(1)	NO		0
3304b IS UNKNOWN	int(1)	NO		0
3305b IS NOT UNKNOWN	int(1)	NO		0
3306b is NULL	int(1)	NO		0
3307b IS NOT NULL	int(1)	NO		0
3308ISNULL(b)	int(1)	NO		0
3309c IS TRUE	int(1)	NO		0
3310c IS NOT TRUE	int(1)	NO		0
3311c IS FALSE	int(1)	NO		0
3312c IS NOT FALSE	int(1)	NO		0
3313c IS UNKNOWN	int(1)	NO		0
3314c IS NOT UNKNOWN	int(1)	NO		0
3315c is NULL	int(1)	NO		0
3316c IS NOT NULL	int(1)	NO		0
3317ISNULL(c)	int(1)	NO		0
3318d IS TRUE	int(1)	NO		0
3319d IS NOT TRUE	int(1)	NO		0
3320d IS FALSE	int(1)	NO		0
3321d IS NOT FALSE	int(1)	NO		0
3322d IS UNKNOWN	int(1)	NO		0
3323d IS NOT UNKNOWN	int(1)	NO		0
3324d is NULL	int(1)	NO		0
3325d IS NOT NULL	int(1)	NO		0
3326ISNULL(d)	int(1)	NO		0
3327create view view_24532_b as
3328select
3329a IS TRUE,
3330if(ifnull(a, 0), 1, 0) as old_istrue,
3331a IS NOT TRUE,
3332if(ifnull(a, 0), 0, 1) as old_isnottrue,
3333a IS FALSE,
3334if(ifnull(a, 1), 0, 1) as old_isfalse,
3335a IS NOT FALSE,
3336if(ifnull(a, 1), 1, 0) as old_isnotfalse
3337from table_24532;
3338describe view_24532_b;
3339Field	Type	Null	Key	Default	Extra
3340a IS TRUE	int(1)	NO		0
3341old_istrue	int(1)	NO		0
3342a IS NOT TRUE	int(1)	NO		0
3343old_isnottrue	int(1)	NO		0
3344a IS FALSE	int(1)	NO		0
3345old_isfalse	int(1)	NO		0
3346a IS NOT FALSE	int(1)	NO		0
3347old_isnotfalse	int(1)	NO		0
3348show create view view_24532_b;
3349View	Create View	character_set_client	collation_connection
3350view_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
3351insert into table_24532 values (0, 0, 0, 0);
3352select * from view_24532_b;
3353a IS TRUE	old_istrue	a IS NOT TRUE	old_isnottrue	a IS FALSE	old_isfalse	a IS NOT FALSE	old_isnotfalse
33540	0	1	1	1	1	0	0
3355update table_24532 set a=1;
3356select * from view_24532_b;
3357a IS TRUE	old_istrue	a IS NOT TRUE	old_isnottrue	a IS FALSE	old_isfalse	a IS NOT FALSE	old_isnotfalse
33581	1	0	0	0	0	1	1
3359update table_24532 set a=NULL;
3360select * from view_24532_b;
3361a IS TRUE	old_istrue	a IS NOT TRUE	old_isnottrue	a IS FALSE	old_isfalse	a IS NOT FALSE	old_isnotfalse
33620	0	1	1	0	0	1	1
3363drop view view_24532_a;
3364drop view view_24532_b;
3365drop table table_24532;
3366CREATE TABLE t1 (
3367lid int NOT NULL PRIMARY KEY,
3368name char(10) NOT NULL
3369);
3370INSERT INTO t1 (lid, name) VALUES
3371(1, 'YES'), (2, 'NO');
3372CREATE TABLE t2 (
3373id int NOT NULL PRIMARY KEY,
3374gid int NOT NULL,
3375lid int NOT NULL,
3376dt date
3377);
3378CREATE TABLE t3 (
3379id int NOT NULL PRIMARY KEY,
3380gid int NOT NULL,
3381lid int NOT NULL,
3382dt date
3383);
3384INSERT INTO t2 (id, gid, lid, dt) VALUES
3385(1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'),
3386(3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02');
3387INSERT INTO t3 (id, gid, lid, dt) VALUES
3388(1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'),
3389(3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02');
3390SELECT DISTINCT t2.gid AS lgid,
3391(SELECT t1.name FROM t1, t3
3392WHERE t1.lid  = t3.lid AND t3.gid = t2.gid
3393ORDER BY t3.dt DESC LIMIT 1
3394) as clid
3395FROM t2;
3396lgid	clid
33971	NO
33982	YES
3399CREATE VIEW v1 AS
3400SELECT DISTINCT t2.gid AS lgid,
3401(SELECT t1.name FROM t1, t3
3402WHERE t1.lid  = t3.lid AND t3.gid = t2.gid
3403ORDER BY t3.dt DESC LIMIT 1
3404) as clid
3405FROM t2;
3406SELECT * FROM v1;
3407lgid	clid
34081	NO
34092	YES
3410DROP VIEW v1;
3411DROP table t1,t2,t3;
3412CREATE TABLE t1 (a INT);
3413INSERT INTO t1 VALUES (1),(2),(3);
3414CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a;
3415SELECT * FROM t1 UNION SELECT * FROM v1;
3416a
34171
34182
34193
3420EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1;
3421id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
34221	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
34232	UNION	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
3424NULL	UNION RESULT	<union1,2>	NULL	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Using temporary
3425Warnings:
3426Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` union /* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`
3427SELECT * FROM v1 UNION SELECT * FROM t1;
3428a
34291
34302
34313
3432EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1;
3433id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
34341	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
34352	UNION	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
3436NULL	UNION RESULT	<union1,2>	NULL	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Using temporary
3437Warnings:
3438Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` union /* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`
3439SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
3440a
34411
34422
34433
3444EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
3445id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
34461	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
34472	UNION	t1	NULL	ALL	NULL	NULL	NULL	NULL	3	100.00	NULL
3448NULL	UNION RESULT	<union1,2>	NULL	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Using temporary; Using filesort
3449Warnings:
3450Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` union /* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` order by `a`
3451DROP VIEW v1;
3452DROP TABLE t1;
3453CREATE VIEW v1 AS SELECT CAST( 1.23456789 AS DECIMAL( 7,5 ) ) AS col;
3454SELECT * FROM v1;
3455col
34561.23457
3457DESCRIBE v1;
3458Field	Type	Null	Key	Default	Extra
3459col	decimal(7,5)	NO		0.00000
3460DROP VIEW v1;
3461CREATE VIEW v1 AS SELECT CAST(1.23456789 AS DECIMAL(8,0)) AS col;
3462SHOW CREATE VIEW v1;
3463View	Create View	character_set_client	collation_connection
3464v1	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
3465DROP VIEW v1;
3466CREATE TABLE t1 (a INT);
3467CREATE TABLE t2 (b INT, c INT DEFAULT 0);
3468INSERT INTO t1 (a) VALUES (1), (2);
3469INSERT INTO t2 (b) VALUES (1), (2);
3470CREATE VIEW v1 AS SELECT t2.b,t2.c FROM t1, t2
3471WHERE t1.a=t2.b AND t2.b < 3 WITH CHECK OPTION;
3472SELECT * FROM v1;
3473b	c
34741	0
34752	0
3476UPDATE v1 SET c=1 WHERE b=1;
3477SELECT * FROM v1;
3478b	c
34791	1
34802	0
3481DROP VIEW v1;
3482DROP TABLE t1,t2;
3483CREATE TABLE t1 (id int);
3484CREATE TABLE t2 (id int, c int DEFAULT 0);
3485INSERT INTO t1 (id) VALUES (1);
3486INSERT INTO t2 (id) VALUES (1);
3487CREATE VIEW v1 AS
3488SELECT t2.c FROM t1, t2
3489WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
3490UPDATE v1 SET c=1;
3491DROP VIEW v1;
3492DROP TABLE t1,t2;
3493CREATE TABLE t1 (a1 INT, c INT DEFAULT 0);
3494CREATE TABLE t2 (a2 INT);
3495CREATE TABLE t3 (a3 INT);
3496CREATE TABLE t4 (a4 INT);
3497INSERT INTO t1 (a1) VALUES (1),(2);
3498INSERT INTO t2 (a2) VALUES (1),(2);
3499INSERT INTO t3 (a3) VALUES (1),(2);
3500INSERT INTO t4 (a4) VALUES (1),(2);
3501CREATE VIEW v1 AS
3502SELECT t1.a1, t1.c FROM t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3
3503WITH CHECK OPTION;
3504SELECT * FROM v1;
3505a1	c
35061	0
35072	0
3508UPDATE v1 SET c=3;
3509ERROR HY000: CHECK OPTION failed 'test.v1'
3510PREPARE t FROM 'UPDATE v1 SET c=3';
3511EXECUTE t;
3512ERROR HY000: CHECK OPTION failed 'test.v1'
3513EXECUTE t;
3514ERROR HY000: CHECK OPTION failed 'test.v1'
3515INSERT INTO v1(a1, c) VALUES (3, 3);
3516ERROR HY000: CHECK OPTION failed 'test.v1'
3517UPDATE v1 SET c=1 WHERE a1=1;
3518SELECT * FROM v1;
3519a1	c
35201	1
35212	0
3522SELECT * FROM t1;
3523a1	c
35241	1
35252	0
3526CREATE VIEW v2 AS SELECT t1.a1, t1.c
3527FROM (t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3)
3528JOIN (t3 JOIN t4 ON t3.a3=t4.a4)
3529ON t2.a2=t3.a3 WITH CHECK OPTION;
3530SELECT * FROM v2;
3531a1	c
35321	1
35332	0
3534UPDATE v2 SET c=3;
3535ERROR HY000: CHECK OPTION failed 'test.v2'
3536PREPARE t FROM 'UPDATE v2 SET c=3';
3537EXECUTE t;
3538ERROR HY000: CHECK OPTION failed 'test.v2'
3539EXECUTE t;
3540ERROR HY000: CHECK OPTION failed 'test.v2'
3541INSERT INTO v2(a1, c) VALUES (3, 3);
3542ERROR HY000: CHECK OPTION failed 'test.v2'
3543UPDATE v2 SET c=2 WHERE a1=1;
3544SELECT * FROM v2;
3545a1	c
35461	2
35472	0
3548SELECT * FROM t1;
3549a1	c
35501	2
35512	0
3552DROP VIEW v1,v2;
3553DROP TABLE t1,t2,t3,t4;
3554CREATE TABLE t1 (a int, b int);
3555INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2);
3556CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1;
3557SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b;
3558b	SUM(a)
35593	4
3560EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b;
3561id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
35621	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
3563Warnings:
3564Note	1003	/* select#1 */ select (`test`.`t1`.`b` + 1) AS `b`,sum(`test`.`t1`.`a`) AS `SUM(a)` from `test`.`t1` where ((`test`.`t1`.`b` + 1) = 3) group by `b`
3565SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a;
3566a	SUM(b)
35671	6
35682	3
3569EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a;
3570id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
35711	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where; Using temporary; Using filesort
3572Warnings:
3573Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,sum((`test`.`t1`.`b` + 1)) AS `SUM(b)` from `test`.`t1` where ((`test`.`t1`.`b` + 1) = 3) group by `test`.`t1`.`a`
3574SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a;
3575a	SUM(b)
35761	10
3577EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a;
3578id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
35791	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	4	25.00	Using where
3580Warnings:
3581Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,sum((`test`.`t1`.`b` + 1)) AS `SUM(b)` from `test`.`t1` where (`test`.`t1`.`a` = 1) group by `test`.`t1`.`a`
3582DROP VIEW v1;
3583DROP TABLE t1;
3584CREATE TABLE t1 (
3585person_id int NOT NULL PRIMARY KEY,
3586username varchar(40) default NULL,
3587status_flg char(1) NOT NULL default 'A'
3588);
3589CREATE TABLE t2 (
3590person_role_id int NOT NULL auto_increment PRIMARY KEY,
3591role_id int NOT NULL,
3592person_id int NOT NULL,
3593INDEX idx_person_id (person_id),
3594INDEX idx_role_id (role_id)
3595);
3596CREATE TABLE t3 (
3597role_id int NOT NULL auto_increment PRIMARY KEY,
3598role_name varchar(100) default NULL,
3599app_name varchar(40) NOT NULL,
3600INDEX idx_app_name(app_name)
3601);
3602CREATE VIEW v1 AS
3603SELECT profile.person_id AS person_id
3604FROM t1 profile, t2 userrole, t3 role
3605WHERE userrole.person_id = profile.person_id AND
3606role.role_id = userrole.role_id AND
3607profile.status_flg = 'A'
3608  ORDER BY profile.person_id,role.app_name,role.role_name;
3609INSERT INTO  t1 VALUES
3610(6,'Sw','A'), (-1136332546,'ols','e'), (0,'    *\n','0'),
3611(-717462680,'ENTS Ta','0'), (-904346964,'ndard SQL\n','0');
3612INSERT INTO t2 VALUES
3613(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);
3614INSERT INTO t3 VALUES
3615(1,'NUCANS_APP_USER','NUCANSAPP'),(2,'NUCANS_TRGAPP_USER','NUCANSAPP'),
3616(3,'IA_INTAKE_COORDINATOR','IACANS'),(4,'IA_SCREENER','IACANS'),
3617(5,'IA_SUPERVISOR','IACANS'),(6,'IA_READONLY','IACANS'),
3618(7,'SOC_USER','SOCCANS'),(8,'CAYIT_USER','CAYITCANS'),
3619(9,'RTOS_DCFSPOS_SUPERVISOR','RTOS');
3620EXPLAIN SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
3621id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
36221	SIMPLE	profile	NULL	const	PRIMARY	PRIMARY	4	const	1	100.00	Using temporary; Using filesort
36231	SIMPLE	userrole	NULL	ref	idx_person_id,idx_role_id	idx_person_id	4	const	2	100.00	NULL
36241	SIMPLE	role	NULL	eq_ref	PRIMARY	PRIMARY	4	test.userrole.role_id	1	100.00	NULL
3625Warnings:
3626Note	1003	/* select#1 */ select '6' AS `a`,'6' AS `b` from `test`.`t1` `profile` join `test`.`t2` `userrole` join `test`.`t3` `role` where ((`role`.`role_id` = `userrole`.`role_id`) and (`userrole`.`person_id` = 6)) order by '6',`role`.`app_name`,`role`.`role_name`
3627SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
3628a	b
36296	6
36306	6
3631DROP VIEW v1;
3632DROP TABLE t1,t2,t3;
3633create table t1 (i int);
3634insert into t1 values (1), (2), (1), (3), (2), (4);
3635create view v1 as select distinct i from t1;
3636select * from v1;
3637i
36381
36392
36403
36414
3642select table_name, is_updatable from information_schema.views
3643where table_name = 'v1';
3644table_name	is_updatable
3645v1	NO
3646drop view v1;
3647drop table t1;
3648CREATE TABLE t1 (a INT);
3649INSERT INTO t1 VALUES (1),(2);
3650CREATE VIEW v1 AS SELECT * FROM t1;
3651SELECT * FROM v1 USE KEY(non_existant);
3652ERROR 42000: Key 'non_existant' doesn't exist in table 'v1'
3653SELECT * FROM v1 FORCE KEY(non_existant);
3654ERROR 42000: Key 'non_existant' doesn't exist in table 'v1'
3655SELECT * FROM v1 IGNORE KEY(non_existant);
3656ERROR 42000: Key 'non_existant' doesn't exist in table 'v1'
3657DROP VIEW v1;
3658DROP TABLE t1;
3659CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL DEFAULT 0,
3660PRIMARY KEY(a), KEY (b));
3661INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),();
3662CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a;
3663SHOW CREATE VIEW v1;
3664View	Create View	character_set_client	collation_connection
3665v1	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
3666EXPLAIN SELECT * FROM v1;
3667id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
36681	SIMPLE	t1	NULL	index	NULL	PRIMARY	4	NULL	15	100.00	NULL
3669Warnings:
3670Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` FORCE INDEX (PRIMARY) FORCE INDEX (`b`) order by `test`.`t1`.`a`
3671CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a;
3672SHOW CREATE VIEW v2;
3673View	Create View	character_set_client	collation_connection
3674v2	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
3675EXPLAIN SELECT * FROM v2;
3676id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
36771	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	Using filesort
3678Warnings:
3679Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` USE INDEX () order by `test`.`t1`.`a`
3680CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a;
3681SHOW CREATE VIEW v3;
3682View	Create View	character_set_client	collation_connection
3683v3	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
3684EXPLAIN SELECT * FROM v3;
3685id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
36861	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	Using filesort
3687Warnings:
3688Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` IGNORE INDEX (`b`) order by `test`.`t1`.`a`
3689DROP VIEW v1;
3690DROP VIEW v2;
3691DROP VIEW v3;
3692DROP TABLE t1;
3693#
3694# Bug#29477 Not all fields of the target table were checked to have
3695#           a default value when inserting into a view.
3696#
3697create table t1(f1 int, f2 int not null);
3698create view v1 as select f1 from t1;
3699insert into v1 values(1);
3700Warnings:
3701Warning	1423	Field of view 'test.v1' underlying table doesn't have a default value
3702set @old_mode=@@sql_mode;
3703set @@sql_mode=traditional;
3704Warnings:
3705Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
3706insert into v1 values(1);
3707ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value
3708set @@sql_mode=@old_mode;
3709Warnings:
3710Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
3711drop view v1;
3712drop table t1;
3713create table t1 (a int, key(a));
3714create table t2 (c int);
3715create view v1 as select a b from t1;
3716create view v2 as select 1 a from t2, v1 where c in
3717(select 1 from t1 where b = a);
3718insert into t1 values (1), (1);
3719insert into t2 values (1), (1);
3720prepare stmt from "select * from v2 where a = 1";
3721execute stmt;
3722a
37231
37241
37251
37261
3727drop view v1, v2;
3728drop table t1, t2;
3729CREATE TABLE t1 (a INT);
3730CREATE VIEW v1 AS SELECT p.a AS a FROM t1 p, t1 q;
3731INSERT INTO t1 VALUES (1), (1);
3732SELECT MAX(a), COUNT(DISTINCT a) FROM v1 GROUP BY a;
3733MAX(a)	COUNT(DISTINCT a)
37341	1
3735DROP VIEW v1;
3736DROP TABLE t1;
3737# -----------------------------------------------------------------
3738# -- Bug#34337 Server crash when Altering a view using a table name.
3739# -----------------------------------------------------------------
3740
3741DROP TABLE IF EXISTS t1;
3742
3743CREATE TABLE t1(c1 INT);
3744
3745SELECT * FROM t1;
3746c1
3747ALTER ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW t1 (c2) AS SELECT (1);
3748ERROR HY000: 'test.t1' is not VIEW
3749
3750DROP TABLE t1;
3751
3752# -- End of test case for Bug#34337.
3753
3754# -----------------------------------------------------------------
3755# -- Bug#35193 VIEW query is rewritten without "FROM DUAL",
3756# --           causing syntax error
3757# -----------------------------------------------------------------
3758
3759CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE 1;
3760
3761SELECT * FROM v1;
37621
37631
3764SHOW CREATE TABLE v1;
3765View	Create View	character_set_client	collation_connection
3766v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 AS `1` from DUAL  where 1	latin1	latin1_swedish_ci
3767
3768DROP VIEW v1;
3769
3770# -- End of test case for Bug#35193.
3771
3772CREATE VIEW v1 AS SELECT 1;
3773DROP VIEW v1;
3774CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, INDEX (c2));
3775INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
3776SELECT * FROM t1 USE INDEX (PRIMARY) WHERE c1=2;
3777c1	c2
37782	2
3779SELECT * FROM t1 USE INDEX (c2) WHERE c2=2;
3780c1	c2
37812	2
3782CREATE VIEW v1 AS SELECT c1, c2 FROM t1;
3783SHOW INDEX FROM v1;
3784Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
3785SELECT * FROM v1 USE INDEX (PRIMARY) WHERE c1=2;
3786ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1'
3787SELECT * FROM v1 FORCE INDEX (PRIMARY) WHERE c1=2;
3788ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1'
3789SELECT * FROM v1 IGNORE INDEX (PRIMARY) WHERE c1=2;
3790ERROR 42000: Key 'PRIMARY' doesn't exist in table 'v1'
3791SELECT * FROM v1 USE INDEX (c2) WHERE c2=2;
3792ERROR 42000: Key 'c2' doesn't exist in table 'v1'
3793SELECT * FROM v1 FORCE INDEX (c2) WHERE c2=2;
3794ERROR 42000: Key 'c2' doesn't exist in table 'v1'
3795SELECT * FROM v1 IGNORE INDEX (c2) WHERE c2=2;
3796ERROR 42000: Key 'c2' doesn't exist in table 'v1'
3797DROP VIEW v1;
3798DROP TABLE t1;
3799#
3800# Bug #45806 crash when replacing into a view with a join!
3801#
3802CREATE TABLE t1(a INT UNIQUE);
3803CREATE VIEW v1 AS SELECT t1.a FROM t1, t1 AS a;
3804INSERT INTO t1 VALUES (1), (2);
3805REPLACE INTO v1(a) SELECT 1 FROM t1,t1 AS c;
3806ERROR HY000: Can not delete from join view 'test.v1'
3807SELECT * FROM v1;
3808a
38091
38102
38111
38122
3813REPLACE INTO v1(a) SELECT 3 FROM t1,t1 AS c;
3814ERROR HY000: Can not delete from join view 'test.v1'
3815SELECT * FROM v1;
3816a
38171
38182
38191
38202
3821DELETE FROM t1 WHERE a=3;
3822INSERT INTO v1(a) SELECT 1 FROM t1,t1 AS c
3823ON DUPLICATE KEY UPDATE `v1`.`a`= 1;
3824SELECT * FROM v1;
3825a
38261
38272
38281
38292
3830CREATE VIEW v2 AS SELECT t1.a FROM t1, v1 AS a;
3831REPLACE INTO v2(a) SELECT 1 FROM t1,t1 AS c;
3832ERROR HY000: Can not delete from join view 'test.v2'
3833SELECT * FROM v2;
3834a
38351
38362
38371
38382
38391
38402
38411
38422
3843REPLACE INTO v2(a) SELECT 3 FROM t1,t1 AS c;
3844ERROR HY000: Can not delete from join view 'test.v2'
3845SELECT * FROM v2;
3846a
38471
38482
38491
38502
38511
38522
38531
38542
3855INSERT INTO v2(a) SELECT 1 FROM t1,t1 AS c
3856ON DUPLICATE KEY UPDATE `v2`.`a`= 1;
3857SELECT * FROM v2;
3858a
38591
38602
38611
38622
38631
38642
38651
38662
3867DROP VIEW v1;
3868DROP VIEW v2;
3869DROP TABLE t1;
3870# -- End of test case for Bug#45806
3871# -----------------------------------------------------------------
3872# -- Bug#40825: Error 1356 while selecting from a view
3873# --            with a "HAVING" clause though query works
3874# -----------------------------------------------------------------
3875
3876CREATE TABLE t1 (c INT);
3877
3878CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
3879SHOW CREATE VIEW v1;
3880View	Create View	character_set_client	collation_connection
3881v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`c` AS `view_column` from `t1` having `view_column`	latin1	latin1_swedish_ci
3882SELECT * FROM v1;
3883view_column
3884
3885DROP VIEW v1;
3886DROP TABLE t1;
3887
3888# -- End of test case for Bug#40825
3889
3890# -----------------------------------------------------------------
3891# -- End of 5.0 tests.
3892# -----------------------------------------------------------------
3893DROP DATABASE IF EXISTS `d-1`;
3894CREATE DATABASE `d-1`;
3895USE `d-1`;
3896CREATE TABLE `t-1` (c1 INT);
3897CREATE VIEW  `v-1` AS SELECT c1 FROM `t-1`;
3898SHOW TABLES;
3899Tables_in_d-1
3900t-1
3901v-1
3902RENAME TABLE `t-1` TO `t-2`;
3903RENAME TABLE `v-1` TO `v-2`;
3904SHOW TABLES;
3905Tables_in_d-1
3906t-2
3907v-2
3908DROP TABLE `t-2`;
3909DROP VIEW  `v-2`;
3910DROP DATABASE `d-1`;
3911USE test;
3912
3913#
3914# Bug#26676 VIEW using old table schema in a session.
3915#
3916
3917DROP VIEW IF EXISTS v1;
3918DROP TABLE IF EXISTS t1;
3919CREATE TABLE t1(c1 INT, c2 INT);
3920INSERT INTO t1 VALUES (1, 2), (3, 4);
3921
3922SELECT * FROM t1;
3923c1	c2
39241	2
39253	4
3926
3927CREATE VIEW v1 AS SELECT * FROM t1;
3928
3929SELECT * FROM v1;
3930c1	c2
39311	2
39323	4
3933
3934ALTER TABLE t1 ADD COLUMN c3 INT AFTER c2;
3935
3936SELECT * FROM t1;
3937c1	c2	c3
39381	2	NULL
39393	4	NULL
3940
3941SELECT * FROM v1;
3942c1	c2
39431	2
39443	4
3945
3946SHOW CREATE VIEW v1;
3947View	Create View	character_set_client	collation_connection
3948v1	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
3949
3950DROP VIEW v1;
3951DROP TABLE t1;
3952
3953# End of test case for Bug#26676.
3954
3955# -----------------------------------------------------------------
3956# -- Bug#32538 View definition picks up character set, but not collation
3957# -----------------------------------------------------------------
3958
3959DROP VIEW IF EXISTS v1;
3960
3961SET collation_connection = latin1_general_ci;
3962CREATE VIEW v1 AS SELECT _latin1 'text1' AS c1, 'text2' AS c2;
3963
3964SELECT COLLATION(c1), COLLATION(c2) FROM v1;
3965COLLATION(c1)	COLLATION(c2)
3966latin1_swedish_ci	latin1_general_ci
3967
3968SHOW CREATE VIEW v1;
3969View	Create View	character_set_client	collation_connection
3970v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select _latin1'text1' AS `c1`,'text2' AS `c2`	latin1	latin1_general_ci
3971
3972SELECT * FROM v1 WHERE c1 = 'text1';
3973ERROR HY000: Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (latin1_general_ci,COERCIBLE) for operation '='
3974
3975SELECT * FROM v1 WHERE c2 = 'text2';
3976c1	c2
3977text1	text2
3978
3979use test;
3980SET names latin1;
3981
3982SELECT COLLATION(c1), COLLATION(c2) FROM v1;
3983COLLATION(c1)	COLLATION(c2)
3984latin1_swedish_ci	latin1_general_ci
3985
3986SELECT * FROM v1 WHERE c1 = 'text1';
3987c1	c2
3988text1	text2
3989
3990SELECT * FROM v1 WHERE c2 = 'text2';
3991ERROR HY000: Illegal mix of collations (latin1_general_ci,COERCIBLE) and (latin1_swedish_ci,COERCIBLE) for operation '='
3992
3993DROP VIEW v1;
3994
3995# -- End of test case for Bug#32538.
3996
3997drop view if exists a;
3998drop procedure if exists p;
3999create procedure p()
4000begin
4001declare continue handler for sqlexception begin end;
4002create view a as select 1;
4003end|
4004call p();
4005call p();
4006drop view a;
4007drop procedure p;
4008#
4009# Bug #44860: ALTER TABLE on view crashes server
4010#
4011CREATE TABLE t1 (a INT);
4012CREATE VIEW v1 AS SELECT a FROM t1;
4013ALTER TABLE v1;
4014ERROR HY000: 'test.v1' is not BASE TABLE
4015DROP VIEW v1;
4016DROP TABLE t1;
4017#
4018# Bug#48449: hang on show create view after upgrading when
4019#            view contains function of view
4020#
4021DROP VIEW IF EXISTS v1,v2;
4022DROP TABLE IF EXISTS t1,t2;
4023DROP FUNCTION IF EXISTS f1;
4024CREATE TABLE t1 (a INT);
4025CREATE TABLE t2 (a INT);
4026CREATE FUNCTION f1() RETURNS INT
4027BEGIN
4028SELECT a FROM v2 INTO @a;
4029RETURN @a;
4030END//
4031# Trigger pre-locking when opening v2.
4032CREATE VIEW v1 AS SELECT f1() FROM t1;
4033SHOW CREATE VIEW v1;
4034View	Create View	character_set_client	collation_connection
4035v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `f1`() AS `f1()` from `t1`	latin1	latin1_swedish_ci
4036Warnings:
4037Note	1599	View `test`.`v2` has no creation context
4038DROP VIEW v1,v2;
4039DROP TABLE t1,t2;
4040DROP FUNCTION f1;
4041CREATE TABLE t1(f1 INT);
4042INSERT INTO t1 VALUES ();
4043CREATE VIEW v1 AS SELECT 1 FROM t1 WHERE
4044ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE  f1 >= ANY ( SELECT '1' )));
4045DROP VIEW v1;
4046DROP TABLE t1;
4047#
4048# Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
4049#
4050CREATE TABLE t1 (a CHAR(1) CHARSET latin1, b CHAR(1) CHARSET utf8);
4051CREATE VIEW v1 AS SELECT 1 from t1
4052WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
4053DROP VIEW v1;
4054DROP TABLE t1;
4055#
4056# Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
4057#
4058CREATE TABLE t1(a int);
4059CREATE VIEW v1 AS SELECT 1 FROM t1 GROUP BY
4060SUBSTRING(1 FROM (SELECT 3 FROM t1 WHERE a >= ANY(SELECT 1)));
4061DROP VIEW v1;
4062DROP TABLE t1;
4063#
4064# Bug#57352 valgrind warnings when creating view
4065#
4066CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f;
4067DROP VIEW v1;
4068#
4069# Bug 11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
4070#
4071CREATE TABLE t1 (a INT);
4072CREATE VIEW v1 AS SELECT s.* FROM t1 s, t1 b HAVING a;
4073SELECT * FROM v1;
4074a
4075DROP VIEW v1;
4076DROP TABLE t1;
4077# -----------------------------------------------------------------
4078# -- End of 5.1 tests.
4079# -----------------------------------------------------------------
4080drop table if exists t_9801;
4081drop view if exists v_9801;
4082create table t_9801 (s1 int);
4083create view v_9801 as
4084select sum(s1) from t_9801 with check option;
4085ERROR HY000: CHECK OPTION on non-updatable view 'test.v_9801'
4086create view v_9801 as
4087select sum(s1) from t_9801 group by s1 with check option;
4088ERROR HY000: CHECK OPTION on non-updatable view 'test.v_9801'
4089create view v_9801 as
4090select sum(s1) from t_9801 group by s1 with rollup with check option;
4091ERROR HY000: CHECK OPTION on non-updatable view 'test.v_9801'
4092drop table t_9801;
4093#
4094# Bug #47335 assert in get_table_share
4095#
4096DROP TABLE IF EXISTS t1;
4097DROP VIEW IF EXISTS v1;
4098CREATE TEMPORARY TABLE t1 (id INT);
4099ALTER VIEW t1 AS SELECT 1 AS f1;
4100ERROR 42S02: Table 'test.t1' doesn't exist
4101DROP TABLE t1;
4102CREATE VIEW v1 AS SELECT 1 AS f1;
4103CREATE TEMPORARY TABLE v1 (id INT);
4104ALTER VIEW v1 AS SELECT 2 AS f1;
4105DROP TABLE v1;
4106SELECT * FROM v1;
4107f1
41082
4109DROP VIEW v1;
4110#
4111# Bug #47635 assert in start_waiting_global_read_lock
4112#            during CREATE VIEW
4113#
4114DROP TABLE IF EXISTS t1, t2;
4115DROP VIEW IF EXISTS t2;
4116CREATE TABLE t1 (f1 integer);
4117CREATE TEMPORARY TABLE IF NOT EXISTS t1 (f1 integer);
4118CREATE TEMPORARY TABLE t2 (f1 integer);
4119DROP TABLE t1;
4120FLUSH TABLES WITH READ LOCK;
4121CREATE VIEW t2 AS SELECT * FROM t1;
4122ERROR HY000: Can't execute the query because you have a conflicting read lock
4123UNLOCK TABLES;
4124DROP TABLE t1, t2;
4125#
4126# Bug#48315 Metadata lock is not taken for merged views that
4127#           use an INFORMATION_SCHEMA table
4128#
4129DROP VIEW IF EXISTS v1;
4130DROP PROCEDURE IF EXISTS p1;
4131# Connection default
4132CREATE VIEW v1 AS SELECT schema_name FROM information_schema.schemata;
4133CREATE PROCEDURE p1() SELECT COUNT(*), GET_LOCK('blocker', 100) FROM v1;
4134# CALL p1() so the view is merged.
4135CALL p1();
4136SELECT RELEASE_LOCK('blocker');
4137RELEASE_LOCK('blocker')
41381
4139# Connection 3
4140SELECT GET_LOCK('blocker', 100);
4141GET_LOCK('blocker', 100)
41421
4143# Connection default
4144# Try to CALL p1() again, this time it should block for t1.
4145# Sending:
4146CALL p1();
4147# Connection 2
4148# ... then try to drop the view. This should block.
4149# Sending:
4150DROP VIEW v1;
4151# Connection 3
4152# Now allow CALL p1() to complete
4153SELECT RELEASE_LOCK('blocker');
4154RELEASE_LOCK('blocker')
41551
4156# Connection default
4157# Reaping: CALL p1()
4158SELECT RELEASE_LOCK('blocker');
4159RELEASE_LOCK('blocker')
41601
4161# Connection 2
4162# Reaping: DROP VIEW v1
4163# Connection default
4164DROP PROCEDURE p1;
4165#
4166# Bug#11757397 49437: CANNOT DO SHOW FIELDS FOR BIG VIEW
4167#
4168DROP TABLE IF EXISTS t1, t2, t3, table_broken;
4169DROP VIEW IF EXISTS view_broken;
4170CREATE TABLE t1 (a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, a10 int, a11 int, a12 int, a13 int, a14 int, a15 int, a16 int, a17 int, a18 int, a19 int, a20 int, a21 int, a22 int, a23 int, a24 int, a25 int, a26 int, a27 int, a28 int, a29 int, a30 int, a31 int, a32 int, a33 int, a34 int, a35 int, a36 int, a37 int, a38 int, a39 int, a40 int, a41 int, a42 int, a43 int, a44 int, a45 int, a46 int, a47 int, a48 int, a49 int, a50 int, a51 int, a52 int, a53 int, a54 int, a55 int, a56 int, a57 int, a58 int, a59 int, a60 int, a61 int, a62 int, a63 int, a64 int, a65 int, a66 int, a67 int, a68 int, a69 int, a70 int, a71 int, a72 int, a73 int, a74 int, a75 int, a76 int, a77 int, a78 int, a79 int, a80 int, a81 int, a82 int, a83 int, a84 int, a85 int, a86 int, a87 int, a88 int, a89 int, a90 int, a91 int, a92 int, a93 int, a94 int, a95 int, a96 int, a97 int, a98 int, a99 int, a100 int, a101 int, a102 int, a103 int, a104 int, a105 int, a106 int, a107 int, a108 int, a109 int, a110 int, a111 int, a112 int, a113 int, a114 int, a115 int, a116 int, a117 int, a118 int, a119 int, a120 int, a121 int, a122 int, a123 int, a124 int, a125 int, a126 int, a127 int, a128 int, a129 int, a130 int, a131 int, a132 int, a133 int, a134 int, a135 int, a136 int, a137 int, a138 int, a139 int, a140 int, a141 int, a142 int, a143 int, a144 int, a145 int, a146 int, a147 int, a148 int, a149 int, a150 int, a151 int, a152 int, a153 int, a154 int, a155 int, a156 int, a157 int, a158 int, a159 int, a160 int, a161 int, a162 int, a163 int, a164 int, a165 int, a166 int, a167 int, a168 int, a169 int, a170 int, a171 int, a172 int, a173 int, a174 int, a175 int, a176 int, a177 int, a178 int, a179 int, a180 int, a181 int, a182 int, a183 int, a184 int, a185 int, a186 int, a187 int, a188 int, a189 int, a190 int, a191 int, a192 int, a193 int, a194 int, a195 int, a196 int, a197 int, a198 int, a199 int, a200 int, a201 int, a202 int, a203 int, a204 int, a205 int, a206 int, a207 int, a208 int, a209 int, a210 int, a211 int, a212 int, a213 int, a214 int, a215 int, a216 int, a217 int, a218 int, a219 int, a220 int, a221 int, a222 int, a223 int, a224 int, a225 int, a226 int, a227 int, a228 int, a229 int, a230 int, a231 int, a232 int, a233 int, a234 int, a235 int, a236 int, a237 int, a238 int, a239 int, a240 int, a241 int, a242 int, a243 int, a244 int, a245 int, a246 int, a247 int, a248 int, a249 int, a250 int, a251 int, a252 int, a253 int, a254 int, a255 int, a256 int, a257 int, a258 int, a259 int, a260 int, a261 int, a262 int, a263 int, a264 int, a265 int, a266 int, a267 int, a268 int, a269 int, a270 int, a271 int, a272 int, a273 int, a274 int, a275 int, a276 int, a277 int, a278 int, a279 int, a280 int, a281 int, a282 int, a283 int, a284 int, a285 int, a286 int, a287 int, a288 int, a289 int, a290 int, a291 int, a292 int, a293 int, a294 int, a295 int, a296 int, a297 int, a298 int, a299 int, a300 int, a301 int, a302 int, a303 int, a304 int, a305 int, a306 int, a307 int, a308 int, a309 int, a310 int, a311 int, a312 int, a313 int, a314 int, a315 int, a316 int, a317 int, a318 int, a319 int, a320 int, a321 int, a322 int, a323 int, a324 int, a325 int, a326 int, a327 int, a328 int, a329 int, a330 int, a331 int, a332 int, a333 int, a334 int, a335 int, a336 int, a337 int, a338 int, a339 int, a340 int, a341 int, a342 int, a343 int, a344 int, a345 int, a346 int, a347 int, a348 int, a349 int, a350 int, a351 int, a352 int, a353 int, a354 int, a355 int, a356 int, a357 int, a358 int, a359 int, a360 int, a361 int, a362 int, a363 int, a364 int, a365 int, a366 int, a367 int, a368 int, a369 int, a370 int, a371 int, a372 int, a373 int, a374 int, a375 int, a376 int, a377 int, a378 int, a379 int, a380 int, a381 int, a382 int, a383 int, a384 int, a385 int, a386 int, a387 int, a388 int, a389 int, a390 int, a391 int, a392 int, a393 int, a394 int, a395 int, a396 int, a397 int, a398 int, a399 int, a400 int, a401 int, a402 int, a403 int, a404 int, a405 int, a406 int, a407 int, a408 int, a409 int, a410 int, a411 int, a412 int, a413 int, a414 int, a415 int, a416 int, a417 int, a418 int, a419 int, a420 int, a421 int, a422 int, a423 int, a424 int, a425 int, a426 int, a427 int, a428 int, a429 int, a430 int, a431 int, a432 int, a433 int, a434 int, a435 int, a436 int, a437 int, a438 int, a439 int, a440 int, a441 int, a442 int, a443 int, a444 int, a445 int, a446 int, a447 int, a448 int, a449 int, a450 int, a451 int, a452 int, a453 int, a454 int, a455 int, a456 int, a457 int, a458 int, a459 int, a460 int, a461 int, a462 int, a463 int, a464 int, a465 int, a466 int, a467 int, a468 int, a469 int, a470 int, a471 int, a472 int, a473 int, a474 int, a475 int, a476 int, a477 int, a478 int, a479 int, a480 int, a481 int, a482 int, a483 int, a484 int, a485 int, a486 int, a487 int, a488 int, a489 int, a490 int, a491 int, a492 int, a493 int, a494 int, a495 int, a496 int, a497 int, a498 int, a499 int, a500 int, a501 int, a502 int, a503 int, a504 int, a505 int, a506 int, a507 int, a508 int, a509 int, a510 int, a511 int, a512 int, a513 int, a514 int, a515 int, a516 int, a517 int, a518 int, a519 int, a520 int, a521 int, a522 int, a523 int, a524 int, a525 int, a526 int, a527 int, a528 int, a529 int, a530 int, a531 int, a532 int, a533 int, a534 int, a535 int, a536 int, a537 int, a538 int, a539 int, a540 int, a541 int, a542 int, a543 int, a544 int, a545 int, a546 int, a547 int, a548 int, a549 int, a550 int, a551 int, a552 int, a553 int, a554 int, a555 int, a556 int, a557 int, a558 int, a559 int, a560 int, a561 int, a562 int, a563 int, a564 int, a565 int, a566 int, a567 int, a568 int, a569 int, a570 int, a571 int, a572 int, a573 int, a574 int, a575 int, a576 int, a577 int, a578 int, a579 int, a580 int, a581 int, a582 int, a583 int, a584 int, a585 int, a586 int, a587 int, a588 int, a589 int, a590 int, a591 int, a592 int, a593 int, a594 int, a595 int, a596 int, a597 int, a598 int, a599 int, a600 int, a601 int, a602 int, a603 int, a604 int, a605 int, a606 int, a607 int, a608 int, a609 int, a610 int, a611 int, a612 int, a613 int, a614 int, a615 int, a616 int, a617 int, a618 int, a619 int, a620 int, a621 int, a622 int, a623 int, a624 int, a625 int, a626 int, a627 int, a628 int, a629 int, a630 int, a631 int, a632 int, a633 int, a634 int, a635 int, a636 int, a637 int, a638 int, a639 int, a640 int, a641 int, a642 int, a643 int, a644 int, a645 int, a646 int, a647 int, a648 int, a649 int, a650 int, a651 int, a652 int, a653 int, a654 int, a655 int, a656 int, a657 int, a658 int, a659 int, a660 int, a661 int, a662 int, a663 int, a664 int, a665 int, a666 int, a667 int, a668 int, a669 int, a670 int, a671 int, a672 int, a673 int, a674 int, a675 int, a676 int, a677 int, a678 int, a679 int, a680 int, a681 int, a682 int, a683 int, a684 int, a685 int, a686 int, a687 int, a688 int, a689 int, a690 int, a691 int, a692 int, a693 int, a694 int, a695 int, a696 int, a697 int, a698 int, a699 int, a700 int, a701 int, a702 int, a703 int, a704 int, a705 int, a706 int, a707 int, a708 int, a709 int, a710 int, a711 int, a712 int, a713 int, a714 int, a715 int, a716 int, a717 int, a718 int, a719 int, a720 int, a721 int, a722 int, a723 int, a724 int, a725 int, a726 int, a727 int, a728 int, a729 int, a730 int, a731 int, a732 int, a733 int, a734 int, a735 int, a736 int, a737 int, a738 int, a739 int, a740 int, a741 int, a742 int, a743 int, a744 int, a745 int, a746 int, a747 int, a748 int, a749 int, a750 int, a751 int, a752 int, a753 int, a754 int, a755 int, a756 int, a757 int, a758 int, a759 int, a760 int, a761 int, a762 int, a763 int, a764 int, a765 int, a766 int, a767 int, a768 int, a769 int, a770 int, a771 int, a772 int, a773 int, a774 int, a775 int, a776 int, a777 int, a778 int, a779 int, a780 int, a781 int, a782 int, a783 int, a784 int, a785 int, a786 int, a787 int, a788 int, a789 int, a790 int, a791 int, a792 int, a793 int, a794 int, a795 int, a796 int, a797 int, a798 int, a799 int, a800 int, a801 int, a802 int, a803 int, a804 int, a805 int, a806 int, a807 int, a808 int, a809 int, a810 int, a811 int, a812 int, a813 int, a814 int, a815 int, a816 int, a817 int, a818 int, a819 int, a820 int, a821 int, a822 int, a823 int, a824 int, a825 int, a826 int, a827 int, a828 int, a829 int, a830 int, a831 int, a832 int, a833 int, a834 int, a835 int, a836 int, a837 int, a838 int, a839 int, a840 int, a841 int, a842 int, a843 int, a844 int, a845 int, a846 int, a847 int, a848 int, a849 int, a850 int, a851 int, a852 int, a853 int, a854 int, a855 int, a856 int, a857 int, a858 int, a859 int, a860 int, a861 int, a862 int, a863 int, a864 int, a865 int, a866 int, a867 int, a868 int, a869 int, a870 int, a871 int, a872 int, a873 int, a874 int, a875 int, a876 int, a877 int, a878 int, a879 int, a880 int, a881 int, a882 int, a883 int, a884 int, a885 int, a886 int, a887 int, a888 int, a889 int, a890 int, a891 int, a892 int, a893 int, a894 int, a895 int, a896 int, a897 int, a898 int, a899 int, a900 int, a901 int, a902 int, a903 int, a904 int, a905 int, a906 int, a907 int, a908 int, a909 int, a910 int, a911 int, a912 int, a913 int, a914 int, a915 int, a916 int, a917 int, a918 int, a919 int, a920 int, a921 int, a922 int, a923 int, a924 int, a925 int, a926 int, a927 int, a928 int, a929 int, a930 int, a931 int, a932 int, a933 int, a934 int, a935 int, a936 int, a937 int, a938 int, a939 int, a940 int, a941 int, a942 int, a943 int, a944 int, a945 int, a946 int, a947 int, a948 int, a949 int, a950 int, a951 int, a952 int, a953 int, a954 int, a955 int, a956 int, a957 int, a958 int, a959 int, a960 int, a961 int, a962 int, a963 int, a964 int, a965 int, a966 int, a967 int, a968 int, a969 int, a970 int, a971 int, a972 int, a973 int, a974 int, a975 int, a976 int, a977 int, a978 int, a979 int, a980 int, a981 int, a982 int, a983 int, a984 int, a985 int, a986 int, a987 int, a988 int, a989 int, a990 int, a991 int, a992 int, a993 int, a994 int, a995 int, a996 int, a997 int, a998 int, a999 int, a1000 int, a1001 int, a1002 int, a1003 int, a1004 int, a1005 int, a1006 int, a1007 int, a1008 int, a1009 int, a1010 int, a1011 int, a1012 int, a1013 int, a1014 int, a1015 int, a1016 int, a1017 int, a1018 int, a1019 int, a1020 int, a1021 int, a1022 int, a1023 int, a1024 int, a1025 int, a1026 int, a1027 int, a1028 int, a1029 int, a1030 int, a1031 int, a1032 int, a1033 int, a1034 int, a1035 int, a1036 int, a1037 int, a1038 int, a1039 int, a1040 int, a1041 int, a1042 int, a1043 int, a1044 int, a1045 int, a1046 int, a1047 int, a1048 int, a1049 int, a1050 int, a1051 int, a1052 int, a1053 int, a1054 int, a1055 int, a1056 int, a1057 int, a1058 int, a1059 int, a1060 int, a1061 int, a1062 int, a1063 int, a1064 int, a1065 int, a1066 int, a1067 int, a1068 int, a1069 int, a1070 int, a1071 int, a1072 int, a1073 int, a1074 int, a1075 int, a1076 int, a1077 int, a1078 int, a1079 int, a1080 int, a1081 int, a1082 int, a1083 int, a1084 int, a1085 int, a1086 int, a1087 int, a1088 int, a1089 int, a1090 int, a1091 int, a1092 int, a1093 int, a1094 int, a1095 int, a1096 int, a1097 int, a1098 int, a1099 int, a1100 int, a1101 int, a1102 int, a1103 int, a1104 int, a1105 int, a1106 int, a1107 int, a1108 int, a1109 int, a1110 int, a1111 int, a1112 int, a1113 int, a1114 int, a1115 int, a1116 int, a1117 int, a1118 int, a1119 int, a1120 int, a1121 int, a1122 int, a1123 int, a1124 int, a1125 int, a1126 int, a1127 int, a1128 int, a1129 int, a1130 int, a1131 int, a1132 int, a1133 int, a1134 int, a1135 int, a1136 int, a1137 int, a1138 int, a1139 int, a1140 int, a1141 int, a1142 int, a1143 int, a1144 int, a1145 int, a1146 int, a1147 int, a1148 int, a1149 int, a1150 int, a1151 int, a1152 int, a1153 int, a1154 int, a1155 int, a1156 int, a1157 int, a1158 int, a1159 int, a1160 int, a1161 int, a1162 int, a1163 int, a1164 int, a1165 int, a1166 int, a1167 int, a1168 int, a1169 int, a1170 int, a1171 int, a1172 int, a1173 int, a1174 int, a1175 int, a1176 int, a1177 int, a1178 int, a1179 int, a1180 int, a1181 int, a1182 int, a1183 int, a1184 int, a1185 int, a1186 int, a1187 int, a1188 int, a1189 int, a1190 int, a1191 int, a1192 int, a1193 int, a1194 int, a1195 int, a1196 int, a1197 int, a1198 int, a1199 int, a1200 int, a1201 int, a1202 int, a1203 int, a1204 int, a1205 int, a1206 int, a1207 int, a1208 int, a1209 int, a1210 int, a1211 int, a1212 int, a1213 int, a1214 int, a1215 int, a1216 int, a1217 int, a1218 int, a1219 int, a1220 int, a1221 int, a1222 int, a1223 int, a1224 int, a1225 int, a1226 int, a1227 int, a1228 int, a1229 int, a1230 int, a1231 int, a1232 int, a1233 int, a1234 int, a1235 int, a1236 int, a1237 int, a1238 int, a1239 int, a1240 int, a1241 int, a1242 int, a1243 int, a1244 int, a1245 int, a1246 int, a1247 int, a1248 int, a1249 int, a1250 int, a1251 int, a1252 int, a1253 int, a1254 int, a1255 int, a1256 int, a1257 int, a1258 int, a1259 int, a1260 int, a1261 int, a1262 int, a1263 int, a1264 int, a1265 int, a1266 int, a1267 int, a1268 int, a1269 int, a1270 int, a1271 int, a1272 int, a1273 int, a1274 int, a1275 int, a1276 int, a1277 int, a1278 int, a1279 int, a1280 int, a1281 int, a1282 int, a1283 int, a1284 int, a1285 int, a1286 int, a1287 int, a1288 int, a1289 int, a1290 int, a1291 int, a1292 int, a1293 int, a1294 int, a1295 int, a1296 int, a1297 int, a1298 int, a1299 int, a1300 int, a1301 int, a1302 int, a1303 int, a1304 int, a1305 int, a1306 int, a1307 int, a1308 int, a1309 int, a1310 int, a1311 int, a1312 int, a1313 int, a1314 int, a1315 int, a1316 int, a1317 int, a1318 int, a1319 int, a1320 int, a1321 int, a1322 int, a1323 int, a1324 int, a1325 int, a1326 int, a1327 int, a1328 int, a1329 int, a1330 int, a1331 int, a1332 int, a1333 int, a1334 int, a1335 int, a1336 int, a1337 int, a1338 int, a1339 int, a1340 int, a1341 int, a1342 int, a1343 int, a1344 int, a1345 int, a1346 int, a1347 int, a1348 int, a1349 int, a1350 int, a1351 int, a1352 int, a1353 int, a1354 int, a1355 int, a1356 int, a1357 int, a1358 int, a1359 int, a1360 int, a1361 int, a1362 int, a1363 int, a1364 int, a1365 int, a1366 int, a1367 int, a1368 int, a1369 int, a1370 int, a1371 int, a1372 int, a1373 int, a1374 int, a1375 int, a1376 int, a1377 int, a1378 int, a1379 int, a1380 int, a1381 int, a1382 int, a1383 int, a1384 int, a1385 int, a1386 int, a1387 int, a1388 int, a1389 int, a1390 int, a1391 int, a1392 int, a1393 int, a1394 int, a1395 int, a1396 int, a1397 int, a1398 int, a1399 int, a1400 int, a1401 int, a1402 int, a1403 int, a1404 int, a1405 int, a1406 int, a1407 int, a1408 int, a1409 int, a1410 int, a1411 int, a1412 int, a1413 int, a1414 int, a1415 int, a1416 int, a1417 int, a1418 int, a1419 int, a1420 int, a1421 int, a1422 int, a1423 int, a1424 int, a1425 int, a1426 int, a1427 int, a1428 int, a1429 int, a1430 int, a1431 int, a1432 int, a1433 int, a1434 int, a1435 int, a1436 int, a1437 int, a1438 int, a1439 int, a1440 int, a1441 int, a1442 int, a1443 int, a1444 int, a1445 int, a1446 int, a1447 int, a1448 int, a1449 int, a1450 int, a1451 int, a1452 int, a1453 int, a1454 int, a1455 int, a1456 int, a1457 int, a1458 int, a1459 int, a1460 int, a1461 int, a1462 int, a1463 int, a1464 int, a1465 int, a1466 int, a1467 int, a1468 int, a1469 int, a1470 int, a1471 int, a1472 int, a1473 int, a1474 int, a1475 int, a1476 int, a1477 int, a1478 int, a1479 int, a1480 int, a1481 int, a1482 int, a1483 int, a1484 int, a1485 int, a1486 int, a1487 int, a1488 int, a1489 int, a1490 int, a1491 int, a1492 int, a1493 int, a1494 int, a1495 int, a1496 int, a1497 int, a1498 int, a1499 int, a1500 int, a text);
4171CREATE TABLE t2 (b1 int, b2 int, b3 int, b4 int, b5 int, b6 int, b7 int, b8 int, b9 int, b10 int, b11 int, b12 int, b13 int, b14 int, b15 int, b16 int, b17 int, b18 int, b19 int, b20 int, b21 int, b22 int, b23 int, b24 int, b25 int, b26 int, b27 int, b28 int, b29 int, b30 int, b31 int, b32 int, b33 int, b34 int, b35 int, b36 int, b37 int, b38 int, b39 int, b40 int, b41 int, b42 int, b43 int, b44 int, b45 int, b46 int, b47 int, b48 int, b49 int, b50 int, b51 int, b52 int, b53 int, b54 int, b55 int, b56 int, b57 int, b58 int, b59 int, b60 int, b61 int, b62 int, b63 int, b64 int, b65 int, b66 int, b67 int, b68 int, b69 int, b70 int, b71 int, b72 int, b73 int, b74 int, b75 int, b76 int, b77 int, b78 int, b79 int, b80 int, b81 int, b82 int, b83 int, b84 int, b85 int, b86 int, b87 int, b88 int, b89 int, b90 int, b91 int, b92 int, b93 int, b94 int, b95 int, b96 int, b97 int, b98 int, b99 int, b100 int, b101 int, b102 int, b103 int, b104 int, b105 int, b106 int, b107 int, b108 int, b109 int, b110 int, b111 int, b112 int, b113 int, b114 int, b115 int, b116 int, b117 int, b118 int, b119 int, b120 int, b121 int, b122 int, b123 int, b124 int, b125 int, b126 int, b127 int, b128 int, b129 int, b130 int, b131 int, b132 int, b133 int, b134 int, b135 int, b136 int, b137 int, b138 int, b139 int, b140 int, b141 int, b142 int, b143 int, b144 int, b145 int, b146 int, b147 int, b148 int, b149 int, b150 int, b151 int, b152 int, b153 int, b154 int, b155 int, b156 int, b157 int, b158 int, b159 int, b160 int, b161 int, b162 int, b163 int, b164 int, b165 int, b166 int, b167 int, b168 int, b169 int, b170 int, b171 int, b172 int, b173 int, b174 int, b175 int, b176 int, b177 int, b178 int, b179 int, b180 int, b181 int, b182 int, b183 int, b184 int, b185 int, b186 int, b187 int, b188 int, b189 int, b190 int, b191 int, b192 int, b193 int, b194 int, b195 int, b196 int, b197 int, b198 int, b199 int, b200 int, b201 int, b202 int, b203 int, b204 int, b205 int, b206 int, b207 int, b208 int, b209 int, b210 int, b211 int, b212 int, b213 int, b214 int, b215 int, b216 int, b217 int, b218 int, b219 int, b220 int, b221 int, b222 int, b223 int, b224 int, b225 int, b226 int, b227 int, b228 int, b229 int, b230 int, b231 int, b232 int, b233 int, b234 int, b235 int, b236 int, b237 int, b238 int, b239 int, b240 int, b241 int, b242 int, b243 int, b244 int, b245 int, b246 int, b247 int, b248 int, b249 int, b250 int, b251 int, b252 int, b253 int, b254 int, b255 int, b256 int, b257 int, b258 int, b259 int, b260 int, b261 int, b262 int, b263 int, b264 int, b265 int, b266 int, b267 int, b268 int, b269 int, b270 int, b271 int, b272 int, b273 int, b274 int, b275 int, b276 int, b277 int, b278 int, b279 int, b280 int, b281 int, b282 int, b283 int, b284 int, b285 int, b286 int, b287 int, b288 int, b289 int, b290 int, b291 int, b292 int, b293 int, b294 int, b295 int, b296 int, b297 int, b298 int, b299 int, b300 int, b301 int, b302 int, b303 int, b304 int, b305 int, b306 int, b307 int, b308 int, b309 int, b310 int, b311 int, b312 int, b313 int, b314 int, b315 int, b316 int, b317 int, b318 int, b319 int, b320 int, b321 int, b322 int, b323 int, b324 int, b325 int, b326 int, b327 int, b328 int, b329 int, b330 int, b331 int, b332 int, b333 int, b334 int, b335 int, b336 int, b337 int, b338 int, b339 int, b340 int, b341 int, b342 int, b343 int, b344 int, b345 int, b346 int, b347 int, b348 int, b349 int, b350 int, b351 int, b352 int, b353 int, b354 int, b355 int, b356 int, b357 int, b358 int, b359 int, b360 int, b361 int, b362 int, b363 int, b364 int, b365 int, b366 int, b367 int, b368 int, b369 int, b370 int, b371 int, b372 int, b373 int, b374 int, b375 int, b376 int, b377 int, b378 int, b379 int, b380 int, b381 int, b382 int, b383 int, b384 int, b385 int, b386 int, b387 int, b388 int, b389 int, b390 int, b391 int, b392 int, b393 int, b394 int, b395 int, b396 int, b397 int, b398 int, b399 int, b400 int, b401 int, b402 int, b403 int, b404 int, b405 int, b406 int, b407 int, b408 int, b409 int, b410 int, b411 int, b412 int, b413 int, b414 int, b415 int, b416 int, b417 int, b418 int, b419 int, b420 int, b421 int, b422 int, b423 int, b424 int, b425 int, b426 int, b427 int, b428 int, b429 int, b430 int, b431 int, b432 int, b433 int, b434 int, b435 int, b436 int, b437 int, b438 int, b439 int, b440 int, b441 int, b442 int, b443 int, b444 int, b445 int, b446 int, b447 int, b448 int, b449 int, b450 int, b451 int, b452 int, b453 int, b454 int, b455 int, b456 int, b457 int, b458 int, b459 int, b460 int, b461 int, b462 int, b463 int, b464 int, b465 int, b466 int, b467 int, b468 int, b469 int, b470 int, b471 int, b472 int, b473 int, b474 int, b475 int, b476 int, b477 int, b478 int, b479 int, b480 int, b481 int, b482 int, b483 int, b484 int, b485 int, b486 int, b487 int, b488 int, b489 int, b490 int, b491 int, b492 int, b493 int, b494 int, b495 int, b496 int, b497 int, b498 int, b499 int, b500 int, b501 int, b502 int, b503 int, b504 int, b505 int, b506 int, b507 int, b508 int, b509 int, b510 int, b511 int, b512 int, b513 int, b514 int, b515 int, b516 int, b517 int, b518 int, b519 int, b520 int, b521 int, b522 int, b523 int, b524 int, b525 int, b526 int, b527 int, b528 int, b529 int, b530 int, b531 int, b532 int, b533 int, b534 int, b535 int, b536 int, b537 int, b538 int, b539 int, b540 int, b541 int, b542 int, b543 int, b544 int, b545 int, b546 int, b547 int, b548 int, b549 int, b550 int, b551 int, b552 int, b553 int, b554 int, b555 int, b556 int, b557 int, b558 int, b559 int, b560 int, b561 int, b562 int, b563 int, b564 int, b565 int, b566 int, b567 int, b568 int, b569 int, b570 int, b571 int, b572 int, b573 int, b574 int, b575 int, b576 int, b577 int, b578 int, b579 int, b580 int, b581 int, b582 int, b583 int, b584 int, b585 int, b586 int, b587 int, b588 int, b589 int, b590 int, b591 int, b592 int, b593 int, b594 int, b595 int, b596 int, b597 int, b598 int, b599 int, b600 int, b601 int, b602 int, b603 int, b604 int, b605 int, b606 int, b607 int, b608 int, b609 int, b610 int, b611 int, b612 int, b613 int, b614 int, b615 int, b616 int, b617 int, b618 int, b619 int, b620 int, b621 int, b622 int, b623 int, b624 int, b625 int, b626 int, b627 int, b628 int, b629 int, b630 int, b631 int, b632 int, b633 int, b634 int, b635 int, b636 int, b637 int, b638 int, b639 int, b640 int, b641 int, b642 int, b643 int, b644 int, b645 int, b646 int, b647 int, b648 int, b649 int, b650 int, b651 int, b652 int, b653 int, b654 int, b655 int, b656 int, b657 int, b658 int, b659 int, b660 int, b661 int, b662 int, b663 int, b664 int, b665 int, b666 int, b667 int, b668 int, b669 int, b670 int, b671 int, b672 int, b673 int, b674 int, b675 int, b676 int, b677 int, b678 int, b679 int, b680 int, b681 int, b682 int, b683 int, b684 int, b685 int, b686 int, b687 int, b688 int, b689 int, b690 int, b691 int, b692 int, b693 int, b694 int, b695 int, b696 int, b697 int, b698 int, b699 int, b700 int, b701 int, b702 int, b703 int, b704 int, b705 int, b706 int, b707 int, b708 int, b709 int, b710 int, b711 int, b712 int, b713 int, b714 int, b715 int, b716 int, b717 int, b718 int, b719 int, b720 int, b721 int, b722 int, b723 int, b724 int, b725 int, b726 int, b727 int, b728 int, b729 int, b730 int, b731 int, b732 int, b733 int, b734 int, b735 int, b736 int, b737 int, b738 int, b739 int, b740 int, b741 int, b742 int, b743 int, b744 int, b745 int, b746 int, b747 int, b748 int, b749 int, b750 int, b751 int, b752 int, b753 int, b754 int, b755 int, b756 int, b757 int, b758 int, b759 int, b760 int, b761 int, b762 int, b763 int, b764 int, b765 int, b766 int, b767 int, b768 int, b769 int, b770 int, b771 int, b772 int, b773 int, b774 int, b775 int, b776 int, b777 int, b778 int, b779 int, b780 int, b781 int, b782 int, b783 int, b784 int, b785 int, b786 int, b787 int, b788 int, b789 int, b790 int, b791 int, b792 int, b793 int, b794 int, b795 int, b796 int, b797 int, b798 int, b799 int, b800 int, b801 int, b802 int, b803 int, b804 int, b805 int, b806 int, b807 int, b808 int, b809 int, b810 int, b811 int, b812 int, b813 int, b814 int, b815 int, b816 int, b817 int, b818 int, b819 int, b820 int, b821 int, b822 int, b823 int, b824 int, b825 int, b826 int, b827 int, b828 int, b829 int, b830 int, b831 int, b832 int, b833 int, b834 int, b835 int, b836 int, b837 int, b838 int, b839 int, b840 int, b841 int, b842 int, b843 int, b844 int, b845 int, b846 int, b847 int, b848 int, b849 int, b850 int, b851 int, b852 int, b853 int, b854 int, b855 int, b856 int, b857 int, b858 int, b859 int, b860 int, b861 int, b862 int, b863 int, b864 int, b865 int, b866 int, b867 int, b868 int, b869 int, b870 int, b871 int, b872 int, b873 int, b874 int, b875 int, b876 int, b877 int, b878 int, b879 int, b880 int, b881 int, b882 int, b883 int, b884 int, b885 int, b886 int, b887 int, b888 int, b889 int, b890 int, b891 int, b892 int, b893 int, b894 int, b895 int, b896 int, b897 int, b898 int, b899 int, b900 int, b901 int, b902 int, b903 int, b904 int, b905 int, b906 int, b907 int, b908 int, b909 int, b910 int, b911 int, b912 int, b913 int, b914 int, b915 int, b916 int, b917 int, b918 int, b919 int, b920 int, b921 int, b922 int, b923 int, b924 int, b925 int, b926 int, b927 int, b928 int, b929 int, b930 int, b931 int, b932 int, b933 int, b934 int, b935 int, b936 int, b937 int, b938 int, b939 int, b940 int, b941 int, b942 int, b943 int, b944 int, b945 int, b946 int, b947 int, b948 int, b949 int, b950 int, b951 int, b952 int, b953 int, b954 int, b955 int, b956 int, b957 int, b958 int, b959 int, b960 int, b961 int, b962 int, b963 int, b964 int, b965 int, b966 int, b967 int, b968 int, b969 int, b970 int, b971 int, b972 int, b973 int, b974 int, b975 int, b976 int, b977 int, b978 int, b979 int, b980 int, b981 int, b982 int, b983 int, b984 int, b985 int, b986 int, b987 int, b988 int, b989 int, b990 int, b991 int, b992 int, b993 int, b994 int, b995 int, b996 int, b997 int, b998 int, b999 int, b1000 int, b1001 int, b1002 int, b1003 int, b1004 int, b1005 int, b1006 int, b1007 int, b1008 int, b1009 int, b1010 int, b1011 int, b1012 int, b1013 int, b1014 int, b1015 int, b1016 int, b1017 int, b1018 int, b1019 int, b1020 int, b1021 int, b1022 int, b1023 int, b1024 int, b1025 int, b1026 int, b1027 int, b1028 int, b1029 int, b1030 int, b1031 int, b1032 int, b1033 int, b1034 int, b1035 int, b1036 int, b1037 int, b1038 int, b1039 int, b1040 int, b1041 int, b1042 int, b1043 int, b1044 int, b1045 int, b1046 int, b1047 int, b1048 int, b1049 int, b1050 int, b1051 int, b1052 int, b1053 int, b1054 int, b1055 int, b1056 int, b1057 int, b1058 int, b1059 int, b1060 int, b1061 int, b1062 int, b1063 int, b1064 int, b1065 int, b1066 int, b1067 int, b1068 int, b1069 int, b1070 int, b1071 int, b1072 int, b1073 int, b1074 int, b1075 int, b1076 int, b1077 int, b1078 int, b1079 int, b1080 int, b1081 int, b1082 int, b1083 int, b1084 int, b1085 int, b1086 int, b1087 int, b1088 int, b1089 int, b1090 int, b1091 int, b1092 int, b1093 int, b1094 int, b1095 int, b1096 int, b1097 int, b1098 int, b1099 int, b1100 int, b1101 int, b1102 int, b1103 int, b1104 int, b1105 int, b1106 int, b1107 int, b1108 int, b1109 int, b1110 int, b1111 int, b1112 int, b1113 int, b1114 int, b1115 int, b1116 int, b1117 int, b1118 int, b1119 int, b1120 int, b1121 int, b1122 int, b1123 int, b1124 int, b1125 int, b1126 int, b1127 int, b1128 int, b1129 int, b1130 int, b1131 int, b1132 int, b1133 int, b1134 int, b1135 int, b1136 int, b1137 int, b1138 int, b1139 int, b1140 int, b1141 int, b1142 int, b1143 int, b1144 int, b1145 int, b1146 int, b1147 int, b1148 int, b1149 int, b1150 int, b1151 int, b1152 int, b1153 int, b1154 int, b1155 int, b1156 int, b1157 int, b1158 int, b1159 int, b1160 int, b1161 int, b1162 int, b1163 int, b1164 int, b1165 int, b1166 int, b1167 int, b1168 int, b1169 int, b1170 int, b1171 int, b1172 int, b1173 int, b1174 int, b1175 int, b1176 int, b1177 int, b1178 int, b1179 int, b1180 int, b1181 int, b1182 int, b1183 int, b1184 int, b1185 int, b1186 int, b1187 int, b1188 int, b1189 int, b1190 int, b1191 int, b1192 int, b1193 int, b1194 int, b1195 int, b1196 int, b1197 int, b1198 int, b1199 int, b1200 int, b1201 int, b1202 int, b1203 int, b1204 int, b1205 int, b1206 int, b1207 int, b1208 int, b1209 int, b1210 int, b1211 int, b1212 int, b1213 int, b1214 int, b1215 int, b1216 int, b1217 int, b1218 int, b1219 int, b1220 int, b1221 int, b1222 int, b1223 int, b1224 int, b1225 int, b1226 int, b1227 int, b1228 int, b1229 int, b1230 int, b1231 int, b1232 int, b1233 int, b1234 int, b1235 int, b1236 int, b1237 int, b1238 int, b1239 int, b1240 int, b1241 int, b1242 int, b1243 int, b1244 int, b1245 int, b1246 int, b1247 int, b1248 int, b1249 int, b1250 int, b1251 int, b1252 int, b1253 int, b1254 int, b1255 int, b1256 int, b1257 int, b1258 int, b1259 int, b1260 int, b1261 int, b1262 int, b1263 int, b1264 int, b1265 int, b1266 int, b1267 int, b1268 int, b1269 int, b1270 int, b1271 int, b1272 int, b1273 int, b1274 int, b1275 int, b1276 int, b1277 int, b1278 int, b1279 int, b1280 int, b1281 int, b1282 int, b1283 int, b1284 int, b1285 int, b1286 int, b1287 int, b1288 int, b1289 int, b1290 int, b1291 int, b1292 int, b1293 int, b1294 int, b1295 int, b1296 int, b1297 int, b1298 int, b1299 int, b1300 int, b1301 int, b1302 int, b1303 int, b1304 int, b1305 int, b1306 int, b1307 int, b1308 int, b1309 int, b1310 int, b1311 int, b1312 int, b1313 int, b1314 int, b1315 int, b1316 int, b1317 int, b1318 int, b1319 int, b1320 int, b1321 int, b1322 int, b1323 int, b1324 int, b1325 int, b1326 int, b1327 int, b1328 int, b1329 int, b1330 int, b1331 int, b1332 int, b1333 int, b1334 int, b1335 int, b1336 int, b1337 int, b1338 int, b1339 int, b1340 int, b1341 int, b1342 int, b1343 int, b1344 int, b1345 int, b1346 int, b1347 int, b1348 int, b1349 int, b1350 int, b1351 int, b1352 int, b1353 int, b1354 int, b1355 int, b1356 int, b1357 int, b1358 int, b1359 int, b1360 int, b1361 int, b1362 int, b1363 int, b1364 int, b1365 int, b1366 int, b1367 int, b1368 int, b1369 int, b1370 int, b1371 int, b1372 int, b1373 int, b1374 int, b1375 int, b1376 int, b1377 int, b1378 int, b1379 int, b1380 int, b1381 int, b1382 int, b1383 int, b1384 int, b1385 int, b1386 int, b1387 int, b1388 int, b1389 int, b1390 int, b1391 int, b1392 int, b1393 int, b1394 int, b1395 int, b1396 int, b1397 int, b1398 int, b1399 int, b1400 int, b1401 int, b1402 int, b1403 int, b1404 int, b1405 int, b1406 int, b1407 int, b1408 int, b1409 int, b1410 int, b1411 int, b1412 int, b1413 int, b1414 int, b1415 int, b1416 int, b1417 int, b1418 int, b1419 int, b1420 int, b1421 int, b1422 int, b1423 int, b1424 int, b1425 int, b1426 int, b1427 int, b1428 int, b1429 int, b1430 int, b1431 int, b1432 int, b1433 int, b1434 int, b1435 int, b1436 int, b1437 int, b1438 int, b1439 int, b1440 int, b1441 int, b1442 int, b1443 int, b1444 int, b1445 int, b1446 int, b1447 int, b1448 int, b1449 int, b1450 int, b1451 int, b1452 int, b1453 int, b1454 int, b1455 int, b1456 int, b1457 int, b1458 int, b1459 int, b1460 int, b1461 int, b1462 int, b1463 int, b1464 int, b1465 int, b1466 int, b1467 int, b1468 int, b1469 int, b1470 int, b1471 int, b1472 int, b1473 int, b1474 int, b1475 int, b1476 int, b1477 int, b1478 int, b1479 int, b1480 int, b1481 int, b1482 int, b1483 int, b1484 int, b1485 int, b1486 int, b1487 int, b1488 int, b1489 int, b1490 int, b1491 int, b1492 int, b1493 int, b1494 int, b1495 int, b1496 int, b1497 int, b1498 int, b1499 int, b1500 int, b text);
4172CREATE TABLE t3 (c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 int, c8 int, c9 int, c10 int, c11 int, c12 int, c13 int, c14 int, c15 int, c16 int, c17 int, c18 int, c19 int, c20 int, c21 int, c22 int, c23 int, c24 int, c25 int, c26 int, c27 int, c28 int, c29 int, c30 int, c31 int, c32 int, c33 int, c34 int, c35 int, c36 int, c37 int, c38 int, c39 int, c40 int, c41 int, c42 int, c43 int, c44 int, c45 int, c46 int, c47 int, c48 int, c49 int, c50 int, c51 int, c52 int, c53 int, c54 int, c55 int, c56 int, c57 int, c58 int, c59 int, c60 int, c61 int, c62 int, c63 int, c64 int, c65 int, c66 int, c67 int, c68 int, c69 int, c70 int, c71 int, c72 int, c73 int, c74 int, c75 int, c76 int, c77 int, c78 int, c79 int, c80 int, c81 int, c82 int, c83 int, c84 int, c85 int, c86 int, c87 int, c88 int, c89 int, c90 int, c91 int, c92 int, c93 int, c94 int, c95 int, c96 int, c97 int, c98 int, c99 int, c100 int, c101 int, c102 int, c103 int, c104 int, c105 int, c106 int, c107 int, c108 int, c109 int, c110 int, c111 int, c112 int, c113 int, c114 int, c115 int, c116 int, c117 int, c118 int, c119 int, c120 int, c121 int, c122 int, c123 int, c124 int, c125 int, c126 int, c127 int, c128 int, c129 int, c130 int, c131 int, c132 int, c133 int, c134 int, c135 int, c136 int, c137 int, c138 int, c139 int, c140 int, c141 int, c142 int, c143 int, c144 int, c145 int, c146 int, c147 int, c148 int, c149 int, c150 int, c151 int, c152 int, c153 int, c154 int, c155 int, c156 int, c157 int, c158 int, c159 int, c160 int, c161 int, c162 int, c163 int, c164 int, c165 int, c166 int, c167 int, c168 int, c169 int, c170 int, c171 int, c172 int, c173 int, c174 int, c175 int, c176 int, c177 int, c178 int, c179 int, c180 int, c181 int, c182 int, c183 int, c184 int, c185 int, c186 int, c187 int, c188 int, c189 int, c190 int, c191 int, c192 int, c193 int, c194 int, c195 int, c196 int, c197 int, c198 int, c199 int, c200 int, c201 int, c202 int, c203 int, c204 int, c205 int, c206 int, c207 int, c208 int, c209 int, c210 int, c211 int, c212 int, c213 int, c214 int, c215 int, c216 int, c217 int, c218 int, c219 int, c220 int, c221 int, c222 int, c223 int, c224 int, c225 int, c226 int, c227 int, c228 int, c229 int, c230 int, c231 int, c232 int, c233 int, c234 int, c235 int, c236 int, c237 int, c238 int, c239 int, c240 int, c241 int, c242 int, c243 int, c244 int, c245 int, c246 int, c247 int, c248 int, c249 int, c250 int, c251 int, c252 int, c253 int, c254 int, c255 int, c256 int, c257 int, c258 int, c259 int, c260 int, c261 int, c262 int, c263 int, c264 int, c265 int, c266 int, c267 int, c268 int, c269 int, c270 int, c271 int, c272 int, c273 int, c274 int, c275 int, c276 int, c277 int, c278 int, c279 int, c280 int, c281 int, c282 int, c283 int, c284 int, c285 int, c286 int, c287 int, c288 int, c289 int, c290 int, c291 int, c292 int, c293 int, c294 int, c295 int, c296 int, c297 int, c298 int, c299 int, c300 int, c301 int, c302 int, c303 int, c304 int, c305 int, c306 int, c307 int, c308 int, c309 int, c310 int, c311 int, c312 int, c313 int, c314 int, c315 int, c316 int, c317 int, c318 int, c319 int, c320 int, c321 int, c322 int, c323 int, c324 int, c325 int, c326 int, c327 int, c328 int, c329 int, c330 int, c331 int, c332 int, c333 int, c334 int, c335 int, c336 int, c337 int, c338 int, c339 int, c340 int, c341 int, c342 int, c343 int, c344 int, c345 int, c346 int, c347 int, c348 int, c349 int, c350 int, c351 int, c352 int, c353 int, c354 int, c355 int, c356 int, c357 int, c358 int, c359 int, c360 int, c361 int, c362 int, c363 int, c364 int, c365 int, c366 int, c367 int, c368 int, c369 int, c370 int, c371 int, c372 int, c373 int, c374 int, c375 int, c376 int, c377 int, c378 int, c379 int, c380 int, c381 int, c382 int, c383 int, c384 int, c385 int, c386 int, c387 int, c388 int, c389 int, c390 int, c391 int, c392 int, c393 int, c394 int, c395 int, c396 int, c397 int, c398 int, c399 int, c400 int, c401 int, c402 int, c403 int, c404 int, c405 int, c406 int, c407 int, c408 int, c409 int, c410 int, c411 int, c412 int, c413 int, c414 int, c415 int, c416 int, c417 int, c418 int, c419 int, c420 int, c421 int, c422 int, c423 int, c424 int, c425 int, c426 int, c427 int, c428 int, c429 int, c430 int, c431 int, c432 int, c433 int, c434 int, c435 int, c436 int, c437 int, c438 int, c439 int, c440 int, c441 int, c442 int, c443 int, c444 int, c445 int, c446 int, c447 int, c448 int, c449 int, c450 int, c451 int, c452 int, c453 int, c454 int, c455 int, c456 int, c457 int, c458 int, c459 int, c460 int, c461 int, c462 int, c463 int, c464 int, c465 int, c466 int, c467 int, c468 int, c469 int, c470 int, c471 int, c472 int, c473 int, c474 int, c475 int, c476 int, c477 int, c478 int, c479 int, c480 int, c481 int, c482 int, c483 int, c484 int, c485 int, c486 int, c487 int, c488 int, c489 int, c490 int, c491 int, c492 int, c493 int, c494 int, c495 int, c496 int, c497 int, c498 int, c499 int, c500 int, c501 int, c502 int, c503 int, c504 int, c505 int, c506 int, c507 int, c508 int, c509 int, c510 int, c511 int, c512 int, c513 int, c514 int, c515 int, c516 int, c517 int, c518 int, c519 int, c520 int, c521 int, c522 int, c523 int, c524 int, c525 int, c526 int, c527 int, c528 int, c529 int, c530 int, c531 int, c532 int, c533 int, c534 int, c535 int, c536 int, c537 int, c538 int, c539 int, c540 int, c541 int, c542 int, c543 int, c544 int, c545 int, c546 int, c547 int, c548 int, c549 int, c550 int, c551 int, c552 int, c553 int, c554 int, c555 int, c556 int, c557 int, c558 int, c559 int, c560 int, c561 int, c562 int, c563 int, c564 int, c565 int, c566 int, c567 int, c568 int, c569 int, c570 int, c571 int, c572 int, c573 int, c574 int, c575 int, c576 int, c577 int, c578 int, c579 int, c580 int, c581 int, c582 int, c583 int, c584 int, c585 int, c586 int, c587 int, c588 int, c589 int, c590 int, c591 int, c592 int, c593 int, c594 int, c595 int, c596 int, c597 int, c598 int, c599 int, c600 int, c601 int, c602 int, c603 int, c604 int, c605 int, c606 int, c607 int, c608 int, c609 int, c610 int, c611 int, c612 int, c613 int, c614 int, c615 int, c616 int, c617 int, c618 int, c619 int, c620 int, c621 int, c622 int, c623 int, c624 int, c625 int, c626 int, c627 int, c628 int, c629 int, c630 int, c631 int, c632 int, c633 int, c634 int, c635 int, c636 int, c637 int, c638 int, c639 int, c640 int, c641 int, c642 int, c643 int, c644 int, c645 int, c646 int, c647 int, c648 int, c649 int, c650 int, c651 int, c652 int, c653 int, c654 int, c655 int, c656 int, c657 int, c658 int, c659 int, c660 int, c661 int, c662 int, c663 int, c664 int, c665 int, c666 int, c667 int, c668 int, c669 int, c670 int, c671 int, c672 int, c673 int, c674 int, c675 int, c676 int, c677 int, c678 int, c679 int, c680 int, c681 int, c682 int, c683 int, c684 int, c685 int, c686 int, c687 int, c688 int, c689 int, c690 int, c691 int, c692 int, c693 int, c694 int, c695 int, c696 int, c697 int, c698 int, c699 int, c700 int, c701 int, c702 int, c703 int, c704 int, c705 int, c706 int, c707 int, c708 int, c709 int, c710 int, c711 int, c712 int, c713 int, c714 int, c715 int, c716 int, c717 int, c718 int, c719 int, c720 int, c721 int, c722 int, c723 int, c724 int, c725 int, c726 int, c727 int, c728 int, c729 int, c730 int, c731 int, c732 int, c733 int, c734 int, c735 int, c736 int, c737 int, c738 int, c739 int, c740 int, c741 int, c742 int, c743 int, c744 int, c745 int, c746 int, c747 int, c748 int, c749 int, c750 int, c751 int, c752 int, c753 int, c754 int, c755 int, c756 int, c757 int, c758 int, c759 int, c760 int, c761 int, c762 int, c763 int, c764 int, c765 int, c766 int, c767 int, c768 int, c769 int, c770 int, c771 int, c772 int, c773 int, c774 int, c775 int, c776 int, c777 int, c778 int, c779 int, c780 int, c781 int, c782 int, c783 int, c784 int, c785 int, c786 int, c787 int, c788 int, c789 int, c790 int, c791 int, c792 int, c793 int, c794 int, c795 int, c796 int, c797 int, c798 int, c799 int, c800 int, c801 int, c802 int, c803 int, c804 int, c805 int, c806 int, c807 int, c808 int, c809 int, c810 int, c811 int, c812 int, c813 int, c814 int, c815 int, c816 int, c817 int, c818 int, c819 int, c820 int, c821 int, c822 int, c823 int, c824 int, c825 int, c826 int, c827 int, c828 int, c829 int, c830 int, c831 int, c832 int, c833 int, c834 int, c835 int, c836 int, c837 int, c838 int, c839 int, c840 int, c841 int, c842 int, c843 int, c844 int, c845 int, c846 int, c847 int, c848 int, c849 int, c850 int, c851 int, c852 int, c853 int, c854 int, c855 int, c856 int, c857 int, c858 int, c859 int, c860 int, c861 int, c862 int, c863 int, c864 int, c865 int, c866 int, c867 int, c868 int, c869 int, c870 int, c871 int, c872 int, c873 int, c874 int, c875 int, c876 int, c877 int, c878 int, c879 int, c880 int, c881 int, c882 int, c883 int, c884 int, c885 int, c886 int, c887 int, c888 int, c889 int, c890 int, c891 int, c892 int, c893 int, c894 int, c895 int, c896 int, c897 int, c898 int, c899 int, c900 int, c901 int, c902 int, c903 int, c904 int, c905 int, c906 int, c907 int, c908 int, c909 int, c910 int, c911 int, c912 int, c913 int, c914 int, c915 int, c916 int, c917 int, c918 int, c919 int, c920 int, c921 int, c922 int, c923 int, c924 int, c925 int, c926 int, c927 int, c928 int, c929 int, c930 int, c931 int, c932 int, c933 int, c934 int, c935 int, c936 int, c937 int, c938 int, c939 int, c940 int, c941 int, c942 int, c943 int, c944 int, c945 int, c946 int, c947 int, c948 int, c949 int, c950 int, c951 int, c952 int, c953 int, c954 int, c955 int, c956 int, c957 int, c958 int, c959 int, c960 int, c961 int, c962 int, c963 int, c964 int, c965 int, c966 int, c967 int, c968 int, c969 int, c970 int, c971 int, c972 int, c973 int, c974 int, c975 int, c976 int, c977 int, c978 int, c979 int, c980 int, c981 int, c982 int, c983 int, c984 int, c985 int, c986 int, c987 int, c988 int, c989 int, c990 int, c991 int, c992 int, c993 int, c994 int, c995 int, c996 int, c997 int, c998 int, c999 int, c1000 int, c1001 int, c1002 int, c1003 int, c1004 int, c1005 int, c1006 int, c1007 int, c1008 int, c1009 int, c1010 int, c1011 int, c1012 int, c1013 int, c1014 int, c1015 int, c1016 int, c1017 int, c1018 int, c1019 int, c1020 int, c1021 int, c1022 int, c1023 int, c1024 int, c1025 int, c1026 int, c1027 int, c1028 int, c1029 int, c1030 int, c1031 int, c1032 int, c1033 int, c1034 int, c1035 int, c1036 int, c1037 int, c1038 int, c1039 int, c1040 int, c1041 int, c1042 int, c1043 int, c1044 int, c1045 int, c1046 int, c1047 int, c1048 int, c1049 int, c1050 int, c1051 int, c1052 int, c1053 int, c1054 int, c1055 int, c1056 int, c1057 int, c1058 int, c1059 int, c1060 int, c1061 int, c1062 int, c1063 int, c1064 int, c1065 int, c1066 int, c1067 int, c1068 int, c1069 int, c1070 int, c1071 int, c1072 int, c1073 int, c1074 int, c1075 int, c1076 int, c1077 int, c1078 int, c1079 int, c1080 int, c1081 int, c1082 int, c1083 int, c1084 int, c1085 int, c1086 int, c1087 int, c1088 int, c1089 int, c1090 int, c1091 int, c1092 int, c1093 int, c1094 int, c1095 int, c1096 int, c1097 int, c1098 int, c1099 int, c1100 int, c1101 int, c1102 int, c1103 int, c1104 int, c1105 int, c1106 int, c1107 int, c1108 int, c1109 int, c1110 int, c1111 int, c1112 int, c1113 int, c1114 int, c1115 int, c1116 int, c1117 int, c1118 int, c1119 int, c1120 int, c1121 int, c1122 int, c1123 int, c1124 int, c1125 int, c1126 int, c1127 int, c1128 int, c1129 int, c1130 int, c1131 int, c1132 int, c1133 int, c1134 int, c1135 int, c1136 int, c1137 int, c1138 int, c1139 int, c1140 int, c1141 int, c1142 int, c1143 int, c1144 int, c1145 int, c1146 int, c1147 int, c1148 int, c1149 int, c1150 int, c1151 int, c1152 int, c1153 int, c1154 int, c1155 int, c1156 int, c1157 int, c1158 int, c1159 int, c1160 int, c1161 int, c1162 int, c1163 int, c1164 int, c1165 int, c1166 int, c1167 int, c1168 int, c1169 int, c1170 int, c1171 int, c1172 int, c1173 int, c1174 int, c1175 int, c1176 int, c1177 int, c1178 int, c1179 int, c1180 int, c1181 int, c1182 int, c1183 int, c1184 int, c1185 int, c1186 int, c1187 int, c1188 int, c1189 int, c1190 int, c1191 int, c1192 int, c1193 int, c1194 int, c1195 int, c1196 int, c1197 int, c1198 int, c1199 int, c1200 int, c1201 int, c1202 int, c1203 int, c1204 int, c1205 int, c1206 int, c1207 int, c1208 int, c1209 int, c1210 int, c1211 int, c1212 int, c1213 int, c1214 int, c1215 int, c1216 int, c1217 int, c1218 int, c1219 int, c1220 int, c1221 int, c1222 int, c1223 int, c1224 int, c1225 int, c1226 int, c1227 int, c1228 int, c1229 int, c1230 int, c1231 int, c1232 int, c1233 int, c1234 int, c1235 int, c1236 int, c1237 int, c1238 int, c1239 int, c1240 int, c1241 int, c1242 int, c1243 int, c1244 int, c1245 int, c1246 int, c1247 int, c1248 int, c1249 int, c1250 int, c1251 int, c1252 int, c1253 int, c1254 int, c1255 int, c1256 int, c1257 int, c1258 int, c1259 int, c1260 int, c1261 int, c1262 int, c1263 int, c1264 int, c1265 int, c1266 int, c1267 int, c1268 int, c1269 int, c1270 int, c1271 int, c1272 int, c1273 int, c1274 int, c1275 int, c1276 int, c1277 int, c1278 int, c1279 int, c1280 int, c1281 int, c1282 int, c1283 int, c1284 int, c1285 int, c1286 int, c1287 int, c1288 int, c1289 int, c1290 int, c1291 int, c1292 int, c1293 int, c1294 int, c1295 int, c1296 int, c1297 int, c1298 int, c1299 int, c1300 int, c1301 int, c1302 int, c1303 int, c1304 int, c1305 int, c1306 int, c1307 int, c1308 int, c1309 int, c1310 int, c1311 int, c1312 int, c1313 int, c1314 int, c1315 int, c1316 int, c1317 int, c1318 int, c1319 int, c1320 int, c1321 int, c1322 int, c1323 int, c1324 int, c1325 int, c1326 int, c1327 int, c1328 int, c1329 int, c1330 int, c1331 int, c1332 int, c1333 int, c1334 int, c1335 int, c1336 int, c1337 int, c1338 int, c1339 int, c1340 int, c1341 int, c1342 int, c1343 int, c1344 int, c1345 int, c1346 int, c1347 int, c1348 int, c1349 int, c1350 int, c1351 int, c1352 int, c1353 int, c1354 int, c1355 int, c1356 int, c1357 int, c1358 int, c1359 int, c1360 int, c1361 int, c1362 int, c1363 int, c1364 int, c1365 int, c1366 int, c1367 int, c1368 int, c1369 int, c1370 int, c1371 int, c1372 int, c1373 int, c1374 int, c1375 int, c1376 int, c1377 int, c1378 int, c1379 int, c1380 int, c1381 int, c1382 int, c1383 int, c1384 int, c1385 int, c1386 int, c1387 int, c1388 int, c1389 int, c1390 int, c1391 int, c1392 int, c1393 int, c1394 int, c1395 int, c1396 int, c1397 int, c1398 int, c1399 int, c1400 int, c1401 int, c1402 int, c1403 int, c1404 int, c1405 int, c1406 int, c1407 int, c1408 int, c1409 int, c1410 int, c1411 int, c1412 int, c1413 int, c1414 int, c1415 int, c1416 int, c1417 int, c1418 int, c1419 int, c1420 int, c1421 int, c1422 int, c1423 int, c1424 int, c1425 int, c1426 int, c1427 int, c1428 int, c1429 int, c1430 int, c1431 int, c1432 int, c1433 int, c1434 int, c1435 int, c1436 int, c1437 int, c1438 int, c1439 int, c1440 int, c1441 int, c1442 int, c1443 int, c1444 int, c1445 int, c1446 int, c1447 int, c1448 int, c1449 int, c1450 int, c1451 int, c1452 int, c1453 int, c1454 int, c1455 int, c1456 int, c1457 int, c1458 int, c1459 int, c1460 int, c1461 int, c1462 int, c1463 int, c1464 int, c1465 int, c1466 int, c1467 int, c1468 int, c1469 int, c1470 int, c1471 int, c1472 int, c1473 int, c1474 int, c1475 int, c1476 int, c1477 int, c1478 int, c1479 int, c1480 int, c1481 int, c1482 int, c1483 int, c1484 int, c1485 int, c1486 int, c1487 int, c1488 int, c1489 int, c1490 int, c1491 int, c1492 int, c1493 int, c1494 int, c1495 int, c1496 int, c1497 int, c1498 int, c1499 int, c1500 int, c text);
4173CREATE VIEW view_broken AS SELECT * FROM t1, t2, t3;
4174ERROR HY000: Too many columns
4175CREATE TABLE table_broken AS SELECT * FROM t1, t2, t3;
4176ERROR HY000: Too many columns
4177DROP TABLE t1, t2, t3;
4178#
4179# Bug#11766440 59546: Assertion m_sp == __null fails in
4180# Item_func_sp::init_result_field with functions
4181#
4182CREATE TABLE t1 (a INT);
4183CREATE FUNCTION f1 () RETURNS INTEGER RETURN 1;
4184CREATE FUNCTION f2 (i INTEGER) RETURNS INTEGER RETURN 1;
4185CREATE VIEW v1 AS SELECT f1() AS a FROM t1;
4186CREATE VIEW v2 AS SELECT f2(a) AS a FROM v1;
4187DROP FUNCTION f1;
4188SELECT f2(a) FROM v2;
4189ERROR HY000: View 'test.v2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
4190DROP VIEW v2;
4191DROP VIEW v1;
4192DROP FUNCTION f2;
4193DROP TABLE t1;
4194#
4195# Bug#13418197: ASSERTION `(*TABLES)->REGINFO.LOCK_TYPE >=
4196#               TL_READ' FAILED | MYSQL_LOCK_TABLES
4197#
4198DROP TABLE IF EXISTS t1;
4199CREATE TEMPORARY TABLE t1 (a INT) engine=InnoDB;
4200CREATE VIEW t1 AS SELECT 1;
4201DROP VIEW t1;
4202DROP TEMPORARY TABLE t1;
4203#
4204# Bug#13601606: FAILED VIEW CREATION ERROR MESSAGE (FOR DB NOT PRESENT)
4205#               NEEDS BIG IMPROVEMENT
4206#
4207DROP DATABASE IF EXISTS nodb;
4208CREATE VIEW nodb.a AS SELECT 1;
4209ERROR 42000: Unknown database 'nodb'
4210#
4211# Bug#13633549 HANDLE_FATAL_SIGNAL IN
4212#              TEST_IF_SKIP_SORT_ORDER/CREATE_SORT_INDEX
4213#
4214CREATE TABLE t1 (
4215pk        INT AUTO_INCREMENT,
4216c_int_key INT,
4217PRIMARY KEY (pk),
4218KEY (c_int_key)
4219)
4220ENGINE=innodb;
4221CREATE VIEW v_t1 AS SELECT * FROM t1;
4222CREATE TABLE t2 (
4223pk              INT auto_increment,
4224c_varchar_600_x VARCHAR(600),
4225c_int_key       INT,
4226c_varchar_600_y VARCHAR(600),
4227c_varchar_600_z VARCHAR(600),
4228PRIMARY KEY (pk),
4229KEY (c_int_key)
4230)
4231ENGINE=innodb;
4232CREATE VIEW v_t2 AS SELECT * FROM t2;
4233INSERT INTO t2 VALUES
4234(
4235NULL,
4236repeat('x', 600),
42373,
4238repeat('y', 600),
4239repeat('z', 600)
4240);
4241SELECT a1.pk AS f1
4242FROM v_t1 AS a1 LEFT JOIN v_t2 AS a2 ON a1.pk=a2.c_int_key
4243WHERE
4244a1.pk > 8
4245OR ((a1.pk BETWEEN 9 AND 13) AND a1.pk = 90)
4246ORDER BY f1 ;
4247f1
4248DROP TABLE t1, t2;
4249DROP VIEW v_t1, v_t2;
4250#
4251# Bug#13783777 CONSTANT PROPAGATION IS WRONG FOR
4252#              DISJUNCTIVE PREDICATES IN VIEWS
4253#
4254CREATE TABLE t1 (
4255pk INTEGER,
4256PRIMARY KEY (pk)
4257);
4258INSERT INTO t1 VALUES (1), (2);
4259CREATE VIEW v_t1 AS SELECT * FROM t1;
4260SELECT pk
4261FROM t1
4262WHERE
4263pk > 8
4264OR ((pk BETWEEN 9 AND 13) AND pk = 90)
4265;
4266pk
4267SELECT pk
4268FROM v_t1
4269WHERE
4270pk > 8
4271OR ((pk BETWEEN 9 AND 13) AND pk = 90)
4272;
4273pk
4274DROP VIEW v_t1;
4275DROP TABLE t1;
4276#
4277# WL#5275 Process subqueries in FROM clause in the same way as view
4278#
4279CREATE TABLE t1(a INTEGER, b INTEGER);
4280CREATE TABLE t2(a INTEGER, b INTEGER);
4281INSERT INTO t1 VALUES(1, 10), (2, 20);
4282INSERT INTO t2 VALUES(1, 100), (2, 200);
4283CREATE VIEW v2 AS SELECT * FROM t2;
4284CREATE VIEW v2_sj AS SELECT * FROM t2
4285WHERE a IN (SELECT a FROM t1);
4286CREATE VIEW v12_1 AS SELECT t2.a, t2.b FROM t1 JOIN t2 USING (a);
4287CREATE VIEW v12_2 AS SELECT t1.a, t2.b FROM t1 JOIN t2 USING (a);
4288CREATE VIEW v12_3 AS SELECT t2.a, t2.b FROM t1 JOIN t2 USING (a)
4289WHERE t1.b > 15;
4290CREATE VIEW vu_1 AS SELECT * FROM t2 UNION SELECT * FROM t2;
4291CREATE VIEW vu_2 AS SELECT * FROM t2 UNION ALL SELECT * FROM t2;
4292CREATE VIEW vd_1 AS SELECT DISTINCT a, b FROM t2;
4293CREATE VIEW va_1 AS SELECT SUM(a) AS a, SUM(b) AS b FROM t2;
4294CREATE VIEW vg_1 AS SELECT a, SUM(b) AS b FROM t2 GROUP BY a;
4295CREATE VIEW vh_1 AS SELECT 1 AS a FROM t2 HAVING COUNT(*) > 1;
4296CREATE VIEW vl_1 AS SELECT * FROM t2 LIMIT 1;
4297CREATE VIEW vlo_1 AS SELECT * FROM t2 LIMIT 2 OFFSET 1;
4298CREATE VIEW vrow AS SELECT 1 AS a;
4299CREATE VIEW vo_1 AS SELECT * FROM t2 ORDER BY a;
4300CREATE VIEW vo_2 AS SELECT * FROM t2 ORDER BY a DESC;
4301CREATE VIEW vx AS SELECT a, (SELECT b) AS b FROM t2;
4302SELECT *
4303FROM t1 JOIN v2 AS dt ON t1.a=dt.a;
4304a	b	a	b
43051	10	1	100
43062	20	2	200
4307explain SELECT *
4308FROM t1 JOIN v2 AS dt ON t1.a=dt.a;
4309id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43101	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
43111	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4312Warnings:
4313Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)
4314SELECT *
4315FROM t1, v2 AS dt WHERE t1.a=dt.a;
4316a	b	a	b
43171	10	1	100
43182	20	2	200
4319explain SELECT *
4320FROM t1, v2 AS dt WHERE t1.a=dt.a;
4321id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43221	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
43231	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4324Warnings:
4325Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)
4326SELECT *
4327FROM (t1 JOIN t2 ON t1.a=t2.a) JOIN v2 AS dt ON t1.a=dt.a;
4328a	b	a	b	a	b
43291	10	1	100	1	100
43302	20	2	200	2	200
4331explain SELECT *
4332FROM (t1 JOIN t2 ON t1.a=t2.a) JOIN v2 AS dt ON t1.a=dt.a;
4333id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43341	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
43351	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43361	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4337Warnings:
4338Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t2`.`a` = `test`.`t1`.`a`))
4339SELECT *
4340FROM t1 JOIN v12_1 AS dt ON t1.a=dt.a;
4341a	b	a	b
43421	10	1	100
43432	20	2	200
4344explain SELECT *
4345FROM t1 JOIN v12_1 AS dt ON t1.a=dt.a;
4346id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43471	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
43481	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43491	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4350Warnings:
4351Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t1`.`a`) and (`test`.`t2`.`a` = `test`.`t1`.`a`))
4352SELECT *
4353FROM (t1 JOIN t2 USING (a))
4354JOIN v12_1 AS dt
4355ON t1.a=dt.a;
4356a	b	b	a	b
43571	10	100	1	100
43582	20	200	2	200
4359explain SELECT *
4360FROM (t1 JOIN t2 USING (a))
4361JOIN v12_1 AS dt
4362ON t1.a=dt.a;
4363id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43641	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
43651	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43661	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43671	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4368Warnings:
4369Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`a` = `test`.`t1`.`a`) and (`test`.`t2`.`a` = `test`.`t1`.`a`))
4370SELECT *
4371FROM (t1 JOIN t2 USING (a))
4372JOIN v12_2 AS dt1
4373ON t1.a=dt1.a AND t2.b=dt1.b
4374JOIN v12_1 AS dt2
4375ON dt1.a=dt2.a;
4376a	b	b	a	b	a	b
43771	10	100	1	100	1	100
43782	20	200	2	200	2	200
4379explain SELECT *
4380FROM (t1 JOIN t2 USING (a))
4381JOIN v12_2 AS dt1
4382ON t1.a=dt1.a AND t2.b=dt1.b
4383JOIN v12_1 AS dt2
4384ON dt1.a=dt2.a;
4385id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
43861	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
43871	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43881	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43891	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43901	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
43911	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4392Warnings:
4393Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t1` join `test`.`t2` join `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t2`.`b`) and (`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`a` = `test`.`t1`.`a`) and (`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`a` = `test`.`t1`.`a`) and (`test`.`t2`.`a` = `test`.`t1`.`a`))
4394SELECT *
4395FROM t1 JOIN v12_3 AS dt ON t1.a=dt.a;
4396a	b	a	b
43972	20	2	200
4398explain SELECT *
4399FROM t1 JOIN v12_3 AS dt ON t1.a=dt.a;
4400id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44011	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
44021	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
44031	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4404Warnings:
4405Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t1`.`a`) and (`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`b` > 15))
4406SELECT *
4407FROM t1 JOIN v2_sj AS dt ON t1.a=dt.a;
4408a	b	a	b
44091	10	1	100
44102	20	2	200
4411explain SELECT *
4412FROM t1 JOIN v2_sj AS dt ON t1.a=dt.a;
4413id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44141	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
44151	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
44161	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; FirstMatch(t2); Using join buffer (Block Nested Loop)
4417Warnings:
4418Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join (`test`.`t1`) join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`a` = `test`.`t1`.`a`))
4419SELECT *
4420FROM t1 JOIN vu_1 AS dt ON t1.a=dt.a;
4421a	b	a	b
44221	10	1	100
44232	20	2	200
4424explain SELECT *
4425FROM t1 JOIN vu_1 AS dt ON t1.a=dt.a;
4426id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44271	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
44281	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.t1.a	2	100.00	NULL
44292	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
44303	UNION	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
4431NULL	UNION RESULT	<union2,3>	NULL	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Using temporary
4432Warnings:
4433Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`dt`.`a` AS `a`,`dt`.`b` AS `b` from `test`.`t1` join `test`.`vu_1` `dt` where (`dt`.`a` = `test`.`t1`.`a`)
4434SELECT *
4435FROM t1 JOIN vu_2 AS dt ON t1.a=dt.a;
4436a	b	a	b
44371	10	1	100
44381	10	1	100
44392	20	2	200
44402	20	2	200
4441explain SELECT *
4442FROM t1 JOIN vu_2 AS dt ON t1.a=dt.a;
4443id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44441	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
44451	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.t1.a	2	100.00	NULL
44462	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
44473	UNION	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
4448Warnings:
4449Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`dt`.`a` AS `a`,`dt`.`b` AS `b` from `test`.`t1` join `test`.`vu_2` `dt` where (`dt`.`a` = `test`.`t1`.`a`)
4450SELECT *
4451FROM t1 JOIN vd_1 AS dt ON t1.a=dt.a;
4452a	b	a	b
44531	10	1	100
44542	20	2	200
4455explain SELECT *
4456FROM t1 JOIN vd_1 AS dt ON t1.a=dt.a;
4457id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44581	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
44591	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.t1.a	2	100.00	NULL
44602	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary
4461Warnings:
4462Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`dt`.`a` AS `a`,`dt`.`b` AS `b` from `test`.`t1` join `test`.`vd_1` `dt` where (`dt`.`a` = `test`.`t1`.`a`)
4463SELECT *
4464FROM t1 JOIN va_1 AS dt ON t1.a=dt.a;
4465a	b	a	b
4466explain SELECT *
4467FROM t1 JOIN va_1 AS dt ON t1.a=dt.a;
4468id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44691	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
44701	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
44712	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
4472Warnings:
4473Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,'3' AS `a`,'300' AS `b` from `test`.`t1` where (`test`.`t1`.`a` = '3')
4474SELECT *
4475FROM t1 JOIN vg_1 AS dt ON t1.a=dt.a;
4476a	b	a	b
44771	10	1	100
44782	20	2	200
4479explain SELECT *
4480FROM t1 JOIN vg_1 AS dt ON t1.a=dt.a;
4481id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44821	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
44831	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.t1.a	2	100.00	NULL
44842	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort
4485Warnings:
4486Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`dt`.`a` AS `a`,`dt`.`b` AS `b` from `test`.`t1` join `test`.`vg_1` `dt` where (`dt`.`a` = `test`.`t1`.`a`)
4487SELECT *
4488FROM t1 JOIN vh_1 AS dt ON t1.a=dt.a;
4489a	b	a
44901	10	1
4491explain SELECT *
4492FROM t1 JOIN vh_1 AS dt ON t1.a=dt.a;
4493id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
44941	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
44952	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
4496Warnings:
4497Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,NULL AS `a` from `test`.`t1` join `test`.`vh_1` `dt` where multiple equal(`test`.`t1`.`a`, NULL)
4498SELECT *
4499FROM t1 JOIN vl_1 AS dt ON t1.a=dt.a;
4500a	b	a	b
45011	10	1	100
4502explain SELECT *
4503FROM t1 JOIN vl_1 AS dt ON t1.a=dt.a;
4504id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45051	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
45061	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
45072	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
4508Warnings:
4509Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,'1' AS `a`,'100' AS `b` from `test`.`t1` where (`test`.`t1`.`a` = '1')
4510SELECT *
4511FROM t1 JOIN vlo_1 AS dt ON t1.a=dt.a;
4512a	b	a	b
45132	20	2	200
4514explain SELECT *
4515FROM t1 JOIN vlo_1 AS dt ON t1.a=dt.a;
4516id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45171	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
45181	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.t1.a	2	100.00	NULL
45192	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
4520Warnings:
4521Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`dt`.`a` AS `a`,`dt`.`b` AS `b` from `test`.`t1` join `test`.`vlo_1` `dt` where (`dt`.`a` = `test`.`t1`.`a`)
4522SELECT *
4523FROM t1 JOIN vrow AS dt ON t1.a=dt.a;
4524a	b	a
45251	10	1
4526explain SELECT *
4527FROM t1 JOIN vrow AS dt ON t1.a=dt.a;
4528id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45291	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
45301	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where
45312	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
4532Warnings:
4533Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,'1' AS `a` from `test`.`t1` where (`test`.`t1`.`a` = '1')
4534SELECT *
4535FROM vo_1 AS dt;
4536a	b
45371	100
45382	200
4539explain SELECT *
4540FROM vo_1 AS dt;
4541id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45421	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using filesort
4543Warnings:
4544Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`a`
4545SELECT *
4546FROM vo_2 AS dt;
4547a	b
45482	200
45491	100
4550explain SELECT *
4551FROM vo_2 AS dt;
4552id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45531	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using filesort
4554Warnings:
4555Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`a` desc
4556SELECT *
4557FROM vo_1 AS dt
4558WHERE dt.a > 0;
4559a	b
45601	100
45612	200
4562explain SELECT *
4563FROM vo_1 AS dt
4564WHERE dt.a > 0;
4565id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45661	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using filesort
4567Warnings:
4568Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` > 0) order by `test`.`t2`.`a`
4569SELECT *
4570FROM vo_2 AS dt
4571WHERE dt.a > 0;
4572a	b
45732	200
45741	100
4575explain SELECT *
4576FROM vo_2 AS dt
4577WHERE dt.a > 0;
4578id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45791	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using filesort
4580Warnings:
4581Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` > 0) order by `test`.`t2`.`a` desc
4582SELECT *
4583FROM t1 JOIN vo_1 AS dt ON t1.a=dt.a;
4584a	b	a	b
45851	10	1	100
45862	20	2	200
4587explain SELECT *
4588FROM t1 JOIN vo_1 AS dt ON t1.a=dt.a;
4589id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
45901	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
45911	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4592Warnings:
4593Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)
4594SELECT *
4595FROM t1 JOIN vo_2 AS dt ON t1.a=dt.a;
4596a	b	a	b
45971	10	1	100
45982	20	2	200
4599explain SELECT *
4600FROM t1 JOIN vo_2 AS dt ON t1.a=dt.a;
4601id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46021	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
46031	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4604Warnings:
4605Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)
4606SELECT dt.a, COUNT(*)
4607FROM vo_1 AS dt
4608GROUP BY dt.a;
4609a	COUNT(*)
46101	1
46112	1
4612explain SELECT dt.a, COUNT(*)
4613FROM vo_1 AS dt
4614GROUP BY dt.a;
4615id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46161	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort
4617Warnings:
4618Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,count(0) AS `COUNT(*)` from `test`.`t2` group by `test`.`t2`.`a`
4619SELECT dt.a, COUNT(*)
4620FROM vo_2 AS dt
4621GROUP BY dt.a;
4622a	COUNT(*)
46231	1
46242	1
4625explain SELECT dt.a, COUNT(*)
4626FROM vo_2 AS dt
4627GROUP BY dt.a;
4628id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46291	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort
4630Warnings:
4631Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a`,count(0) AS `COUNT(*)` from `test`.`t2` group by `test`.`t2`.`a`
4632SELECT COUNT(*)
4633FROM vo_1 AS dt;
4634COUNT(*)
46352
4636explain SELECT COUNT(*)
4637FROM vo_1 AS dt;
4638id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46391	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
4640Warnings:
4641Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t2`
4642SELECT COUNT(*)
4643FROM vo_2 AS dt;
4644COUNT(*)
46452
4646explain SELECT COUNT(*)
4647FROM vo_2 AS dt;
4648id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46491	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
4650Warnings:
4651Note	1003	/* select#1 */ select count(0) AS `COUNT(*)` from `test`.`t2`
4652SELECT DISTINCT *
4653FROM vo_1 AS dt;
4654a	b
46551	100
46562	200
4657explain SELECT DISTINCT *
4658FROM vo_1 AS dt;
4659id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46601	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary
4661Warnings:
4662Note	1003	/* select#1 */ select distinct `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2`
4663SELECT DISTINCT *
4664FROM vo_2 AS dt;
4665a	b
46661	100
46672	200
4668explain SELECT DISTINCT *
4669FROM vo_2 AS dt;
4670id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46711	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary
4672Warnings:
4673Note	1003	/* select#1 */ select distinct `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2`
4674SELECT *
4675FROM t1 JOIN vo_1 AS dt ON t1.a=dt.a
4676ORDER BY t1.b;
4677a	b	a	b
46781	10	1	100
46792	20	2	200
4680explain SELECT *
4681FROM t1 JOIN vo_1 AS dt ON t1.a=dt.a
4682ORDER BY t1.b;
4683id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46841	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort
46851	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4686Warnings:
4687Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`) order by `test`.`t1`.`b`
4688SELECT *
4689FROM t1 JOIN vo_2 AS dt ON t1.a=dt.a
4690ORDER BY t1.b;
4691a	b	a	b
46921	10	1	100
46932	20	2	200
4694explain SELECT *
4695FROM t1 JOIN vo_2 AS dt ON t1.a=dt.a
4696ORDER BY t1.b;
4697id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
46981	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort
46991	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4700Warnings:
4701Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`) order by `test`.`t1`.`b`
4702SELECT *
4703FROM t1 JOIN vx AS dt ON t1.a=dt.a;
4704a	b	a	b
47051	10	1	100
47062	20	2	200
4707explain SELECT *
4708FROM t1 JOIN vx AS dt ON t1.a=dt.a;
4709id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47101	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
47111	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.t1.a	2	100.00	NULL
47122	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
47133	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
4714Warnings:
4715Note	1276	Field or reference 'test.t2.b' of SELECT #3 was resolved in SELECT #2
4716Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`dt`.`a` AS `a`,`dt`.`b` AS `b` from `test`.`t1` join `test`.`vx` `dt` where (`dt`.`a` = `test`.`t1`.`a`)
4717SET @optimizer_switch_saved= @@optimizer_switch;
4718SET @@optimizer_switch="derived_merge=off";
4719SELECT *
4720FROM (t1 JOIN t2 USING (a))
4721JOIN v12_1 AS dt
4722ON t1.a=dt.a;
4723a	b	b	a	b
47241	10	100	1	100
47252	20	200	2	200
4726explain SELECT *
4727FROM (t1 JOIN t2 USING (a))
4728JOIN v12_1 AS dt
4729ON t1.a=dt.a;
4730id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47311	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
47321	PRIMARY	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
47331	PRIMARY	<derived2>	NULL	ref	<auto_key0>	<auto_key0>	5	test.t1.a	2	100.00	NULL
47342	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
47352	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4736Warnings:
4737Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`dt`.`a` AS `a`,`dt`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`v12_1` `dt` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`dt`.`a` = `test`.`t1`.`a`))
4738SET @@optimizer_switch="derived_merge=on";
4739SELECT *
4740FROM (t1 JOIN t2 USING (a))
4741JOIN v12_1 AS dt
4742ON t1.a=dt.a;
4743a	b	b	a	b
47441	10	100	1	100
47452	20	200	2	200
4746explain SELECT *
4747FROM (t1 JOIN t2 USING (a))
4748JOIN v12_1 AS dt
4749ON t1.a=dt.a;
4750id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47511	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
47521	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
47531	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
47541	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	2	50.00	Using where; Using join buffer (Block Nested Loop)
4755Warnings:
4756Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`a` = `test`.`t1`.`a`) and (`test`.`t2`.`a` = `test`.`t1`.`a`))
4757SET @@optimizer_switch= @optimizer_switch_saved;
4758DROP VIEW v2, v2_sj, v12_1, v12_2, v12_3;
4759DROP VIEW vu_1, vu_2, vd_1, va_1, vg_1, vh_1, vl_1;
4760DROP VIEW vlo_1, vrow, vo_1, vo_2, vx;
4761DROP TABLE t1, t2;
4762CREATE TABLE t1(a INTEGER, b INTEGER);
4763CREATE TABLE t2(a INTEGER);
4764INSERT INTO t1 VALUES
4765(1, 10),
4766(2, 20), (2, 21),
4767(3, NULL),
4768(4, 40), (4, 41), (4, 42), (4, 43), (4, 44);
4769INSERT INTO t2 VALUES (1), (2), (3), (4), (5), (NULL);
4770CREATE VIEW v1 AS
4771SELECT * FROM (SELECT * FROM t2) AS dt;
4772SELECT * FROM v1;
4773a
47741
47752
47763
47774
47785
4779NULL
4780SELECT * FROM (SELECT * FROM t2) AS dt;
4781a
47821
47832
47843
47854
47865
4787NULL
4788explain SELECT * FROM v1;
4789id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47901	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
4791Warnings:
4792Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2`
4793explain SELECT * FROM (SELECT * FROM t2) AS dt;
4794id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47951	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
4796Warnings:
4797Note	1003	/* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2`
4798DROP VIEW v1;
4799CREATE VIEW v1 AS
4800SELECT * FROM (SELECT * FROM t1 WHERE b=a*10) AS dt;
4801SELECT * FROM v1;
4802a	b
48031	10
48042	20
48054	40
4806SELECT * FROM (SELECT * FROM t1 WHERE b=a*10) AS dt;
4807a	b
48081	10
48092	20
48104	40
4811explain SELECT * FROM v1;
4812id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48131	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
4814Warnings:
4815Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`b` = (`test`.`t1`.`a` * 10))
4816explain SELECT * FROM (SELECT * FROM t1 WHERE b=a*10) AS dt;
4817id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48181	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
4819Warnings:
4820Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`b` = (`test`.`t1`.`a` * 10))
4821DROP VIEW v1;
4822CREATE VIEW v1 AS
4823SELECT * FROM (SELECT a, SUM(b) AS s, COUNT(*) AS c FROM t1 GROUP BY a ORDER BY a) AS dt;
4824SELECT * FROM v1;
4825a	s	c
48261	10	1
48272	41	2
48283	NULL	1
48294	210	5
4830SELECT * FROM (SELECT a, SUM(b) AS s, COUNT(*) AS c FROM t1 GROUP BY a ORDER BY a) AS dt;
4831a	s	c
48321	10	1
48332	41	2
48343	NULL	1
48354	210	5
4836explain SELECT * FROM v1;
4837id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48381	PRIMARY	<derived3>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
48393	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
4840Warnings:
4841Note	1003	/* select#1 */ select `dt`.`a` AS `a`,`dt`.`s` AS `s`,`dt`.`c` AS `c` from (/* select#3 */ select `test`.`t1`.`a` AS `a`,sum(`test`.`t1`.`b`) AS `s`,count(0) AS `c` from `test`.`t1` group by `test`.`t1`.`a` order by `test`.`t1`.`a`) `dt`
4842explain SELECT * FROM (SELECT a, SUM(b) AS s, COUNT(*) AS c FROM t1 GROUP BY a ORDER BY a) AS dt;
4843id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48441	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
48452	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
4846Warnings:
4847Note	1003	/* select#1 */ select `dt`.`a` AS `a`,`dt`.`s` AS `s`,`dt`.`c` AS `c` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,sum(`test`.`t1`.`b`) AS `s`,count(0) AS `c` from `test`.`t1` group by `test`.`t1`.`a` order by `test`.`t1`.`a`) `dt`
4848DROP VIEW v1;
4849CREATE VIEW v1 AS
4850SELECT * FROM (SELECT DISTINCT a FROM t1) AS dt;
4851SELECT * FROM v1;
4852a
48531
48542
48553
48564
4857SELECT * FROM (SELECT DISTINCT a FROM t1) AS dt;
4858a
48591
48602
48613
48624
4863explain SELECT * FROM v1;
4864id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48651	PRIMARY	<derived3>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
48663	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary
4867Warnings:
4868Note	1003	/* select#1 */ select `dt`.`a` AS `a` from (/* select#3 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt`
4869explain SELECT * FROM (SELECT DISTINCT a FROM t1) AS dt;
4870id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48711	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
48722	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary
4873Warnings:
4874Note	1003	/* select#1 */ select `dt`.`a` AS `a` from (/* select#2 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt`
4875DROP VIEW v1;
4876CREATE VIEW v1 AS
4877SELECT * FROM (SELECT * FROM t1 LIMIT 3 OFFSET 3) AS dt;
4878SELECT * FROM v1;
4879a	b
48803	NULL
48814	40
48824	41
4883SELECT * FROM (SELECT * FROM t1 LIMIT 3 OFFSET 3) AS dt;
4884a	b
48853	NULL
48864	40
48874	41
4888explain SELECT * FROM v1;
4889id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48901	PRIMARY	<derived3>	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
48913	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
4892Warnings:
4893Note	1003	/* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b` from (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` limit 3,3) `dt`
4894explain SELECT * FROM (SELECT * FROM t1 LIMIT 3 OFFSET 3) AS dt;
4895id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48961	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
48972	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
4898Warnings:
4899Note	1003	/* select#1 */ select `dt`.`a` AS `a`,`dt`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` limit 3,3) `dt`
4900DROP VIEW v1;
4901CREATE VIEW v1 AS
4902SELECT * FROM (SELECT DISTINCT a FROM t1 UNION ALL SELECT a FROM t2) AS dt;
4903SELECT * FROM v1;
4904a
49051
49062
49073
49084
49091
49102
49113
49124
49135
4914NULL
4915SELECT * FROM (SELECT DISTINCT a FROM t1 UNION ALL SELECT a FROM t2) AS dt;
4916a
49171
49182
49193
49204
49211
49222
49233
49244
49255
4926NULL
4927explain SELECT * FROM v1;
4928id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49291	PRIMARY	<derived3>	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	NULL
49303	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary
49314	UNION	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
4932Warnings:
4933Note	1003	/* select#1 */ select `dt`.`a` AS `a` from (/* select#3 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1` union all /* select#4 */ select `test`.`t2`.`a` AS `a` from `test`.`t2`) `dt`
4934explain SELECT * FROM (SELECT DISTINCT a FROM t1 UNION ALL SELECT a FROM t2) AS dt;
4935id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49361	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	15	100.00	NULL
49372	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary
49383	UNION	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	NULL
4939Warnings:
4940Note	1003	/* select#1 */ select `dt`.`a` AS `a` from (/* select#2 */ select distinct `test`.`t1`.`a` AS `a` from `test`.`t1` union all /* select#3 */ select `test`.`t2`.`a` AS `a` from `test`.`t2`) `dt`
4941DROP VIEW v1;
4942CREATE VIEW v1 AS
4943SELECT * FROM (SELECT * FROM t1 WHERE (SELECT a FROM t1 LIMIT 1) = b/10) AS dt;
4944SELECT * FROM v1;
4945a	b
49461	10
4947SELECT * FROM (SELECT * FROM t1 WHERE (SELECT a FROM t1 LIMIT 1) = b/10) AS dt;
4948a	b
49491	10
4950explain SELECT * FROM v1;
4951id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49521	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using where
49534	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
4954Warnings:
4955Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((/* select#4 */ select `test`.`t1`.`a` from `test`.`t1` limit 1) = (`test`.`t1`.`b` / 10))
4956explain SELECT * FROM (SELECT * FROM t1 WHERE (SELECT a FROM t1 LIMIT 1) = b/10) AS dt;
4957id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49581	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using where
49593	SUBQUERY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
4960Warnings:
4961Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((/* select#3 */ select `test`.`t1`.`a` from `test`.`t1` limit 1) = (`test`.`t1`.`b` / 10))
4962DROP VIEW v1;
4963CREATE VIEW v1 AS
4964SELECT * FROM (SELECT * FROM t1 WHERE a IN (SELECT a FROM t2 WHERE a % 2 = 0)) AS dt;
4965SELECT * FROM v1;
4966a	b
49672	20
49682	21
49694	40
49704	41
49714	42
49724	43
49734	44
4974SELECT * FROM (SELECT * FROM t1 WHERE a IN (SELECT a FROM t2 WHERE a % 2 = 0)) AS dt;
4975a	b
49762	20
49772	21
49784	40
49794	41
49804	42
49814	43
49824	44
4983explain SELECT * FROM v1;
4984id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49851	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using where; Start temporary
49861	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where; End temporary; Using join buffer (Block Nested Loop)
4987Warnings:
4988Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and ((`test`.`t2`.`a` % 2) = 0))
4989explain SELECT * FROM (SELECT * FROM t1 WHERE a IN (SELECT a FROM t2 WHERE a % 2 = 0)) AS dt;
4990id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
49911	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Using where; Start temporary
49921	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where; End temporary; Using join buffer (Block Nested Loop)
4993Warnings:
4994Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and ((`test`.`t2`.`a` % 2) = 0))
4995DROP VIEW v1;
4996CREATE VIEW v1 AS
4997SELECT * FROM (SELECT a, (SELECT a FROM t2 WHERE a=t1.a)
4998FROM t1 WHERE b IN (SELECT a*10 FROM t2)) AS dt;
4999SELECT * FROM v1;
5000a	(SELECT a FROM t2 WHERE a=t1.a)
50011	1
50022	2
50034	4
5004SELECT * FROM (SELECT a, (SELECT a FROM t2 WHERE a=t1.a)
5005FROM t1 WHERE b IN (SELECT a*10 FROM t2)) AS dt;
5006a	(SELECT a FROM t2 WHERE a=t1.a)
50071	1
50082	2
50094	4
5010explain SELECT * FROM v1;
5011id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50121	PRIMARY	<derived3>	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
50133	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Start temporary
50143	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where; End temporary; Using join buffer (Block Nested Loop)
50155	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5016Warnings:
5017Note	1276	Field or reference 'test.t1.a' of SELECT #5 was resolved in SELECT #3
5018Note	1003	/* select#1 */ select `dt`.`a` AS `a`,`dt`.`(SELECT a FROM t2 WHERE a=t1.a)` AS `(SELECT a FROM t2 WHERE a=t1.a)` from (/* select#3 */ select `test`.`t1`.`a` AS `a`,(/* select#5 */ select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)) AS `(SELECT a FROM t2 WHERE a=t1.a)` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t1`.`b` = (`test`.`t2`.`a` * 10))) `dt`
5019explain SELECT * FROM (SELECT a, (SELECT a FROM t2 WHERE a=t1.a)
5020FROM t1 WHERE b IN (SELECT a*10 FROM t2)) AS dt;
5021id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50221	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
50232	DERIVED	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Start temporary
50242	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where; End temporary; Using join buffer (Block Nested Loop)
50253	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5026Warnings:
5027Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5028Note	1003	/* select#1 */ select `dt`.`a` AS `a`,`dt`.`(SELECT a FROM t2 WHERE a=t1.a)` AS `(SELECT a FROM t2 WHERE a=t1.a)` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,(/* select#3 */ select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)) AS `(SELECT a FROM t2 WHERE a=t1.a)` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t1`.`b` = (`test`.`t2`.`a` * 10))) `dt`
5029DROP VIEW v1;
5030CREATE VIEW v1 AS
5031SELECT * FROM (SELECT a, (SELECT a FROM t2) FROM t1 WHERE b=a*10) AS dt;
5032SELECT * FROM v1;
5033ERROR 21000: Subquery returns more than 1 row
5034SELECT * FROM (SELECT a, (SELECT a FROM t2) FROM t1 WHERE b=a*10) AS dt;
5035ERROR 21000: Subquery returns more than 1 row
5036DROP VIEW v1;
5037CREATE VIEW v1 AS
5038SELECT * FROM (SELECT a, b FROM t1 WHERE b IN (SELECT a*10 FROM t2)) AS dt;
5039SELECT * FROM v1 JOIN t2 ON v1.a=t2.a;
5040a	b	a
50411	10	1
50422	20	2
50434	40	4
5044SELECT * FROM (SELECT a, b FROM t1 WHERE b IN (SELECT a*10 FROM t2)) AS dt JOIN t2 ON dt.a=t2.a;
5045a	b	a
50461	10	1
50472	20	2
50484	40	4
5049explain SELECT * FROM v1 JOIN t2 ON v1.a=t2.a;
5050id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50511	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Start temporary
50521	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where; End temporary; Using join buffer (Block Nested Loop)
50531	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where; Using join buffer (Block Nested Loop)
5054Warnings:
5055Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`b` = (`test`.`t2`.`a` * 10)))
5056explain SELECT * FROM (SELECT a, b FROM t1 WHERE b IN (SELECT a*10 FROM t2)) AS dt JOIN t2 ON dt.a=t2.a;
5057id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
50581	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	100.00	Start temporary
50591	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where; End temporary; Using join buffer (Block Nested Loop)
50601	SIMPLE	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where; Using join buffer (Block Nested Loop)
5061Warnings:
5062Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` where ((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t1`.`b` = (`test`.`t2`.`a` * 10)))
5063DROP VIEW v1;
5064DROP TABLE t1, t2;
5065CREATE TABLE t1(a INTEGER, b INTEGER);
5066CREATE TABLE t2(a INTEGER);
5067INSERT INTO t1 VALUES
5068(1, 10),
5069(2, 20), (2, 21),
5070(3, NULL),
5071(4, 40), (4, 41), (4, 42), (4, 43), (4, 44);
5072INSERT INTO t2 VALUES (1), (2), (3), (4), (5), (NULL);
5073CREATE VIEW v1 AS SELECT a, b, (SELECT 1 FROM t2 WHERE a=3) AS s
5074FROM t1;
5075SELECT * FROM v1;
5076a	b	s
50771	10	1
50782	20	1
50792	21	1
50803	NULL	1
50814	40	1
50824	41	1
50834	42	1
50844	43	1
50854	44	1
5086SELECT a FROM v1;
5087a
50881
50892
50902
50913
50924
50934
50944
50954
50964
5097SELECT a, b, (SELECT 1 FROM t2 WHERE a=3) AS s
5098FROM t1;
5099a	b	s
51001	10	1
51012	20	1
51022	21	1
51033	NULL	1
51044	40	1
51054	41	1
51064	42	1
51074	43	1
51084	44	1
5109explain SELECT * FROM v1;
5110id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
51111	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
51123	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5113Warnings:
5114Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#3 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = 3)) AS `s` from `test`.`t1`
5115explain SELECT a FROM v1;
5116id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
51171	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
5118Warnings:
5119Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`
5120explain SELECT a, b, (SELECT 1 FROM t2 WHERE a=3) AS s
5121FROM t1;
5122id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
51231	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
51242	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5125Warnings:
5126Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#2 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = 3)) AS `s` from `test`.`t1`
5127DROP VIEW v1;
5128CREATE VIEW v1 AS SELECT a, b, (SELECT 1 FROM t2 WHERE a=6) AS s
5129FROM t1;
5130SELECT * FROM v1;
5131a	b	s
51321	10	NULL
51332	20	NULL
51342	21	NULL
51353	NULL	NULL
51364	40	NULL
51374	41	NULL
51384	42	NULL
51394	43	NULL
51404	44	NULL
5141SELECT a FROM v1;
5142a
51431
51442
51452
51463
51474
51484
51494
51504
51514
5152SELECT a, b, (SELECT 1 FROM t2 WHERE a=6) AS s
5153FROM t1;
5154a	b	s
51551	10	NULL
51562	20	NULL
51572	21	NULL
51583	NULL	NULL
51594	40	NULL
51604	41	NULL
51614	42	NULL
51624	43	NULL
51634	44	NULL
5164explain SELECT * FROM v1;
5165id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
51661	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
51673	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5168Warnings:
5169Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#3 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = 6)) AS `s` from `test`.`t1`
5170explain SELECT a FROM v1;
5171id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
51721	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
5173Warnings:
5174Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`
5175explain SELECT a, b, (SELECT 1 FROM t2 WHERE a=6) AS s
5176FROM t1;
5177id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
51781	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
51792	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5180Warnings:
5181Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#2 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = 6)) AS `s` from `test`.`t1`
5182DROP VIEW v1;
5183CREATE VIEW v1 AS SELECT a, b, (SELECT 1 FROM t2 WHERE a>=3) AS s
5184FROM t1;
5185SELECT * FROM v1;
5186ERROR 21000: Subquery returns more than 1 row
5187SELECT a FROM v1;
5188a
51891
51902
51912
51923
51934
51944
51954
51964
51974
5198SELECT a, b, (SELECT 1 FROM t2 WHERE a>=3) AS s
5199FROM t1;
5200ERROR 21000: Subquery returns more than 1 row
5201explain SELECT a FROM v1;
5202id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52031	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
5204Warnings:
5205Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`
5206DROP VIEW v1;
5207CREATE VIEW v1 AS SELECT a, b, a IN (SELECT 1 FROM t2 WHERE a=6) AS s
5208FROM t1;
5209SELECT * FROM v1;
5210a	b	s
52111	10	0
52122	20	0
52132	21	0
52143	NULL	0
52154	40	0
52164	41	0
52174	42	0
52184	43	0
52194	44	0
5220SELECT a FROM v1;
5221a
52221
52232
52242
52253
52264
52274
52284
52294
52304
5231SELECT a, b, a IN (SELECT 1 FROM t2 WHERE a=6) AS s
5232FROM t1;
5233a	b	s
52341	10	0
52352	20	0
52362	21	0
52373	NULL	0
52384	40	0
52394	41	0
52404	42	0
52414	43	0
52424	44	0
5243explain SELECT * FROM v1;
5244id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52451	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
52462	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
52473	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5248Warnings:
5249Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`s` AS `s` from `test`.`v1`
5250explain SELECT a FROM v1;
5251id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52521	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
52532	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
52543	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5255Warnings:
5256Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5257explain SELECT a, b, a IN (SELECT 1 FROM t2 WHERE a=6) AS s
5258FROM t1;
5259id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
52601	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
52612	SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5262Warnings:
5263Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = 6) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on <auto_key> where ((`test`.`t1`.`a` = `materialized-subquery`.`1`))))) AS `s` from `test`.`t1`
5264DROP VIEW v1;
5265CREATE VIEW v1 AS SELECT a, b, (SELECT COUNT(*) FROM t2) AS c
5266FROM t1;
5267SELECT * FROM v1;
5268a	b	c
52691	10	6
52702	20	6
52712	21	6
52723	NULL	6
52734	40	6
52744	41	6
52754	42	6
52764	43	6
52774	44	6
5278SELECT a FROM v1;
5279a
52801
52812
52822
52833
52844
52854
52864
52874
52884
5289SELECT a, b, (SELECT COUNT(*) FROM t2) AS c
5290FROM t1;
5291a	b	c
52921	10	6
52932	20	6
52942	21	6
52953	NULL	6
52964	40	6
52974	41	6
52984	42	6
52994	43	6
53004	44	6
5301explain SELECT * FROM v1;
5302id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
53031	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
53043	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
5305Warnings:
5306Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#3 */ select count(0) from `test`.`t2`) AS `c` from `test`.`t1`
5307explain SELECT a FROM v1;
5308id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
53091	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
5310Warnings:
5311Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`
5312explain SELECT a, b, (SELECT COUNT(*) FROM t2) AS c
5313FROM t1;
5314id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
53151	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
53162	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
5317Warnings:
5318Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#2 */ select count(0) from `test`.`t2`) AS `c` from `test`.`t1`
5319DROP VIEW v1;
5320CREATE VIEW v1 AS SELECT a, b, a IN (SELECT COUNT(*) FROM t2) AS c
5321FROM t1;
5322SELECT * FROM v1;
5323a	b	c
53241	10	0
53252	20	0
53262	21	0
53273	NULL	0
53284	40	0
53294	41	0
53304	42	0
53314	43	0
53324	44	0
5333SELECT a FROM v1;
5334a
53351
53362
53372
53383
53394
53404
53414
53424
53434
5344SELECT a, b, a IN (SELECT COUNT(*) FROM t2) AS c
5345FROM t1;
5346a	b	c
53471	10	0
53482	20	0
53492	21	0
53503	NULL	0
53514	40	0
53524	41	0
53534	42	0
53544	43	0
53554	44	0
5356explain SELECT * FROM v1;
5357id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
53581	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
53592	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
53603	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
5361Warnings:
5362Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`c` AS `c` from `test`.`v1`
5363explain SELECT a FROM v1;
5364id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
53651	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
53662	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
53673	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
5368Warnings:
5369Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5370explain SELECT a, b, a IN (SELECT COUNT(*) FROM t2) AS c
5371FROM t1;
5372id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
53731	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
53742	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
5375Warnings:
5376Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select count(0) from `test`.`t2` having <if>(outer_field_is_not_null, (<cache>(`test`.`t1`.`a`) = <ref_null_helper>(count(0))), true))) AS `c` from `test`.`t1`
5377DROP VIEW v1;
5378CREATE VIEW v1 AS SELECT a, b, (SELECT a*2 FROM t2 WHERE a=t1.a) AS s
5379FROM t1;
5380SELECT * FROM v1;
5381a	b	s
53821	10	2
53832	20	4
53842	21	4
53853	NULL	6
53864	40	8
53874	41	8
53884	42	8
53894	43	8
53904	44	8
5391SELECT a FROM v1;
5392a
53931
53942
53952
53963
53974
53984
53994
54004
54014
5402SELECT a, b, (SELECT a*2 FROM t2 WHERE a=t1.a) AS s
5403FROM t1;
5404a	b	s
54051	10	2
54062	20	4
54072	21	4
54083	NULL	6
54094	40	8
54104	41	8
54114	42	8
54124	43	8
54134	44	8
5414explain SELECT * FROM v1;
5415id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
54161	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54172	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54183	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5419Warnings:
5420Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5421Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`s` AS `s` from `test`.`v1`
5422explain SELECT a FROM v1;
5423id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
54241	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54252	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54263	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5427Warnings:
5428Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5429Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5430explain SELECT a, b, (SELECT a*2 FROM t2 WHERE a=t1.a) AS s
5431FROM t1;
5432id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
54331	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54342	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5435Warnings:
5436Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5437Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#2 */ select (`test`.`t2`.`a` * 2) from `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)) AS `s` from `test`.`t1`
5438DROP VIEW v1;
5439CREATE VIEW v1 AS SELECT a, b, EXISTS (SELECT a*2 FROM t2 WHERE a=t1.a) AS s
5440FROM t1;
5441SELECT * FROM v1;
5442a	b	s
54431	10	1
54442	20	1
54452	21	1
54463	NULL	1
54474	40	1
54484	41	1
54494	42	1
54504	43	1
54514	44	1
5452SELECT a FROM v1;
5453a
54541
54552
54562
54573
54584
54594
54604
54614
54624
5463SELECT a, b, EXISTS (SELECT a*2 FROM t2 WHERE a=t1.a) AS s
5464FROM t1;
5465a	b	s
54661	10	1
54672	20	1
54682	21	1
54693	NULL	1
54704	40	1
54714	41	1
54724	42	1
54734	43	1
54744	44	1
5475explain SELECT * FROM v1;
5476id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
54771	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54782	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54793	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5480Warnings:
5481Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5482Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`s` AS `s` from `test`.`v1`
5483explain SELECT a FROM v1;
5484id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
54851	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54862	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54873	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5488Warnings:
5489Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5490Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5491explain SELECT a, b, EXISTS (SELECT a*2 FROM t2 WHERE a=t1.a) AS s
5492FROM t1;
5493id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
54941	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
54952	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5496Warnings:
5497Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5498Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,exists(/* select#2 */ select (`test`.`t2`.`a` * 2) from `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`a`)) AS `s` from `test`.`t1`
5499DROP VIEW v1;
5500CREATE VIEW v1 AS SELECT a, b, (SELECT COUNT(*) FROM t1 AS t2 WHERE a=t1.a) AS s
5501FROM t1;
5502SELECT * FROM v1;
5503a	b	s
55041	10	1
55052	20	2
55062	21	2
55073	NULL	1
55084	40	5
55094	41	5
55104	42	5
55114	43	5
55124	44	5
5513SELECT a FROM v1;
5514a
55151
55162
55172
55183
55194
55204
55214
55224
55234
5524SELECT a, b, (SELECT COUNT(*) FROM t1 AS t2 WHERE a=t1.a) AS s
5525FROM t1;
5526a	b	s
55271	10	1
55282	20	2
55292	21	2
55303	NULL	1
55314	40	5
55324	41	5
55334	42	5
55344	43	5
55354	44	5
5536explain SELECT * FROM v1;
5537id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
55381	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
55392	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
55403	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
5541Warnings:
5542Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5543Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`s` AS `s` from `test`.`v1`
5544explain SELECT a FROM v1;
5545id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
55461	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
55472	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
55483	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
5549Warnings:
5550Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5551Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5552explain SELECT a, b, (SELECT COUNT(*) FROM t1 AS t2 WHERE a=t1.a) AS s
5553FROM t1;
5554id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
55551	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
55562	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
5557Warnings:
5558Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5559Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,(/* select#2 */ select count(0) from `test`.`t1` `t2` where (`t2`.`a` = `test`.`t1`.`a`)) AS `s` from `test`.`t1`
5560DROP VIEW v1;
5561CREATE VIEW v1 AS SELECT a, b, EXISTS (SELECT COUNT(*) FROM t1 AS t2 WHERE a=t1.a) AS s
5562FROM t1;
5563SELECT * FROM v1;
5564a	b	s
55651	10	1
55662	20	1
55672	21	1
55683	NULL	1
55694	40	1
55704	41	1
55714	42	1
55724	43	1
55734	44	1
5574SELECT a FROM v1;
5575a
55761
55772
55782
55793
55804
55814
55824
55834
55844
5585SELECT a, b, EXISTS (SELECT COUNT(*) FROM t1 AS t2 WHERE a=t1.a) AS s
5586FROM t1;
5587a	b	s
55881	10	1
55892	20	1
55902	21	1
55913	NULL	1
55924	40	1
55934	41	1
55944	42	1
55954	43	1
55964	44	1
5597explain SELECT * FROM v1;
5598id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
55991	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56002	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56013	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
5602Warnings:
5603Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5604Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`b` AS `b`,`v1`.`s` AS `s` from `test`.`v1`
5605explain SELECT a FROM v1;
5606id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56071	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56082	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56093	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
5610Warnings:
5611Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5612Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5613explain SELECT a, b, EXISTS (SELECT COUNT(*) FROM t1 AS t2 WHERE a=t1.a) AS s
5614FROM t1;
5615id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56161	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56172	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	9	11.11	Using where
5618Warnings:
5619Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5620Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,exists(/* select#2 */ select count(0) from `test`.`t1` `t2` where (`t2`.`a` = `test`.`t1`.`a`)) AS `s` from `test`.`t1`
5621DROP VIEW v1;
5622CREATE VIEW v1 AS SELECT (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5623FROM t1;
5624SELECT * FROM v1;
5625s
56264
5627SELECT (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5628FROM t1;
5629s
56304
5631explain SELECT * FROM v1;
5632id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56331	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
56342	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56353	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5636Warnings:
5637Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5638Note	1003	/* select#1 */ select '4' AS `s` from dual
5639explain SELECT (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5640FROM t1;
5641id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56421	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56432	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5644Warnings:
5645Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5646Note	1003	/* select#1 */ select (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = floor((count(`test`.`t1`.`a`) / 2)))) AS `s` from `test`.`t1`
5647DROP VIEW v1;
5648CREATE VIEW v1 AS SELECT COUNT(*) AS a, (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5649FROM t1;
5650SELECT * FROM v1;
5651a	s
56529	4
5653SELECT a FROM v1;
5654a
56559
5656SELECT COUNT(*) AS a, (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5657FROM t1;
5658a	s
56599	4
5660explain SELECT * FROM v1;
5661id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56621	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
56632	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56643	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5665Warnings:
5666Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5667Note	1003	/* select#1 */ select '9' AS `a`,'4' AS `s` from dual
5668explain SELECT a FROM v1;
5669id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56701	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
56712	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56723	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5673Warnings:
5674Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5675Note	1003	/* select#1 */ select '9' AS `a` from dual
5676explain SELECT COUNT(*) AS a, (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5677FROM t1;
5678id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56791	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56802	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5681Warnings:
5682Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5683Note	1003	/* select#1 */ select count(0) AS `a`,(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = floor((count(`test`.`t1`.`a`) / 2)))) AS `s` from `test`.`t1`
5684DROP VIEW v1;
5685CREATE VIEW v1 AS SELECT a IN (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5686FROM t1;
5687SELECT * FROM v1;
5688s
56890
5690SELECT a IN (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5691FROM t1;
5692s
56930
5694explain SELECT * FROM v1;
5695id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
56961	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
56972	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
56983	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5699Warnings:
5700Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5701Note	1003	/* select#1 */ select '0' AS `s` from dual
5702explain SELECT a IN (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5703FROM t1;
5704id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57051	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
57062	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5707Warnings:
5708Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5709Note	1003	/* select#1 */ select <in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = floor((count(`test`.`t1`.`a`) / 2))) having <if>(outer_field_is_not_null, (<cache>(`test`.`t1`.`a`) = <ref_null_helper>(`test`.`t2`.`a`)), true))) AS `s` from `test`.`t1`
5710DROP VIEW v1;
5711CREATE VIEW v1 AS SELECT COUNT(*) AS a, a IN (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5712FROM t1;
5713SELECT * FROM v1;
5714a	s
57159	0
5716SELECT a FROM v1;
5717a
57189
5719SELECT COUNT(*) AS a, a IN (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5720FROM t1;
5721a	s
57229	0
5723explain SELECT * FROM v1;
5724id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57251	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
57262	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
57273	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5728Warnings:
5729Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5730Note	1003	/* select#1 */ select '9' AS `a`,'0' AS `s` from dual
5731explain SELECT a FROM v1;
5732id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57331	PRIMARY	<derived2>	NULL	system	NULL	NULL	NULL	NULL	1	100.00	NULL
57342	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
57353	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5736Warnings:
5737Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5738Note	1003	/* select#1 */ select '9' AS `a` from dual
5739explain SELECT COUNT(*) AS a, a IN (SELECT a FROM t2 WHERE a=FLOOR(COUNT(t1.a)/2)) AS s
5740FROM t1;
5741id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57421	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
57432	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5744Warnings:
5745Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5746Note	1003	/* select#1 */ select count(0) AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = floor((count(`test`.`t1`.`a`) / 2))) having <if>(outer_field_is_not_null, (<cache>(`test`.`t1`.`a`) = <ref_null_helper>(`test`.`t2`.`a`)), true))) AS `s` from `test`.`t1`
5747DROP VIEW v1;
5748CREATE VIEW v1 AS SELECT a, COUNT(*) AS c, (SELECT a FROM t2 WHERE a=COUNT(t1.a)) AS s
5749FROM t1
5750GROUP BY a;
5751SELECT * FROM v1;
5752a	c	s
57531	1	1
57542	2	2
57553	1	1
57564	5	5
5757SELECT a FROM v1;
5758a
57591
57602
57613
57624
5763SELECT a, COUNT(*) AS c, (SELECT a FROM t2 WHERE a=COUNT(t1.a)) AS s
5764FROM t1
5765GROUP BY a;
5766a	c	s
57671	1	1
57682	2	2
57693	1	1
57704	5	5
5771explain SELECT * FROM v1;
5772id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57731	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
57742	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
57753	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5776Warnings:
5777Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5778Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`c` AS `c`,`v1`.`s` AS `s` from `test`.`v1`
5779explain SELECT a FROM v1;
5780id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57811	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
57822	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
57833	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5784Warnings:
5785Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5786Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5787explain SELECT a, COUNT(*) AS c, (SELECT a FROM t2 WHERE a=COUNT(t1.a)) AS s
5788FROM t1
5789GROUP BY a;
5790id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
57911	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
57922	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5793Warnings:
5794Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5795Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,count(0) AS `c`,(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` where (`test`.`t2`.`a` = count(`test`.`t1`.`a`))) AS `s` from `test`.`t1` group by `test`.`t1`.`a`
5796DROP VIEW v1;
5797CREATE VIEW v1 AS SELECT a, COUNT(*) AS c, a IN (SELECT a FROM t2 WHERE a=COUNT(t1.a)) AS s
5798FROM t1
5799GROUP BY a;
5800SELECT * FROM v1;
5801a	c	s
58021	1	1
58032	2	1
58043	1	0
58054	5	0
5806SELECT a FROM v1;
5807a
58081
58092
58103
58114
5812SELECT a, COUNT(*) AS c, a IN (SELECT a FROM t2 WHERE a=COUNT(t1.a)) AS s
5813FROM t1
5814GROUP BY a;
5815a	c	s
58161	1	1
58172	2	1
58183	1	0
58194	5	0
5820explain SELECT * FROM v1;
5821id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
58221	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
58232	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
58243	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5825Warnings:
5826Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5827Note	1003	/* select#1 */ select `v1`.`a` AS `a`,`v1`.`c` AS `c`,`v1`.`s` AS `s` from `test`.`v1`
5828explain SELECT a FROM v1;
5829id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
58301	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	NULL
58312	DERIVED	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
58323	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5833Warnings:
5834Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
5835Note	1003	/* select#1 */ select `v1`.`a` AS `a` from `test`.`v1`
5836explain SELECT a, COUNT(*) AS c, a IN (SELECT a FROM t2 WHERE a=COUNT(t1.a)) AS s
5837FROM t1
5838GROUP BY a;
5839id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
58401	PRIMARY	t1	NULL	ALL	NULL	NULL	NULL	NULL	9	100.00	Using temporary; Using filesort
58412	DEPENDENT SUBQUERY	t2	NULL	ALL	NULL	NULL	NULL	NULL	6	16.67	Using where
5842Warnings:
5843Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
5844Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a`,count(0) AS `c`,<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select 1 from `test`.`t2` where (`test`.`t2`.`a` = count(`test`.`t1`.`a`)) having <if>(outer_field_is_not_null, (<cache>(`test`.`t1`.`a`) = <ref_null_helper>(`test`.`t2`.`a`)), true))) AS `s` from `test`.`t1` group by `test`.`t1`.`a`
5845DROP VIEW v1;
5846DROP TABLE t1, t2;
5847#
5848# Bug#19789450 Assert fail in add_key_field
5849#
5850CREATE TABLE t1 (
5851pk int NOT NULL,
5852col_date_key date DEFAULT NULL,
5853PRIMARY KEY (pk),
5854KEY col_date_key (col_date_key)
5855) ;
5856CREATE TABLE t2 (
5857pk int NOT NULL,
5858col_time_key time DEFAULT NULL,
5859col_datetime_key datetime DEFAULT NULL,
5860PRIMARY KEY (pk),
5861KEY col_time_key (col_time_key),
5862KEY col_datetime_key (col_datetime_key)
5863);
5864CREATE ALGORITHM=MERGE VIEW v1 AS
5865SELECT col_date_key
5866FROM t1 WHERE (pk, pk, col_date_key) IN
5867(SELECT col_datetime_key,
5868col_time_key,
5869col_time_key
5870FROM t2
5871WHERE pk <= 7);
5872SELECT * FROM v1;
5873col_date_key
5874DROP VIEW v1;
5875DROP TABLE t1, t2;
5876#
5877# BUG#14117018 - MYSQL SERVER CREATES INVALID VIEW DEFINITION
5878# BUG#18405221 - SHOW CREATE VIEW OUTPUT INCCORRECT
5879#
5880CREATE VIEW v1 AS (SELECT '' FROM DUAL);
5881CREATE VIEW v2 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL
5882(SELECT '' FROM DUAL);
5883CREATE VIEW v3 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL
5884(SELECT '' FROM DUAL) UNION ALL
5885(SELECT '' FROM DUAL);
5886CREATE VIEW v4 AS (SELECT 'BUG#14117018' AS col1 FROM DUAL) UNION ALL
5887(SELECT '' AS col2 FROM DUAL) UNION ALL
5888(SELECT '' FROM DUAL);
5889# Name for the column in select1 is set properly with or
5890# without this fix.
5891SHOW CREATE VIEW v1;
5892View	Create View	character_set_client	collation_connection
5893v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select '' AS `Name_exp_1`)	latin1	latin1_swedish_ci
5894# Name for the column in select2 is set with this fix.
5895# Without this fix, name would not have set for the
5896# columns in select2.
5897SHOW CREATE VIEW v2;
5898View	Create View	character_set_client	collation_connection
5899v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS (select 'BUG#14117018' AS `col1`) union all (select '' AS `Name_exp_2`)	latin1	latin1_swedish_ci
5900# Name for the field item in select2 & select3 is set with this fix.
5901# Without this fix, name would not have set for the
5902# columns in select2 & select3.
5903SHOW CREATE VIEW v3;
5904View	Create View	character_set_client	collation_connection
5905v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS (select 'BUG#14117018' AS `col1`) union all (select '' AS `Name_exp_2`) union all (select '' AS `Name_exp_3`)	latin1	latin1_swedish_ci
5906# Name for the field item in select3 is set with this fix.
5907# Without this fix, name would not have set for the
5908# columns in select3.
5909SHOW CREATE VIEW v4;
5910View	Create View	character_set_client	collation_connection
5911v4	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_3`)	latin1	latin1_swedish_ci
5912DROP VIEW v1, v2, v3, v4;
5913# Bug#20087932 Assert fail in Join_tab_compare_straight::operator()
5914CREATE TABLE t1 (
5915pk int NOT NULL,
5916col_varchar_key varchar(1) NOT NULL,
5917PRIMARY KEY (pk)
5918);
5919CREATE TABLE t2 (
5920pk int NOT NULL,
5921col_varchar_key varchar(1) NOT NULL,
5922col_varchar_nokey varchar(1) NOT NULL,
5923PRIMARY KEY (pk)
5924);
5925CREATE TABLE t3 (
5926pk int NOT NULL,
5927col_int_key int NOT NULL,
5928col_varchar_nokey varchar(1) NOT NULL,
5929PRIMARY KEY (pk)
5930);
5931CREATE VIEW v2 AS SELECT * FROM t2;
5932explain SELECT STRAIGHT_JOIN alias1.pk
5933FROM t2 AS alias1
5934RIGHT JOIN
5935(SELECT sq1_alias2.*
5936FROM t1 AS sq1_alias1
5937RIGHT OUTER JOIN
5938v2 AS sq1_alias2
5939ON sq1_alias2.col_varchar_key = sq1_alias1.col_varchar_key AND
5940sq1_alias2.col_varchar_nokey IN
5941(SELECT c_sq1_alias1.col_varchar_nokey AS c_sq1_field1
5942FROM t3 AS c_sq1_alias1
5943WHERE c_sq1_alias1.col_int_key <> c_sq1_alias1.col_int_key
5944)
5945) AS alias2
5946ON alias2.col_varchar_key = alias1.col_varchar_key;
5947id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	filtered	Extra
59481	PRIMARY	alias1	NULL	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
59491	PRIMARY	<derived2>	NULL	ALL	NULL	NULL	NULL	NULL	2	100.00	NULL
59502	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
5951Warnings:
5952Note	1003	/* select#1 */ select straight_join NULL AS `pk` from (/* select#2 */ select NULL AS `pk`,NULL AS `col_varchar_key`,NULL AS `col_varchar_nokey` from `test`.`t2` left join (`test`.`t1` `sq1_alias1` semi join (`test`.`t3` `c_sq1_alias1`)) on((1 and (`test`.`c_sq1_alias1`.`col_int_key` <> `test`.`c_sq1_alias1`.`col_int_key`) and multiple equal(NULL, `test`.`sq1_alias1`.`col_varchar_key`) and multiple equal(NULL, `test`.`c_sq1_alias1`.`col_varchar_nokey`)))) `alias2` where 1
5953SELECT STRAIGHT_JOIN alias1.pk
5954FROM t2 AS alias1
5955RIGHT JOIN
5956(SELECT sq1_alias2.*
5957FROM t1 AS sq1_alias1
5958RIGHT OUTER JOIN
5959v2 AS sq1_alias2
5960ON sq1_alias2.col_varchar_key = sq1_alias1.col_varchar_key AND
5961sq1_alias2.col_varchar_nokey IN
5962(SELECT c_sq1_alias1.col_varchar_nokey AS c_sq1_field1
5963FROM t3 AS c_sq1_alias1
5964WHERE c_sq1_alias1.col_int_key <> c_sq1_alias1.col_int_key
5965)
5966) AS alias2
5967ON alias2.col_varchar_key = alias1.col_varchar_key;
5968pk
5969DROP VIEW v2;
5970DROP TABLE t1, t2, t3;
5971CREATE TABLE t0(x INTEGER);
5972INSERT INTO t0 VALUES(0);
5973CREATE TABLE t1(a1 INTEGER PRIMARY KEY, b1 INTEGER);
5974CREATE TABLE t2(a2 INTEGER PRIMARY KEY, b2 INTEGER);
5975CREATE VIEW v0 AS SELECT DISTINCT x FROM t0;
5976CREATE VIEW vmat1 AS SELECT DISTINCT * FROM t1;
5977CREATE VIEW vmat2 AS SELECT DISTINCT * FROM t2;
5978CREATE VIEW vtt AS
5979SELECT * FROM t1 JOIN t2 ON t1.a1=t2.a2;
5980CREATE VIEW vtr AS
5981SELECT * FROM t1 JOIN vmat2 AS dt2 ON t1.a1=dt2.a2;
5982CREATE VIEW vtrd AS
5983SELECT * FROM t1 JOIN (SELECT DISTINCT * FROM t2) AS dt2 ON t1.a1=dt2.a2;
5984CREATE VIEW vrt AS
5985SELECT * FROM vmat1 AS dt1 JOIN t2 ON dt1.a1=t2.a2;
5986CREATE VIEW vrtd AS
5987SELECT * FROM (SELECT DISTINCT * FROM t1) AS dt1 JOIN t2 ON dt1.a1=t2.a2;
5988CREATE VIEW vrr AS
5989SELECT * FROM vmat1 AS dt1 JOIN vmat2 AS dt2 ON dt1.a1=dt2.a2;
5990CREATE VIEW vrrd AS
5991SELECT * FROM (SELECT DISTINCT * FROM t1) AS dt1 JOIN
5992(SELECT DISTINCT * FROM t2) AS dt2 ON dt1.a1=dt2.a2;
5993INSERT INTO vtt(a1,b1) VALUES (1,100);
5994INSERT INTO vtt(a2,b2) VALUES (1,100);
5995INSERT INTO vtr(a1,b1) VALUES (2,100);
5996ERROR HY000: The target table vtr of the INSERT is not insertable-into
5997INSERT INTO vtrd(a1,b1) VALUES (3,100);
5998ERROR HY000: The target table vtrd of the INSERT is not insertable-into
5999INSERT INTO vtr(a2,b2) VALUES (2,100);
6000ERROR HY000: The target table vtr of the INSERT is not insertable-into
6001INSERT INTO vtrd(a2,b2) VALUES (3,100);
6002ERROR HY000: The target table vtrd of the INSERT is not insertable-into
6003INSERT INTO vrt(a1,b1) VALUES (4,100);
6004ERROR HY000: The target table vrt of the INSERT is not insertable-into
6005INSERT INTO vrtd(a1,b1) VALUES (5,100);
6006ERROR HY000: The target table vrtd of the INSERT is not insertable-into
6007INSERT INTO vrt(a2,b2) VALUES (4,100);
6008ERROR HY000: The target table vrt of the INSERT is not insertable-into
6009INSERT INTO vrtd(a2,b2) VALUES (5,100);
6010ERROR HY000: The target table vrtd of the INSERT is not insertable-into
6011INSERT INTO vrr(a1,b1) VALUES (6,100);
6012ERROR HY000: The target table vrr of the INSERT is not insertable-into
6013INSERT INTO vrrd(a1,b1) VALUES (7,100);
6014ERROR HY000: The target table vrrd of the INSERT is not insertable-into
6015INSERT INTO vrr(a2,b2) VALUES (6,100);
6016ERROR HY000: The target table vrr of the INSERT is not insertable-into
6017INSERT INTO vrrd(a2,b2) VALUES (7,100);
6018ERROR HY000: The target table vrrd of the INSERT is not insertable-into
6019SELECT * FROM vtt;
6020a1	b1	a2	b2
60211	100	1	100
6022DELETE FROM t1;
6023DELETE FROM t2;
6024INSERT INTO vtt(a1,b1) SELECT 1,100;
6025INSERT INTO vtt(a2,b2) SELECT 1,100;
6026INSERT INTO vtr(a1,b1) SELECT 2,100;
6027ERROR HY000: The target table vtr of the INSERT is not insertable-into
6028INSERT INTO vtrd(a1,b1) SELECT 3,100;
6029ERROR HY000: The target table vtrd of the INSERT is not insertable-into
6030INSERT INTO vtr(a2,b2) SELECT 2,100;
6031ERROR HY000: The target table vtr of the INSERT is not insertable-into
6032INSERT INTO vtrd(a2,b2) SELECT 3,100;
6033ERROR HY000: The target table vtrd of the INSERT is not insertable-into
6034INSERT INTO vrt(a1,b1) SELECT 4,100;
6035ERROR HY000: The target table vrt of the INSERT is not insertable-into
6036INSERT INTO vrtd(a1,b1) SELECT 5,100;
6037ERROR HY000: The target table vrtd of the INSERT is not insertable-into
6038INSERT INTO vrt(a2,b2) SELECT 4,100;
6039ERROR HY000: The target table vrt of the INSERT is not insertable-into
6040INSERT INTO vrtd(a2,b2) SELECT 5,100;
6041ERROR HY000: The target table vrtd of the INSERT is not insertable-into
6042INSERT INTO vrr(a1,b1) SELECT 6,100;
6043ERROR HY000: The target table vrr of the INSERT is not insertable-into
6044INSERT INTO vrrd(a1,b1) SELECT 7,100;
6045ERROR HY000: The target table vrrd of the INSERT is not insertable-into
6046INSERT INTO vrr(a2,b2) SELECT 6,100;
6047ERROR HY000: The target table vrr of the INSERT is not insertable-into
6048INSERT INTO vrrd(a2,b2) SELECT 7,100;
6049ERROR HY000: The target table vrrd of the INSERT is not insertable-into
6050SELECT * FROM vtt;
6051a1	b1	a2	b2
60521	100	1	100
6053DELETE FROM t1;
6054DELETE FROM t2;
6055INSERT INTO t1 VALUES
6056(1,100), (2,100), (3,100), (4,100), (5,100),
6057(6,100), (7,100), (8,100), (9,100), (10,100),
6058(11,100), (12,100), (13,100), (14,100);
6059INSERT INTO t2 VALUES
6060(1,100), (2,100), (3,100), (4,100), (5,100),
6061(6,100), (7,100), (8,100), (9,100), (10,100),
6062(11,100), (12,100), (13,100), (14,100);
6063DELETE FROM vtt WHERE a1=1;
6064ERROR HY000: Can not delete from join view 'test.vtt'
6065DELETE FROM vtr WHERE a1=2;
6066ERROR HY000: Can not delete from join view 'test.vtr'
6067DELETE FROM vtrd WHERE a1=3;
6068ERROR HY000: Can not delete from join view 'test.vtrd'
6069DELETE FROM vrt WHERE a1=4;
6070ERROR HY000: Can not delete from join view 'test.vrt'
6071DELETE FROM vrtd WHERE a1=5;
6072ERROR HY000: Can not delete from join view 'test.vrtd'
6073DELETE FROM vrr WHERE a1=6;
6074ERROR HY000: The target table vrr of the DELETE is not updatable
6075DELETE FROM vrrd WHERE a1=7;
6076ERROR HY000: The target table vrrd of the DELETE is not updatable
6077DELETE vtt FROM vtt WHERE a1=8;
6078ERROR HY000: Can not delete from join view 'test.vtt'
6079DELETE vtr FROM vtr WHERE a1=9;
6080ERROR HY000: Can not delete from join view 'test.vtr'
6081DELETE vtrd FROM vtrd WHERE a1=10;
6082ERROR HY000: Can not delete from join view 'test.vtrd'
6083DELETE vrt FROM vrt WHERE a1=11;
6084ERROR HY000: Can not delete from join view 'test.vrt'
6085DELETE vrtd FROM vrtd WHERE a1=12;
6086ERROR HY000: Can not delete from join view 'test.vrtd'
6087DELETE vrr FROM vrr WHERE a1=13;
6088ERROR HY000: The target table vrr of the DELETE is not updatable
6089DELETE vrrd FROM vrrd WHERE a1=14;
6090ERROR HY000: The target table vrrd of the DELETE is not updatable
6091SELECT * FROM vtt;
6092a1	b1	a2	b2
60931	100	1	100
60942	100	2	100
60953	100	3	100
60964	100	4	100
60975	100	5	100
60986	100	6	100
60997	100	7	100
61008	100	8	100
61019	100	9	100
610210	100	10	100
610311	100	11	100
610412	100	12	100
610513	100	13	100
610614	100	14	100
6107DELETE FROM t1;
6108DELETE FROM t2;
6109INSERT INTO t1 VALUES (1,100);
6110INSERT INTO t2 VALUES (1,100);
6111UPDATE vtt SET b1=b1+1 WHERE a1=1;
6112UPDATE vtt SET b2=b2+1 WHERE a2=1;
6113UPDATE vtr SET b1=b1+1 WHERE a1=1;
6114UPDATE vtrd SET b1=b1+1 WHERE a1=1;
6115UPDATE vtr SET b2=b2+1 WHERE a2=1;
6116ERROR HY000: The target table dt2 of the UPDATE is not updatable
6117UPDATE vtrd SET b2=b2+1 WHERE a2=1;
6118ERROR HY000: The target table dt2 of the UPDATE is not updatable
6119UPDATE vrt SET b1=b1+1 WHERE a1=1;
6120ERROR HY000: The target table dt1 of the UPDATE is not updatable
6121UPDATE vrtd SET b1=b1+1 WHERE a1=1;
6122ERROR HY000: The target table dt1 of the UPDATE is not updatable
6123UPDATE vrt SET b2=b2+1 WHERE a2=1;
6124UPDATE vrtd SET b2=b2+1 WHERE a2=1;
6125UPDATE vrr SET b1=b1+1 WHERE a1=1;
6126ERROR HY000: The target table vrr of the UPDATE is not updatable
6127UPDATE vrrd SET b1=b1+1 WHERE a1=1;
6128ERROR HY000: The target table vrrd of the UPDATE is not updatable
6129UPDATE vrr SET b2=b2+1 WHERE a2=1;
6130ERROR HY000: The target table vrr of the UPDATE is not updatable
6131UPDATE vrrd SET b2=b2+1 WHERE a2=1;
6132ERROR HY000: The target table vrrd of the UPDATE is not updatable
6133UPDATE vtt, v0 AS dt SET b1=b1+1 WHERE a1=1;
6134UPDATE vtt, v0 SET b2=b2+1 WHERE a2=1;
6135UPDATE vtr, v0 SET b1=b1+1 WHERE a1=1;
6136UPDATE vtrd, v0 SET b1=b1+1 WHERE a1=1;
6137UPDATE vtr, v0 SET b2=b2+1 WHERE a2=1;
6138ERROR HY000: The target table dt2 of the UPDATE is not updatable
6139UPDATE vtrd, v0 SET b2=b2+1 WHERE a2=1;
6140ERROR HY000: The target table dt2 of the UPDATE is not updatable
6141UPDATE vrt, v0 SET b1=b1+1 WHERE a1=1;
6142ERROR HY000: The target table dt1 of the UPDATE is not updatable
6143UPDATE vrtd, v0 SET b1=b1+1 WHERE a1=1;
6144ERROR HY000: The target table dt1 of the UPDATE is not updatable
6145UPDATE vrt, v0 SET b2=b2+1 WHERE a2=1;
6146UPDATE vrtd, v0 SET b2=b2+1 WHERE a2=1;
6147UPDATE vrr, v0 SET b1=b1+1 WHERE a1=1;
6148ERROR HY000: The target table dt1 of the UPDATE is not updatable
6149UPDATE vrrd, v0 SET b1=b1+1 WHERE a1=1;
6150ERROR HY000: The target table dt1 of the UPDATE is not updatable
6151UPDATE vrr, v0 SET b2=b2+1 WHERE a2=1;
6152ERROR HY000: The target table dt2 of the UPDATE is not updatable
6153UPDATE vrrd, v0 SET b2=b2+1 WHERE a2=1;
6154ERROR HY000: The target table dt2 of the UPDATE is not updatable
6155SELECT * FROM vtt;
6156a1	b1	a2	b2
61571	106	1	106
6158DROP VIEW v0, vtt, vtr, vrt, vrr, vmat1, vmat2;
6159DROP VIEW vtrd, vrtd, vrrd;
6160DROP TABLE t0, t1, t2;
6161#
6162# Bug#20407961 VIEW'S CHECK OPTION SOMETIMES NOT HONOURED IF INCLUDED IN A TOP VIEW
6163#
6164create table t1 (a varchar(100));
6165# n/c/l letter suffix means: no/cascaded/local check option
6166create view v1n as select * from t1 where a like '%v1n%';
6167create view v2c as select * from t1 where a like '%v2c%'
6168 with check option;
6169show create view v2c;
6170View	Create View	character_set_client	collation_connection
6171v2c	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2c` AS select `t1`.`a` AS `a` from `t1` where (`t1`.`a` like '%v2c%') WITH CASCADED CHECK OPTION	latin1	latin1_swedish_ci
6172create view v3l as select * from t1 where a like '%v3l%'
6173 with local check option;
6174show create view v3l;
6175View	Create View	character_set_client	collation_connection
6176v3l	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3l` AS select `t1`.`a` AS `a` from `t1` where (`t1`.`a` like '%v3l%') WITH LOCAL CHECK OPTION	latin1	latin1_swedish_ci
6177# The basic, single-view feature works:
6178insert into t1 values('');
6179insert into v1n values('');
6180insert into v2c values('');
6181ERROR HY000: CHECK OPTION failed 'test.v2c'
6182insert into v2c values('v2c');
6183insert into v3l values('');
6184ERROR HY000: CHECK OPTION failed 'test.v3l'
6185insert into v3l values('v3l');
6186# We also test UPDATE of the successfully inserted row
6187update v1n set a='_';
6188# if this update to v2c was allowed, it would be produce a row in t1
6189# not matching v2c's filter, which is against the goal of CHECK
6190# OPTION.
6191update v2c set a='';
6192ERROR HY000: CHECK OPTION failed 'test.v2c'
6193update v3l set a='';
6194ERROR HY000: CHECK OPTION failed 'test.v3l'
6195# Top view without no CHECK OPTION, still CHECK OPTION conditions
6196# of underlying views are checked.
6197create view v4n as select * from v2c where a like '%v4n%';
6198create view v5n as select * from v3l where a like '%v5n%';
6199# The view's nesting structure is:
6200# v4n -> v2c -> t1
6201# We present the query with needed tags, verify that it passes,
6202# then we take each tag away and verify that it fails.
6203insert into v4n values('v2c');
6204insert into v4n values('');
6205ERROR HY000: CHECK OPTION failed 'test.v4n'
6206# To check UPDATE on v4n, we need to update a row originally
6207# visible in v4n, so we create it:
6208insert into v4n values('v4n v2c');
6209# This row can legally disappear from v4n:
6210update v4n set a='v2c';
6211insert into v4n values('v4n v2c');
6212# But this row cannot disappear from v2c:
6213update v4n set a='v4n';
6214ERROR HY000: CHECK OPTION failed 'test.v4n'
6215# Lest we delete it:
6216delete from v4n;
6217# v5n -> v3l -> t1
6218insert into v5n values('v3l');
6219insert into v5n values('');
6220ERROR HY000: CHECK OPTION failed 'test.v5n'
6221# Top view with LOCAL CHECK OPTION, still CHECK OPTION conditions
6222# of underlying views are checked.
6223create view v4l as select * from v2c where a like '%v4l%'
6224 with local check option;
6225create view v5l as select * from v3l where a like '%v5l%'
6226 with local check option;
6227# v4l -> v2c -> t1
6228insert into v4l values('v4l v2c');
6229insert into v4l values('v2c');
6230ERROR HY000: CHECK OPTION failed 'test.v4l'
6231update v4l set a='v2c';
6232ERROR HY000: CHECK OPTION failed 'test.v4l'
6233insert into v4l values('v4l');
6234ERROR HY000: CHECK OPTION failed 'test.v4l'
6235update v4l set a='v4l';
6236ERROR HY000: CHECK OPTION failed 'test.v4l'
6237# v5l -> v3l -> t1
6238insert into v5l values('v5l v3l');
6239insert into v5l values('v3l');
6240ERROR HY000: CHECK OPTION failed 'test.v5l'
6241update v5l set a='v3l';
6242ERROR HY000: CHECK OPTION failed 'test.v5l'
6243insert into v5l values('v5l');
6244ERROR HY000: CHECK OPTION failed 'test.v5l'
6245update v5l set a='v5l';
6246ERROR HY000: CHECK OPTION failed 'test.v5l'
6247# CASCADED makes all filtering conditions a requirement
6248create view v6c as select * from v5n where a like '%v6c%'
6249 with cascaded check option;
6250# v6c -> v5n -> v3l -> t1
6251insert into v6c values('v6c v5n v3l');
6252insert into v6c values('v5n v3l');
6253ERROR HY000: CHECK OPTION failed 'test.v6c'
6254update v6c set a='v5n v3l';
6255ERROR HY000: CHECK OPTION failed 'test.v6c'
6256insert into v6c values('v6c v3l');
6257ERROR HY000: CHECK OPTION failed 'test.v6c'
6258update v6c set a='v6c v3l';
6259ERROR HY000: CHECK OPTION failed 'test.v6c'
6260insert into v6c values('v6c v5n');
6261ERROR HY000: CHECK OPTION failed 'test.v6c'
6262update v6c set a='v6c v5n';
6263ERROR HY000: CHECK OPTION failed 'test.v6c'
6264# Also true if top view has no check option:
6265create view v7n as select * from v6c where a like '%v7n%';
6266# v7n -> v6c -> v5n -> v3l -> t1
6267insert into v7n values('v6c v5n v3l');
6268insert into v7n values('v5n v3l');
6269ERROR HY000: CHECK OPTION failed 'test.v7n'
6270insert into v7n values('v6c v3l');
6271ERROR HY000: CHECK OPTION failed 'test.v7n'
6272insert into v7n values('v6c v5n');
6273ERROR HY000: CHECK OPTION failed 'test.v7n'
6274# Make a visible row to update:
6275insert into v7n values('v7n v6c v5n v3l');
6276update v7n set a='v7n v5n v3l';
6277ERROR HY000: CHECK OPTION failed 'test.v7n'
6278update v7n set a='v7n v6c v3l';
6279ERROR HY000: CHECK OPTION failed 'test.v7n'
6280update v7n set a='v7n v6c v5nà';
6281ERROR HY000: CHECK OPTION failed 'test.v7n'
6282# Also true if top view has LOCAL:
6283create view v8l as select * from v7n where a like '%v8l%'
6284 with local check option;
6285# v8l -> v7n -> v6c -> v5n -> v3l -> t1
6286insert into v8l values('v8l v6c v5n v3l');
6287insert into v8l values('v6c v5n v3l');
6288ERROR HY000: CHECK OPTION failed 'test.v8l'
6289insert into v8l values('v8l v5n v3l');
6290ERROR HY000: CHECK OPTION failed 'test.v8l'
6291insert into v8l values('v8l v6c v3l');
6292ERROR HY000: CHECK OPTION failed 'test.v8l'
6293insert into v8l values('v8l v6c v5n');
6294ERROR HY000: CHECK OPTION failed 'test.v8l'
6295# Make a visible row (=> satisfy v7n's WHERE clause):
6296insert into v8l values('v8l v7n v6c v5n v3l');
6297update v8l set a='v7n v6c v5n v3l';
6298ERROR HY000: CHECK OPTION failed 'test.v8l'
6299update v8l set a='v8l v7n v5n v3l';
6300ERROR HY000: CHECK OPTION failed 'test.v8l'
6301update v8l set a='v8l v7n v6c v3l';
6302ERROR HY000: CHECK OPTION failed 'test.v8l'
6303update v8l set a='v8l v7n v6c v5n';
6304ERROR HY000: CHECK OPTION failed 'test.v8l'
6305drop view v1n,v2c,v3l,v4n,v5n,v4l,v5l,v6c,v7n,v8l;
6306drop table t1;
6307# Bug#20982756 Crash in Table_list::fetch_number_of_rows
6308CREATE TABLE t1(a INTEGER) engine=innodb;
6309CREATE VIEW v3 AS SELECT 1 FROM t1;
6310CREATE VIEW v2 AS SELECT 1 FROM v3 LEFT JOIN t1 ON 1;
6311PREPARE s FROM "set @a:=(SELECT 1 FROM t1,v2);";
6312EXECUTE s;
6313EXECUTE s;
6314DROP VIEW  v2,v3;
6315DROP TABLE t1;
6316# Bug#21097485 *insert_table_ref && (*insert_table_ref)->is_insertable
6317CREATE TABLE t1 (r INTEGER) engine=innodb;
6318CREATE VIEW v1 AS
6319SELECT 1 AS z from t1;
6320INSERT INTO v1(z) VALUES(1);
6321ERROR HY000: Column 'z' is not updatable
6322DROP VIEW  v1;
6323DROP TABLE t1;
6324# Bug#21277074: crash (segfault) in THD::change_item_tree on exec of prep
6325CREATE TABLE t (i INTEGER);
6326PREPARE s1 FROM
6327"SELECT (SELECT MAX(i)) AS field1
6328   FROM (SELECT * FROM t) AS table1"
6329;
6330EXECUTE s1;
6331field1
6332NULL
6333CREATE VIEW v AS SELECT * FROM t;
6334PREPARE s2 FROM
6335"SELECT (SELECT MAX(i)) AS field1
6336   FROM v AS table1"
6337;
6338EXECUTE s2;
6339field1
6340NULL
6341DEALLOCATE PREPARE s1;
6342DEALLOCATE PREPARE s2;
6343DROP VIEW v;
6344DROP TABLE t;
6345#
6346# BUG#19886430: VIEW CREATION WITH NAMED COLUMNS, OVER UNION,
6347#               IS REJECTED
6348# Without the patch, reports an error.
6349CREATE VIEW v1 (fld1, fld2) AS
6350SELECT 1 AS a, 2 AS b
6351UNION ALL
6352SELECT 1 AS a, 1 AS a;
6353# The column names are explicitly specified and not duplicates, hence
6354# succeeds.
6355CREATE VIEW v2 (fld1, fld2) AS
6356SELECT 1 AS a, 2 AS a
6357UNION ALL
6358SELECT 1 AS a, 1 AS a;
6359# The column name in the first SELECT are not duplicates, hence succeeds.
6360CREATE VIEW v3 AS
6361SELECT 1 AS a, 2 AS b
6362UNION ALL
6363SELECT 1 AS a, 1 AS a;
6364# Should report an error, since the explicitly specified column names are
6365# duplicates.
6366CREATE VIEW v4 (fld1, fld1) AS
6367SELECT 1 AS a, 2 AS b
6368UNION ALL
6369SELECT 1 AS a, 1 AS a;
6370ERROR 42S21: Duplicate column name 'fld1'
6371# Should report an error, since duplicate column name is specified in the
6372# First SELECT.
6373CREATE VIEW v4 AS
6374SELECT 1 AS a, 2 AS a
6375UNION ALL
6376SELECT 1 AS a, 1 AS a;
6377ERROR 42S21: Duplicate column name 'a'
6378# Cleanup
6379DROP VIEW v1, v2, v3;
6380#
6381# Bug #22108567 ASSERTION `TABLE != 0' FAILED
6382#
6383PREPARE X FROM 'CREATE VIEW bug22108567_v1 AS SELECT 1 FROM (SELECT 1) AS D1';
6384EXECUTE X;
6385DROP VIEW bug22108567_v1;
6386#
6387# BUG#21877062: MIN/MAX IN VIEW ON TIMESTAMDIFF IN VIEW CONFUSES
6388#               OPTIMIZER TO THROW SYNTAX ERROR
6389#
6390CREATE TABLE t(ts1 DATETIME(6), ts2 DATETIME(6));
6391INSERT INTO t VALUES('2016-01-11 09:15:25','2016-01-11 21:15:25');
6392CREATE VIEW v1 AS
6393SELECT TIMESTAMPDIFF(MICROSECOND, ts1, ts2) duration FROM t;
6394# Without the patch, a syntax error is reported.
6395SELECT * FROM v1;
6396duration
639743200000000
6398CREATE VIEW v2 AS
6399SELECT MIN(duration) AS dmin, MAX(duration) AS dmax FROM v1;
6400DROP VIEW v1, v2;
6401DROP TABLE t;
6402