create table t1 (a int, b blob) engine=MyISAM;
create table t2 (c int, d blob) engine=MyISAM;
create table t3 (e int, f blob) engine=MyISAM;
insert into t1 values (5,5),(6,6);
insert into t2 values (2,2),(3,3);
insert into t3 values (1,1),(3,3);
set SQL_MODE=ORACLE;
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
a	b
3	3
4	4
explain extended
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	<derived6>	ALL	NULL	NULL	NULL	NULL	2	100.00	
6	DERIVED	<derived4>	ALL	NULL	NULL	NULL	NULL	2	100.00	
4	DERIVED	<derived2>	ALL	NULL	NULL	NULL	NULL	4	100.00	
2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
3	UNION	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
5	INTERSECT	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	INTERSECT RESULT	<intersect4,5>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
7	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
NULL	UNION RESULT	<union6,7>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
Warnings:
Note	1003	/* select#1 */ select "__7"."a" AS "a","__7"."b" AS "b" from (/* select#6 */ select "__5"."a" AS "a","__5"."b" AS "b" from (/* select#4 */ select "__3"."a" AS "a","__3"."b" AS "b" from ((/* select#2 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1") union (/* select#3 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2")) "__3" intersect (/* select#5 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3")) "__5" union (/* select#7 */ select 4 AS "4",4 AS "4")) "__7"
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
e	f
3	3
5	5
6	6
4	4
explain extended
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	<derived6>	ALL	NULL	NULL	NULL	NULL	4	100.00	
6	DERIVED	<derived4>	ALL	NULL	NULL	NULL	NULL	4	100.00	
4	DERIVED	<derived2>	ALL	NULL	NULL	NULL	NULL	2	100.00	
2	DERIVED	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
3	INTERSECT	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	INTERSECT RESULT	<intersect2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
5	UNION	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	UNION RESULT	<union4,5>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
7	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
NULL	UNION RESULT	<union6,7>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
Warnings:
Note	1003	/* select#1 */ select "__7"."e" AS "e","__7"."f" AS "f" from (/* select#6 */ select "__5"."e" AS "e","__5"."f" AS "f" from (/* select#4 */ select "__3"."e" AS "e","__3"."f" AS "f" from ((/* select#2 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3") intersect (/* select#3 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2")) "__3" union (/* select#5 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1")) "__5" union (/* select#7 */ select 4 AS "4",4 AS "4")) "__7"
create table t12(c1 int);
insert into t12 values(1);
insert into t12 values(2);
create table t13(c1 int);
insert into t13 values(1);
insert into t13 values(3);
create table t234(c1 int);
insert into t234 values(2);
insert into t234 values(3);
insert into t234 values(4);
select * from t13 union select * from t234 intersect select * from t12;
c1
1
2
set SQL_MODE=default;
drop table t1,t2,t3;
drop table t12,t13, t234;
create table t1 (a int, b blob) engine=MyISAM;
create table t2 (c int, d blob) engine=MyISAM;
create table t3 (e int, f blob) engine=MyISAM;
insert into t1 values (5,5),(6,6);
insert into t2 values (2,2),(3,3);
insert into t3 values (1,1),(3,3);
set SQL_MODE=ORACLE;
select a,b from t1 union all select c,d from t2 intersect select e,f from t3 union all select 4,'4' from dual;
a	b
3	3
4	4
explain extended
select a,b from t1 union all select c,d from t2 intersect select e,f from t3 union all select 4,'4' from dual;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	<derived6>	ALL	NULL	NULL	NULL	NULL	2	100.00	
6	DERIVED	<derived4>	ALL	NULL	NULL	NULL	NULL	2	100.00	
4	DERIVED	<derived2>	ALL	NULL	NULL	NULL	NULL	4	100.00	
2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
3	UNION	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
5	INTERSECT	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	INTERSECT RESULT	<intersect4,5>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
7	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
Warnings:
Note	1003	/* select#1 */ select "__7"."a" AS "a","__7"."b" AS "b" from (/* select#6 */ select "__5"."a" AS "a","__5"."b" AS "b" from (/* select#4 */ select "__3"."a" AS "a","__3"."b" AS "b" from (/* select#2 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" union all /* select#3 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") "__3" intersect /* select#5 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3") "__5" union all /* select#7 */ select 4 AS "4",'4' AS "4") "__7"
select a,b from t1 union all select c,d from t2 intersect all select e,f from t3 union all select 4,'4' from dual;
a	b
3	3
4	4
explain extended
select a,b from t1 union all select c,d from t2 intersect all select e,f from t3 union all select 4,'4' from dual;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	<derived6>	ALL	NULL	NULL	NULL	NULL	2	100.00	
6	DERIVED	<derived4>	ALL	NULL	NULL	NULL	NULL	2	100.00	
4	DERIVED	<derived2>	ALL	NULL	NULL	NULL	NULL	4	100.00	
2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
3	UNION	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
5	INTERSECT	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	INTERSECT RESULT	<intersect4,5>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
7	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
Warnings:
Note	1003	/* select#1 */ select "__7"."a" AS "a","__7"."b" AS "b" from (/* select#6 */ select "__5"."a" AS "a","__5"."b" AS "b" from (/* select#4 */ select "__3"."a" AS "a","__3"."b" AS "b" from (/* select#2 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" union all /* select#3 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") "__3" intersect all /* select#5 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3") "__5" union all /* select#7 */ select 4 AS "4",'4' AS "4") "__7"
select e,f from t3 intersect select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual;
e	f
3	3
5	5
6	6
4	4
explain extended
select e,f from t3 intersect select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	<derived6>	ALL	NULL	NULL	NULL	NULL	4	100.00	
6	DERIVED	<derived4>	ALL	NULL	NULL	NULL	NULL	4	100.00	
4	DERIVED	<derived2>	ALL	NULL	NULL	NULL	NULL	2	100.00	
2	DERIVED	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
3	INTERSECT	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	INTERSECT RESULT	<intersect2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
5	UNION	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
7	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
Warnings:
Note	1003	/* select#1 */ select "__7"."e" AS "e","__7"."f" AS "f" from (/* select#6 */ select "__5"."e" AS "e","__5"."f" AS "f" from (/* select#4 */ select "__3"."e" AS "e","__3"."f" AS "f" from (/* select#2 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3" intersect /* select#3 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") "__3" union all /* select#5 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1") "__5" union all /* select#7 */ select 4 AS "4",'4' AS "4") "__7"
select e,f from t3 intersect all select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual;
e	f
3	3
5	5
6	6
4	4
explain extended
select e,f from t3 intersect all select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	PRIMARY	<derived6>	ALL	NULL	NULL	NULL	NULL	4	100.00	
6	DERIVED	<derived4>	ALL	NULL	NULL	NULL	NULL	4	100.00	
4	DERIVED	<derived2>	ALL	NULL	NULL	NULL	NULL	2	100.00	
2	DERIVED	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
3	INTERSECT	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
NULL	INTERSECT RESULT	<intersect2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
5	UNION	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
7	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
Warnings:
Note	1003	/* select#1 */ select "__7"."e" AS "e","__7"."f" AS "f" from (/* select#6 */ select "__5"."e" AS "e","__5"."f" AS "f" from (/* select#4 */ select "__3"."e" AS "e","__3"."f" AS "f" from (/* select#2 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3" intersect all /* select#3 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") "__3" union all /* select#5 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1") "__5" union all /* select#7 */ select 4 AS "4",'4' AS "4") "__7"
set SQL_MODE=default;
drop table t1,t2,t3;
set SQL_MODE=oracle;
select * from t13 union select * from t234 intersect all select * from t12;
ERROR 42S02: Table 'test.t13' doesn't exist
set SQL_MODE=default;
#
# MDEV-38799 Some views are broken in Oracle mode after upgrade to Q1 2026
#
set sql_mode='';
create view v as select 'foo' as a union select 'bar' as a;
create view v2 as select 'foo' as a, 'baz' as b union select 'bar' as a, 'qux' as b;
create view v3 as select * from (select 'foo' as a, 'baz' as b) s union select * from (select 'bar' as a, 'qux' as b) s2;
create view v4 as select * from (select 'foo' as a) s union select * from (select 'bar' as a) s2;
select a from v;
a
foo
bar
select a, b from v2;
a	b
foo	baz
bar	qux
select a, b from v3;
a	b
foo	baz
bar	qux
select a from v4;
a
foo
bar
set sql_mode=oracle;
show create view v;
View	Create View	character_set_client	collation_connection
v	CREATE VIEW "v" AS select "__4"."a" AS "a" from (select 'foo' AS "a" union select 'bar' AS "a") "__4"	latin1	latin1_swedish_ci
show create view v2;
View	Create View	character_set_client	collation_connection
v2	CREATE VIEW "v2" AS select "__4"."a" AS "a","__4"."b" AS "b" from (select 'foo' AS "a",'baz' AS "b" union select 'bar' AS "a",'qux' AS "b") "__4"	latin1	latin1_swedish_ci
select a from v;
a
foo
bar
select a, b from v2;
a	b
foo	baz
bar	qux
select a, b from v3;
a	b
foo	baz
bar	qux
select a from v4;
a
foo
bar
drop view v;
drop view v2;
drop view v3;
drop view v4;
set sql_mode=default;
# End of 10.11 tests
#
# MDEV-38987 ASAN heap-use-after-free upon using a view through a trigger in ORACLE mode
#
set sql_mode = oracle;
create table t1 (f int);
create table t2 (a int);
create view v as select 'x' union select 'x' union select 'x';
create trigger tr before insert on t1 for each row delete from v;
insert into t1 values (1);
ERROR HY000: The target table v of the DELETE is not updatable
drop view v;
create view v as select * from t2;
INSERT into t1 values (2);
drop view v;
drop table t1, t2;
# End of 11.4 tests
