@ -1235,8 +1235,8 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
CREATE PROCEDURE bug20953()
CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE();
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'PROCEDURE ANALYSE()' at line 2
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1;
ERROR HY000: View's SELECT contains a subquery in the FROM clause
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1 into @w;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into @w' at line 1
CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i;
ERROR HY000: View's SELECT contains a variable or parameter
create view v1 as select a from t1 procedure analyse();
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'procedure analyse()' at line 1
create view v1 as select 1 from (select 1) as d1;
ERROR HY000: View's SELECT contains a subquery in the FROM clause
drop view v1;
drop table t1;
create table t1 (s1 int, primary key (s1));
create view v1 as select * from t1;
@ -1494,7 +1494,7 @@ a
create view v2 (a,b) as select t1.b as a, t2.a as b from t1, t2;
set updatable_views_with_limit=NO;
update v2 set a= 10 where a=200 limit 1;
ERROR HY000: The target table t1 of the UPDATE is not updatable
ERROR HY000: The target table v2 of the UPDATE is not updatable
ERROR HY000: View's SELECT contains a subquery in the FROM clause
SELECT * FROM (SELECT 1) AS t into @w;
CREATE VIEW v1 AS SELECT * FROM (SELECT 1) AS t into @w;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into @w' at line 1
# Previously the following would fail.
SELECT * FROM (SELECT 1) AS t;
1
1
SELECT * FROM (SELECT 1) AS t into @w;
drop view if exists view_24532_a;
drop view if exists view_24532_b;
drop table if exists table_24532;
@ -4100,7 +4096,7 @@ ERROR HY000: The target table v1 of the INSERT is not insertable-into
DELETE from v1;
ERROR HY000: The target table v1 of the DELETE is not updatable
UPDATE v3 SET b= 10;
ERROR HY000: The target table v2 of the UPDATE is not updatable
ERROR HY000: The target table v3 of the UPDATE is not updatable
REPLACE v3 SET b= 10;
ERROR HY000: The target table v3 of the INSERT is not insertable-into
INSERT into v3(b) values (20);
@ -5953,5 +5949,241 @@ t3 CREATE TABLE `t3` (
DROP VIEW v1;
DROP TABLE t1,t2,t3;
#
# MDEV-3944: Allow derived tables in VIEWS
#
create table t1 (s1 int);
insert into t1 values (1),(2),(3);
CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1>1) AS x;
CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1<3) AS x;
select * from v1;
s1
2
3
select * from v2;
s1
1
2
select * from v1 natural join v2;
s1
2
select * from v1 natural join t1;
s1
2
3
select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x;
s1
2
select * from v1 left join v2 on (v1.s1=v2.s1);
s1 s1
2 2
3 NULL
select * from v1 left join t1 on (v1.s1=t1.s1);
s1 s1
2 2
3 3
select * from t1 left join v2 on (t1.s1=v2.s1);
s1 s1
1 1
2 2
3 NULL
select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1);
s1 s1
2 2
3 NULL
select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1);
s1 s1
2 2
3 NULL
drop view v1,v2;
CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1
< 100) as xx WHERE s1>1) AS x;
CREATE VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1
> -100) as xx WHERE s1<3) AS x;
insert into t1 values (200),(-200);
select * from t1;
s1
-200
1
2
200
3
select * from v1;
s1
2
3
select * from v2;
s1
1
2
select * from v1 natural join v2;
s1
2
select * from v1 natural join t1;
s1
2
3
select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x;
s1
2
select * from v1 left join v2 on (v1.s1=v2.s1);
s1 s1
2 2
3 NULL
select * from v1 left join t1 on (v1.s1=t1.s1);
s1 s1
2 2
3 3
select * from t1 left join v2 on (t1.s1=v2.s1);
s1 s1
-200 NULL
1 1
2 2
200 NULL
3 NULL
select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1);
s1 s1
2 2
3 NULL
select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1);
s1 s1
2 2
200 NULL
3 NULL
drop view v1,v2;
CREATE algorithm=temptable VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1
< 100) as xx WHERE s1>1) AS x;
CREATE algorithm=temptable VIEW v2 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1
> -100) as xx WHERE s1<3) AS x;
select * from t1;
s1
-200
1
2
200
3
select * from v1;
s1
2
3
select * from v2;
s1
1
2
select * from v1 natural join v2;
s1
2
select * from v1 natural join t1;
s1
2
3
select * from v1 natural join (SELECT s1 FROM t1 WHERE s1<3) as x;
s1
2
select * from v1 left join v2 on (v1.s1=v2.s1);
s1 s1
2 2
3 NULL
select * from v1 left join t1 on (v1.s1=t1.s1);
s1 s1
2 2
3 3
select * from t1 left join v2 on (t1.s1=v2.s1);
s1 s1
-200 NULL
1 1
2 2
200 NULL
3 NULL
select * from v1 left join (SELECT s1 FROM t1 WHERE s1<3) as x on (v1.s1=x.s1);
s1 s1
2 2
3 NULL
select * from (SELECT s1 FROM t1 WHERE s1>1) AS x left join v2 on (x.s1=v2.s1);
s1 s1
2 2
200 NULL
3 NULL
drop view v1,v2;
CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1
< 100) as xx WHERE s1>1) AS x;
insert into v1 values (-300);
ERROR HY000: The target table v1 of the INSERT is not insertable-into
update v1 set s1=s1+1;
ERROR HY000: The target table v1 of the UPDATE is not updatable
drop view v1;
CREATE VIEW v1 AS SELECT s1,s2 FROM (SELECT s1 as s2 FROM t1 WHERE s1 <
100) x, t1 WHERE t1.s1=x.s2;
select * from v1;
s1 s2
1 1
2 2
3 3
-200 -200
insert into v1 (s1) values (-300);
update v1 set s1=s1+1;
select * from v1;
s1 s2
2 2
3 3
4 4
-199 -199
-299 -299
select * from t1;
s1
2
3
4
200
-199
-299
insert into v1(s2) values (-300);
ERROR HY000: The target table v1 of the INSERT is not insertable-into
update v1 set s2=s2+1;
ERROR HY000: The target table v1 of the UPDATE is not updatable
drop view v1;
CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM t1 WHERE s1
< 100) AS x;
insert into v1 values (-300);
ERROR HY000: The target table v1 of the INSERT is not insertable-into
update v1 set s1=s1+1;
ERROR HY000: The target table v1 of the UPDATE is not updatable
drop view v1;
CREATE VIEW v1 AS SELECT * FROM (SELECT s1 FROM (SELECT s1 FROM t1 WHERE s1
< 100) as xx WHERE s1>1) AS x;
insert into v1 values (-300);
ERROR HY000: The target table v1 of the INSERT is not insertable-into
update v1 set s1=s1+1;
ERROR HY000: The target table v1 of the UPDATE is not updatable
create view v2 as select * from v1;
insert into v2 values (-300);
ERROR HY000: The target table v2 of the INSERT is not insertable-into
update v2 set s1=s1+1;
ERROR HY000: The target table v2 of the UPDATE is not updatable
drop view v1, v2;
drop table t1;
#
# MDEV-9671:Wrong result upon select from a view with a FROM subquery
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (3),(2);
CREATE TABLE t2 (j INT);
INSERT INTO t2 VALUES (8),(3),(3);
CREATE TABLE t3 (k INT);
INSERT INTO t3 VALUES (1),(8);
CREATE VIEW v1 AS SELECT * FROM t1 LEFT JOIN ( SELECT t2.* FROM t2 INNER JOIN t3 ON ( k = j ) ) AS alias1 ON ( i = j );