2004-07-16 00:15:55 +02:00
|
|
|
|
--disable_warnings
|
2005-05-13 11:08:08 +02:00
|
|
|
|
drop table if exists t1,t2,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
|
2004-07-20 17:51:02 +02:00
|
|
|
|
drop view if exists t1,t2,`t1a``b`,v1,v2,v3,v4,v5,v6;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
drop database if exists mysqltest;
|
|
|
|
|
--enable_warnings
|
|
|
|
|
use test;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# some basic test of views and its functionality
|
|
|
|
|
#
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# create view on nonexistent table
|
2004-07-16 00:15:55 +02:00
|
|
|
|
-- error 1146
|
|
|
|
|
create view v1 (c,d) as select a,b from t1;
|
|
|
|
|
|
|
|
|
|
create temporary table t1 (a int, b int);
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# view on temporary table
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1352
|
2004-07-16 00:15:55 +02:00
|
|
|
|
create view v1 (c) as select b+1 from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2004-11-29 22:47:50 +01:00
|
|
|
|
create table t1 (a int, b int);
|
2004-07-16 00:15:55 +02:00
|
|
|
|
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# view with variable
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1351
|
2004-07-16 00:15:55 +02:00
|
|
|
|
create view v1 (c,d) as select a,b+@@global.max_user_connections from t1;
|
|
|
|
|
|
|
|
|
|
# simple view
|
|
|
|
|
create view v1 (c) as select b+1 from t1;
|
|
|
|
|
select c from v1;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# temporary table should not hide table of view
|
2004-07-16 00:15:55 +02:00
|
|
|
|
create temporary table t1 (a int, b int);
|
|
|
|
|
# this is empty
|
|
|
|
|
select * from t1;
|
|
|
|
|
# but this based on normal t1
|
|
|
|
|
select c from v1;
|
|
|
|
|
show create table v1;
|
|
|
|
|
show create view v1;
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1347
|
2004-07-16 00:15:55 +02:00
|
|
|
|
show create view t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# try to use fields from underlying table
|
2004-07-16 00:15:55 +02:00
|
|
|
|
-- error 1054
|
|
|
|
|
select a from v1;
|
|
|
|
|
-- error 1054
|
|
|
|
|
select v1.a from v1;
|
|
|
|
|
-- error 1054
|
|
|
|
|
select b from v1;
|
|
|
|
|
-- error 1054
|
|
|
|
|
select v1.b from v1;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# view with different algorithms (explain output differs)
|
2004-07-16 00:15:55 +02:00
|
|
|
|
explain extended select c from v1;
|
|
|
|
|
create algorithm=temptable view v2 (c) as select b+1 from t1;
|
2004-09-24 11:50:10 +02:00
|
|
|
|
show create view v2;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
select c from v2;
|
|
|
|
|
explain extended select c from v2;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# try to use underlying table fields in VIEW creation process
|
2004-07-16 00:15:55 +02:00
|
|
|
|
-- error 1054
|
|
|
|
|
create view v3 (c) as select a+1 from v1;
|
|
|
|
|
-- error 1054
|
|
|
|
|
create view v3 (c) as select b+1 from v1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# VIEW on VIEW test with mixing different algorithms on different order
|
|
|
|
|
create view v3 (c) as select c+1 from v1;
|
|
|
|
|
select c from v3;
|
|
|
|
|
explain extended select c from v3;
|
|
|
|
|
create algorithm=temptable view v4 (c) as select c+1 from v2;
|
|
|
|
|
select c from v4;
|
|
|
|
|
explain extended select c from v4;
|
|
|
|
|
create view v5 (c) as select c+1 from v2;
|
|
|
|
|
select c from v5;
|
|
|
|
|
explain extended select c from v5;
|
|
|
|
|
create algorithm=temptable view v6 (c) as select c+1 from v1;
|
|
|
|
|
select c from v6;
|
|
|
|
|
explain extended select c from v6;
|
|
|
|
|
|
|
|
|
|
# show table/table status test
|
|
|
|
|
show tables;
|
2004-10-10 12:15:14 +02:00
|
|
|
|
show full tables;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
--replace_column 12 # 13 #
|
2004-11-29 22:47:50 +01:00
|
|
|
|
--replace_result 2147483647 38654705663
|
2004-07-16 00:15:55 +02:00
|
|
|
|
show table status;
|
|
|
|
|
|
|
|
|
|
drop view v1,v2,v3,v4,v5,v6;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# alter/create view test
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# view with subqueries of different types
|
|
|
|
|
create 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;
|
|
|
|
|
create view v2 as select c, d from v1;
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from v2;
|
|
|
|
|
|
|
|
|
|
# try to create VIEW with name of existing VIEW
|
|
|
|
|
-- error 1050
|
|
|
|
|
create 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;
|
|
|
|
|
|
|
|
|
|
# 'or replace' should work in this case
|
|
|
|
|
create 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;
|
|
|
|
|
|
|
|
|
|
# try to ALTER unexisting VIEW
|
|
|
|
|
drop view v2;
|
|
|
|
|
-- error 1146
|
|
|
|
|
alter view v2 as select c, d from v1;
|
|
|
|
|
|
|
|
|
|
# 'or replace' on unexisting view
|
|
|
|
|
create or replace view v2 as select c, d from v1;
|
|
|
|
|
|
|
|
|
|
# alter view on existing view
|
|
|
|
|
alter view v1 (c,d) as select a,max(b) from t1 group by a;
|
|
|
|
|
|
|
|
|
|
# check that created view works
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from v2;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# try to drop nonexistent VIEW
|
2004-07-16 00:15:55 +02:00
|
|
|
|
-- error 1051
|
|
|
|
|
drop view v100;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# try to drop table with DROP VIEW
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1347
|
2004-07-16 00:15:55 +02:00
|
|
|
|
drop view t1;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# try to drop VIEW with DROP TABLE
|
2004-07-16 00:15:55 +02:00
|
|
|
|
-- error 1051
|
|
|
|
|
drop table v1;
|
|
|
|
|
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# try to drop table with DROP VIEW
|
2004-07-16 00:15:55 +02:00
|
|
|
|
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# outer left join with merged views
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert into t1 values (1), (2), (3);
|
|
|
|
|
|
|
|
|
|
create view v1 (a) as select a+1 from t1;
|
|
|
|
|
create view v2 (a) as select a-1 from t1;
|
|
|
|
|
|
2005-05-11 01:31:13 +02:00
|
|
|
|
# WL #2486 should enable these tests
|
|
|
|
|
#select * from t1 natural left join v1;
|
|
|
|
|
#select * from v2 natural left join t1;
|
|
|
|
|
#select * from v2 natural left join v1;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
|
|
|
|
|
drop view v1, v2;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# DISTINCT option for VIEW
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert into t1 values (1), (2), (3), (1), (2), (3);
|
|
|
|
|
create view v1 as select distinct a from t1;
|
|
|
|
|
select * from v1;
|
|
|
|
|
explain select * from v1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# syntax compatibility
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1368
|
2004-07-16 00:15:55 +02:00
|
|
|
|
create view v1 as select distinct a from t1 WITH CHECK OPTION;
|
2004-09-03 14:18:40 +02:00
|
|
|
|
create view v1 as select a from t1 WITH CHECK OPTION;
|
|
|
|
|
create view v2 as select a from t1 WITH CASCADED CHECK OPTION;
|
|
|
|
|
create view v3 as select a from t1 WITH LOCAL CHECK OPTION;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
drop view v3 RESTRICT;
|
|
|
|
|
drop view v2 CASCADE;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# aliases
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int);
|
|
|
|
|
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
|
|
|
|
|
create view v1 (c) as select b+1 from t1;
|
|
|
|
|
select test.c from v1 test;
|
|
|
|
|
create algorithm=temptable view v2 (c) as select b+1 from t1;
|
|
|
|
|
select test.c from v2 test;
|
|
|
|
|
select test1.* from v1 test1, v2 test2 where test1.c=test2.c;
|
|
|
|
|
select test2.* from v1 test1, v2 test2 where test1.c=test2.c;
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# LIMIT clause test
|
2004-07-16 00:15:55 +02:00
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert into t1 values (1), (2), (3), (4);
|
|
|
|
|
create view v1 as select a+1 from t1 order by 1 desc limit 2;
|
|
|
|
|
select * from v1;
|
|
|
|
|
explain select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# CREATE ... SELECT view test
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert into t1 values (1), (2), (3), (4);
|
|
|
|
|
create view v1 as select a+1 from t1;
|
|
|
|
|
create table t2 select * from v1;
|
|
|
|
|
show columns from t2;
|
|
|
|
|
select * from t2;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1,t2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# simple view + simple update
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, primary key(a));
|
|
|
|
|
insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10);
|
|
|
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
|
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
|
|
|
# try to update expression
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1348
|
2004-07-16 00:15:55 +02:00
|
|
|
|
update v1 set c=a+c;
|
|
|
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
|
|
|
-- error 1288
|
|
|
|
|
update v2 set a=a+c;
|
|
|
|
|
# updatable field of updateable view
|
|
|
|
|
update v1 set a=a+c;
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# simple view + simple multi-update
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, primary key(a));
|
|
|
|
|
insert into t1 values (10,2), (20,3), (30,4), (40,5), (50,10);
|
|
|
|
|
create table t2 (x int);
|
|
|
|
|
insert into t2 values (10), (20);
|
|
|
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
|
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
|
|
|
# try to update expression
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1348
|
2004-07-16 00:15:55 +02:00
|
|
|
|
update t2,v1 set v1.c=v1.a+v1.c where t2.x=v1.a;
|
|
|
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
|
|
|
-- error 1288
|
|
|
|
|
update t2,v2 set v2.a=v2.v2.a+c where t2.x=v2.a;
|
|
|
|
|
# updatable field of updateable view
|
|
|
|
|
update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.a;
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop table t1,t2;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# MERGE VIEW with WHERE clause
|
2004-07-16 00:15:55 +02:00
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, primary key(b));
|
|
|
|
|
insert into t1 values (1,20), (2,30), (3,40), (4,50), (5,100);
|
|
|
|
|
create view v1 (c) as select b from t1 where a<3;
|
|
|
|
|
# simple select and explaint to be sure that it is MERGE
|
|
|
|
|
select * from v1;
|
|
|
|
|
explain extended select * from v1;
|
|
|
|
|
# update test
|
|
|
|
|
update v1 set c=c+1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
# join of such VIEWs test
|
|
|
|
|
create view v2 (c) as select b from t1 where a>=3;
|
|
|
|
|
select * from v1, v2;
|
|
|
|
|
drop view v1, v2;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# simple view + simple delete
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, primary key(a));
|
|
|
|
|
insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10);
|
|
|
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
|
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
|
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
|
|
|
-- error 1288
|
|
|
|
|
delete from v2 where c < 4;
|
|
|
|
|
# updatable field of updateable view
|
|
|
|
|
delete from v1 where c < 4;
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# simple view + simple multi-delete
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, primary key(a));
|
|
|
|
|
insert into t1 values (1,2), (2,3), (3,4), (4,5), (5,10);
|
|
|
|
|
create table t2 (x int);
|
|
|
|
|
insert into t2 values (1), (2), (3), (4);
|
|
|
|
|
create view v1 (a,c) as select a, b+1 from t1;
|
|
|
|
|
create algorithm=temptable view v2 (a,c) as select a, b+1 from t1;
|
|
|
|
|
# try to update VIEW with forced TEMPORARY TABLE algorithm
|
|
|
|
|
-- error 1288
|
|
|
|
|
delete v2 from t2,v2 where t2.x=v2.a;
|
|
|
|
|
# updatable field of updateable view
|
|
|
|
|
delete v1 from t2,v1 where t2.x=v1.a;
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop table t1,t2;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# key presence check
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, c int, primary key(a,b));
|
|
|
|
|
insert into t1 values (10,2,-1), (20,3,-2), (30,4,-3), (40,5,-4), (50,10,-5);
|
|
|
|
|
create view v1 (x,y) as select a, b from t1;
|
|
|
|
|
create view v2 (x,y) as select a, c from t1;
|
2004-10-07 11:13:42 +02:00
|
|
|
|
set updatable_views_with_limit=NO;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
update v1 set x=x+1;
|
|
|
|
|
update v2 set x=x+1;
|
|
|
|
|
update v1 set x=x+1 limit 1;
|
|
|
|
|
-- error 1288
|
|
|
|
|
update v2 set x=x+1 limit 1;
|
2004-10-07 11:13:42 +02:00
|
|
|
|
set updatable_views_with_limit=YES;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
update v1 set x=x+1 limit 1;
|
|
|
|
|
update v2 set x=x+1 limit 1;
|
2004-10-07 11:13:42 +02:00
|
|
|
|
set updatable_views_with_limit=DEFAULT;
|
|
|
|
|
show variables like "updatable_views_with_limit";
|
2004-07-16 00:15:55 +02:00
|
|
|
|
select * from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# simple insert
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, c int, primary key(a,b));
|
|
|
|
|
insert into t1 values (10,2,-1), (20,3,-2);
|
|
|
|
|
create view v1 (x,y,z) as select c, b, a from t1;
|
|
|
|
|
create view v2 (x,y) as select b, a from t1;
|
|
|
|
|
create view v3 (x,y,z) as select b, a, b from t1;
|
|
|
|
|
create view v4 (x,y,z) as select c+1, b, a from t1;
|
|
|
|
|
create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1;
|
|
|
|
|
# try insert to VIEW with fields duplicate
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v3 values (-60,4,30);
|
|
|
|
|
# try insert to VIEW with expression in SELECT list
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v4 values (-60,4,30);
|
|
|
|
|
# try insert to VIEW using temporary table algorithm
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v5 values (-60,4,30);
|
|
|
|
|
insert into v1 values (-60,4,30);
|
|
|
|
|
insert into v1 (z,y,x) values (50,6,-100);
|
|
|
|
|
insert into v2 values (5,40);
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1,v2,v3,v4,v5;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# insert ... select
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int, c int, primary key(a,b));
|
|
|
|
|
insert into t1 values (10,2,-1), (20,3,-2);
|
|
|
|
|
create table t2 (a int, b int, c int, primary key(a,b));
|
|
|
|
|
insert into t2 values (30,4,-60);
|
|
|
|
|
create view v1 (x,y,z) as select c, b, a from t1;
|
|
|
|
|
create view v2 (x,y) as select b, a from t1;
|
|
|
|
|
create view v3 (x,y,z) as select b, a, b from t1;
|
|
|
|
|
create view v4 (x,y,z) as select c+1, b, a from t1;
|
|
|
|
|
create algorithm=temptable view v5 (x,y,z) as select c, b, a from t1;
|
|
|
|
|
# try insert to VIEW with fields duplicate
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v3 select c, b, a from t2;
|
|
|
|
|
# try insert to VIEW with expression in SELECT list
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v4 select c, b, a from t2;
|
|
|
|
|
# try insert to VIEW using temporary table algorithm
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v5 select c, b, a from t2;
|
|
|
|
|
insert into v1 select c, b, a from t2;
|
|
|
|
|
insert into v1 (z,y,x) select a+20,b+2,-100 from t2;
|
|
|
|
|
insert into v2 select b+1, a+10 from t2;
|
|
|
|
|
select * from t1;
|
2004-08-24 18:50:16 +02:00
|
|
|
|
drop table t1, t2;
|
2004-07-16 00:15:55 +02:00
|
|
|
|
drop view v1,v2,v3,v4,v5;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# outer join based on VIEW with WHERE clause
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, primary key(a));
|
|
|
|
|
insert into t1 values (1), (2), (3);
|
|
|
|
|
create view v1 (x) as select a from t1 where a > 1;
|
|
|
|
|
select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# merging WHERE condition on VIEW on VIEW
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, primary key(a));
|
|
|
|
|
insert into t1 values (1), (2), (3), (200);
|
|
|
|
|
create view v1 (x) as select a from t1 where a > 1;
|
|
|
|
|
create view v2 (y) as select x from v1 where x < 100;
|
|
|
|
|
select * from v2;
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW on non-updatable view
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, primary key(a));
|
|
|
|
|
insert into t1 values (1), (2), (3), (200);
|
|
|
|
|
create ALGORITHM=TEMPTABLE view v1 (x) as select a from t1;
|
|
|
|
|
create view v2 (y) as select x from v1;
|
|
|
|
|
-- error 1288
|
|
|
|
|
update v2 set y=10 where y=2;
|
|
|
|
|
drop table t1;
|
|
|
|
|
drop view v1,v2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# auto_increment field out of VIEW
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int not null auto_increment, b int not null, primary key(a), unique(b));
|
|
|
|
|
create view v1 (x) as select b from t1;
|
|
|
|
|
insert into v1 values (1);
|
|
|
|
|
select last_insert_id();
|
|
|
|
|
insert into t1 (b) values (2);
|
|
|
|
|
select last_insert_id();
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2004-07-20 07:48:28 +02:00
|
|
|
|
#
|
|
|
|
|
# VIEW fields quoting
|
|
|
|
|
#
|
|
|
|
|
set sql_mode='ansi';
|
|
|
|
|
create table t1 ("a*b" int);
|
|
|
|
|
create view v1 as select "a*b" from t1;
|
|
|
|
|
show create view v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
set sql_mode=default;
|
2004-07-20 09:34:39 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW without tables
|
|
|
|
|
#
|
|
|
|
|
create table t1 (t_column int);
|
|
|
|
|
create view v1 as select 'a';
|
|
|
|
|
select * from v1, t1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-07-20 17:51:02 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# quote mark inside table name
|
|
|
|
|
#
|
|
|
|
|
create table `t1a``b` (col1 char(2));
|
|
|
|
|
create view v1 as select * from `t1a``b`;
|
|
|
|
|
select * from v1;
|
|
|
|
|
describe v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table `t1a``b`;
|
2004-07-21 03:26:20 +02:00
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# Changing of underlying table
|
2004-07-21 03:26:20 +02:00
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 char(5),col2 char(5));
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
create table t1 (col1 char(5),newcol2 char(5));
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1356
|
2004-07-21 03:26:20 +02:00
|
|
|
|
insert into v1 values('a','aa');
|
|
|
|
|
drop table t1;
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1356
|
2004-07-21 03:26:20 +02:00
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
2004-07-21 11:14:45 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# check of duplication of column names
|
|
|
|
|
#
|
|
|
|
|
-- error 1060
|
|
|
|
|
create view v1 (a,a) as select 'a','a';
|
2004-07-22 13:05:00 +02:00
|
|
|
|
|
2004-07-22 15:04:30 +02:00
|
|
|
|
#
|
|
|
|
|
# SP variables inside view test
|
|
|
|
|
#
|
WL#2130: Table locking for stored FUNCTIONs
Collect all tables and SPs refered by a statement, and open all tables
with an implicit LOCK TABLES. Do find things refered by triggers and views,
we open them first (and then repeat this until nothing new is found), before
doing the actual lock tables.
mysql-test/r/information_schema.result:
Updated result for WL#2130.
mysql-test/r/lock.result:
Updated result for WL#2130.
mysql-test/r/sp-error.result:
Updated result for WL#2130.
mysql-test/r/sp.result:
Updated result for WL#2130.
mysql-test/r/view.result:
Updated result for WL#2130.
mysql-test/t/information_schema.test:
Disabled one test case due to a bug involving LOCK TABLES,
which shows up with WL#2130.
mysql-test/t/lock.test:
New error message with WL#2130. This change is under debate and might change
in the future, but will do for now.
mysql-test/t/sp-error.test:
Updated for WL#2130. Some tests are voided when table access does work from
functions.
mysql-test/t/sp.test:
Updated for WL#2130.
mysql-test/t/view.test:
Updated for WL#2130.
sql/item_func.cc:
We now have to set net.no_send_ok for functions too, with WL#2130.
sql/share/errmsg.txt:
Reused an error code since the old use was voided by WL#2130, but a new
one was needed instead (similar, but more specific restriction).
sql/sp.cc:
Fixed error handling and collection of used tables for WL#2130.
sql/sp.h:
Fixed error handling and collection of used tables for WL#2130.
sql/sp_head.cc:
Added support functions for collecting and merging hash tables and lists
of used tables from SPs and substatements, for WL#2130.
sql/sp_head.h:
Added support functions for collecting and merging hash tables and lists
of used tables from SPs and substatements, for WL#2130.
sql/sql_base.cc:
Changed the way table->query_id is tested and set during with locked tables
in effect. This makes some SP test cases work with WL#2130, but has a side
effect on some error cases with explicit LOCK TABLES. It's still debated if
this is the correct way, so it might change.
sql/sql_class.h:
Added flags for circumventing some interference between WL#2130 and mysql_make_view().
sql/sql_derived.cc:
Added some missing initializations. (Potential bugs.)
sql/sql_lex.cc:
Clear the new hash tables for WL#2130.
sql/sql_lex.h:
Added hash tables for procedures and tables too (as for functions), for WL#2130.
sql/sql_parse.cc:
WL#2130: Make table accesses from stored functions work by adding an implicit
LOCK TABLES around (most) executed statements. To do this, we have to go through
a loop where we collect all SPs and tables in mysql_execute_statement.
sql/sql_prepare.cc:
Cache both functions and procedures for WL#2130.
sql/sql_show.cc:
Added some missing initializations. (Potential bugs.)
sql/sql_view.cc:
Shortcut mysql_make_view() if thd->shortcut_make_view is true during
the pre-open phase for collecting tables in WL#2130. Otherwise, the
similar mechanism here causes interference.
sql/sql_yacc.yy:
For WL#2130, added caching of procedures and disallowed LOCK/UNLOCK TABLES in SPs.
2005-02-08 20:52:50 +01:00
|
|
|
|
# QQ This can't be tested with the new table locking for functions,
|
|
|
|
|
# QQ since views created in an SP can't be used within the same SP
|
|
|
|
|
# QQ (just as for tables). Instead it fails with error 1146.
|
|
|
|
|
#delimiter //;
|
|
|
|
|
#create procedure p1 () begin declare v int; create view v1 as select v; end;//
|
|
|
|
|
#delimiter ;//
|
|
|
|
|
#-- error 1351
|
|
|
|
|
#call p1();
|
|
|
|
|
#drop procedure p1;
|
2004-07-22 16:52:04 +02:00
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# updatablity should be transitive
|
2004-07-22 16:52:04 +02:00
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 int,col2 char(22));
|
|
|
|
|
insert into t1 values(5,'Hello, world of views');
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
create view v2 as select * from v1;
|
|
|
|
|
update v2 set col2='Hello, view world';
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v2, v1;
|
|
|
|
|
drop table t1;
|
2004-07-23 02:13:21 +02:00
|
|
|
|
|
2004-07-22 13:05:00 +02:00
|
|
|
|
#
|
|
|
|
|
# check 'use index' on view with temporary table
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int);
|
|
|
|
|
create view v1 as select a, sum(b) from t1 group by a;
|
|
|
|
|
-- error 1072
|
|
|
|
|
select b from v1 use index (some_index) where b=1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-07-23 08:25:08 +02:00
|
|
|
|
|
2004-07-23 08:20:58 +02:00
|
|
|
|
#
|
|
|
|
|
# using VIEW fields several times in query resolved via temporary tables
|
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 char(5),col2 char(5));
|
|
|
|
|
create view v1 (col1,col2) as select col1,col2 from t1;
|
|
|
|
|
insert into v1 values('s1','p1'),('s1','p2'),('s1','p3'),('s1','p4'),('s2','p1'),('s3','p2'),('s4','p4');
|
|
|
|
|
select distinct first.col2 from t1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1);
|
|
|
|
|
select distinct first.col2 from v1 first where first.col2 in (select second.col2 from t1 second where second.col1<>first.col1);
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-08-16 22:15:31 +02:00
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# Test of view updatability in prepared statement
|
2004-08-16 22:15:31 +02:00
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create view v1 as select a from t1;
|
|
|
|
|
insert into t1 values (1);
|
|
|
|
|
|
|
|
|
|
#update
|
|
|
|
|
SET @v0 = '2';
|
|
|
|
|
PREPARE stmt FROM 'UPDATE v1 SET a = ?';
|
|
|
|
|
EXECUTE stmt USING @v0;
|
|
|
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
|
|
|
|
|
|
#insert without field list
|
|
|
|
|
SET @v0 = '3';
|
|
|
|
|
PREPARE stmt FROM 'insert into v1 values (?)';
|
|
|
|
|
EXECUTE stmt USING @v0;
|
|
|
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
|
|
|
|
|
|
#insert with field list
|
|
|
|
|
SET @v0 = '4';
|
|
|
|
|
PREPARE stmt FROM 'insert into v1 (a) values (?)';
|
|
|
|
|
EXECUTE stmt USING @v0;
|
|
|
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
|
|
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-08-23 11:38:55 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# error on preparation
|
|
|
|
|
#
|
|
|
|
|
-- error 1096
|
|
|
|
|
CREATE VIEW v02 AS SELECT * FROM DUAL;
|
|
|
|
|
SHOW TABLES;
|
2004-08-23 12:19:59 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# EXISTS with UNION VIEW
|
|
|
|
|
#
|
|
|
|
|
CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2);
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
2004-08-24 14:37:51 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# using VIEW where table is required
|
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 int,col2 char(22));
|
|
|
|
|
create view v1 as select * from t1;
|
2004-09-09 05:59:26 +02:00
|
|
|
|
-- error 1347
|
2004-08-24 14:37:51 +02:00
|
|
|
|
create index i1 on v1 (col1);
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-08-24 17:46:27 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# connection_id(), pi(), current_user(), version() representation test
|
|
|
|
|
#
|
|
|
|
|
CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version();
|
|
|
|
|
SHOW CREATE VIEW v1;
|
|
|
|
|
drop view v1;
|
2004-08-24 18:50:16 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW built over UNION
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 int);
|
|
|
|
|
create table t2 (s2 int);
|
|
|
|
|
insert into t1 values (1), (2);
|
|
|
|
|
insert into t2 values (2), (3);
|
|
|
|
|
create view v1 as select * from t1,t2 union all select * from t1,t2;
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop tables t1, t2;
|
2004-08-24 19:29:44 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Aggregate functions in view list
|
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 int);
|
|
|
|
|
insert into t1 values (1);
|
|
|
|
|
create view v1 as select count(*) from t1;
|
|
|
|
|
insert into t1 values (null);
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-08-24 21:51:23 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Showing VIEW with VIEWs in subquery
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create table t2 (a int);
|
|
|
|
|
create view v1 as select a from t1;
|
|
|
|
|
create view v2 as select a from t2 where a in (select a from v1);
|
|
|
|
|
show create view v2;
|
|
|
|
|
drop view v2, v1;
|
|
|
|
|
drop table t1, t2;
|
2004-08-24 22:07:34 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# SHOW VIEW view with name with spaces
|
|
|
|
|
#
|
|
|
|
|
CREATE VIEW `v 1` AS select 5 AS `5`;
|
|
|
|
|
show create view `v 1`;
|
|
|
|
|
drop view `v 1`;
|
2004-08-25 13:57:57 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Removing database with .frm archives
|
|
|
|
|
#
|
|
|
|
|
create database mysqltest;
|
|
|
|
|
create table mysqltest.t1 (a int, b int);
|
|
|
|
|
create view mysqltest.v1 as select a from mysqltest.t1;
|
|
|
|
|
alter view mysqltest.v1 as select b from mysqltest.t1;
|
|
|
|
|
alter view mysqltest.v1 as select a from mysqltest.t1;
|
|
|
|
|
drop database mysqltest;
|
2004-08-25 15:14:42 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW with full text
|
|
|
|
|
#
|
|
|
|
|
CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2));
|
|
|
|
|
insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer');
|
|
|
|
|
select * from t1 WHERE match (c2) against ('Beer');
|
|
|
|
|
CREATE VIEW v1 AS SELECT * from t1 WHERE match (c2) against ('Beer');
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-08-26 12:11:06 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# distinct in temporary table with a VIEW
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert into t1 values (1),(1),(2),(2),(3),(3);
|
|
|
|
|
create view v1 as select a from t1;
|
|
|
|
|
select distinct a from v1;
|
|
|
|
|
select distinct a from v1 limit 2;
|
|
|
|
|
select distinct a from t1 limit 2;
|
2004-08-26 13:34:56 +02:00
|
|
|
|
prepare stmt1 from "select distinct a from v1 limit 2";
|
|
|
|
|
execute stmt1;
|
|
|
|
|
execute stmt1;
|
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# aggregate function of aggregate function
|
|
|
|
|
#
|
|
|
|
|
create table t1 (tg_column bigint);
|
|
|
|
|
create view v1 as select count(tg_column) as vg_column from t1;
|
|
|
|
|
select avg(vg_column) from v1;
|
2004-08-26 12:11:06 +02:00
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-08-26 23:08:59 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW of VIEW with column renaming
|
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 bigint not null, primary key (col1));
|
|
|
|
|
create table t2 (col1 bigint not null, key (col1));
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
create view v2 as select * from t2;
|
|
|
|
|
insert into v1 values (1);
|
|
|
|
|
insert into v2 values (1);
|
|
|
|
|
create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1;
|
|
|
|
|
select * from v3;
|
|
|
|
|
show create view v3;
|
|
|
|
|
drop view v3, v2, v1;
|
|
|
|
|
drop table t2, t1;
|
2004-08-30 20:47:52 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW based on functions with complex names
|
|
|
|
|
#
|
|
|
|
|
create function `f``1` () returns int return 5;
|
|
|
|
|
create view v1 as select test.`f``1` ();
|
|
|
|
|
show create view v1;
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop function `f``1`;
|
2004-08-30 21:52:50 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# tested problem when function name length close to ALIGN_SIZE
|
|
|
|
|
#
|
|
|
|
|
create function x () returns int return 5;
|
|
|
|
|
create view v1 as select x ();
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop function x;
|
2004-08-31 09:06:38 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW with collation
|
|
|
|
|
#
|
|
|
|
|
create table t2 (col1 char collate latin1_german2_ci);
|
|
|
|
|
create view v2 as select col1 collate latin1_german1_ci from t2;
|
|
|
|
|
show create view v2;
|
|
|
|
|
show create view v2;
|
|
|
|
|
drop view v2;
|
|
|
|
|
drop table t2;
|
2004-08-31 10:58:45 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# order by refers on integer field
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
insert into t1 values (1), (2);
|
|
|
|
|
create view v1 as select 5 from t1 order by 1;
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-09-01 18:00:41 +02:00
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# VIEW over dropped function
|
2004-09-01 18:00:41 +02:00
|
|
|
|
#
|
|
|
|
|
create function x1 () returns int return 5;
|
2004-11-29 22:47:50 +01:00
|
|
|
|
create table t1 (s1 int);
|
2004-09-01 18:00:41 +02:00
|
|
|
|
create view v1 as select x1() from t1;
|
|
|
|
|
drop function x1;
|
2004-12-16 14:31:36 +01:00
|
|
|
|
-- error 1356
|
2004-09-01 18:00:41 +02:00
|
|
|
|
select * from v1;
|
2005-03-15 18:54:44 +01:00
|
|
|
|
--replace_column 8 # 12 # 13 #
|
2004-09-01 18:00:41 +02:00
|
|
|
|
show table status;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-09-01 19:30:48 +02:00
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# VIEW with floating point (long number) as column
|
2004-09-01 19:30:48 +02:00
|
|
|
|
#
|
|
|
|
|
create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1;
|
|
|
|
|
show create view v1;
|
|
|
|
|
drop view v1;
|
2004-09-01 21:48:59 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEWs with national characters
|
|
|
|
|
#
|
|
|
|
|
create table t<> (c<> char);
|
|
|
|
|
create view v<> as select c<> from t<>;
|
|
|
|
|
insert into v<> values ('<27>');
|
|
|
|
|
select * from v<>;
|
|
|
|
|
drop view v<>;
|
|
|
|
|
drop table t<>;
|
2004-09-01 22:27:40 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# problem with used_tables() of outer reference resolved in VIEW
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, b int);
|
|
|
|
|
insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10);
|
|
|
|
|
create view v1(c) as select a+1 from t1 where b >= 4;
|
|
|
|
|
select c from v1 where exists (select * from t1 where a=2 and b=c);
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-09-01 23:11:40 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# view with cast operation
|
|
|
|
|
#
|
|
|
|
|
create view v1 as select cast(1 as char(3));
|
|
|
|
|
show create view v1;
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
2004-09-02 06:40:48 +02:00
|
|
|
|
|
|
|
|
|
#
|
2004-11-28 18:00:42 +01:00
|
|
|
|
# bug handling from VIEWs
|
2004-09-02 06:40:48 +02:00
|
|
|
|
#
|
|
|
|
|
create view v1 as select 'a',1;
|
|
|
|
|
create view v2 as select * from v1 union all select * from v1;
|
|
|
|
|
create view v3 as select * from v2 where 1 = (select `1` from v2);
|
|
|
|
|
create view v4 as select * from v3;
|
|
|
|
|
-- error 1242
|
|
|
|
|
select * from v4;
|
|
|
|
|
drop view v4, v3, v2, v1;
|
2004-09-02 11:09:26 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# VIEW over SELECT with prohibited clauses
|
|
|
|
|
#
|
2004-09-09 13:55:28 +02:00
|
|
|
|
-- error 1350
|
2004-09-02 11:09:26 +02:00
|
|
|
|
create view v1 as select 5 into @w;
|
2004-09-09 13:55:28 +02:00
|
|
|
|
-- error 1350
|
2004-09-02 11:09:26 +02:00
|
|
|
|
create view v1 as select 5 into outfile 'ttt';
|
|
|
|
|
create table t1 (a int);
|
2004-09-09 13:55:28 +02:00
|
|
|
|
-- error 1350
|
2004-09-02 11:09:26 +02:00
|
|
|
|
create view v1 as select a from t1 procedure analyse();
|
|
|
|
|
drop table t1;
|
2004-09-06 13:37:10 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# INSERT into VIEW with ON DUPLICATE
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 int, primary key (s1));
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
insert into v1 values (1) on duplicate key update s1 = 7;
|
|
|
|
|
insert into v1 values (1) on duplicate key update s1 = 7;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-09-07 09:42:23 +02:00
|
|
|
|
|
2004-09-08 09:18:04 +02:00
|
|
|
|
#
|
|
|
|
|
# test of updating and fetching from the same table check
|
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 int);
|
|
|
|
|
create table t2 (col1 int);
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
create view v2 as select * from v1;
|
2005-03-28 14:13:31 +02:00
|
|
|
|
create view v3 as select v2.col1 from v2,t2 where v2.col1 = t2.col1;
|
2004-09-08 09:18:04 +02:00
|
|
|
|
-- error 1093
|
|
|
|
|
update v2 set col1 = (select max(col1) from v1);
|
2005-03-28 14:13:31 +02:00
|
|
|
|
-- error 1093
|
|
|
|
|
update v2 set col1 = (select max(col1) from t1);
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v2 set col1 = (select max(col1) from v2);
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v3 set v3.col1 = (select max(col1) from v1);
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v3 set v3.col1 = (select max(col1) from t1);
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v3 set v3.col1 = (select max(col1) from v2);
|
|
|
|
|
-- error 1093
|
|
|
|
|
update v3 set v3.col1 = (select max(col1) from v3);
|
2004-09-08 09:18:04 +02:00
|
|
|
|
-- error 1093
|
|
|
|
|
delete from v2 where col1 = (select max(col1) from v1);
|
2005-03-28 14:13:31 +02:00
|
|
|
|
-- error 1093
|
|
|
|
|
delete from v2 where col1 = (select max(col1) from t1);
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete from v2 where col1 = (select max(col1) from v2);
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1;
|
|
|
|
|
-- error 1093
|
|
|
|
|
delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1;
|
2004-09-08 09:18:04 +02:00
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v2 values ((select max(col1) from v1));
|
2005-03-28 14:13:31 +02:00
|
|
|
|
-- error 1093
|
|
|
|
|
insert into t1 values ((select max(col1) from v1));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v2 values ((select max(col1) from v1));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v2 values ((select max(col1) from t1));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into t1 values ((select max(col1) from t1));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v2 values ((select max(col1) from t1));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v2 values ((select max(col1) from v2));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into t1 values ((select max(col1) from v2));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v2 values ((select max(col1) from v2));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v3 (col1) values ((select max(col1) from v1));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v3 (col1) values ((select max(col1) from t1));
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v3 (col1) values ((select max(col1) from v2));
|
|
|
|
|
#check with TZ tables in list
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from v2));
|
|
|
|
|
insert into v3 (col1) values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
|
|
|
|
|
-- error 1048
|
|
|
|
|
insert into mysql.time_zone values ('', (select CONVERT_TZ('20050101000000','UTC','MET') from t2));
|
|
|
|
|
# temporary table algorithm view should be equal to subquery in the from clause
|
|
|
|
|
create algorithm=temptable view v4 as select * from t1;
|
|
|
|
|
insert into t1 values (1),(2),(3);
|
|
|
|
|
insert into t1 (col1) values ((select max(col1) from v4));
|
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
|
|
drop view v4,v3,v2,v1;
|
2004-09-08 09:18:04 +02:00
|
|
|
|
drop table t1,t2;
|
2004-09-10 13:01:02 +02:00
|
|
|
|
|
2004-09-07 09:42:23 +02:00
|
|
|
|
#
|
|
|
|
|
# HANDLER with VIEW
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 int);
|
|
|
|
|
create view v1 as select * from t1;
|
2004-09-10 14:08:30 +02:00
|
|
|
|
-- error 1347
|
2004-09-07 09:42:23 +02:00
|
|
|
|
handler v1 open as xx;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-09-10 21:39:04 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# view with WHERE in nested join
|
|
|
|
|
#
|
|
|
|
|
create table t1(a int);
|
|
|
|
|
insert into t1 values (0), (1), (2), (3);
|
|
|
|
|
create table t2 (a int);
|
|
|
|
|
insert into t2 select a from t1 where a > 1;
|
|
|
|
|
create view v1 as select a from t1 where a > 1;
|
|
|
|
|
select * from t1 left join (t2 as t, v1) on v1.a=t1.a;
|
|
|
|
|
select * from t1 left join (t2 as t, t2) on t2.a=t1.a;
|
|
|
|
|
drop view v1;
|
2004-09-24 11:50:10 +02:00
|
|
|
|
drop table t1, t2;
|
2004-09-16 22:45:20 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Collation with view update
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 char);
|
|
|
|
|
create view v1 as select s1 collate latin1_german1_ci as s1 from t1;
|
|
|
|
|
insert into v1 values ('a');
|
|
|
|
|
select * from v1;
|
|
|
|
|
update v1 set s1='b';
|
|
|
|
|
select * from v1;
|
|
|
|
|
update v1,t1 set v1.s1='c' where t1.s1=v1.s1;
|
|
|
|
|
select * from v1;
|
2004-10-09 17:51:19 +02:00
|
|
|
|
prepare stmt1 from "update v1,t1 set v1.s1=? where t1.s1=v1.s1";
|
|
|
|
|
set @arg='d';
|
|
|
|
|
execute stmt1 using @arg;
|
|
|
|
|
select * from v1;
|
|
|
|
|
set @arg='e';
|
|
|
|
|
execute stmt1 using @arg;
|
|
|
|
|
select * from v1;
|
|
|
|
|
deallocate prepare stmt1;
|
2004-09-16 22:45:20 +02:00
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-09-24 11:50:10 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# test view with LOCK TABLES (work around)
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create table t2 (a int);
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
lock tables t1 read, v1 read;
|
|
|
|
|
select * from v1;
|
|
|
|
|
-- error 1100
|
|
|
|
|
select * from t2;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1, t2;
|
2004-09-29 16:10:17 +02:00
|
|
|
|
|
2004-09-03 14:18:40 +02:00
|
|
|
|
#
|
|
|
|
|
# WITH CHECK OPTION insert/update test
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create view v1 as select * from t1 where a < 2 with check option;
|
|
|
|
|
# simple insert
|
|
|
|
|
insert into v1 values(1);
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1369
|
2004-09-03 14:18:40 +02:00
|
|
|
|
insert into v1 values(3);
|
|
|
|
|
# simple insert with ignore
|
|
|
|
|
insert ignore into v1 values (2),(3),(0);
|
|
|
|
|
select * from t1;
|
|
|
|
|
# prepare data for next check
|
|
|
|
|
delete from t1;
|
|
|
|
|
# INSERT SELECT test
|
|
|
|
|
insert into v1 SELECT 1;
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1369
|
2004-09-03 14:18:40 +02:00
|
|
|
|
insert into v1 SELECT 3;
|
|
|
|
|
# prepare data for next check
|
|
|
|
|
create table t2 (a int);
|
|
|
|
|
insert into t2 values (2),(3),(0);
|
|
|
|
|
# INSERT SELECT with ignore test
|
|
|
|
|
insert ignore into v1 SELECT a from t2;
|
|
|
|
|
select * from t1;
|
|
|
|
|
#simple UPDATE test
|
|
|
|
|
update v1 set a=-1 where a=0;
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1369
|
2004-09-03 14:18:40 +02:00
|
|
|
|
update v1 set a=2 where a=1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
# prepare data for next check
|
|
|
|
|
update v1 set a=0 where a=0;
|
|
|
|
|
insert into t2 values (1);
|
|
|
|
|
# multiupdate test
|
|
|
|
|
update v1,t2 set v1.a=v1.a-1 where v1.a=t2.a;
|
|
|
|
|
select * from t1;
|
|
|
|
|
# prepare data for next check
|
|
|
|
|
update v1 set a=a+1;
|
|
|
|
|
# multiupdate with ignore test
|
|
|
|
|
update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a;
|
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1, t2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# CASCADED/LOCAL CHECK OPTION test
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create view v1 as select * from t1 where a < 2 with check option;
|
|
|
|
|
create view v2 as select * from v1 where a > 0 with local check option;
|
|
|
|
|
create view v3 as select * from v1 where a > 0 with cascaded check option;
|
|
|
|
|
insert into v2 values (1);
|
|
|
|
|
insert into v3 values (1);
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1369
|
2004-09-03 14:18:40 +02:00
|
|
|
|
insert into v2 values (0);
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1369
|
2004-09-03 14:18:40 +02:00
|
|
|
|
insert into v3 values (0);
|
|
|
|
|
insert into v2 values (2);
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1369
|
2004-09-03 14:18:40 +02:00
|
|
|
|
insert into v3 values (2);
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v3,v2,v1;
|
|
|
|
|
drop table t1;
|
2004-09-06 22:55:36 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# CHECK OPTION with INSERT ... ON DUPLICATE KEY UPDATE
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, primary key (a));
|
|
|
|
|
create view v1 as select * from t1 where a < 2 with check option;
|
|
|
|
|
insert into v1 values (1) on duplicate key update a=2;
|
2004-10-05 02:05:20 +02:00
|
|
|
|
-- error 1369
|
2004-09-06 22:55:36 +02:00
|
|
|
|
insert into v1 values (1) on duplicate key update a=2;
|
|
|
|
|
insert ignore into v1 values (1) on duplicate key update a=2;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-10-07 14:43:04 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# check cyclic referencing protection on altering view
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 int);
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
create view v2 as select * from v1;
|
|
|
|
|
-- error 1146
|
|
|
|
|
alter view v1 as select * from v2;
|
|
|
|
|
-- error 1066
|
|
|
|
|
alter view v1 as select * from v1;
|
|
|
|
|
-- error 1146
|
|
|
|
|
create or replace view v1 as select * from v2;
|
|
|
|
|
-- error 1066
|
|
|
|
|
create or replace view v1 as select * from v1;
|
|
|
|
|
drop view v2,v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# check altering differ options
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
show create view v1;
|
|
|
|
|
alter algorithm=undefined view v1 as select * from t1 with check option;
|
|
|
|
|
show create view v1;
|
|
|
|
|
alter algorithm=merge view v1 as select * from t1 with cascaded check option;
|
|
|
|
|
show create view v1;
|
|
|
|
|
alter algorithm=temptable view v1 as select * from t1;
|
|
|
|
|
show create view v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-10-07 21:54:31 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# updating view with subquery in the WHERE clause
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 int);
|
|
|
|
|
create table t2 (s1 int);
|
|
|
|
|
create view v2 as select * from t2 where s1 in (select s1 from t1);
|
|
|
|
|
insert into v2 values (5);
|
|
|
|
|
insert into t1 values (5);
|
|
|
|
|
select * from v2;
|
|
|
|
|
update v2 set s1 = 0;
|
|
|
|
|
select * from v2;
|
|
|
|
|
select * from t2;
|
|
|
|
|
# check it with check option
|
|
|
|
|
alter view v2 as select * from t2 where s1 in (select s1 from t1) with check option;
|
|
|
|
|
insert into v2 values (5);
|
|
|
|
|
-- error 1369
|
|
|
|
|
update v2 set s1 = 1;
|
|
|
|
|
insert into t1 values (1);
|
|
|
|
|
update v2 set s1 = 1;
|
|
|
|
|
select * from v2;
|
|
|
|
|
select * from t2;
|
|
|
|
|
# scheck how VIEWs with subqueries work with prepared statements
|
|
|
|
|
prepare stmt1 from "select * from v2;";
|
|
|
|
|
execute stmt1;
|
|
|
|
|
insert into t1 values (0);
|
|
|
|
|
execute stmt1;
|
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
|
drop view v2;
|
|
|
|
|
drop table t1, t2;
|
2004-10-21 12:11:15 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# test of substring_index with view
|
|
|
|
|
#
|
|
|
|
|
create table t1 (t time);
|
|
|
|
|
create view v1 as select substring_index(t,':',2) as t from t1;
|
|
|
|
|
insert into t1 (t) values ('12:24:10');
|
|
|
|
|
select substring_index(t,':',2) from t1;
|
|
|
|
|
select substring_index(t,':',2) from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2004-10-21 12:30:25 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# test of cascaded check option for whiew without WHERE clause
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 tinyint);
|
|
|
|
|
create view v1 as select * from t1 where s1 <> 0 with local check option;
|
|
|
|
|
create view v2 as select * from v1 with cascaded check option;
|
|
|
|
|
-- error 1369
|
|
|
|
|
insert into v2 values (0);
|
|
|
|
|
drop view v2, v1;
|
|
|
|
|
drop table t1;
|
2004-10-21 13:32:10 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# inserting single value with check option failed always get error
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 int);
|
|
|
|
|
create view v1 as select * from t1 where s1 < 5 with check option;
|
|
|
|
|
#single value
|
|
|
|
|
-- error 1369
|
|
|
|
|
insert ignore into v1 values (6);
|
|
|
|
|
#several values
|
|
|
|
|
insert ignore into v1 values (6),(3);
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2004-10-21 16:05:45 +02:00
|
|
|
|
#
|
|
|
|
|
# changing value by trigger and CHECK OPTION
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 tinyint);
|
|
|
|
|
create trigger t1_bi before insert on t1 for each row set new.s1 = 500;
|
|
|
|
|
create view v1 as select * from t1 where s1 <> 127 with check option;
|
|
|
|
|
-- error 1369
|
|
|
|
|
insert into v1 values (0);
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from t1;
|
2004-10-21 17:10:59 +02:00
|
|
|
|
drop trigger t1.t1_bi;
|
2004-10-21 16:05:45 +02:00
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2004-10-21 17:10:59 +02:00
|
|
|
|
#
|
|
|
|
|
# CASCADED should be used for all underlaying VIEWs
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 tinyint);
|
|
|
|
|
create view v1 as select * from t1 where s1 <> 0;
|
|
|
|
|
create view v2 as select * from v1 where s1 <> 1 with cascaded check option;
|
|
|
|
|
-- error 1369
|
|
|
|
|
insert into v2 values (0);
|
|
|
|
|
select * from v2;
|
|
|
|
|
select * from t1;
|
|
|
|
|
drop view v2, v1;
|
|
|
|
|
drop table t1;
|
2004-10-21 20:53:27 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# LOAD DATA with view and CHECK OPTION
|
|
|
|
|
#
|
|
|
|
|
# fixed length fields
|
|
|
|
|
create table t1 (a int, b char(10));
|
|
|
|
|
create view v1 as select * from t1 where a != 0 with check option;
|
|
|
|
|
-- error 1369
|
|
|
|
|
load data infile '../../std_data/loaddata3.dat' into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
|
|
|
|
|
select * from t1;
|
|
|
|
|
select * from v1;
|
|
|
|
|
delete from t1;
|
|
|
|
|
load data infile '../../std_data/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
|
|
|
|
|
select * from t1;
|
|
|
|
|
select * from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
# variable length fields
|
|
|
|
|
create table t1 (a text, b text);
|
|
|
|
|
create view v1 as select * from t1 where a <> 'Field A' with check option;
|
|
|
|
|
-- error 1369
|
|
|
|
|
load data infile '../../std_data/loaddata2.dat' into table v1 fields terminated by ',' enclosed by '''';
|
|
|
|
|
select concat('|',a,'|'), concat('|',b,'|') from t1;
|
|
|
|
|
select concat('|',a,'|'), concat('|',b,'|') from v1;
|
|
|
|
|
delete from t1;
|
|
|
|
|
load data infile '../../std_data/loaddata2.dat' ignore into table v1 fields terminated by ',' enclosed by '''';
|
|
|
|
|
select concat('|',a,'|'), concat('|',b,'|') from t1;
|
|
|
|
|
select concat('|',a,'|'), concat('|',b,'|') from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2004-10-25 16:32:28 +02:00
|
|
|
|
#
|
|
|
|
|
# Trys update table from which we select using views and subqueries
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 smallint);
|
|
|
|
|
create view v1 as select * from t1 where 20 < (select (s1) from t1);
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v1 values (30);
|
|
|
|
|
create view v2 as select * from t1;
|
|
|
|
|
create view v3 as select * from t1 where 20 < (select (s1) from v2);
|
|
|
|
|
-- error 1288
|
|
|
|
|
insert into v3 values (30);
|
|
|
|
|
create view v4 as select * from v2 where 20 < (select (s1) from t1);
|
|
|
|
|
-- error 1093
|
|
|
|
|
insert into v4 values (30);
|
|
|
|
|
drop view v4, v3, v2, v1;
|
|
|
|
|
drop table t1;
|
2004-11-21 09:12:11 +01:00
|
|
|
|
|
2004-10-28 18:37:25 +02:00
|
|
|
|
#
|
|
|
|
|
# CHECK TABLE with VIEW
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
check table t1,v1;
|
|
|
|
|
check table v1,t1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
check table v1;
|
|
|
|
|
drop view v1;
|
2004-11-21 19:08:12 +01:00
|
|
|
|
|
2004-09-14 18:28:29 +02:00
|
|
|
|
#
|
|
|
|
|
# merge of VIEW with several tables
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create table t2 (a int);
|
|
|
|
|
create table t3 (a int);
|
|
|
|
|
insert into t1 values (1), (2), (3);
|
|
|
|
|
insert into t2 values (1), (3);
|
|
|
|
|
insert into t3 values (1), (2), (4);
|
|
|
|
|
# view over tables
|
|
|
|
|
create view v3 (a,b) as select t1.a as a, t2.a as b from t1 left join t2 on (t1.a=t2.a);
|
|
|
|
|
select * from t3 left join v3 on (t3.a = v3.a);
|
|
|
|
|
explain extended select * from t3 left join v3 on (t3.a = v3.a);
|
|
|
|
|
# view over views
|
|
|
|
|
create view v1 (a) as select a from t1;
|
|
|
|
|
create view v2 (a) as select a from t2;
|
|
|
|
|
create view v4 (a,b) as select v1.a as a, v2.a as b from v1 left join v2 on (v1.a=v2.a);
|
|
|
|
|
select * from t3 left join v4 on (t3.a = v4.a);
|
|
|
|
|
explain extended select * from t3 left join v4 on (t3.a = v4.a);
|
|
|
|
|
# PS with view over views
|
|
|
|
|
prepare stmt1 from "select * from t3 left join v4 on (t3.a = v4.a);";
|
|
|
|
|
execute stmt1;
|
|
|
|
|
execute stmt1;
|
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
|
drop view v4,v3,v2,v1;
|
|
|
|
|
drop tables t1,t2,t3;
|
2004-09-15 22:42:56 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# updating of join view
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, primary key (a), b int);
|
|
|
|
|
create table t2 (a int, primary key (a));
|
|
|
|
|
insert into t1 values (1,100), (2,200);
|
|
|
|
|
insert into t2 values (1), (3);
|
|
|
|
|
# legal view for update
|
|
|
|
|
create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2;
|
|
|
|
|
update v3 set a= 10 where a=1;
|
|
|
|
|
select * from t1;
|
|
|
|
|
select * from t2;
|
|
|
|
|
# view without primary key
|
|
|
|
|
create view v2 (a,b) as select t1.b as a, t2.a as b from t1, t2;
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
set updatable_views_with_limit=NO;
|
2004-09-15 22:42:56 +02:00
|
|
|
|
-- error 1288
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
update v2 set a= 10 where a=200 limit 1;
|
|
|
|
|
set updatable_views_with_limit=DEFAULT;
|
2004-09-15 22:42:56 +02:00
|
|
|
|
# just view selects
|
|
|
|
|
select * from v3;
|
|
|
|
|
select * from v2;
|
|
|
|
|
# prepare statement with updating join view
|
|
|
|
|
set @a= 10;
|
|
|
|
|
set @b= 100;
|
|
|
|
|
prepare stmt1 from "update v3 set a= ? where a=?";
|
|
|
|
|
execute stmt1 using @a,@b;
|
|
|
|
|
select * from v3;
|
|
|
|
|
set @a= 300;
|
|
|
|
|
set @b= 10;
|
|
|
|
|
execute stmt1 using @a,@b;
|
|
|
|
|
select * from v3;
|
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
|
drop view v3,v2;
|
|
|
|
|
drop tables t1,t2;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# inserting/deleting join view
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int, primary key (a), b int);
|
|
|
|
|
create table t2 (a int, primary key (a), b int);
|
|
|
|
|
insert into t2 values (1000, 2000);
|
|
|
|
|
create view v3 (a,b) as select t1.a as a, t2.a as b from t1, t2;
|
|
|
|
|
# inserting into join view without field list
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
-- error 1394
|
2004-09-15 22:42:56 +02:00
|
|
|
|
insert into v3 values (1,2);
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
-- error 1394
|
2004-09-15 22:42:56 +02:00
|
|
|
|
insert into v3 select * from t2;
|
|
|
|
|
# inserting in several tables of join view
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
-- error 1393
|
2004-09-15 22:42:56 +02:00
|
|
|
|
insert into v3(a,b) values (1,2);
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
-- error 1393
|
2004-09-15 22:42:56 +02:00
|
|
|
|
insert into v3(a,b) select * from t2;
|
|
|
|
|
# correct inserts into join view
|
|
|
|
|
insert into v3(a) values (1);
|
|
|
|
|
insert into v3(b) values (10);
|
|
|
|
|
insert into v3(a) select a from t2;
|
|
|
|
|
insert into v3(b) select b from t2;
|
|
|
|
|
insert into v3(a) values (1) on duplicate key update a=a+10000+VALUES(a);
|
|
|
|
|
select * from t1;
|
|
|
|
|
select * from t2;
|
|
|
|
|
# try delete from join view
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
-- error 1395
|
2004-09-15 22:42:56 +02:00
|
|
|
|
delete from v3;
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
-- error 1395
|
2004-09-15 22:42:56 +02:00
|
|
|
|
delete v3,t1 from v3,t1;
|
2005-03-28 14:13:31 +02:00
|
|
|
|
-- error 1395
|
|
|
|
|
delete t1,v3 from t1,v3;
|
2004-09-15 22:42:56 +02:00
|
|
|
|
# delete from t1 just to reduce result set size
|
|
|
|
|
delete from t1;
|
|
|
|
|
# prepare statement with insert join view
|
|
|
|
|
prepare stmt1 from "insert into v3(a) values (?);";
|
|
|
|
|
set @a= 100;
|
|
|
|
|
execute stmt1 using @a;
|
|
|
|
|
set @a= 300;
|
|
|
|
|
execute stmt1 using @a;
|
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
|
prepare stmt1 from "insert into v3(a) select ?;";
|
|
|
|
|
set @a= 101;
|
|
|
|
|
execute stmt1 using @a;
|
|
|
|
|
set @a= 301;
|
|
|
|
|
execute stmt1 using @a;
|
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
|
select * from v3;
|
|
|
|
|
|
post-merge fix
mysql-test/r/view.result:
changes in error number, and key in view processing
mysql-test/t/view.test:
changes in error number, and key in view processing
sql/mysql_priv.h:
changes functions
sql/sp.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_base.cc:
fixed finding table, taking in account join view, which can have not TABLE pointer
now we report to setup_tables(), are we setuping SELECT...INSERT and ennumerete insert table separately
sql/sql_delete.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_help.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_insert.cc:
fixed returning value of functions
sql/sql_load.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
removed second setup_tables call (merge)
sql/sql_olap.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_parse.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_prepare.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_select.cc:
now we report to setup_tables(), are we setuping SELECT...INSERT
sql/sql_update.cc:
UPDATE->MULTIUPDATE switching fixed
sql/sql_view.cc:
returning value fixed
sql/sql_view.h:
returning value fixed
2004-11-25 01:23:13 +01:00
|
|
|
|
drop view v3;
|
2004-09-15 22:42:56 +02:00
|
|
|
|
drop tables t1,t2;
|
2005-01-19 14:19:10 +01:00
|
|
|
|
|
2005-01-19 17:23:24 +01:00
|
|
|
|
#
|
2005-01-19 14:19:10 +01:00
|
|
|
|
# View field names should be case insensitive
|
2005-01-19 17:23:24 +01:00
|
|
|
|
#
|
2005-01-19 14:19:10 +01:00
|
|
|
|
create table t1(f1 int);
|
|
|
|
|
create view v1 as select f1 from t1;
|
|
|
|
|
select * from v1 where F1 = 1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2005-01-19 17:23:24 +01:00
|
|
|
|
|
2005-01-18 20:58:12 +01:00
|
|
|
|
#
|
|
|
|
|
# Resolving view fields in subqueries in VIEW (Bug #6394)
|
|
|
|
|
#
|
|
|
|
|
create table t1(c1 int);
|
|
|
|
|
create table t2(c2 int);
|
|
|
|
|
insert into t1 values (1),(2),(3);
|
|
|
|
|
insert into t2 values (1);
|
|
|
|
|
SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2);
|
|
|
|
|
SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1);
|
|
|
|
|
create view v1 as SELECT c1 FROM t1 WHERE c1 IN (SELECT c2 FROM t2);
|
|
|
|
|
create view v2 as SELECT c1 FROM t1 WHERE EXISTS (SELECT c2 FROM t2 WHERE c2 = c1);
|
|
|
|
|
select * from v1;
|
|
|
|
|
select * from v2;
|
2005-02-10 22:01:59 +01:00
|
|
|
|
select * from (select c1 from v2) X;
|
2005-01-18 20:58:12 +01:00
|
|
|
|
drop view v2, v1;
|
|
|
|
|
drop table t1, t2;
|
2005-01-31 09:43:36 +01:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# view over other view setup (BUG#7433)
|
|
|
|
|
#
|
|
|
|
|
CREATE TABLE t1 (C1 INT, C2 INT);
|
|
|
|
|
CREATE TABLE t2 (C2 INT);
|
|
|
|
|
CREATE VIEW v1 AS SELECT C2 FROM t2;
|
|
|
|
|
CREATE VIEW v2 AS SELECT C1 FROM t1 LEFT OUTER JOIN v1 USING (C2);
|
|
|
|
|
SELECT * FROM v2;
|
|
|
|
|
drop view v2, v1;
|
|
|
|
|
drop table t1, t2;
|
2005-01-31 15:24:11 +01:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# view and group_concat() (BUG#7116)
|
|
|
|
|
#
|
|
|
|
|
create table t1 (col1 char(5),col2 int,col3 int);
|
|
|
|
|
insert into t1 values ('one',10,25), ('two',10,50), ('two',10,50), ('one',20,25), ('one',30,25);
|
|
|
|
|
create view v1 as select * from t1;
|
|
|
|
|
select col1,group_concat(col2,col3) from t1 group by col1;
|
|
|
|
|
select col1,group_concat(col2,col3) from v1 group by col1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
2005-02-22 11:27:08 +01:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Item_ref resolved as view field (BUG#6894)
|
|
|
|
|
#
|
|
|
|
|
create table t1 (s1 int, s2 char);
|
|
|
|
|
create view v1 as select s1, s2 from t1;
|
|
|
|
|
-- error 1054
|
|
|
|
|
select s2 from v1 vq1 where 2 = (select count(*) from v1 vq2 having vq1.s2 = vq2.s2);
|
|
|
|
|
select s2 from v1 vq1 where 2 = (select count(*) aa from v1 vq2 having vq1.s2 = aa);
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1;
|
|
|
|
|
|
2005-03-28 14:13:31 +02:00
|
|
|
|
#
|
|
|
|
|
# Test case for bug #9398 CREATE TABLE with SELECT from a multi-table view
|
|
|
|
|
#
|
|
|
|
|
CREATE TABLE t1 (a1 int);
|
|
|
|
|
CREATE TABLE t2 (a2 int);
|
|
|
|
|
INSERT INTO t1 VALUES (1), (2), (3), (4);
|
|
|
|
|
INSERT INTO t2 VALUES (1), (2), (3);
|
|
|
|
|
CREATE VIEW v1(a,b) AS SELECT a1,a2 FROM t1 JOIN t2 ON a1=a2 WHERE a1>1;
|
|
|
|
|
|
|
|
|
|
SELECT * FROM v1;
|
|
|
|
|
CREATE TABLE t3 SELECT * FROM v1;
|
|
|
|
|
SELECT * FROM t3;
|
|
|
|
|
|
|
|
|
|
DROP VIEW v1;
|
|
|
|
|
DROP TABLE t1,t2,t3;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Test for BUG#8703 "insert into table select from view crashes"
|
|
|
|
|
#
|
|
|
|
|
create table t1 (a int);
|
|
|
|
|
create table t2 like t1;
|
|
|
|
|
create table t3 like t1;
|
|
|
|
|
create view v1 as select t1.a x, t2.a y from t1 join t2 where t1.a=t2.a;
|
|
|
|
|
insert into t3 select x from v1;
|
|
|
|
|
insert into t2 select x from v1;
|
|
|
|
|
drop view v1;
|
|
|
|
|
drop table t1,t2,t3;
|
2005-04-14 08:06:37 +02:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Test for BUG #6106: query over a view using subquery for the underlying table
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 (col1 int PRIMARY KEY, col2 varchar(10));
|
|
|
|
|
INSERT INTO t1 VALUES(1,'trudy');
|
|
|
|
|
INSERT INTO t1 VALUES(2,'peter');
|
|
|
|
|
INSERT INTO t1 VALUES(3,'sanja');
|
|
|
|
|
INSERT INTO t1 VALUES(4,'monty');
|
|
|
|
|
INSERT INTO t1 VALUES(5,'david');
|
|
|
|
|
INSERT INTO t1 VALUES(6,'kent');
|
|
|
|
|
INSERT INTO t1 VALUES(7,'carsten');
|
|
|
|
|
INSERT INTO t1 VALUES(8,'ranger');
|
|
|
|
|
INSERT INTO t1 VALUES(10,'matt');
|
|
|
|
|
CREATE TABLE t2 (col1 int, col2 int, col3 char(1));
|
|
|
|
|
INSERT INTO t2 VALUES (1,1,'y');
|
|
|
|
|
INSERT INTO t2 VALUES (1,2,'y');
|
|
|
|
|
INSERT INTO t2 VALUES (2,1,'n');
|
|
|
|
|
INSERT INTO t2 VALUES (3,1,'n');
|
|
|
|
|
INSERT INTO t2 VALUES (4,1,'y');
|
|
|
|
|
INSERT INTO t2 VALUES (4,2,'n');
|
|
|
|
|
INSERT INTO t2 VALUES (4,3,'n');
|
|
|
|
|
INSERT INTO t2 VALUES (6,1,'n');
|
|
|
|
|
INSERT INTO t2 VALUES (8,1,'y');
|
|
|
|
|
|
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
|
|
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
|
|
|
FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1
|
|
|
|
|
WHERE b.col2 IS NULL OR
|
|
|
|
|
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
|
|
|
|
|
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
|
|
|
FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1
|
|
|
|
|
WHERE b.col2 IS NULL OR
|
|
|
|
|
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
|
|
|
|
|
|
|
|
|
|
CREATE VIEW v2 AS SELECT * FROM t2;
|
|
|
|
|
|
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
|
|
|
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
|
|
|
|
WHERE b.col2 IS NULL OR
|
|
|
|
|
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
|
|
|
|
|
|
|
|
|
# Tests from the report for bug #6107
|
|
|
|
|
|
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
|
|
|
FROM v2 b RIGHT JOIN v1 a ON a.col1=b.col1
|
|
|
|
|
WHERE a.col1 IN (1,5,9) AND
|
|
|
|
|
(b.col2 IS NULL OR
|
|
|
|
|
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1));
|
|
|
|
|
|
|
|
|
|
CREATE VIEW v3 AS SELECT * FROM t1 WHERE col1 IN (1,5,9);
|
|
|
|
|
|
|
|
|
|
SELECT a.col1,a.col2,b.col2,b.col3
|
|
|
|
|
FROM v2 b RIGHT JOIN v3 a ON a.col1=b.col1
|
|
|
|
|
WHERE b.col2 IS NULL OR
|
|
|
|
|
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
|
|
|
|
|
|
|
|
|
|
DROP VIEW v1,v2,v3;
|
|
|
|
|
DROP TABLE t1,t2;
|
2005-04-22 22:13:46 +02:00
|
|
|
|
|
|
|
|
|
# BUG#8490 Select from views containing subqueries causes server to hang
|
|
|
|
|
# forever.
|
|
|
|
|
create table t1 as select 1 A union select 2 union select 3;
|
|
|
|
|
create table t2 as select * from t1;
|
|
|
|
|
create view v1 as select * from t1 where a in (select * from t2);
|
|
|
|
|
select * from v1 A, v1 B where A.a = B.a;
|
|
|
|
|
create table t3 as select a a,a b from t2;
|
|
|
|
|
create view v2 as select * from t3 where
|
|
|
|
|
a in (select * from t1) or b in (select * from t2);
|
|
|
|
|
select * from v2 A, v2 B where A.a = B.b;
|
|
|
|
|
drop view v1, v2;
|
|
|
|
|
drop table t1, t2, t3;
|
|
|
|
|
|
2005-05-11 01:31:13 +02:00
|
|
|
|
#
|
|
|
|
|
# Test case for bug #8528: select from view over multi-table view
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
CREATE TABLE t1 (a int);
|
|
|
|
|
CREATE TABLE t2 (b int);
|
|
|
|
|
INSERT INTO t1 VALUES (1), (2), (3), (4);
|
|
|
|
|
INSERT INTO t2 VALUES (4), (2);
|
|
|
|
|
|
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1,t2 WHERE t1.a=t2.b;
|
|
|
|
|
SELECT * FROM v1;
|
|
|
|
|
CREATE VIEW v2 AS SELECT * FROM v1;
|
|
|
|
|
SELECT * FROM v2;
|
|
|
|
|
|
|
|
|
|
DROP VIEW v2,v1;
|