2004-07-16 00:15:55 +02:00
--disable_warnings
2005-11-02 05:05:19 +01:00
drop table if exists t1,t2,t3,t4,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;
2011-12-15 09:21:15 +01:00
SET @save_optimizer_switch=@@optimizer_switch;
SET optimizer_switch='outer_join_with_cache=off';
2004-07-16 00:15:55 +02:00
#
# some basic test of views and its functionality
#
2004-11-28 18:00:42 +01:00
# create view on nonexistent table
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2004-07-16 00:15:55 +02:00
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
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_SELECT_TMPTABLE
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
2006-10-12 16:02:57 +02:00
-- error ER_VIEW_SELECT_VARIABLE
2004-07-16 00:15:55 +02:00
create view v1 (c,d) as select a,b+@@global.max_user_connections from t1;
2006-10-12 16:02:57 +02:00
-- error ER_VIEW_SELECT_VARIABLE
create view v1 (c,d) as select a,b from t1
where a = @@global.max_user_connections;
2004-07-16 00:15:55 +02:00
# simple view
create view v1 (c) as select b+1 from t1;
select c from v1;
2007-06-09 13:52:37 +02:00
select is_updatable from information_schema.views where table_name='v1';
2004-07-16 00:15:55 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_WRONG_OBJECT
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
2009-03-03 21:34:18 +01:00
-- error ER_BAD_FIELD_ERROR
2004-07-16 00:15:55 +02:00
select a from v1;
2009-03-03 21:34:18 +01:00
-- error ER_BAD_FIELD_ERROR
2004-07-16 00:15:55 +02:00
select v1.a from v1;
2009-03-03 21:34:18 +01:00
-- error ER_BAD_FIELD_ERROR
2004-07-16 00:15:55 +02:00
select b from v1;
2009-03-03 21:34:18 +01:00
-- error ER_BAD_FIELD_ERROR
2004-07-16 00:15:55 +02:00
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
2009-03-03 21:34:18 +01:00
-- error ER_BAD_FIELD_ERROR
2004-07-16 00:15:55 +02:00
create view v3 (c) as select a+1 from v1;
2009-03-03 21:34:18 +01:00
-- error ER_BAD_FIELD_ERROR
2004-07-16 00:15:55 +02:00
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;
2010-02-10 20:06:24 +01:00
--replace_column 8 # 12 # 13 # 14 #
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
2009-03-03 21:34:18 +01:00
-- error ER_TABLE_EXISTS_ERROR
2004-07-16 00:15:55 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2004-07-16 00:15:55 +02:00
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
2009-03-03 21:34:18 +01:00
-- error ER_BAD_TABLE_ERROR
2004-07-16 00:15:55 +02:00
drop view v100;
2004-11-28 18:00:42 +01:00
# try to drop table with DROP VIEW
2009-03-03 21:34:18 +01:00
-- error ER_WRONG_OBJECT
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
2009-03-03 21:34:18 +01:00
-- error ER_BAD_TABLE_ERROR
2004-07-16 00:15:55 +02:00
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-07-31 11:49:55 +02:00
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);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_NONUPD_CHECK
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;
2007-06-09 13:52:37 +02:00
select is_updatable from information_schema.views where table_name='v2';
select is_updatable from information_schema.views where table_name='v1';
2004-07-16 00:15:55 +02:00
# try to update expression
2009-03-03 21:34:18 +01:00
-- error ER_NONUPDATEABLE_COLUMN
2004-07-16 00:15:55 +02:00
update v1 set c=a+c;
# try to update VIEW with forced TEMPORARY TABLE algorithm
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
2004-07-16 00:15:55 +02:00
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
2009-03-03 21:34:18 +01:00
-- error ER_NONUPDATEABLE_COLUMN
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
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
2004-07-16 00:15:55 +02:00
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
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
2004-07-16 00:15:55 +02:00
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
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
2004-07-16 00:15:55 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
2004-07-16 00:15:55 +02:00
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
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-07-16 00:15:55 +02:00
insert into v3 values (-60,4,30);
# try insert to VIEW with expression in SELECT list
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-07-16 00:15:55 +02:00
insert into v4 values (-60,4,30);
# try insert to VIEW using temporary table algorithm
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-07-16 00:15:55 +02:00
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
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-07-16 00:15:55 +02:00
insert into v3 select c, b, a from t2;
# try insert to VIEW with expression in SELECT list
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-07-16 00:15:55 +02:00
insert into v4 select c, b, a from t2;
# try insert to VIEW using temporary table algorithm
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-07-16 00:15:55 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
2004-07-16 00:15:55 +02:00
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));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_INVALID
2004-07-21 03:26:20 +02:00
insert into v1 values('a','aa');
drop table t1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_INVALID
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
#
2009-03-03 21:34:18 +01:00
-- error ER_DUP_FIELDNAME
2004-07-21 11:14:45 +02:00
create view v1 (a,a) as select 'a','a';
2004-07-22 13:05:00 +02:00
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';
2007-06-09 13:52:37 +02:00
select is_updatable from information_schema.views;
2004-07-22 16:52:04 +02:00
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;
2008-11-28 17:13:12 +01:00
--error ER_KEY_DOES_NOT_EXITS
2004-07-22 13:05:00 +02:00
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
#
2009-03-03 21:34:18 +01:00
-- error ER_NO_TABLES_USED
2004-08-23 11:38:55 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_WRONG_OBJECT
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
#
2006-11-02 19:01:53 +01:00
create function a() returns int return 5;
create view v1 as select a();
2004-08-30 21:52:50 +02:00
select * from v1;
drop view v1;
2006-11-02 19:01:53 +01:00
drop function a;
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_INVALID
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
#
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
SET @old_cs_client = @@character_set_client;
SET @old_cs_results = @@character_set_results;
SET @old_cs_connection = @@character_set_connection;
2007-02-23 18:49:01 +01:00
set names utf8;
create table tü (cü char);
create view vü as select cü from tü;
insert into vü values ('ü');
select * from vü;
drop view vü;
drop table tü;
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
SET character_set_client = @old_cs_client;
SET character_set_results = @old_cs_results;
SET character_set_connection = @old_cs_connection;
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
2005-09-16 17:13:21 +02:00
#
# renaming views
#
create table t1 (a int);
create view v1 as select a from t1;
2005-10-11 23:58:22 +02:00
create view v3 as select a from t1;
create database mysqltest;
2009-03-03 21:34:18 +01:00
-- error ER_FORBID_SCHEMA_CHANGE
2005-10-11 23:58:22 +02:00
rename table v1 to mysqltest.v1;
2005-09-16 17:13:21 +02:00
rename table v1 to v2;
2009-03-03 21:34:18 +01:00
--error ER_TABLE_EXISTS_ERROR
2005-10-11 23:58:22 +02:00
rename table v3 to v1, v2 to t1;
2005-09-16 17:13:21 +02:00
drop table t1;
2005-10-11 23:58:22 +02:00
drop view v2,v3;
drop database mysqltest;
2005-09-16 17:13:21 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_SUBQUERY_NO_1_ROW
2004-09-02 06:40:48 +02:00
select * from v4;
drop view v4, v3, v2, v1;
2004-09-02 11:09:26 +02:00
#
# VIEW over SELECT with prohibited clauses
#
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_SELECT_CLAUSE
2004-09-02 11:09:26 +02:00
create view v1 as select 5 into @w;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_SELECT_CLAUSE
2004-09-02 11:09:26 +02:00
create view v1 as select 5 into outfile 'ttt';
create table t1 (a int);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_SELECT_CLAUSE
2004-09-02 11:09:26 +02:00
create view v1 as select a from t1 procedure analyse();
2006-10-12 16:02:57 +02:00
-- error ER_VIEW_SELECT_DERIVED
create view v1 as select 1 from (select 1) as d1;
2004-09-02 11:09:26 +02:00
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);
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
mysql-test/r/help.result:
Update result.
mysql-test/r/lock.result:
Update result.
mysql-test/r/sp-error.result:
Update result.
mysql-test/r/timezone2.result:
Add result for bug#9953: CONVERT_TZ requires mysql.time_zone_name
to be locked.
mysql-test/r/view.result:
Update result: use table t3 rather than utilize MySQL system table.
mysql-test/t/help.test:
Test that we can use HELP even under LOCK TABLES.
mysql-test/t/lock.test:
Test LOCK TABLE on system tables.
mysql-test/t/timezone2.test:
Add test case for bug#9953: CONVERT_TZ requires mysql.time_zone_name
to be locked.
mysql-test/t/view.test:
Update test: use table t3 rather that utilize MySQL system table.
sql/handler.h:
Fix comment for 'count' parameter of check_if_locking_is_allowed().
Add 'current' and 'system_count' parameters.
sql/item_create.cc:
We no longer have LEX::add_time_zone_tables_to_query_tables().
sql/item_timefunc.cc:
We no longer have LEX::time_zone_tables_used, so
Item_func_convert_tz::fix_fields() became the same as base
Item_date_func::fix_fields().
my_tz_find() no longer takes table list, but takes THD pointer now.
sql/item_timefunc.h:
Remove dead field and method.
sql/lock.cc:
Pass values for 'current' and 'system_count' to
check_if_locking_is_allowed().
sql/log_event.cc:
We no longer have my_tz_find_with_opening_tz_tables(), its functions is
performed by my_tz_find().
sql/mysql_priv.h:
Add functions to work with MySQL system tables.
sql/set_var.cc:
my_tz_find() no longer takes table list, but takes THD pointer now.
sql/sp.cc:
Remove close_proc_table(). Use close_system_tables() instead.
Use open_system_tables_for_read() and open_system_table_for_update().
sql/sp.h:
Remove close_proc_table() declaration.
sql/sql_base.cc:
Add implementation of open_system_tables_for_read(),
close_system_tables(), open_system_table_for_update().
sql/sql_help.cc:
Operate on MySQL system tables mysql.help_* with
open_system_tables_for_read() and close_system_tables() to allow the
usage of HELP statement under LOCK TABLES.
sql/sql_lex.cc:
Remove LEX::time_zone_tables_used and
LEX::add_time_zone_tables_to_query_tables() which are no longer used.
sql/sql_lex.h:
Remove LEX::time_zone_tables_used and
LEX::add_time_zone_tables_to_query_tables() which are no longer used.
sql/sql_parse.cc:
Remove references to LEX::time_zone_tables_used and
my_tz_check_n_skip_implicit_tables() which are no longer used.
sql/sql_show.cc:
Use close_system_tables() instead of removed close_proc_table().
sql/sql_view.cc:
LEX::time_zone_tables_used is no longer there.
sql/sql_yacc.yy:
LEX::add_time_zone_tables_to_query_tables() is no longer there.
sql/table.cc:
Add more tables that should be treated as MySQL system tables.
sql/share/errmsg.txt:
Change the error message, as now we allow write-locking of several
system tables if not mixed with ordinary tables.
sql/tztime.cc:
Do not add time zone tables to the list of query tables in
tz_init_table_list().
Remove fake_time_zone_tables_list and my_tz_get_tables_list().
In my_tz_init(), open mysql.time_zone_leap_second with
simple_open_n_lock_tables(), but pass time zone name to my_tz_find(),
which will open and close time zone tables as necessary.
In tz_load_from_open_tables() do not call table->use_all_columns(), as
this was already done in open_system_tables_for_read().
my_tz_find() takes THD pointer instead of table list, and calls
open_system_tables_for_read() and close_system_tables() as necessary.
Remove my_tz_find_with_opening_tz_tables().
sql/tztime.h:
Remove declarations of my_tz_get_table_list(),
my_tz_find_with_opening_tz_tables(), fake_time_zone_tables_list,
definition of my_tz_check_n_skip_implicit_tables().
Update prototype for my_tz_find().
storage/csv/ha_tina.cc:
Add new parameters to check_if_locking_is_allowed().
storage/csv/ha_tina.h:
Add new parameters to check_if_locking_is_allowed().
storage/myisam/ha_myisam.cc:
Add new parameters to check_if_locking_is_allowed(). In this
function we count system tables. If there are system tables, but
there are also non-system tables, we report an error.
storage/myisam/ha_myisam.h:
Add new parameters to check_if_locking_is_allowed().
2007-03-09 11:12:31 +01:00
create table t3 (col1 datetime not null);
2004-09-08 09:18:04 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2004-09-08 09:18:04 +02:00
update v2 set col1 = (select max(col1) from v1);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v2 set col1 = (select max(col1) from t1);
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update v2 set col1 = (select max(col1) from v2);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v2,t2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t1,t2 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update v1,t2 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t2,v2 set v2.col1 = (select max(col1) from v1) where v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t2,t1 set t1.col1 = (select max(col1) from v1) where t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t2,v1 set v1.col1 = (select max(col1) from v1) where v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v2,t2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v1,t2 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update t2,v2 set v2.col1 = (select max(col1) from t1) where v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update t2,t1 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update t2,v1 set v1.col1 = (select max(col1) from t1) where v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update v2,t2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t1,t2 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v1,t2 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t2,v2 set v2.col1 = (select max(col1) from v2) where v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t2,t1 set t1.col1 = (select max(col1) from v2) where t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update t2,v1 set v1.col1 = (select max(col1) from v2) where v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v3 set v3.col1 = (select max(col1) from v1);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v3 set v3.col1 = (select max(col1) from t1);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
update v3 set v3.col1 = (select max(col1) from v2);
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
update v3 set v3.col1 = (select max(col1) from v3);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2004-09-08 09:18:04 +02:00
delete from v2 where col1 = (select max(col1) from v1);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
delete from v2 where col1 = (select max(col1) from t1);
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
delete from v2 where col1 = (select max(col1) from v2);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
delete v2 from v2,t2 where (select max(col1) from v1) > 0 and v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
delete t1 from t1,t2 where (select max(col1) from v1) > 0 and t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
delete v1 from v1,t2 where (select max(col1) from v1) > 0 and v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
delete v2 from v2,t2 where (select max(col1) from t1) > 0 and v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
delete t1 from t1,t2 where (select max(col1) from t1) > 0 and t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
delete v1 from v1,t2 where (select max(col1) from t1) > 0 and v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
delete v2 from v2,t2 where (select max(col1) from v2) > 0 and v2.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
delete t1 from t1,t2 where (select max(col1) from v2) > 0 and t1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
delete v1 from v1,t2 where (select max(col1) from v2) > 0 and v1.col1 = t2.col1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2004-09-08 09:18:04 +02:00
insert into v2 values ((select max(col1) from v1));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into t1 values ((select max(col1) from v1));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into v2 values ((select max(col1) from v1));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into v2 values ((select max(col1) from t1));
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
insert into t1 values ((select max(col1) from t1));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into v2 values ((select max(col1) from t1));
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
insert into v2 values ((select max(col1) from v2));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into t1 values ((select max(col1) from v2));
2009-03-03 21:34:18 +01:00
-- error ER_UPDATE_TABLE_USED
2005-03-28 14:13:31 +02:00
insert into v2 values ((select max(col1) from v2));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into v3 (col1) values ((select max(col1) from v1));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into v3 (col1) values ((select max(col1) from t1));
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
insert into v3 (col1) values ((select max(col1) from v2));
2009-03-03 21:34:18 +01:00
# check with TZ tables in list
-- error ER_VIEW_PREVENT_UPDATE
2005-03-28 14:13:31 +02:00
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));
2009-03-03 21:34:18 +01:00
-- error ER_BAD_NULL_ERROR
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
mysql-test/r/help.result:
Update result.
mysql-test/r/lock.result:
Update result.
mysql-test/r/sp-error.result:
Update result.
mysql-test/r/timezone2.result:
Add result for bug#9953: CONVERT_TZ requires mysql.time_zone_name
to be locked.
mysql-test/r/view.result:
Update result: use table t3 rather than utilize MySQL system table.
mysql-test/t/help.test:
Test that we can use HELP even under LOCK TABLES.
mysql-test/t/lock.test:
Test LOCK TABLE on system tables.
mysql-test/t/timezone2.test:
Add test case for bug#9953: CONVERT_TZ requires mysql.time_zone_name
to be locked.
mysql-test/t/view.test:
Update test: use table t3 rather that utilize MySQL system table.
sql/handler.h:
Fix comment for 'count' parameter of check_if_locking_is_allowed().
Add 'current' and 'system_count' parameters.
sql/item_create.cc:
We no longer have LEX::add_time_zone_tables_to_query_tables().
sql/item_timefunc.cc:
We no longer have LEX::time_zone_tables_used, so
Item_func_convert_tz::fix_fields() became the same as base
Item_date_func::fix_fields().
my_tz_find() no longer takes table list, but takes THD pointer now.
sql/item_timefunc.h:
Remove dead field and method.
sql/lock.cc:
Pass values for 'current' and 'system_count' to
check_if_locking_is_allowed().
sql/log_event.cc:
We no longer have my_tz_find_with_opening_tz_tables(), its functions is
performed by my_tz_find().
sql/mysql_priv.h:
Add functions to work with MySQL system tables.
sql/set_var.cc:
my_tz_find() no longer takes table list, but takes THD pointer now.
sql/sp.cc:
Remove close_proc_table(). Use close_system_tables() instead.
Use open_system_tables_for_read() and open_system_table_for_update().
sql/sp.h:
Remove close_proc_table() declaration.
sql/sql_base.cc:
Add implementation of open_system_tables_for_read(),
close_system_tables(), open_system_table_for_update().
sql/sql_help.cc:
Operate on MySQL system tables mysql.help_* with
open_system_tables_for_read() and close_system_tables() to allow the
usage of HELP statement under LOCK TABLES.
sql/sql_lex.cc:
Remove LEX::time_zone_tables_used and
LEX::add_time_zone_tables_to_query_tables() which are no longer used.
sql/sql_lex.h:
Remove LEX::time_zone_tables_used and
LEX::add_time_zone_tables_to_query_tables() which are no longer used.
sql/sql_parse.cc:
Remove references to LEX::time_zone_tables_used and
my_tz_check_n_skip_implicit_tables() which are no longer used.
sql/sql_show.cc:
Use close_system_tables() instead of removed close_proc_table().
sql/sql_view.cc:
LEX::time_zone_tables_used is no longer there.
sql/sql_yacc.yy:
LEX::add_time_zone_tables_to_query_tables() is no longer there.
sql/table.cc:
Add more tables that should be treated as MySQL system tables.
sql/share/errmsg.txt:
Change the error message, as now we allow write-locking of several
system tables if not mixed with ordinary tables.
sql/tztime.cc:
Do not add time zone tables to the list of query tables in
tz_init_table_list().
Remove fake_time_zone_tables_list and my_tz_get_tables_list().
In my_tz_init(), open mysql.time_zone_leap_second with
simple_open_n_lock_tables(), but pass time zone name to my_tz_find(),
which will open and close time zone tables as necessary.
In tz_load_from_open_tables() do not call table->use_all_columns(), as
this was already done in open_system_tables_for_read().
my_tz_find() takes THD pointer instead of table list, and calls
open_system_tables_for_read() and close_system_tables() as necessary.
Remove my_tz_find_with_opening_tz_tables().
sql/tztime.h:
Remove declarations of my_tz_get_table_list(),
my_tz_find_with_opening_tz_tables(), fake_time_zone_tables_list,
definition of my_tz_check_n_skip_implicit_tables().
Update prototype for my_tz_find().
storage/csv/ha_tina.cc:
Add new parameters to check_if_locking_is_allowed().
storage/csv/ha_tina.h:
Add new parameters to check_if_locking_is_allowed().
storage/myisam/ha_myisam.cc:
Add new parameters to check_if_locking_is_allowed(). In this
function we count system tables. If there are system tables, but
there are also non-system tables, we report an error.
storage/myisam/ha_myisam.h:
Add new parameters to check_if_locking_is_allowed().
2007-03-09 11:12:31 +01:00
insert into t3 values ((select CONVERT_TZ('20050101000000','UTC','MET') from t2));
2005-03-28 14:13:31 +02:00
# 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;
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
mysql-test/r/help.result:
Update result.
mysql-test/r/lock.result:
Update result.
mysql-test/r/sp-error.result:
Update result.
mysql-test/r/timezone2.result:
Add result for bug#9953: CONVERT_TZ requires mysql.time_zone_name
to be locked.
mysql-test/r/view.result:
Update result: use table t3 rather than utilize MySQL system table.
mysql-test/t/help.test:
Test that we can use HELP even under LOCK TABLES.
mysql-test/t/lock.test:
Test LOCK TABLE on system tables.
mysql-test/t/timezone2.test:
Add test case for bug#9953: CONVERT_TZ requires mysql.time_zone_name
to be locked.
mysql-test/t/view.test:
Update test: use table t3 rather that utilize MySQL system table.
sql/handler.h:
Fix comment for 'count' parameter of check_if_locking_is_allowed().
Add 'current' and 'system_count' parameters.
sql/item_create.cc:
We no longer have LEX::add_time_zone_tables_to_query_tables().
sql/item_timefunc.cc:
We no longer have LEX::time_zone_tables_used, so
Item_func_convert_tz::fix_fields() became the same as base
Item_date_func::fix_fields().
my_tz_find() no longer takes table list, but takes THD pointer now.
sql/item_timefunc.h:
Remove dead field and method.
sql/lock.cc:
Pass values for 'current' and 'system_count' to
check_if_locking_is_allowed().
sql/log_event.cc:
We no longer have my_tz_find_with_opening_tz_tables(), its functions is
performed by my_tz_find().
sql/mysql_priv.h:
Add functions to work with MySQL system tables.
sql/set_var.cc:
my_tz_find() no longer takes table list, but takes THD pointer now.
sql/sp.cc:
Remove close_proc_table(). Use close_system_tables() instead.
Use open_system_tables_for_read() and open_system_table_for_update().
sql/sp.h:
Remove close_proc_table() declaration.
sql/sql_base.cc:
Add implementation of open_system_tables_for_read(),
close_system_tables(), open_system_table_for_update().
sql/sql_help.cc:
Operate on MySQL system tables mysql.help_* with
open_system_tables_for_read() and close_system_tables() to allow the
usage of HELP statement under LOCK TABLES.
sql/sql_lex.cc:
Remove LEX::time_zone_tables_used and
LEX::add_time_zone_tables_to_query_tables() which are no longer used.
sql/sql_lex.h:
Remove LEX::time_zone_tables_used and
LEX::add_time_zone_tables_to_query_tables() which are no longer used.
sql/sql_parse.cc:
Remove references to LEX::time_zone_tables_used and
my_tz_check_n_skip_implicit_tables() which are no longer used.
sql/sql_show.cc:
Use close_system_tables() instead of removed close_proc_table().
sql/sql_view.cc:
LEX::time_zone_tables_used is no longer there.
sql/sql_yacc.yy:
LEX::add_time_zone_tables_to_query_tables() is no longer there.
sql/table.cc:
Add more tables that should be treated as MySQL system tables.
sql/share/errmsg.txt:
Change the error message, as now we allow write-locking of several
system tables if not mixed with ordinary tables.
sql/tztime.cc:
Do not add time zone tables to the list of query tables in
tz_init_table_list().
Remove fake_time_zone_tables_list and my_tz_get_tables_list().
In my_tz_init(), open mysql.time_zone_leap_second with
simple_open_n_lock_tables(), but pass time zone name to my_tz_find(),
which will open and close time zone tables as necessary.
In tz_load_from_open_tables() do not call table->use_all_columns(), as
this was already done in open_system_tables_for_read().
my_tz_find() takes THD pointer instead of table list, and calls
open_system_tables_for_read() and close_system_tables() as necessary.
Remove my_tz_find_with_opening_tz_tables().
sql/tztime.h:
Remove declarations of my_tz_get_table_list(),
my_tz_find_with_opening_tz_tables(), fake_time_zone_tables_list,
definition of my_tz_check_n_skip_implicit_tables().
Update prototype for my_tz_find().
storage/csv/ha_tina.cc:
Add new parameters to check_if_locking_is_allowed().
storage/csv/ha_tina.h:
Add new parameters to check_if_locking_is_allowed().
storage/myisam/ha_myisam.cc:
Add new parameters to check_if_locking_is_allowed(). In this
function we count system tables. If there are system tables, but
there are also non-system tables, we report an error.
storage/myisam/ha_myisam.h:
Add new parameters to check_if_locking_is_allowed().
2007-03-09 11:12:31 +01:00
drop table t1,t2,t3;
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;
2009-03-03 21:34:18 +01:00
-- error ER_WRONG_OBJECT
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;
2009-03-03 21:34:18 +01:00
-- error ER_TABLE_NOT_LOCKED
2004-09-24 11:50:10 +02:00
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);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
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;
2006-06-01 11:53:27 +02:00
select * from t1 order by a desc;
2009-03-03 21:34:18 +01:00
# simple UPDATE test
2004-09-03 14:18:40 +02:00
update v1 set a=-1 where a=0;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-09-03 14:18:40 +02:00
update v1 set a=2 where a=1;
2006-06-01 11:53:27 +02:00
select * from t1 order by a desc;
2004-09-03 14:18:40 +02:00
# 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;
2006-06-01 11:53:27 +02:00
select * from t1 order by a desc;
2004-09-03 14:18:40 +02:00
# 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);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-09-03 14:18:40 +02:00
insert into v2 values (0);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-09-03 14:18:40 +02:00
insert into v3 values (0);
insert into v2 values (2);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
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;
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2004-10-07 14:43:04 +02:00
alter view v1 as select * from v2;
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2004-10-07 14:43:04 +02:00
alter view v1 as select * from v1;
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2004-10-07 14:43:04 +02:00
create or replace view v1 as select * from v2;
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2004-10-07 14:43:04 +02:00
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);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-10-07 21:54:31 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-10-21 12:30:25 +02:00
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
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-10-21 13:32:10 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-10-21 16:05:45 +02:00
insert into v1 values (0);
select * from v1;
select * from t1;
2005-07-19 18:06:49 +02:00
drop trigger 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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2004-10-21 17:10:59 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2007-12-12 18:19:24 +01:00
load data infile '../../std_data/loaddata3.dat' into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
2004-10-21 20:53:27 +02:00
select * from t1;
select * from v1;
delete from t1;
2007-12-12 18:19:24 +01:00
load data infile '../../std_data/loaddata3.dat' ignore into table v1 fields terminated by '' enclosed by '' ignore 1 lines;
2006-06-01 11:53:27 +02:00
select * from t1 order by a,b;
select * from v1 order by a,b;
2004-10-21 20:53:27 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2007-12-12 18:19:24 +01:00
load data infile '../../std_data/loaddata2.dat' into table v1 fields terminated by ',' enclosed by '''';
2004-10-21 20:53:27 +02:00
select concat('|',a,'|'), concat('|',b,'|') from t1;
select concat('|',a,'|'), concat('|',b,'|') from v1;
delete from t1;
2007-12-12 18:19:24 +01:00
load data infile '../../std_data/loaddata2.dat' ignore into table v1 fields terminated by ',' enclosed by '''';
2004-10-21 20:53:27 +02:00
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);
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-10-25 16:32:28 +02:00
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);
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-10-25 16:32:28 +02:00
insert into v3 values (30);
create view v4 as select * from v2 where 20 < (select (s1) from t1);
2006-10-09 13:47:06 +02:00
-- error ER_NON_INSERTABLE_TABLE
2004-10-25 16:32:28 +02:00
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;
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
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
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_NO_INSERT_FIELD_LIST
2004-09-15 22:42:56 +02:00
insert into v3 values (1,2);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_NO_INSERT_FIELD_LIST
2004-09-15 22:42:56 +02:00
insert into v3 select * from t2;
# inserting in several tables of join view
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_MULTIUPDATE
2004-09-15 22:42:56 +02:00
insert into v3(a,b) values (1,2);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_MULTIUPDATE
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
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_DELETE_MERGE_VIEW
2004-09-15 22:42:56 +02:00
delete from v3;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_DELETE_MERGE_VIEW
2004-09-15 22:42:56 +02:00
delete v3,t1 from v3,t1;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_DELETE_MERGE_VIEW
2005-03-28 14:13:31 +02:00
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
#
2009-03-03 21:34:18 +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
#
2009-03-03 21:34:18 +01:00
# Resolving view fields in subqueries in VIEW (Bug#6394)
2005-01-18 20:58:12 +01:00
#
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
#
2009-03-03 21:34:18 +01:00
# view over other view setup (Bug#7433)
2005-01-31 09:43:36 +01:00
#
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
#
2009-03-03 21:34:18 +01:00
# view and group_concat() (Bug#7116)
2005-01-31 15:24:11 +01:00
#
2009-03-03 21:34:18 +01:00
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);
2005-01-31 15:24:11 +01:00
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
#
2009-03-03 21:34:18 +01:00
# Item_ref resolved as view field (Bug#6894)
2005-02-22 11:27:08 +01:00
#
create table t1 (s1 int, s2 char);
create view v1 as select s1, s2 from t1;
2009-03-03 21:34:18 +01:00
-- error ER_BAD_FIELD_ERROR
2005-02-22 11:27:08 +01:00
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
#
2009-03-03 21:34:18 +01:00
# Test case for Bug#9398 CREATE TABLE with SELECT from a multi-table view
2005-03-28 14:13:31 +02:00
#
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;
#
2009-03-03 21:34:18 +01:00
# Test for Bug#8703 insert into table select from view crashes
2005-03-28 14:13:31 +02:00
#
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
#
2009-03-03 21:34:18 +01: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');
2005-04-14 08:06:37 +02:00
INSERT INTO t2 VALUES (8,1,'y');
2009-03-03 21:34:18 +01:00
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT a.col1,a.col2,b.col2,b.col3
2005-04-14 08:06:37 +02:00
FROM t1 a LEFT JOIN t2 b ON a.col1=b.col1
2009-03-03 21:34:18 +01:00
WHERE b.col2 IS NULL OR
2005-04-14 08:06:37 +02:00
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
2009-03-03 21:34:18 +01:00
SELECT a.col1,a.col2,b.col2,b.col3
2005-04-14 08:06:37 +02:00
FROM v1 a LEFT JOIN t2 b ON a.col1=b.col1
2009-03-03 21:34:18 +01:00
WHERE b.col2 IS NULL OR
2005-04-14 08:06:37 +02:00
b.col2=(SELECT MAX(col2) FROM t2 b WHERE b.col1=a.col1);
2009-03-03 21:34:18 +01:00
CREATE VIEW v2 AS SELECT * FROM t2;
2005-04-14 08:06:37 +02:00
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
2009-03-03 21:34:18 +01:00
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
2005-04-14 08:06:37 +02:00
2009-03-03 21:34:18 +01:00
# Tests from the report for Bug#6107
2005-04-14 08:06:37 +02:00
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
2009-03-03 21:34:18 +01:00
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1));
2005-04-14 08:06:37 +02:00
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
2009-03-03 21:34:18 +01:00
b.col2=(SELECT MAX(col2) FROM v2 b WHERE b.col1=a.col1);
2005-04-14 08:06:37 +02:00
DROP VIEW v1,v2,v3;
DROP TABLE t1,t2;
2005-04-22 22:13:46 +02:00
2005-05-17 17:08:43 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#8490 Select from views containing subqueries causes server to hang
# forever.
2005-05-17 17:08:43 +02:00
#
2005-04-22 22:13:46 +02:00
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;
2009-03-03 21:34:18 +01:00
create view v2 as select * from t3 where
2005-04-22 22:13:46 +02:00
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
#
2009-03-03 21:34:18 +01:00
# Test case for Bug#8528 select from view over multi-table view
2005-05-11 01:31:13 +02:00
#
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;
2005-05-17 17:08:43 +02:00
DROP TABLE t1, t2;
#
2009-03-03 21:34:18 +01:00
# Correct restoring view name in SP table locking Bug#9758
2005-05-17 17:08:43 +02:00
#
create table t1 (a int);
create view v1 as select sum(a) from t1 group by a;
delimiter //;
create procedure p1()
begin
select * from v1;
end//
delimiter ;//
call p1();
call p1();
drop procedure p1;
drop view v1;
drop table t1;
2005-06-21 18:14:50 +02:00
#
# Bug#7422 "order by" doesn't work
#
CREATE TABLE t1(a char(2) primary key, b char(2));
CREATE TABLE t2(a char(2), b char(2), index i(a));
INSERT INTO t1 VALUES ('a','1'), ('b','2');
INSERT INTO t2 VALUES ('a','5'), ('a','6'), ('b','5'), ('b','6');
CREATE VIEW v1 AS
SELECT t1.b as c, t2.b as d FROM t1,t2 WHERE t1.a=t2.a;
2005-06-22 07:38:28 +02:00
SELECT d, c FROM v1 ORDER BY d,c;
2005-06-21 18:14:50 +02:00
DROP VIEW v1;
DROP TABLE t1, t2;
2005-06-17 16:27:47 +02:00
#
2009-03-03 21:34:18 +01:00
# using sum(distinct ) & avg(distinct ) in views (Bug#7015)
2005-06-17 16:27:47 +02:00
#
create table t1 (s1 int);
create view v1 as select sum(distinct s1) from t1;
select * from v1;
drop view v1;
create view v1 as select avg(distinct s1) from t1;
select * from v1;
drop view v1;
drop table t1;
#
2009-03-03 21:34:18 +01:00
# using cast(... as decimal) in views (Bug#11387);
2005-06-17 16:27:47 +02:00
#
create view v1 as select cast(1 as decimal);
select * from v1;
drop view v1;
2005-06-20 13:56:17 +02:00
2005-06-22 02:45:10 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#11298 insert into select from VIEW produces incorrect result when
2005-06-22 02:45:10 +02:00
# using ORDER BY
create table t1(f1 int);
create table t2(f2 int);
insert into t1 values(1),(2),(3);
insert into t2 values(1),(2),(3);
create view v1 as select * from t1,t2 where f1=f2;
create table t3 (f1 int, f2 int);
insert into t3 select * from v1 order by 1;
select * from t3;
drop view v1;
drop table t1,t2,t3;
2005-06-21 19:30:48 +02:00
#
2009-03-03 21:34:18 +01:00
# Generation unique names for columns, and correct names check (Bug#7448)
2005-06-21 19:30:48 +02:00
#
# names with ' and \
create view v1 as select '\\','\\shazam';
select * from v1;
drop view v1;
create view v1 as select '\'','\shazam';
select * from v1;
drop view v1;
# autogenerated names differ by case only
create view v1 as select 'k','K';
select * from v1;
drop view v1;
create table t1 (s1 int);
# same autogenerated names
create view v1 as select s1, 's1' from t1;
select * from v1;
drop view v1;
create view v1 as select 's1', s1 from t1;
select * from v1;
drop view v1;
# set name as one of expected autogenerated
create view v1 as select 's1', s1, 1 as My_exp_s1 from t1;
select * from v1;
drop view v1;
create view v1 as select 1 as My_exp_s1, 's1', s1 from t1;
select * from v1;
drop view v1;
# set name conflict with autogenerated names
create view v1 as select 1 as s1, 's1', 's1' from t1;
select * from v1;
drop view v1;
create view v1 as select 's1', 's1', 1 as s1 from t1;
select * from v1;
drop view v1;
# underlying field name conflict with autogenerated names
create view v1 as select s1, 's1', 's1' from t1;
select * from v1;
drop view v1;
create view v1 as select 's1', 's1', s1 from t1;
select * from v1;
drop view v1;
# underlying field name conflict with set name
2009-03-03 21:34:18 +01:00
-- error ER_DUP_FIELDNAME
2005-06-21 19:30:48 +02:00
create view v1 as select 1 as s1, 's1', s1 from t1;
2009-03-03 21:34:18 +01:00
-- error ER_DUP_FIELDNAME
2005-06-21 19:30:48 +02:00
create view v1 as select 's1', s1, 1 as s1 from t1;
drop table t1;
# set names differ by case only
2009-03-03 21:34:18 +01:00
-- error ER_DUP_FIELDNAME
2005-06-21 19:30:48 +02:00
create view v1(k, K) as select 1,2;
2005-06-22 07:42:03 +02:00
2005-06-20 13:56:17 +02:00
#
2009-03-03 21:34:18 +01:00
# using time_format in view (Bug#7521)
2005-06-20 13:56:17 +02:00
#
create view v1 as SELECT TIME_FORMAT(SEC_TO_TIME(3600),'%H:%i') as t;
select * from v1;
drop view v1;
2005-06-23 23:24:11 +02:00
2005-07-15 23:01:44 +02:00
#
2009-03-03 21:34:18 +01:00
# evaluation constant functions in WHERE (Bug#4663)
2005-07-15 23:01:44 +02:00
#
create table t1 (a timestamp default now());
create table t2 (b timestamp default now());
create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now();
SHOW CREATE VIEW v1;
drop view v1;
drop table t1, t2;
CREATE TABLE t1 ( a varchar(50) );
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER();
SHOW CREATE VIEW v1;
DROP VIEW v1;
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION();
SHOW CREATE VIEW v1;
DROP VIEW v1;
CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE();
SHOW CREATE VIEW v1;
DROP VIEW v1;
DROP TABLE t1;
2005-07-15 23:17:05 +02:00
2005-07-05 12:37:02 +02:00
#
2009-03-03 21:34:18 +01:00
# checking views after some view with error (Bug#11337)
2005-07-05 12:37:02 +02:00
#
CREATE TABLE t1 (col1 time);
CREATE TABLE t2 (col1 time);
CREATE VIEW v1 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
CREATE VIEW v2 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
CREATE VIEW v3 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
CREATE VIEW v4 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
CREATE VIEW v5 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t1;
CREATE VIEW v6 AS SELECT CONVERT_TZ(col1,'GMT','MET') FROM t2;
DROP TABLE t1;
CHECK TABLE v1, v2, v3, v4, v5, v6;
drop view v1, v2, v3, v4, v5, v6;
drop table t2;
2005-08-09 01:23:34 +02:00
--disable_warnings
drop function if exists f1;
drop function if exists f2;
--enable_warnings
2005-07-05 12:37:02 +02:00
CREATE TABLE t1 (col1 time);
CREATE TABLE t2 (col1 time);
CREATE TABLE t3 (col1 time);
create function f1 () returns int return (select max(col1) from t1);
create function f2 () returns int return (select max(col1) from t2);
CREATE VIEW v1 AS SELECT f1() FROM t3;
CREATE VIEW v2 AS SELECT f2() FROM t3;
CREATE VIEW v3 AS SELECT f1() FROM t3;
CREATE VIEW v4 AS SELECT f2() FROM t3;
CREATE VIEW v5 AS SELECT f1() FROM t3;
CREATE VIEW v6 AS SELECT f2() FROM t3;
drop function f1;
CHECK TABLE v1, v2, v3, v4, v5, v6;
create function f1 () returns int return (select max(col1) from t1);
DROP TABLE t1;
CHECK TABLE v1, v2, v3, v4, v5, v6;
drop function f1;
drop function f2;
drop view v1, v2, v3, v4, v5, v6;
drop table t2,t3;
2005-07-05 12:42:19 +02:00
2005-06-24 18:16:52 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#11325 Wrong date comparison in views
2005-06-24 18:16:52 +02:00
#
create table t1 (f1 date);
insert into t1 values ('2005-01-01'),('2005-02-02');
create view v1 as select * from t1;
select * from v1 where f1='2005.02.02';
select * from v1 where '2005.02.02'=f1;
drop view v1;
drop table t1;
2005-06-24 19:47:17 +02:00
2005-06-23 23:24:11 +02:00
#
2009-03-03 21:34:18 +01:00
# using encrypt & substring_index in view (Bug#7024)
2005-06-23 23:24:11 +02:00
#
CREATE VIEW v1 AS SELECT ENCRYPT("dhgdhgd");
disable_result_log;
SELECT * FROM v1;
enable_result_log;
drop view v1;
CREATE VIEW v1 AS SELECT SUBSTRING_INDEX("dkjhgd:kjhdjh", ":", 1);
SELECT * FROM v1;
drop view v1;
2005-07-01 06:05:42 +02:00
2005-08-02 21:54:49 +02:00
#
2009-03-03 21:34:18 +01:00
# hide underlying tables names in case of imposibility to update (Bug#10773)
2005-08-02 21:54:49 +02:00
#
create table t1 (f59 int, f60 int, f61 int);
insert into t1 values (19,41,32);
2009-03-03 21:34:18 +01:00
create view v1 as select f59, f60 from t1 where f59 in
2005-08-02 21:54:49 +02:00
(select f59 from t1);
2009-03-03 21:34:18 +01:00
-- error ER_NON_UPDATABLE_TABLE
2005-08-02 21:54:49 +02:00
update v1 set f60=2345;
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_PREVENT_UPDATE
2005-08-02 21:54:49 +02:00
update t1 set f60=(select max(f60) from v1);
drop view v1;
drop table t1;
2005-07-02 15:12:32 +02:00
#
2009-03-03 21:34:18 +01:00
# Using var_samp with view (Bug#10651)
2005-07-02 15:12:32 +02:00
#
create table t1 (s1 int);
create view v1 as select var_samp(s1) from t1;
show create view v1;
drop view v1;
drop table t1;
2009-03-03 21:34:18 +01:00
2005-07-01 06:05:42 +02:00
#
# Correct inserting data check (absence of default value) for view
2009-03-03 21:34:18 +01:00
# underlying tables (Bug#6443)
2005-07-01 06:05:42 +02:00
#
set sql_mode='strict_all_tables';
2006-10-17 17:06:11 +02:00
CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL);
2005-07-01 06:05:42 +02:00
CREATE VIEW v1 (vcol1) AS SELECT col1 FROM t1;
CREATE VIEW v2 (vcol1) AS SELECT col1 FROM t1 WHERE col2 > 2;
2009-03-03 21:34:18 +01:00
-- error ER_NO_DEFAULT_FOR_FIELD
2005-07-01 06:05:42 +02:00
INSERT INTO t1 (col1) VALUES(12);
2009-03-03 21:34:18 +01:00
-- error ER_NO_DEFAULT_FOR_VIEW_FIELD
2005-07-01 06:05:42 +02:00
INSERT INTO v1 (vcol1) VALUES(12);
2009-03-03 21:34:18 +01:00
-- error ER_NO_DEFAULT_FOR_VIEW_FIELD
2005-07-01 06:05:42 +02:00
INSERT INTO v2 (vcol1) VALUES(12);
set sql_mode=default;
drop view v2,v1;
drop table t1;
2005-07-06 18:00:17 +02:00
2009-03-03 21:34:18 +01:00
2005-07-12 18:45:34 +02:00
#
# Bug#11399 Use an alias in a select statement on a view
#
create table t1 (f1 int);
insert into t1 values (1);
create view v1 as select f1 from t1;
select f1 as alias from v1;
drop view v1;
drop table t1;
2005-07-12 18:49:43 +02:00
2009-03-03 21:34:18 +01:00
2005-07-06 18:00:17 +02:00
#
2009-03-03 21:34:18 +01:00
# Test for Bug#6120 SP cache to be invalidated when altering a view
2005-07-06 18:00:17 +02:00
#
CREATE TABLE t1 (s1 int, s2 int);
INSERT INTO t1 VALUES (1,2);
CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1;
SELECT * FROM v1;
CREATE PROCEDURE p1 () SELECT * FROM v1;
CALL p1();
ALTER VIEW v1 AS SELECT s1 AS s1, s2 AS s2 FROM t1;
CALL p1();
2005-07-12 19:44:32 +02:00
DROP VIEW v1;
CREATE VIEW v1 AS SELECT s2 AS s1, s1 AS s2 FROM t1;
CALL p1();
2005-07-06 18:00:17 +02:00
DROP PROCEDURE p1;
DROP VIEW v1;
DROP TABLE t1;
2005-07-12 14:18:05 +02:00
2009-03-03 21:34:18 +01:00
2005-07-12 21:22:08 +02:00
#
2009-03-03 21:34:18 +01:00
# Test for Bug#11709 View was ordered by wrong column
2005-07-12 21:22:08 +02:00
#
create table t1 (f1 int, f2 int);
create view v1 as select f1 as f3, f2 as f1 from t1;
insert into t1 values (1,3),(2,1),(3,2);
select * from v1 order by f1;
2005-07-13 02:10:19 +02:00
drop view v1;
2005-07-12 21:22:08 +02:00
drop table t1;
2005-07-12 21:24:35 +02:00
2009-03-03 21:34:18 +01:00
2005-07-12 14:18:05 +02:00
#
2009-03-03 21:34:18 +01:00
# Test for Bug#11771 wrong query_id in SELECT * FROM <view>
2005-07-12 14:18:05 +02:00
#
2006-10-17 17:06:11 +02:00
CREATE TABLE t1 (f1 char);
2005-07-12 14:18:05 +02:00
INSERT INTO t1 VALUES ('A');
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES('B');
SELECT * FROM v1;
SELECT * FROM t1;
DROP VIEW v1;
DROP TABLE t1;
2005-07-15 00:22:14 +02:00
2009-03-03 21:34:18 +01:00
2005-07-15 00:22:14 +02:00
#
2009-03-03 21:34:18 +01:00
# opening table in correct locking mode (Bug#9597)
2005-07-15 00:22:14 +02:00
#
CREATE TABLE t1 ( bug_table_seq INTEGER NOT NULL);
CREATE OR REPLACE VIEW v1 AS SELECT * from t1;
DROP PROCEDURE IF EXISTS p1;
delimiter //;
CREATE PROCEDURE p1 ( )
BEGIN
DO (SELECT @next := IFNULL(max(bug_table_seq),0) + 1 FROM v1);
INSERT INTO t1 VALUES (1);
END //
delimiter ;//
CALL p1();
DROP PROCEDURE p1;
DROP VIEW v1;
DROP TABLE t1;
2005-07-20 04:55:51 +02:00
2009-03-03 21:34:18 +01:00
2005-07-20 04:55:51 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#11760 Typo in Item_func_add_time::print() results in NULLs returned
2005-07-20 04:55:51 +02:00
# subtime() in view
create table t1(f1 datetime);
insert into t1 values('2005.01.01 12:0:0');
create view v1 as select f1, subtime(f1, '1:1:1') as sb from t1;
select * from v1;
drop view v1;
2005-07-25 21:57:23 +02:00
drop table t1;
2009-03-03 21:34:18 +01:00
2005-07-25 21:57:23 +02:00
#
2009-03-03 21:34:18 +01:00
# Test for Bug#11412 query over a multitable view with GROUP_CONCAT
2005-07-25 21:57:23 +02:00
#
CREATE TABLE t1 (
aid int PRIMARY KEY,
fn varchar(20) NOT NULL,
ln varchar(20) NOT NULL
);
CREATE TABLE t2 (
aid int NOT NULL,
pid int NOT NULL
);
INSERT INTO t1 VALUES(1,'a','b'), (2,'c','d');
INSERT INTO t2 values (1,1), (2,1), (2,2);
CREATE VIEW v1 AS SELECT t1.*,t2.pid FROM t1,t2 WHERE t1.aid = t2.aid;
2009-03-03 21:34:18 +01:00
SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM t1,t2
2005-07-25 21:57:23 +02:00
WHERE t1.aid = t2.aid GROUP BY pid;
SELECT pid,GROUP_CONCAT(CONCAT(fn,' ',ln) ORDER BY 1) FROM v1 GROUP BY pid;
DROP VIEW v1;
DROP TABLE t1,t2;
2005-08-12 01:10:34 +02:00
2009-03-03 21:34:18 +01:00
2005-08-12 01:10:34 +02:00
#
2009-03-03 21:34:18 +01:00
# Test for Bug#12382 SELECT * FROM view after INSERT command
2005-08-12 01:10:34 +02:00
#
CREATE TABLE t1 (id int PRIMARY KEY, f varchar(255));
CREATE VIEW v1 AS SELECT id, f FROM t1 WHERE id <= 2;
INSERT INTO t1 VALUES (2, 'foo2');
INSERT INTO t1 VALUES (1, 'foo1');
SELECT * FROM v1;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2005-08-12 10:27:04 +02:00
#
2009-03-03 21:34:18 +01:00
# Test for Bug#12470 crash for a simple select from a view defined
# as a join over 5 tables
2005-08-12 10:27:04 +02:00
CREATE TABLE t1 (pk int PRIMARY KEY, b int);
CREATE TABLE t2 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
CREATE TABLE t3 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
CREATE TABLE t4 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
CREATE TABLE t5 (pk int PRIMARY KEY, fk int, INDEX idx(fk));
CREATE VIEW v1 AS
SELECT t1.pk as a FROM t1,t2,t3,t4,t5
WHERE t1.b IS NULL AND
t1.pk=t2.fk AND t2.pk=t3.fk AND t3.pk=t4.fk AND t4.pk=t5.fk;
2005-08-12 01:10:34 +02:00
2005-08-12 10:27:04 +02:00
SELECT a FROM v1;
DROP VIEW v1;
DROP TABLE t1,t2,t3,t4,t5;
2005-08-12 01:10:34 +02:00
2009-03-03 21:34:18 +01:00
2005-08-12 20:42:50 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#12298 Typo in function name results in erroneous view being created.
2005-08-12 20:42:50 +02:00
#
create view v1 as select timestampdiff(day,'1997-01-01 00:00:00','1997-01-02 00:00:00') as f1;
select * from v1;
drop view v1;
2005-08-18 07:19:12 +02:00
2005-08-17 21:42:53 +02:00
#
2009-03-03 21:34:18 +01:00
# repeatable CREATE VIEW statement Bug#12468
2005-08-17 21:42:53 +02:00
#
create table t1(a int);
create procedure p1() create view v1 as select * from t1;
drop table t1;
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2005-08-17 21:42:53 +02:00
call p1();
2009-03-03 21:34:18 +01:00
-- error ER_NO_SUCH_TABLE
2005-08-17 21:42:53 +02:00
call p1();
drop procedure p1;
2005-08-25 16:47:18 +02:00
2009-03-03 21:34:18 +01:00
2005-08-19 00:18:26 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#10624 Views with multiple UNION and UNION ALL produce incorrect results
2005-08-19 00:18:26 +02:00
#
create table t1 (f1 int);
create table t2 (f1 int);
insert into t1 values (1);
insert into t2 values (2);
create view v1 as select * from t1 union select * from t2 union all select * from t2;
select * from v1;
drop view v1;
drop table t1,t2;
2009-03-03 21:34:18 +01:00
#
# Test for Bug#10970 view referring a temporary table indirectly
2005-08-18 07:19:12 +02:00
#
CREATE TEMPORARY TABLE t1 (a int);
CREATE FUNCTION f1 () RETURNS int RETURN (SELECT COUNT(*) FROM t1);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_SELECT_TMPTABLE
2005-08-18 07:19:12 +02:00
CREATE VIEW v1 AS SELECT f1();
DROP FUNCTION f1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2005-08-25 09:24:21 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#12533 (crash on DESCRIBE <view> after renaming base table column)
2005-08-25 09:24:21 +02:00
#
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP VIEW IF EXISTS v1;
--enable_warnings
CREATE TABLE t1 (f4 CHAR(5));
CREATE VIEW v1 AS SELECT * FROM t1;
DESCRIBE v1;
ALTER TABLE t1 CHANGE COLUMN f4 f4x CHAR(5);
2009-03-03 21:34:18 +01:00
--error ER_VIEW_INVALID
2005-08-25 09:24:21 +02:00
DESCRIBE v1;
DROP TABLE t1;
DROP VIEW v1;
2005-08-30 22:54:41 +02:00
2009-03-03 21:34:18 +01:00
#
# Bug#12489 wrongly printed strcmp() function results in creation of broken
2005-08-30 22:54:41 +02:00
# view
create table t1 (f1 char);
create view v1 as select strcmp(f1,'a') from t1;
select * from v1;
drop view v1;
drop table t1;
2005-09-07 09:50:41 +02:00
2009-03-03 21:34:18 +01:00
2005-09-07 09:50:41 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#12922 if(sum(),...) with group from view returns wrong results
2005-09-07 20:38:36 +02:00
#
create table t1 (f1 int, f2 int,f3 int);
insert into t1 values (1,10,20),(2,0,0);
create view v1 as select * from t1;
select if(sum(f1)>1,f2,f3) from v1 group by f1;
drop view v1;
drop table t1;
2009-03-03 21:34:18 +01:00
# Bug#12941
2005-09-07 09:50:41 +02:00
#
2005-09-25 15:44:05 +02:00
--disable_warnings
2005-09-07 09:50:41 +02:00
create table t1 (
r_object_id char(16) NOT NULL,
group_name varchar(32) NOT NULL
) engine = InnoDB;
create table t2 (
r_object_id char(16) NOT NULL,
2009-03-03 21:34:18 +01:00
i_position int(11) NOT NULL,
2005-09-07 09:50:41 +02:00
users_names varchar(32) default NULL
) Engine = InnoDB;
2005-09-25 15:44:05 +02:00
--enable_warnings
2005-09-07 09:50:41 +02:00
create view v1 as select r_object_id, group_name from t1;
create view v2 as select r_object_id, i_position, users_names from t2;
create unique index r_object_id on t1(r_object_id);
create index group_name on t1(group_name);
create unique index r_object_id_i_position on t2(r_object_id,i_position);
create index users_names on t2(users_names);
insert into t1 values('120001a080000542','tstgroup1');
insert into t2 values('120001a080000542',-1, 'guser01');
insert into t2 values('120001a080000542',-2, 'guser02');
select v1.r_object_id, v2.users_names from v1, v2
2009-03-03 21:34:18 +01:00
where (v1.group_name='tstgroup1') and v2.r_object_id=v1.r_object_id
2005-09-07 09:50:41 +02:00
order by users_names;
drop view v1, v2;
drop table t1, t2;
2005-09-12 16:01:17 +02:00
2009-03-03 21:34:18 +01:00
2005-09-12 16:01:17 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#6808 Views: CREATE VIEW v ... FROM t AS v fails
2005-09-12 16:01:17 +02:00
#
2009-03-03 21:34:18 +01:00
create table t1 (s1 int);
2005-09-12 16:01:17 +02:00
create view abc as select * from t1 as abc;
drop table t1;
drop view abc;
2005-09-13 20:22:51 +02:00
2009-03-03 21:34:18 +01:00
2005-09-12 00:46:35 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#12993 View column rename broken in subselect
2005-09-12 00:46:35 +02:00
#
create table t1(f1 char(1));
create view v1 as select * from t1;
select * from (select f1 as f2 from v1) v where v.f2='a';
drop view v1;
drop table t1;
Fixed BUG#12963, BUG#13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
mysql-test/r/func_time.result:
Fixed new results for testcases containing EXPLAIN EXTENDED SELECT ...
WEEKDAY ... DAYNAME. The new results are correct and correspond to
the changes in create_func_weekday() and create_func_dayname().
mysql-test/r/view.result:
Fixed some testcases results (bugs #12963, #13000).
mysql-test/t/view.test:
Added testcases for for bugs #12963, #13000.
sql/item_create.cc:
Fixed bugs #12963, #13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
Modified create_func_dayname(), create_func_dayofweek(), and
create_func_weekday(). They don´t insert Item_func_to_days
object now.
sql/item_timefunc.cc:
Fixed bugs #12963, #13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
Modified Item_func_weekday::val_int(). The argument of weekday should
not be considered now to be Item_func_to_days object.
sql/item_timefunc.h:
Fixed bugs #12963, 13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY.
Modified Item_func_weekday::func_name(). It returns now different
names depending on the odbc_type attribute value.
2005-09-14 18:25:00 +02:00
2009-03-03 21:34:18 +01:00
2005-09-14 22:08:12 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#11416 Server crash if using a view that uses function convert_tz
2005-09-14 22:08:12 +02:00
#
create view v1 as SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
select * from v1;
drop view v1;
2005-09-15 18:50:10 +02:00
2009-03-03 21:34:18 +01:00
Fixed BUG#12963, BUG#13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
mysql-test/r/func_time.result:
Fixed new results for testcases containing EXPLAIN EXTENDED SELECT ...
WEEKDAY ... DAYNAME. The new results are correct and correspond to
the changes in create_func_weekday() and create_func_dayname().
mysql-test/r/view.result:
Fixed some testcases results (bugs #12963, #13000).
mysql-test/t/view.test:
Added testcases for for bugs #12963, #13000.
sql/item_create.cc:
Fixed bugs #12963, #13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
Modified create_func_dayname(), create_func_dayofweek(), and
create_func_weekday(). They don´t insert Item_func_to_days
object now.
sql/item_timefunc.cc:
Fixed bugs #12963, #13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
Modified Item_func_weekday::val_int(). The argument of weekday should
not be considered now to be Item_func_to_days object.
sql/item_timefunc.h:
Fixed bugs #12963, 13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY.
Modified Item_func_weekday::func_name(). It returns now different
names depending on the odbc_type attribute value.
2005-09-14 18:25:00 +02:00
#
2009-03-03 21:34:18 +01:00
# Bugs#12963, #13000 wrong creation of VIEW with DAYNAME, DAYOFWEEK, and WEEKDAY
Fixed BUG#12963, BUG#13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
mysql-test/r/func_time.result:
Fixed new results for testcases containing EXPLAIN EXTENDED SELECT ...
WEEKDAY ... DAYNAME. The new results are correct and correspond to
the changes in create_func_weekday() and create_func_dayname().
mysql-test/r/view.result:
Fixed some testcases results (bugs #12963, #13000).
mysql-test/t/view.test:
Added testcases for for bugs #12963, #13000.
sql/item_create.cc:
Fixed bugs #12963, #13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
Modified create_func_dayname(), create_func_dayofweek(), and
create_func_weekday(). They don´t insert Item_func_to_days
object now.
sql/item_timefunc.cc:
Fixed bugs #12963, #13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY().
Modified Item_func_weekday::val_int(). The argument of weekday should
not be considered now to be Item_func_to_days object.
sql/item_timefunc.h:
Fixed bugs #12963, 13000: wrong VIEW creation with DAYNAME(),
DAYOFWEEK(), and WEEKDAY.
Modified Item_func_weekday::func_name(). It returns now different
names depending on the odbc_type attribute value.
2005-09-14 18:25:00 +02:00
#
CREATE TABLE t1 (date DATE NOT NULL);
INSERT INTO t1 VALUES ('2005-09-06');
CREATE VIEW v1 AS SELECT DAYNAME(date) FROM t1;
SHOW CREATE VIEW v1;
CREATE VIEW v2 AS SELECT DAYOFWEEK(date) FROM t1;
SHOW CREATE VIEW v2;
CREATE VIEW v3 AS SELECT WEEKDAY(date) FROM t1;
SHOW CREATE VIEW v3;
SELECT DAYNAME('2005-09-06');
SELECT DAYNAME(date) FROM t1;
SELECT * FROM v1;
SELECT DAYOFWEEK('2005-09-06');
SELECT DAYOFWEEK(date) FROM t1;
SELECT * FROM v2;
SELECT WEEKDAY('2005-09-06');
SELECT WEEKDAY(date) FROM t1;
SELECT * FROM v3;
DROP TABLE t1;
DROP VIEW v1, v2, v3;
2005-09-27 05:18:59 +02:00
2009-03-03 21:34:18 +01:00
2005-09-27 05:18:59 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#13411 crash when using non-qualified view column in HAVING clause
2005-09-27 05:18:59 +02:00
#
CREATE TABLE t1 ( a int, b int );
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
CREATE VIEW v1 AS SELECT a,b FROM t1;
SELECT t1.a FROM t1 GROUP BY t1.a HAVING a > 1;
SELECT v1.a FROM v1 GROUP BY v1.a HAVING a > 1;
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2005-09-27 08:29:02 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#13410 failed name resolution for qualified view column in HAVING
2005-09-27 08:29:02 +02:00
#
CREATE TABLE t1 ( a int, b int );
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
CREATE VIEW v1 AS SELECT a,b FROM t1;
SELECT t1.a FROM t1 GROUP BY t1.a HAVING t1.a > 1;
SELECT v1.a FROM v1 GROUP BY v1.a HAVING v1.a > 1;
2005-10-01 08:35:30 +02:00
SELECT t_1.a FROM t1 AS t_1 GROUP BY t_1.a HAVING t_1.a IN (1,2,3);
SELECT v_1.a FROM v1 AS v_1 GROUP BY v_1.a HAVING v_1.a IN (1,2,3);
2005-09-27 05:18:59 +02:00
2005-09-27 08:29:02 +02:00
DROP VIEW v1;
DROP TABLE t1;
2005-10-10 16:53:57 +02:00
2009-03-03 21:34:18 +01:00
2005-10-10 16:53:57 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#13327 view wasn't using index for const condition
2005-10-10 16:53:57 +02:00
#
CREATE TABLE t1 (a INT, b INT, INDEX(a,b));
CREATE TABLE t2 LIKE t1;
CREATE TABLE t3 (a INT);
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
INSERT INTO t3 VALUES (1),(2),(3);
CREATE VIEW v1 AS SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a AND t1.b=t2.b;
CREATE VIEW v2 AS SELECT t3.* FROM t1,t3 WHERE t1.a=t3.a;
EXPLAIN SELECT t1.* FROM t1 JOIN t2 WHERE t1.a=t2.a AND t1.b=t2.b AND t1.a=1;
EXPLAIN SELECT * FROM v1 WHERE a=1;
EXPLAIN SELECT * FROM v2 WHERE a=1;
DROP VIEW v1,v2;
DROP TABLE t1,t2,t3;
2009-03-03 21:34:18 +01:00
2005-11-01 15:27:10 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#13622 Wrong view .frm created if some field's alias contain \n
2005-11-11 18:03:32 +01:00
#
create table t1 (f1 int);
create view v1 as select t1.f1 as '123
456' from t1;
select * from v1;
drop view v1;
drop table t1;
2005-10-10 16:53:57 +02:00
2009-03-03 21:34:18 +01:00
# Bug#14466 lost sort order in GROUP_CONCAT() in a view
2005-11-01 15:27:10 +01:00
#
create table t1 (f1 int, f2 int);
insert into t1 values(1,1),(1,2),(1,3);
create view v1 as select f1 ,group_concat(f2 order by f2 asc) from t1 group by f1;
create view v2 as select f1 ,group_concat(f2 order by f2 desc) from t1 group by f1;
select * from v1;
select * from v2;
drop view v1,v2;
drop table t1;
2005-11-03 10:38:46 +01:00
2009-03-03 21:34:18 +01:00
2005-11-03 10:38:46 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#14026 Crash on second PS execution when using views
2005-11-03 10:38:46 +01:00
#
create table t1 (x int, y int);
create table t2 (x int, y int, z int);
create table t3 (x int, y int, z int);
create table t4 (x int, y int, z int);
create view v1 as
select t1.x
from (
2009-03-03 21:34:18 +01:00
(t1 join t2 on ((t1.y = t2.y)))
join
2005-11-03 10:38:46 +01:00
(t3 left join t4 on (t3.y = t4.y) and (t3.z = t4.z))
);
prepare stmt1 from "select count(*) from v1 where x = ?";
set @parm1=1;
execute stmt1 using @parm1;
execute stmt1 using @parm1;
drop view v1;
drop table t1,t2,t3,t4;
2005-11-06 07:45:54 +01:00
2009-03-03 21:34:18 +01:00
2005-11-06 07:45:54 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#14540 OPTIMIZE, ANALYZE, REPAIR applied to not a view
2005-11-02 22:44:58 +01:00
#
2005-11-03 07:13:10 +01:00
CREATE TABLE t1(id INT);
2005-11-02 22:44:58 +01:00
CREATE VIEW v1 AS SELECT id FROM t1;
OPTIMIZE TABLE v1;
ANALYZE TABLE v1;
REPAIR TABLE v1;
DROP TABLE t1;
OPTIMIZE TABLE v1;
2007-04-12 20:21:37 +02:00
ANALYZE TABLE v1;
REPAIR TABLE v1;
2005-11-02 22:44:58 +01:00
DROP VIEW v1;
2005-11-09 16:51:00 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#14719 Views DEFINER grammar is incorrect
2005-11-09 16:51:00 +01:00
#
create definer = current_user() sql security invoker view v1 as select 1;
show create view v1;
drop view v1;
create definer = current_user sql security invoker view v1 as select 1;
show create view v1;
drop view v1;
2005-11-14 19:52:39 +01:00
2009-03-03 21:34:18 +01:00
2005-11-14 20:10:34 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#14816 test_if_order_by_key() expected only Item_fields.
2005-11-14 20:10:34 +01:00
#
create table t1 (id INT, primary key(id));
insert into t1 values (1),(2);
create view v1 as select * from t1;
explain select id from v1 order by id;
drop view v1;
drop table t1;
2005-11-16 00:08:20 +01:00
2009-03-03 21:34:18 +01:00
2005-11-14 19:52:39 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#14850 Item_ref's values wasn't updated
2005-11-14 19:52:39 +01:00
#
create table t1(f1 int, f2 int);
insert into t1 values (null, 10), (null,2);
2006-01-05 23:47:49 +01:00
select f1, sum(f2) from t1 group by f1;
2005-11-14 19:52:39 +01:00
create view v1 as select * from t1;
select f1, sum(f2) from v1 group by f1;
drop view v1;
drop table t1;
2005-12-01 11:15:48 +01:00
2009-03-03 21:34:18 +01:00
2005-12-02 20:18:12 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#14885 incorrect SOURCE in view created in a procedure
2005-12-02 20:18:12 +01:00
# TODO: here SOURCE string must be shown when it will be possible
#
--disable_warnings
drop procedure if exists p1;
--enable_warnings
delimiter //;
create procedure p1 () deterministic
begin
create view v1 as select 1;
end;
//
delimiter ;//
call p1();
show create view v1;
drop view v1;
drop procedure p1;
2005-12-02 20:20:25 +01:00
2009-03-03 21:34:18 +01:00
2005-12-01 11:15:48 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#15096 using function with view for view creation
2005-12-01 11:15:48 +01:00
#
CREATE VIEW v1 AS SELECT 42 AS Meaning;
--disable_warnings
DROP FUNCTION IF EXISTS f1;
--enable_warnings
DELIMITER //;
CREATE FUNCTION f1() RETURNS INTEGER
BEGIN
DECLARE retn INTEGER;
SELECT Meaning FROM v1 INTO retn;
RETURN retn;
END
//
DELIMITER ;//
CREATE VIEW v2 AS SELECT f1();
select * from v2;
drop view v2,v1;
drop function f1;
2005-12-19 12:36:03 +01:00
2009-03-03 21:34:18 +01:00
2005-12-19 12:36:03 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#14861 aliased column names are not preserved.
2005-12-19 12:36:03 +01:00
#
create table t1 (id numeric, warehouse_id numeric);
create view v1 as select id from t1;
create view v2 as
select t1.warehouse_id, v1.id as receipt_id
from t1, v1 where t1.id = v1.id;
insert into t1 (id, warehouse_id) values(3, 2);
insert into t1 (id, warehouse_id) values(4, 2);
insert into t1 (id, warehouse_id) values(5, 1);
select v2.receipt_id as alias1, v2.receipt_id as alias2 from v2
order by v2.receipt_id;
drop view v2, v1;
drop table t1;
2006-01-07 07:28:26 +01:00
2009-03-03 21:34:18 +01:00
2006-01-07 07:28:26 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#16016 MIN/MAX optimization for views
2006-01-07 07:28:26 +01:00
#
CREATE TABLE t1 (a int PRIMARY KEY, b int);
INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT MAX(a) FROM t1;
SELECT MAX(a) FROM v1;
EXPLAIN SELECT MAX(a) FROM t1;
EXPLAIN SELECT MAX(a) FROM v1;
SELECT MIN(a) FROM t1;
SELECT MIN(a) FROM v1;
EXPLAIN SELECT MIN(a) FROM t1;
EXPLAIN SELECT MIN(a) FROM v1;
DROP VIEW v1;
DROP TABLE t1;
2006-02-02 05:43:43 +01:00
2009-03-03 21:34:18 +01:00
2006-02-02 05:43:43 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#16382 grouping name is resolved against a view column name
# which coincides with a select column name
2006-02-02 05:43:43 +01:00
CREATE TABLE t1 (x varchar(10));
INSERT INTO t1 VALUES (null), ('foo'), ('bar'), (null);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT IF(x IS NULL, 'blank', 'not blank') FROM v1 GROUP BY x;
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM t1 GROUP BY x;
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1;
SELECT IF(x IS NULL, 'blank', 'not blank') AS y FROM v1 GROUP BY y;
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x;
DROP VIEW v1;
DROP TABLE t1;
2006-02-13 17:53:34 +01:00
2009-03-03 21:34:18 +01:00
2006-02-13 17:53:34 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#15943 mysql_next_result hangs on invalid SHOW CREATE VIEW
2006-02-13 17:53:34 +01:00
#
delimiter //;
2009-03-03 21:34:18 +01:00
drop table if exists t1;
drop view if exists v1;
create table t1 (id int);
create view v1 as select * from t1;
drop table t1;
show create view v1;
2006-02-13 17:53:34 +01:00
drop view v1;
//
delimiter ;//
2006-03-03 14:19:57 +01:00
2009-03-03 21:34:18 +01:00
2006-03-03 14:19:57 +01:00
#
# Bug#17726 Not checked empty list caused endless loop
#
create table t1(f1 int, f2 int);
create view v1 as select ta.f1 as a, tb.f1 as b from t1 ta, t1 tb where ta.f1=tb
.f1 and ta.f2=tb.f2;
insert into t1 values(1,1),(2,2);
2007-02-16 02:47:39 +01:00
create view v2 as select * from v1 where a > 1 with local check option;
2006-03-03 14:19:57 +01:00
select * from v2;
update v2 set b=3 where a=2;
select * from v2;
drop view v2, v1;
drop table t1;
2006-03-28 04:28:55 +02:00
2009-03-03 21:34:18 +01:00
2006-03-28 04:28:55 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#18386 select from view over a table with ORDER BY view_col clause
# given view_col is not an image of any column from the base table
2006-03-28 04:28:55 +02:00
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1), (2);
CREATE VIEW v1 AS SELECT SQRT(a) my_sqrt FROM t1;
SELECT my_sqrt FROM v1 ORDER BY my_sqrt;
DROP VIEW v1;
DROP TABLE t1;
2006-04-04 21:55:02 +02:00
2009-03-03 21:34:18 +01:00
#
# Bug#18237 invalid count optimization applied to an outer join with a view
2006-04-04 21:55:02 +02:00
#
CREATE TABLE t1 (id int PRIMARY KEY);
CREATE TABLE t2 (id int PRIMARY KEY);
INSERT INTO t1 VALUES (1), (3);
INSERT INTO t2 VALUES (1), (2), (3);
CREATE VIEW v2 AS SELECT * FROM t2;
SELECT COUNT(*) FROM t1 LEFT JOIN t2 ON t1.id=t2.id;
SELECT * FROM t1 LEFT JOIN t2 ON t1.id=t2.id;
SELECT COUNT(*) FROM t1 LEFT JOIN v2 ON t1.id=v2.id;
DROP VIEW v2;
DROP TABLE t1, t2;
2006-04-08 20:42:09 +02:00
2009-03-03 21:34:18 +01:00
2006-04-08 20:42:09 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#16069 VIEW does return the same results as underlying SELECT
# with WHERE condition containing BETWEEN over dates
2006-09-26 18:52:54 +02:00
# Dates as strings should be casted to date type
2006-04-08 20:42:09 +02:00
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY,
td date DEFAULT NULL, KEY idx(td));
2009-03-03 21:34:18 +01:00
INSERT INTO t1 VALUES
2006-04-08 20:42:09 +02:00
(1, '2005-01-01'), (2, '2005-01-02'), (3, '2005-01-02'),
(4, '2005-01-03'), (5, '2005-01-04'), (6, '2005-01-05'),
(7, '2005-01-05'), (8, '2005-01-05'), (9, '2005-01-06');
CREATE VIEW v1 AS SELECT * FROM t1;
2006-09-18 12:14:27 +02:00
SELECT * FROM t1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE);
SELECT * FROM v1 WHERE td BETWEEN CAST('2005.01.02' AS DATE) AND CAST('2005.01.04' AS DATE);
2006-04-08 20:42:09 +02:00
DROP VIEW v1;
DROP TABLE t1;
2006-04-13 22:12:26 +02:00
2009-03-03 21:34:18 +01:00
2006-04-13 22:12:26 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#14308 Recursive view definitions
2006-04-13 22:12:26 +02:00
#
# using view only
create table t1 (a int);
create view v1 as select * from t1;
create view v2 as select * from v1;
drop table t1;
rename table v2 to t1;
-- error ER_VIEW_RECURSIVE
select * from v1;
drop view t1, v1;
# using SP function
create table t1 (a int);
delimiter //;
create function f1() returns int
begin
declare mx int;
select max(a) from t1 into mx;
return mx;
end//
delimiter ;//
create view v1 as select f1() as a;
create view v2 as select * from v1;
drop table t1;
rename table v2 to t1;
-- error ER_SP_NO_RECURSION
select * from v1;
drop function f1;
drop view t1, v1;
2006-04-22 09:54:25 +02:00
2009-03-03 21:34:18 +01:00
2006-04-22 09:54:25 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#15153 CONVERT_TZ() is not allowed in all places in VIEWs
2006-04-22 09:54:25 +02:00
#
# Error was reported when one tried to use CONVERT_TZ() function
# select list of view which was processed using MERGE algorithm.
# (Also see additional test in timezone_grant.test)
create table t1 (dt datetime);
insert into t1 values (20040101000000), (20050101000000), (20060101000000);
# Let us test that convert_tz() can be used in view's select list
create view v1 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from t1;
select * from v1;
drop view v1;
2009-03-03 21:34:18 +01:00
# And in its where part
2006-04-22 09:54:25 +02:00
create view v1 as select * from t1 where convert_tz(dt, 'UTC', 'Europe/Moscow') >= 20050101000000;
select * from v1;
# Other interesting case - a view which uses convert_tz() function
# through other view.
create view v2 as select * from v1 where dt < 20060101000000;
select * from v2;
drop view v2;
# And even more interesting case when view uses convert_tz() both
# directly and indirectly
create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1;
select * from v2;
drop view v1, v2;
drop table t1;
2006-05-13 03:24:38 +02:00
2009-03-03 21:34:18 +01:00
2006-05-13 03:24:38 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#19490 usage of view specified by a query with GROUP BY
# an expression containing non-constant interval
2006-05-13 03:24:38 +02:00
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, d datetime);
CREATE VIEW v1 AS
SELECT id, date(d) + INTERVAL TIME_TO_SEC(d) SECOND AS t, COUNT(*)
FROM t1 GROUP BY id, t;
SHOW CREATE VIEW v1;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
2006-05-17 07:19:44 +02:00
2009-03-03 21:34:18 +01:00
2006-05-17 22:55:28 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#19077 A nested materialized view is used before being populated.
2006-05-17 22:55:28 +02:00
#
CREATE TABLE t1 (i INT, j BIGINT);
INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
CREATE VIEW v1 AS SELECT MIN(j) AS j FROM t1;
CREATE VIEW v2 AS SELECT MIN(i) FROM t1 WHERE j = ( SELECT * FROM v1 );
SELECT * FROM v2;
DROP VIEW v2, v1;
DROP TABLE t1;
2006-05-18 20:30:42 +02:00
2009-03-03 21:34:18 +01:00
#
# Bug#19573 VIEW with HAVING that refers an alias name
2006-05-17 07:19:44 +02:00
#
CREATE TABLE t1(
fName varchar(25) NOT NULL,
lName varchar(25) NOT NULL,
DOB date NOT NULL,
2007-10-10 09:16:13 +02:00
test_date date NOT NULL,
2006-05-17 07:19:44 +02:00
uID int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY);
2009-03-03 21:34:18 +01:00
2007-10-10 09:16:13 +02:00
INSERT INTO t1(fName, lName, DOB, test_date) VALUES
('Hank', 'Hill', '1964-09-29', '2007-01-01'),
('Tom', 'Adams', '1908-02-14', '2007-01-01'),
('Homer', 'Simpson', '1968-03-05', '2007-01-01');
2006-05-17 07:19:44 +02:00
CREATE VIEW v1 AS
2007-10-10 09:16:13 +02:00
SELECT (year(test_date)-year(DOB)) AS Age
2009-03-03 21:34:18 +01:00
FROM t1 HAVING Age < 75;
SHOW CREATE VIEW v1;
2006-05-17 07:19:44 +02:00
2007-10-10 09:16:13 +02:00
SELECT (year(test_date)-year(DOB)) AS Age FROM t1 HAVING Age < 75;
2006-05-17 07:19:44 +02:00
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2006-05-21 03:54:43 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#19089 wrong inherited dafault values in temp table views
2006-05-21 03:54:43 +02:00
#
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a char(6) DEFAULT 'xxx');
INSERT INTO t1(id) VALUES (1), (2), (3), (4);
INSERT INTO t1 VALUES (5,'yyy'), (6,'yyy');
SELECT * FROM t1;
CREATE VIEW v1(a, m) AS SELECT a, MIN(id) FROM t1 GROUP BY a;
SELECT * FROM v1;
CREATE TABLE t2 SELECT * FROM v1;
INSERT INTO t2(m) VALUES (0);
SELECT * FROM t2;
2006-05-17 07:19:44 +02:00
2006-05-21 03:54:43 +02:00
DROP VIEW v1;
DROP TABLE t1,t2;
CREATE TABLE t1 (id int PRIMARY KEY, e ENUM('a','b') NOT NULL DEFAULT 'b');
INSERT INTO t1(id) VALUES (1), (2), (3);
INSERT INTO t1 VALUES (4,'a');
SELECT * FROM t1;
CREATE VIEW v1(m, e) AS SELECT MIN(id), e FROM t1 GROUP BY e;
CREATE TABLE t2 SELECT * FROM v1;
SELECT * FROM t2;
DROP VIEW v1;
2006-07-04 11:10:12 +02:00
DROP TABLE t1,t2;
2006-10-10 11:44:04 +02:00
2006-07-04 11:10:12 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#16110 insert permitted into view col w/o default value
2006-07-04 11:10:12 +02:00
#
CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL);
CREATE VIEW v1 AS SELECT a, b FROM t1;
INSERT INTO v1 (b) VALUES (2);
SET SQL_MODE = STRICT_ALL_TABLES;
2009-03-03 21:34:18 +01:00
--error ER_NO_DEFAULT_FOR_VIEW_FIELD
2006-07-04 11:10:12 +02:00
INSERT INTO v1 (b) VALUES (4);
SET SQL_MODE = '';
SELECT * FROM t1;
DROP VIEW v1;
DROP TABLE t1;
2006-07-06 23:41:01 +02:00
2009-03-03 21:34:18 +01:00
2006-07-06 23:41:01 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#18243 expression over a view column that with the REVERSE function
2006-07-06 23:41:01 +02:00
#
CREATE TABLE t1 (firstname text, surname text);
INSERT INTO t1 VALUES
("Bart","Simpson"),("Milhouse","van Houten"),("Montgomery","Burns");
CREATE VIEW v1 AS SELECT CONCAT(firstname," ",surname) AS name FROM t1;
SELECT CONCAT(LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," ")),
LEFT(name,LENGTH(name)-INSTR(REVERSE(name)," "))) AS f1
FROM v1;
DROP VIEW v1;
DROP TABLE t1;
2006-07-14 05:48:26 +02:00
2009-03-03 21:34:18 +01:00
2006-07-14 05:48:26 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#19714 wrong type of a view column specified by an expressions over ints
2006-07-14 05:48:26 +02:00
#
CREATE TABLE t1 (i int, j int);
CREATE VIEW v1 AS SELECT COALESCE(i,j) FROM t1;
DESCRIBE v1;
2009-03-03 21:34:18 +01:00
CREATE TABLE t2 SELECT COALESCE(i,j) FROM t1;
2006-07-14 05:48:26 +02:00
DESCRIBE t2;
DROP VIEW v1;
DROP TABLE t1,t2;
2006-07-20 01:42:19 +02:00
2009-03-03 21:34:18 +01:00
2006-07-20 01:42:19 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#17526 views with TRIM functions
2006-07-20 01:42:19 +02:00
#
CREATE TABLE t1 (s varchar(10));
INSERT INTO t1 VALUES ('yadda'), ('yady');
SELECT TRIM(BOTH 'y' FROM s) FROM t1;
CREATE VIEW v1 AS SELECT TRIM(BOTH 'y' FROM s) FROM t1;
SELECT * FROM v1;
DROP VIEW v1;
2009-03-03 21:34:18 +01:00
SELECT TRIM(LEADING 'y' FROM s) FROM t1;
2006-07-20 01:42:19 +02:00
CREATE VIEW v1 AS SELECT TRIM(LEADING 'y' FROM s) FROM t1;
SELECT * FROM v1;
DROP VIEW v1;
2009-03-03 21:34:18 +01:00
SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
2006-07-20 01:42:19 +02:00
CREATE VIEW v1 AS SELECT TRIM(TRAILING 'y' FROM s) FROM t1;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
2006-07-25 17:42:49 +02:00
2009-03-03 21:34:18 +01:00
2006-07-25 17:42:49 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#21080 ALTER VIEW makes user restate SQL SECURITY mode, and ALGORITHM
2006-07-31 16:33:37 +02:00
#
CREATE TABLE t1 (x INT, y INT);
CREATE ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
SHOW CREATE VIEW v1;
ALTER VIEW v1 AS SELECT x, y FROM t1;
SHOW CREATE VIEW v1;
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
# Bug#21086 server crashes when VIEW defined with a SELECT with COLLATE
# clause is called
2006-07-25 17:42:49 +02:00
#
CREATE TABLE t1 (s1 char);
INSERT INTO t1 VALUES ('Z');
CREATE VIEW v1 AS SELECT s1 collate latin1_german1_ci AS col FROM t1;
CREATE VIEW v2 (col) AS SELECT s1 collate latin1_german1_ci FROM t1;
# either of these statements will cause crash
INSERT INTO v1 (col) VALUES ('b');
INSERT INTO v2 (col) VALUES ('c');
SELECT s1 FROM t1;
DROP VIEW v1, v2;
DROP TABLE t1;
2006-07-31 19:56:06 +02:00
2009-03-03 21:34:18 +01:00
2006-07-31 19:56:06 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#11551 Asymmetric + undocumented behaviour of DROP VIEW and DROP TABLE
2006-07-31 19:56:06 +02:00
#
CREATE TABLE t1 (id INT);
CREATE VIEW v1 AS SELECT id FROM t1;
SHOW TABLES;
2009-03-03 21:34:18 +01:00
--error ER_BAD_TABLE_ERROR
2006-07-31 19:56:06 +02:00
DROP VIEW v2,v1;
SHOW TABLES;
CREATE VIEW v1 AS SELECT id FROM t1;
2009-03-03 21:34:18 +01:00
--error ER_WRONG_OBJECT
2006-07-31 19:56:06 +02:00
DROP VIEW t1,v1;
SHOW TABLES;
DROP TABLE t1;
2006-08-30 01:22:59 +02:00
--disable_warnings
DROP VIEW IF EXISTS v1;
--enable_warnings
2009-03-03 21:34:18 +01:00
2006-08-30 01:22:59 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#21261 Wrong access rights was required for an insert to a view
2006-08-30 01:22:59 +02:00
#
2009-03-03 21:34:18 +01:00
2011-05-31 14:33:14 +02:00
CREATE DATABASE bug21261DB;
USE bug21261DB;
connect (root,localhost,root,,bug21261DB);
connection root;
CREATE TABLE t1 (x INT);
CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT x FROM t1;
GRANT INSERT, UPDATE ON v1 TO 'user21261'@'localhost';
GRANT INSERT, UPDATE ON t1 TO 'user21261'@'localhost';
CREATE TABLE t2 (y INT);
GRANT SELECT ON t2 TO 'user21261'@'localhost';
connect (user21261, localhost, user21261,, bug21261DB);
connection user21261;
INSERT INTO v1 (x) VALUES (5);
UPDATE v1 SET x=1;
connection root;
GRANT SELECT ON v1 TO 'user21261'@'localhost';
GRANT SELECT ON t1 TO 'user21261'@'localhost';
connection user21261;
UPDATE v1,t2 SET x=1 WHERE x=y;
connection root;
SELECT * FROM t1;
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user21261'@'localhost';
DROP USER 'user21261'@'localhost';
DROP VIEW v1;
DROP TABLE t1;
DROP DATABASE bug21261DB;
connection default;
USE test;
disconnect root;
disconnect user21261;
2009-03-03 21:34:18 +01:00
2006-08-23 19:31:00 +02:00
2006-08-30 01:22:59 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#15950 NOW() optimized away in VIEWs
2006-08-30 01:22:59 +02:00
#
create table t1 (f1 datetime);
create view v1 as select * from t1 where f1 between now() and now() + interval 1 minute;
show create view v1;
drop view v1;
drop table t1;
2009-03-03 21:34:18 +01:00
2006-08-23 19:31:00 +02:00
#
2009-03-03 21:34:18 +01:00
# Test for Bug#16899 Possible buffer overflow in handling of DEFINER-clause.
2006-08-23 19:31:00 +02:00
#
# Prepare.
2006-07-31 19:56:06 +02:00
--disable_warnings
2006-08-23 19:31:00 +02:00
DROP TABLE IF EXISTS t1;
2006-07-31 19:56:06 +02:00
DROP VIEW IF EXISTS v1;
2006-08-23 19:31:00 +02:00
DROP VIEW IF EXISTS v2;
--enable_warnings
CREATE TABLE t1(a INT, b INT);
--error ER_WRONG_STRING_LENGTH
CREATE DEFINER=1234567890abcdefGHIKL@localhost
VIEW v1 AS SELECT a FROM t1;
--error ER_WRONG_STRING_LENGTH
CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY
VIEW v2 AS SELECT b FROM t1;
# Cleanup.
DROP TABLE t1;
2006-08-29 12:37:52 +02:00
2006-08-29 12:32:59 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#17591 Updatable view not possible with trigger or stored function
2006-08-29 12:32:59 +02:00
#
# During prelocking phase we didn't update lock type of view tables,
# hence READ lock was always requested.
#
2006-07-31 19:56:06 +02:00
--disable_warnings
2006-08-29 12:32:59 +02:00
DROP FUNCTION IF EXISTS f1;
DROP FUNCTION IF EXISTS f2;
DROP VIEW IF EXISTS v1, v2;
DROP TABLE IF EXISTS t1;
2006-07-31 19:56:06 +02:00
--enable_warnings
2006-08-29 12:32:59 +02:00
CREATE TABLE t1 (i INT);
CREATE VIEW v1 AS SELECT * FROM t1;
delimiter |;
CREATE FUNCTION f1() RETURNS INT
BEGIN
INSERT INTO v1 VALUES (0);
RETURN 0;
END |
delimiter ;|
SELECT f1();
CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1;
delimiter |;
CREATE FUNCTION f2() RETURNS INT
BEGIN
INSERT INTO v2 VALUES (0);
RETURN 0;
END |
delimiter ;|
2006-09-28 23:00:18 +02:00
--error ER_NON_INSERTABLE_TABLE
2006-08-29 12:32:59 +02:00
SELECT f2();
DROP FUNCTION f1;
DROP FUNCTION f2;
DROP VIEW v1, v2;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2006-09-06 17:21:43 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#5500 wrong select_type in EXPLAIN output for queries over views
2006-09-06 17:21:43 +02:00
#
2009-03-03 21:34:18 +01:00
CREATE TABLE t1 (s1 int);
2006-09-06 17:21:43 +02:00
CREATE VIEW v1 AS SELECT * FROM t1;
EXPLAIN SELECT * FROM t1;
EXPLAIN SELECT * FROM v1;
2006-08-15 19:45:24 +02:00
2006-09-06 17:21:43 +02:00
INSERT INTO t1 VALUES (1), (3), (2);
2009-03-03 21:34:18 +01:00
EXPLAIN SELECT * FROM t1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1);
EXPLAIN SELECT * FROM v1 t WHERE t.s1+1 < (SELECT MAX(t1.s1) FROM t1);
2006-09-06 17:21:43 +02:00
DROP VIEW v1;
DROP TABLE t1;
2006-09-25 15:15:14 +02:00
2009-03-03 21:34:18 +01:00
2006-09-28 23:00:18 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#5505 Wrong error message on INSERT into a view
2006-09-28 23:00:18 +02:00
#
create table t1 (s1 int);
create view v1 as select s1 as a, s1 as b from t1;
2006-10-09 13:47:06 +02:00
--error ER_NON_INSERTABLE_TABLE
2009-03-03 21:34:18 +01:00
insert into v1 values (1,1);
2006-09-28 23:00:18 +02:00
update v1 set a = 5;
drop view v1;
drop table t1;
2009-03-03 21:34:18 +01:00
2006-09-25 15:15:14 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#21646 view qith a subquery in ON expression
2006-09-25 15:15:14 +02:00
#
2009-03-03 21:34:18 +01:00
CREATE TABLE t1(pk int PRIMARY KEY);
2006-09-25 15:15:14 +02:00
CREATE TABLE t2(pk int PRIMARY KEY, fk int, ver int, org int);
2009-03-03 21:34:18 +01:00
CREATE ALGORITHM=MERGE VIEW v1 AS
2006-09-25 15:15:14 +02:00
SELECT t1.*
2009-03-03 21:34:18 +01:00
FROM t1 JOIN t2
ON t2.fk = t1.pk AND
2006-09-25 15:15:14 +02:00
t2.ver = (SELECT MAX(t.ver) FROM t2 t WHERE t.org = t2.org);
SHOW WARNINGS;
SHOW CREATE VIEW v1;
DROP VIEW v1;
DROP TABLE t1, t2;
2006-10-01 13:43:35 +02:00
2006-10-10 14:44:59 +02:00
2006-09-29 09:16:07 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#19111 TRIGGERs selecting from a VIEW on the firing base table fail
2006-10-10 11:44:04 +02:00
#
# Allow to select from a view on a table being modified in a trigger
# and stored function, since plain select is allowed there.
#
--disable_warnings
DROP FUNCTION IF EXISTS f1;
DROP VIEW IF EXISTS v1;
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1);
CREATE VIEW v1 AS SELECT MAX(i) FROM t1;
# Plain 'SET NEW.i = (SELECT MAX(i) FROM t1) + 1' works, so select
# from a view should work too.
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
SET NEW.i = (SELECT * FROM v1) + 1;
INSERT INTO t1 VALUES (1);
# Plain 'RETURN (SELECT MAX(i) FROM t1)' works in INSERT, so select
# from a view should work too.
CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1);
UPDATE t1 SET i= f1();
DROP FUNCTION f1;
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2006-09-29 09:16:07 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#16813 (WITH CHECK OPTION doesn't work with UPDATE)
2006-09-29 09:16:07 +02:00
#
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL);
CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION;
INSERT INTO v1 (val) VALUES (2);
INSERT INTO v1 (val) VALUES (4);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2006-09-29 09:16:07 +02:00
INSERT INTO v1 (val) VALUES (6);
2009-03-03 21:34:18 +01:00
-- error ER_VIEW_CHECK_FAILED
2006-09-29 09:16:07 +02:00
UPDATE v1 SET val=6 WHERE id=2;
DROP VIEW v1;
DROP TABLE t1;
2006-10-10 11:44:04 +02:00
2006-10-27 11:32:41 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#22584 last_insert_id not updated after inserting a record
2006-10-27 11:32:41 +02:00
# through a updatable view
#
# We still do not update LAST_INSERT_ID if AUTO_INCREMENT column is
# not accessible through a view. However, we do not reset the value
# of LAST_INSERT_ID, but keep it unchanged.
#
--disable_warnings
DROP VIEW IF EXISTS v1, v2;
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT);
CREATE VIEW v1 AS SELECT j FROM t1;
CREATE VIEW v2 AS SELECT * FROM t1;
INSERT INTO t1 (j) VALUES (1);
SELECT LAST_INSERT_ID();
INSERT INTO v1 (j) VALUES (2);
--echo # LAST_INSERT_ID() should not change.
SELECT LAST_INSERT_ID();
INSERT INTO v2 (j) VALUES (3);
--echo # LAST_INSERT_ID() should be updated.
SELECT LAST_INSERT_ID();
INSERT INTO v1 (j) SELECT j FROM t1;
--echo # LAST_INSERT_ID() should not change.
SELECT LAST_INSERT_ID();
SELECT * FROM t1;
DROP VIEW v1, v2;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2007-02-16 02:47:39 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#25580 !0 as an operand in a select expression of a view
2007-02-16 02:47:39 +01:00
#
CREATE VIEW v AS SELECT !0 * 5 AS x FROM DUAL;
SHOW CREATE VIEW v;
SELECT !0 * 5 AS x FROM DUAL;
SELECT * FROM v;
DROP VIEW v;
2009-03-03 21:34:18 +01:00
2006-12-19 13:32:02 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#24293 '\Z' token is not handled correctly in views
2006-12-19 13:32:02 +01:00
#
--disable_warnings
DROP VIEW IF EXISTS v1;
--enable_warnings
CREATE VIEW v1 AS SELECT 'The\ZEnd';
SELECT * FROM v1;
SHOW CREATE VIEW v1;
DROP VIEW v1;
2006-10-27 11:32:41 +02:00
2009-03-03 21:34:18 +01:00
2007-02-16 02:47:39 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#26124 BETWEEN over a view column of the DATETIME type
2007-02-16 02:47:39 +01:00
#
CREATE TABLE t1 (mydate DATETIME);
INSERT INTO t1 VALUES
('2007-01-01'), ('2007-01-02'), ('2007-01-30'), ('2007-01-31');
CREATE VIEW v1 AS SELECT mydate from t1;
SELECT * FROM t1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2007-02-16 02:47:39 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#25931 update of a multi-table view with check option
2007-02-16 02:47:39 +01:00
#
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1), (2);
CREATE VIEW v1 AS
SELECT t2.b FROM t1,t2 WHERE t1.a = t2.b WITH CHECK OPTION;
SELECT * FROM v1;
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-02-16 02:47:39 +01:00
UPDATE v1 SET b=3;
SELECT * FROM v1;
SELECT * FROM t1;
SELECT * FROM t2;
DROP VIEW v1;
DROP TABLE t1,t2;
2009-03-03 21:34:18 +01:00
2007-02-16 02:47:39 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#12122 Views with ORDER BY can't be resolved using MERGE algorithm.
2007-02-16 02:47:39 +01:00
#
create table t1(f1 int, f2 int);
insert into t1 values(1,2),(1,3),(1,1),(2,3),(2,1),(2,2);
select * from t1;
create view v1 as select * from t1 order by f2;
select * from v1;
explain extended select * from v1;
select * from v1 order by f1;
explain extended select * from v1 order by f1;
drop view v1;
drop table t1;
#
2009-03-03 21:34:18 +01:00
# Bug#26209 queries with GROUP BY and ORDER BY using views
2007-02-16 02:47:39 +01:00
#
CREATE TABLE t1 (
id int(11) NOT NULL PRIMARY KEY,
country varchar(32),
code int(11) default NULL
);
INSERT INTO t1 VALUES
(1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id);
SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id);
DROP VIEW v1;
DROP TABLE t1;
2007-02-04 14:49:24 +01:00
2009-03-03 21:34:18 +01:00
2007-02-04 14:49:24 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#25897 Some queries are no longer possible after a CREATE VIEW fails
2007-02-04 14:49:24 +01:00
#
--disable_warnings
DROP VIEW IF EXISTS v1;
--enable_warnings
let $query = SELECT * FROM (SELECT 1) AS t;
eval $query;
--error ER_VIEW_SELECT_DERIVED
eval CREATE VIEW v1 AS $query;
--echo # Previously the following would fail.
eval $query;
2009-03-03 21:34:18 +01:00
2007-02-13 01:20:41 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#24532 The return data type of IS TRUE is different from similar operations
2007-02-13 01:20:41 +01:00
#
--disable_warnings
drop view if exists view_24532_a;
drop view if exists view_24532_b;
drop table if exists table_24532;
--enable_warnings
create table table_24532 (
a int,
b bigint,
c int(4),
d bigint(48)
);
create view view_24532_a as
select
a IS TRUE,
a IS NOT TRUE,
a IS FALSE,
a IS NOT FALSE,
a IS UNKNOWN,
a IS NOT UNKNOWN,
a is NULL,
a IS NOT NULL,
ISNULL(a),
b IS TRUE,
b IS NOT TRUE,
b IS FALSE,
b IS NOT FALSE,
b IS UNKNOWN,
b IS NOT UNKNOWN,
b is NULL,
b IS NOT NULL,
ISNULL(b),
c IS TRUE,
c IS NOT TRUE,
c IS FALSE,
c IS NOT FALSE,
c IS UNKNOWN,
c IS NOT UNKNOWN,
c is NULL,
c IS NOT NULL,
ISNULL(c),
d IS TRUE,
d IS NOT TRUE,
d IS FALSE,
d IS NOT FALSE,
d IS UNKNOWN,
d IS NOT UNKNOWN,
d is NULL,
d IS NOT NULL,
ISNULL(d)
from table_24532;
describe view_24532_a;
create view view_24532_b as
select
a IS TRUE,
if(ifnull(a, 0), 1, 0) as old_istrue,
a IS NOT TRUE,
if(ifnull(a, 0), 0, 1) as old_isnottrue,
a IS FALSE,
if(ifnull(a, 1), 0, 1) as old_isfalse,
a IS NOT FALSE,
if(ifnull(a, 1), 1, 0) as old_isnotfalse
from table_24532;
describe view_24532_b;
show create view view_24532_b;
insert into table_24532 values (0, 0, 0, 0);
select * from view_24532_b;
update table_24532 set a=1;
select * from view_24532_b;
update table_24532 set a=NULL;
select * from view_24532_b;
drop view view_24532_a;
drop view view_24532_b;
drop table table_24532;
2009-03-03 21:34:18 +01:00
2007-03-05 04:54:35 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#26560 view using subquery with a reference to an outer alias
2007-03-05 04:54:35 +01:00
#
CREATE TABLE t1 (
lid int NOT NULL PRIMARY KEY,
name char(10) NOT NULL
);
INSERT INTO t1 (lid, name) VALUES
(1, 'YES'), (2, 'NO');
CREATE TABLE t2 (
2009-03-03 21:34:18 +01:00
id int NOT NULL PRIMARY KEY,
2007-03-05 04:54:35 +01:00
gid int NOT NULL,
lid int NOT NULL,
dt date
);
INSERT INTO t2 (id, gid, lid, dt) VALUES
(1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'),
(3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02');
SELECT DISTINCT t2.gid AS lgid,
(SELECT t1.name FROM t1, t2
WHERE t1.lid = t2.lid AND t2.gid = lgid
ORDER BY t2.dt DESC LIMIT 1
) as clid
FROM t2;
CREATE VIEW v1 AS
SELECT DISTINCT t2.gid AS lgid,
(SELECT t1.name FROM t1, t2
WHERE t1.lid = t2.lid AND t2.gid = lgid
ORDER BY t2.dt DESC LIMIT 1
) as clid
FROM t2;
SELECT * FROM v1;
DROP VIEW v1;
DROP table t1,t2;
2007-02-04 14:49:24 +01:00
2009-03-03 21:34:18 +01:00
2007-04-20 09:49:45 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#27786 Inconsistent Operation Performing UNION On View With ORDER BY
2007-04-20 09:49:45 +02:00
#
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1),(2),(3);
CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a;
SELECT * FROM t1 UNION SELECT * FROM v1;
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1;
SELECT * FROM v1 UNION SELECT * FROM t1;
EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1;
SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a;
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2007-05-11 15:19:47 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#27921 View ignores precision for CAST()
2007-05-11 15:19:47 +02:00
#
CREATE VIEW v1 AS SELECT CAST( 1.23456789 AS DECIMAL( 7,5 ) ) AS col;
SELECT * FROM v1;
DESCRIBE v1;
DROP VIEW v1;
CREATE VIEW v1 AS SELECT CAST(1.23456789 AS DECIMAL(8,0)) AS col;
SHOW CREATE VIEW v1;
DROP VIEW v1;
2009-03-03 21:34:18 +01:00
2007-05-30 09:21:39 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#28716 CHECK OPTION expression is evaluated over expired record buffers
# when VIEW is updated via temporary tables
2007-05-30 09:21:39 +02:00
#
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (b INT, c INT DEFAULT 0);
INSERT INTO t1 (a) VALUES (1), (2);
INSERT INTO t2 (b) VALUES (1), (2);
CREATE VIEW v1 AS SELECT t2.b,t2.c FROM t1, t2
WHERE t1.a=t2.b AND t2.b < 3 WITH CHECK OPTION;
SELECT * FROM v1;
UPDATE v1 SET c=1 WHERE b=1;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1,t2;
2009-03-03 21:34:18 +01:00
2007-05-31 09:04:03 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#28561 update on multi-table view with CHECK OPTION and a subquery
# in WHERE condition
2007-05-31 09:04:03 +02:00
#
CREATE TABLE t1 (id int);
CREATE TABLE t2 (id int, c int DEFAULT 0);
INSERT INTO t1 (id) VALUES (1);
INSERT INTO t2 (id) VALUES (1);
2009-03-03 21:34:18 +01:00
CREATE VIEW v1 AS
SELECT t2.c FROM t1, t2
2007-05-31 09:04:03 +02:00
WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION;
UPDATE v1 SET c=1;
DROP VIEW v1;
DROP TABLE t1,t2;
2009-03-03 21:34:18 +01:00
2007-05-31 23:15:40 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#27827 CHECK OPTION ignores ON conditions when updating
# a multi-table view with CHECK OPTION.
2007-05-31 23:15:40 +02:00
#
CREATE TABLE t1 (a1 INT, c INT DEFAULT 0);
CREATE TABLE t2 (a2 INT);
CREATE TABLE t3 (a3 INT);
CREATE TABLE t4 (a4 INT);
INSERT INTO t1 (a1) VALUES (1),(2);
INSERT INTO t2 (a2) VALUES (1),(2);
INSERT INTO t3 (a3) VALUES (1),(2);
INSERT INTO t4 (a4) VALUES (1),(2);
CREATE VIEW v1 AS
SELECT t1.a1, t1.c FROM t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3
WITH CHECK OPTION;
SELECT * FROM v1;
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
UPDATE v1 SET c=3;
PREPARE t FROM 'UPDATE v1 SET c=3';
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
EXECUTE t;
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
EXECUTE t;
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
INSERT INTO v1(a1, c) VALUES (3, 3);
UPDATE v1 SET c=1 WHERE a1=1;
SELECT * FROM v1;
SELECT * FROM t1;
CREATE VIEW v2 AS SELECT t1.a1, t1.c
FROM (t1 JOIN t2 ON t1.a1=t2.a2 AND t1.c < 3)
JOIN (t3 JOIN t4 ON t3.a3=t4.a4)
ON t2.a2=t3.a3 WITH CHECK OPTION;
SELECT * FROM v2;
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
UPDATE v2 SET c=3;
PREPARE t FROM 'UPDATE v2 SET c=3';
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
EXECUTE t;
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
EXECUTE t;
2009-03-03 21:34:18 +01:00
--error ER_VIEW_CHECK_FAILED
2007-05-31 23:15:40 +02:00
INSERT INTO v2(a1, c) VALUES (3, 3);
UPDATE v2 SET c=2 WHERE a1=1;
SELECT * FROM v2;
SELECT * FROM t1;
DROP VIEW v1,v2;
DROP TABLE t1,t2,t3,t4;
2009-03-03 21:34:18 +01:00
2007-06-20 21:43:14 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#29104 assertion abort for a query with a view column reference
# in the GROUP BY list and a condition requiring the value
# of another view column to be equal to a constant
2007-06-20 21:43:14 +02:00
#
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2);
CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1;
SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b;
EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b;
SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a;
EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a;
SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a;
EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a;
DROP VIEW v1;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2007-07-05 06:12:07 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#29392 SELECT over a multi-table view with ORDER BY
# selecting the same view column with two different aliases
2007-07-05 06:12:07 +02:00
#
CREATE TABLE t1 (
person_id int NOT NULL PRIMARY KEY,
username varchar(40) default NULL,
status_flg char(1) NOT NULL default 'A'
);
CREATE TABLE t2 (
person_role_id int NOT NULL auto_increment PRIMARY KEY,
role_id int NOT NULL,
person_id int NOT NULL,
INDEX idx_person_id (person_id),
INDEX idx_role_id (role_id)
);
CREATE TABLE t3 (
role_id int NOT NULL auto_increment PRIMARY KEY,
role_name varchar(100) default NULL,
app_name varchar(40) NOT NULL,
INDEX idx_app_name(app_name)
);
2009-03-03 21:34:18 +01:00
CREATE VIEW v1 AS
2007-07-05 06:12:07 +02:00
SELECT profile.person_id AS person_id
FROM t1 profile, t2 userrole, t3 role
WHERE userrole.person_id = profile.person_id AND
role.role_id = userrole.role_id AND
profile.status_flg = 'A'
ORDER BY profile.person_id,role.app_name,role.role_name;
INSERT INTO t1 VALUES
(6,'Sw','A'), (-1136332546,'ols','e'), (0,' *\n','0'),
(-717462680,'ENTS Ta','0'), (-904346964,'ndard SQL\n','0');
INSERT INTO t2 VALUES
(1,3,6),(2,4,7),(3,5,8),(4,6,9),(5,1,6),(6,1,7),(7,1,8),(8,1,9),(9,1,10);
2009-03-03 21:34:18 +01:00
INSERT INTO t3 VALUES
2007-07-05 06:12:07 +02:00
(1,'NUCANS_APP_USER','NUCANSAPP'),(2,'NUCANS_TRGAPP_USER','NUCANSAPP'),
(3,'IA_INTAKE_COORDINATOR','IACANS'),(4,'IA_SCREENER','IACANS'),
(5,'IA_SUPERVISOR','IACANS'),(6,'IA_READONLY','IACANS'),
(7,'SOC_USER','SOCCANS'),(8,'CAYIT_USER','CAYITCANS'),
(9,'RTOS_DCFSPOS_SUPERVISOR','RTOS');
2009-03-03 21:34:18 +01:00
2007-07-05 06:12:07 +02:00
EXPLAIN SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
SELECT t.person_id AS a, t.person_id AS b FROM v1 t WHERE t.person_id=6;
DROP VIEW v1;
DROP TABLE t1,t2,t3;
2009-03-03 21:34:18 +01:00
2007-07-28 14:02:29 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#30020 Insufficient check led to a wrong info provided by the
# information schema table.
2007-07-28 14:02:29 +02:00
#
create table t1 (i int);
insert into t1 values (1), (2), (1), (3), (2), (4);
create view v1 as select distinct i from t1;
select * from v1;
2009-03-03 21:34:18 +01:00
select table_name, is_updatable from information_schema.views
2007-07-28 14:02:29 +02:00
where table_name = 'v1';
drop view v1;
drop table t1;
2009-03-03 21:34:18 +01:00
2007-06-06 16:54:14 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#28701 SELECTs from VIEWs completely ignore USE/FORCE KEY, allowing
# invalid statements
2007-06-06 16:54:14 +02:00
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE VIEW v1 AS SELECT * FROM t1;
2008-11-28 17:13:12 +01:00
--error ER_KEY_DOES_NOT_EXITS
2007-06-06 16:54:14 +02:00
SELECT * FROM v1 USE KEY(non_existant);
2008-11-28 17:13:12 +01:00
--error ER_KEY_DOES_NOT_EXITS
2007-06-06 16:54:14 +02:00
SELECT * FROM v1 FORCE KEY(non_existant);
2008-11-28 17:13:12 +01:00
--error ER_KEY_DOES_NOT_EXITS
2007-06-06 16:54:14 +02:00
SELECT * FROM v1 IGNORE KEY(non_existant);
DROP VIEW v1;
DROP TABLE t1;
2007-09-24 14:34:10 +02:00
#
2009-03-03 21:34:18 +01:00
# Bug#28702 VIEWs defined with USE/FORCE KEY ignore that request
2007-09-24 14:34:10 +02:00
#
CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT, b INT NOT NULL DEFAULT 0,
PRIMARY KEY(a), KEY (b));
INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),();
CREATE VIEW v1 AS SELECT * FROM t1 FORCE KEY (PRIMARY,b) ORDER BY a;
SHOW CREATE VIEW v1;
EXPLAIN SELECT * FROM v1;
CREATE VIEW v2 AS SELECT * FROM t1 USE KEY () ORDER BY a;
SHOW CREATE VIEW v2;
EXPLAIN SELECT * FROM v2;
CREATE VIEW v3 AS SELECT * FROM t1 IGNORE KEY (b) ORDER BY a;
SHOW CREATE VIEW v3;
EXPLAIN SELECT * FROM v3;
DROP VIEW v1;
DROP VIEW v2;
DROP VIEW v3;
DROP TABLE t1;
2009-03-03 21:34:18 +01:00
2008-01-11 18:10:54 +01:00
--echo #
2009-03-03 21:34:18 +01:00
--echo # Bug#29477 Not all fields of the target table were checked to have
--echo # a default value when inserting into a view.
2008-01-11 18:10:54 +01:00
--echo #
create table t1(f1 int, f2 int not null);
create view v1 as select f1 from t1;
insert into v1 values(1);
set @old_mode=@@sql_mode;
set @@sql_mode=traditional;
--error ER_NO_DEFAULT_FOR_VIEW_FIELD
insert into v1 values(1);
set @@sql_mode=@old_mode;
drop view v1;
drop table t1;
2007-09-26 13:22:48 +02:00
2009-03-03 21:34:18 +01:00
2008-02-12 10:43:55 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#33389 Selecting from a view into a table from within SP or trigger
# crashes server
2008-02-12 10:43:55 +01:00
#
create table t1 (a int, key(a));
create table t2 (c int);
2009-03-03 21:34:18 +01:00
2008-02-12 10:43:55 +01:00
create view v1 as select a b from t1;
2009-03-03 21:34:18 +01:00
create view v2 as select 1 a from t2, v1 where c in
2008-02-12 10:43:55 +01:00
(select 1 from t1 where b = a);
2009-03-03 21:34:18 +01:00
2008-02-12 10:43:55 +01:00
insert into t1 values (1), (1);
insert into t2 values (1), (1);
2009-03-03 21:34:18 +01:00
2008-02-12 10:43:55 +01:00
prepare stmt from "select * from v2 where a = 1";
2009-03-03 21:34:18 +01:00
execute stmt;
2008-02-12 10:43:55 +01:00
drop view v1, v2;
drop table t1, t2;
2009-03-03 21:34:18 +01:00
2008-02-22 09:34:18 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#33049 Assert while running test-as3ap test(mysql-bench suite)
2008-02-22 09:34:18 +01:00
#
CREATE TABLE t1 (a INT);
CREATE VIEW v1 AS SELECT p.a AS a FROM t1 p, t1 q;
INSERT INTO t1 VALUES (1), (1);
SELECT MAX(a), COUNT(DISTINCT a) FROM v1 GROUP BY a;
DROP VIEW v1;
DROP TABLE t1;
2008-02-21 10:17:32 +01:00
###########################################################################
--echo # -----------------------------------------------------------------
2009-03-03 21:34:18 +01:00
--echo # -- Bug#34337 Server crash when Altering a view using a table name.
2008-02-21 10:17:32 +01:00
--echo # -----------------------------------------------------------------
--echo
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--echo
CREATE TABLE t1(c1 INT);
--echo
SELECT * FROM t1;
--error ER_WRONG_OBJECT
ALTER ALGORITHM=TEMPTABLE SQL SECURITY INVOKER VIEW t1 (c2) AS SELECT (1);
--echo
DROP TABLE t1;
--echo
--echo # -- End of test case for Bug#34337.
--echo
###########################################################################
2008-03-26 19:43:12 +01:00
--echo # -----------------------------------------------------------------
2009-03-03 21:34:18 +01:00
--echo # -- Bug#35193 VIEW query is rewritten without "FROM DUAL",
--echo # -- causing syntax error
2008-03-26 19:43:12 +01:00
--echo # -----------------------------------------------------------------
--echo
CREATE VIEW v1 AS SELECT 1 FROM DUAL WHERE 1;
--echo
SELECT * FROM v1;
SHOW CREATE TABLE v1;
--echo
DROP VIEW v1;
--echo
--echo # -- End of test case for Bug#35193.
--echo
###########################################################################
2008-10-27 11:22:38 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#39040 valgrind errors/crash when creating views with binlog logging
# enabled
2008-10-27 11:22:38 +01:00
#
# Bug is visible only when running in valgrind with binary logging.
CREATE VIEW v1 AS SELECT 1;
DROP VIEW v1;
2009-03-03 21:34:18 +01:00
2008-11-28 17:13:12 +01:00
#
2009-03-03 21:34:18 +01:00
# Bug#33461 SELECT ... FROM <view> USE INDEX (...) throws an error
2008-11-28 17:13:12 +01:00
#
CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, INDEX (c2));
INSERT INTO t1 VALUES (1,1), (2,2), (3,3);
SELECT * FROM t1 USE INDEX (PRIMARY) WHERE c1=2;
SELECT * FROM t1 USE INDEX (c2) WHERE c2=2;
CREATE VIEW v1 AS SELECT c1, c2 FROM t1;
SHOW INDEX FROM v1;
--error ER_KEY_DOES_NOT_EXITS
SELECT * FROM v1 USE INDEX (PRIMARY) WHERE c1=2;
--error ER_KEY_DOES_NOT_EXITS
SELECT * FROM v1 FORCE INDEX (PRIMARY) WHERE c1=2;
--error ER_KEY_DOES_NOT_EXITS
SELECT * FROM v1 IGNORE INDEX (PRIMARY) WHERE c1=2;
--error ER_KEY_DOES_NOT_EXITS
SELECT * FROM v1 USE INDEX (c2) WHERE c2=2;
--error ER_KEY_DOES_NOT_EXITS
SELECT * FROM v1 FORCE INDEX (c2) WHERE c2=2;
--error ER_KEY_DOES_NOT_EXITS
SELECT * FROM v1 IGNORE INDEX (c2) WHERE c2=2;
DROP VIEW v1;
DROP TABLE t1;
2008-10-27 11:22:38 +01:00
2009-05-18 20:43:06 +02:00
--echo # -----------------------------------------------------------------
--echo # -- Bug#40825: Error 1356 while selecting from a view
--echo # -- with a "HAVING" clause though query works
--echo # -----------------------------------------------------------------
--echo
CREATE TABLE t1 (c INT);
--echo
CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
SHOW CREATE VIEW v1;
SELECT * FROM v1;
--echo
DROP VIEW v1;
DROP TABLE t1;
--echo
--echo # -- End of test case for Bug#40825
--echo
2008-02-12 20:09:16 +01:00
--echo # -----------------------------------------------------------------
--echo # -- End of 5.0 tests.
--echo # -----------------------------------------------------------------
2006-10-16 19:42:03 +02:00
#
# Bug#21370 View renaming lacks tablename_to_filename encoding
#
--disable_warnings
DROP DATABASE IF EXISTS `d-1`;
--enable_warnings
CREATE DATABASE `d-1`;
USE `d-1`;
CREATE TABLE `t-1` (c1 INT);
CREATE VIEW `v-1` AS SELECT c1 FROM `t-1`;
SHOW TABLES;
RENAME TABLE `t-1` TO `t-2`;
RENAME TABLE `v-1` TO `v-2`;
SHOW TABLES;
DROP TABLE `t-2`;
DROP VIEW `v-2`;
DROP DATABASE `d-1`;
USE test;
2007-03-09 13:52:50 +01:00
2007-11-30 10:14:07 +01:00
--echo
--echo #
2009-03-06 15:56:17 +01:00
--echo # Bug#26676 VIEW using old table schema in a session.
2007-11-30 10:14:07 +01:00
--echo #
--echo
--disable_warnings
DROP VIEW IF EXISTS v1;
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1(c1 INT, c2 INT);
INSERT INTO t1 VALUES (1, 2), (3, 4);
--echo
SELECT * FROM t1;
--echo
CREATE VIEW v1 AS SELECT * FROM t1;
--echo
SELECT * FROM v1;
--echo
ALTER TABLE t1 ADD COLUMN c3 INT AFTER c2;
--echo
SELECT * FROM t1;
--echo
SELECT * FROM v1;
--echo
SHOW CREATE VIEW v1;
--echo
DROP VIEW v1;
DROP TABLE t1;
--echo
--echo # End of test case for Bug#26676.
--echo
2008-02-12 20:09:16 +01:00
###########################################################################
--echo # -----------------------------------------------------------------
2009-03-06 15:56:17 +01:00
--echo # -- Bug#32538 View definition picks up character set, but not collation
2008-02-12 20:09:16 +01:00
--echo # -----------------------------------------------------------------
--echo
--disable_warnings
DROP VIEW IF EXISTS v1;
--enable_warnings
--echo
SET collation_connection = latin1_general_ci;
CREATE VIEW v1 AS SELECT _latin1 'text1' AS c1, 'text2' AS c2;
--echo
SELECT COLLATION(c1), COLLATION(c2) FROM v1;
--echo
SHOW CREATE VIEW v1;
--echo
--error ER_CANT_AGGREGATE_2COLLATIONS
SELECT * FROM v1 WHERE c1 = 'text1';
--echo
SELECT * FROM v1 WHERE c2 = 'text2';
--echo
use test;
SET names latin1;
--echo
SELECT COLLATION(c1), COLLATION(c2) FROM v1;
--echo
SELECT * FROM v1 WHERE c1 = 'text1';
--echo
--error ER_CANT_AGGREGATE_2COLLATIONS
SELECT * FROM v1 WHERE c2 = 'text2';
--echo
DROP VIEW v1;
--echo
--echo # -- End of test case for Bug#32538.
--echo
2008-02-20 21:26:50 +01:00
#
# Bug#34587 Creating a view inside a stored procedure leads to a server crash
#
--disable_warnings
drop view if exists a;
drop procedure if exists p;
--enable_warnings
delimiter |;
create procedure p()
begin
declare continue handler for sqlexception begin end;
create view a as select 1;
end|
delimiter ;|
call p();
call p();
2008-02-21 02:30:29 +01:00
drop view a;
2008-02-20 21:26:50 +01:00
drop procedure p;
2008-02-12 20:09:16 +01:00
###########################################################################
2009-05-19 06:25:36 +02:00
--echo #
--echo # Bug #44860: ALTER TABLE on view crashes server
--echo #
CREATE TABLE t1 (a INT);
CREATE VIEW v1 AS SELECT a FROM t1;
ALTER TABLE v1;
DROP VIEW v1;
DROP TABLE t1;
2010-02-10 19:11:08 +01:00
--echo #
--echo # Bug#48449: hang on show create view after upgrading when
--echo # view contains function of view
--echo #
--disable_warnings
DROP VIEW IF EXISTS v1,v2;
DROP TABLE IF EXISTS t1,t2;
DROP FUNCTION IF EXISTS f1;
--enable_warnings
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
delimiter //;
CREATE FUNCTION f1() RETURNS INT
BEGIN
SELECT a FROM v2 INTO @a;
RETURN @a;
END//
delimiter ;//
--echo # Trigger pre-locking when opening v2.
CREATE VIEW v1 AS SELECT f1() FROM t1;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
copy_file std_data/bug48449.frm $MYSQLD_DATADIR/test/v2.frm;
SHOW CREATE VIEW v1;
DROP VIEW v1,v2;
DROP TABLE t1,t2;
DROP FUNCTION f1;
2010-02-12 10:44:20 +01:00
#
# Bug#48294 assertion when creating a view based on some row() construct in select query
#
CREATE TABLE t1(f1 INT);
INSERT INTO t1 VALUES ();
CREATE VIEW v1 AS SELECT 1 FROM t1 WHERE
ROW(1,1) >= ROW(1, (SELECT 1 FROM t1 WHERE f1 >= ANY ( SELECT '1' )));
DROP VIEW v1;
DROP TABLE t1;
2009-05-19 06:25:36 +02:00
2010-04-06 09:26:59 +02:00
--echo #
--echo # Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
--echo #
CREATE TABLE t1 (a CHAR(1) CHARSET latin1, b CHAR(1) CHARSET utf8);
CREATE VIEW v1 AS SELECT 1 from t1
WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
DROP VIEW v1;
DROP TABLE t1;
Fixed following problems:
--Bug#52157 various crashes and assertions with multi-table update, stored function
--Bug#54475 improper error handling causes cascading crashing failures in innodb/ndb
--Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
--Bug#57352 valgrind warnings when creating view
--Recently discovered problem when a nested materialized derived table is used
before being populated and it leads to incorrect result
We have several modes when we should disable subquery evaluation.
The reasons for disabling are different. It could be
uselessness of the evaluation as in case of 'CREATE VIEW'
or 'PREPARE stmt', or we should disable subquery evaluation
if tables are not locked yet as it happens in bug#54475, or
too early evaluation of subqueries can lead to wrong result
as it happened in Bug#19077.
Main problem is that if subquery items are treated as const
they are evaluated in ::fix_fields(), ::fix_length_and_dec()
of the parental items as a lot of these methods have
Item::val_...() calls inside.
We have to make subqueries non-const to prevent unnecessary
subquery evaluation. At the moment we have different methods
for this. Here is a list of these modes:
1. PREPARE stmt;
We use UNCACHEABLE_PREPARE flag.
It is set during parsing in sql_parse.cc, mysql_new_select() for
each SELECT_LEX object and cleared at the end of PREPARE in
sql_prepare.cc, init_stmt_after_parse(). If this flag is set
subquery becomes non-const and evaluation does not happen.
2. CREATE|ALTER VIEW, SHOW CREATE VIEW, I_S tables which
process FRM files
We use LEX::view_prepare_mode field. We set it before
view preparation and check this flag in
::fix_fields(), ::fix_length_and_dec().
Some bugs are fixed using this approach,
some are not(Bug#57352, Bug#57703). The problem here is
that we have a lot of ::fix_fields(), ::fix_length_and_dec()
where we use Item::val_...() calls for const items.
3. Derived tables with subquery = wrong result(Bug19077)
The reason of this bug is too early subquery evaluation.
It was fixed by adding Item::with_subselect field
The check of this field in appropriate places prevents
const item evaluation if the item have subquery.
The fix for Bug19077 fixes only the problem with
convert_constant_item() function and does not cover
other places(::fix_fields(), ::fix_length_and_dec() again)
where subqueries could be evaluated.
Example:
CREATE TABLE t1 (i INT, j BIGINT);
INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
SELECT * FROM (SELECT MIN(i) FROM t1
WHERE j = SUBSTRING('12', (SELECT * FROM (SELECT MIN(j) FROM t1) t2))) t3;
DROP TABLE t1;
4. Derived tables with subquery where subquery
is evaluated before table locking(Bug#54475, Bug#52157)
Suggested solution is following:
-Introduce new field LEX::context_analysis_only with the following
possible flags:
#define CONTEXT_ANALYSIS_ONLY_PREPARE 1
#define CONTEXT_ANALYSIS_ONLY_VIEW 2
#define CONTEXT_ANALYSIS_ONLY_DERIVED 4
-Set/clean these flags when we perform
context analysis operation
-Item_subselect::const_item() returns
result depending on LEX::context_analysis_only.
If context_analysis_only is set then we return
FALSE that means that subquery is non-const.
As all subquery types are wrapped by Item_subselect
it allow as to make subquery non-const when
it's necessary.
mysql-test/r/derived.result:
test case
mysql-test/r/multi_update.result:
test case
mysql-test/r/view.result:
test case
mysql-test/suite/innodb/r/innodb_multi_update.result:
test case
mysql-test/suite/innodb/t/innodb_multi_update.test:
test case
mysql-test/suite/innodb_plugin/r/innodb_multi_update.result:
test case
mysql-test/suite/innodb_plugin/t/innodb_multi_update.test:
test case
mysql-test/t/derived.test:
test case
mysql-test/t/multi_update.test:
test case
mysql-test/t/view.test:
test case
sql/item.cc:
--removed unnecessary code
sql/item_cmpfunc.cc:
--removed unnecessary checks
--THD::is_context_analysis_only() is replaced with LEX::is_ps_or_view_context_analysis()
sql/item_func.cc:
--refactored context analysis checks
sql/item_row.cc:
--removed unnecessary checks
sql/item_subselect.cc:
--removed unnecessary code
--added DBUG_ASSERT into Item_subselect::exec()
which asserts that subquery execution can not happen
if LEX::context_analysis_only is set, i.e. at context
analysis stage.
--Item_subselect::const_item()
Return FALSE if LEX::context_analysis_only is set.
It prevents subquery evaluation in ::fix_fields &
::fix_length_and_dec at context analysis stage.
sql/item_subselect.h:
--removed unnecessary code
sql/mysql_priv.h:
--Added new set of flags.
sql/sql_class.h:
--removed unnecessary code
sql/sql_derived.cc:
--added LEX::context_analysis_only analysis intialization/cleanup
sql/sql_lex.cc:
--init LEX::context_analysis_only field
sql/sql_lex.h:
--New LEX::context_analysis_only field
sql/sql_parse.cc:
--removed unnecessary code
sql/sql_prepare.cc:
--removed unnecessary code
--added LEX::context_analysis_only analysis intialization/cleanup
sql/sql_select.cc:
--refactored context analysis checks
sql/sql_show.cc:
--added LEX::context_analysis_only analysis intialization/cleanup
sql/sql_view.cc:
--added LEX::context_analysis_only analysis intialization/cleanup
2010-12-14 10:33:03 +01:00
--echo #
--echo # Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
--echo #
CREATE TABLE t1(a int);
CREATE VIEW v1 AS SELECT 1 FROM t1 GROUP BY
SUBSTRING(1 FROM (SELECT 3 FROM t1 WHERE a >= ANY(SELECT 1)));
DROP VIEW v1;
DROP TABLE t1;
--echo #
--echo # Bug#57352 valgrind warnings when creating view
--echo #
CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f;
DROP VIEW v1;
2011-04-08 10:05:20 +02:00
--echo #
--echo # Bug 11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
--echo #
CREATE TABLE t1 (a INT);
CREATE VIEW v1 AS SELECT s.* FROM t1 s, t1 b HAVING a;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
2011-07-21 10:20:55 +02:00
--echo #
--echo # LP BUG#777809 (a retrograded condition for view ON)
--echo #
CREATE TABLE t1 ( f1 int NOT NULL , f6 int NOT NULL ) ;
INSERT IGNORE INTO t1 VALUES (20, 2);
CREATE TABLE t2 ( f3 int NOT NULL ) ;
INSERT IGNORE INTO t2 VALUES (7);
CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
PREPARE prep_stmt FROM 'SELECT t1.f6 FROM t1 RIGHT JOIN v2 ON v2.f3 WHERE t1.f1 != 0';
EXECUTE prep_stmt;
EXECUTE prep_stmt;
drop view v2;
drop table t1,t2;
2008-02-12 20:09:16 +01:00
--echo # -----------------------------------------------------------------
--echo # -- End of 5.1 tests.
--echo # -----------------------------------------------------------------
2012-02-03 12:01:05 +01:00
--echo #
--echo # Bug #794005: crash in st_table::mark_virtual_columns_for_write
--echo #
CREATE TABLE t1 (a int);
insert into t1 values (1);
CREATE TABLE t2 (a int);
insert into t2 values (1);
CREATE VIEW v2 AS SELECT * FROM t2;
CREATE VIEW v1 AS SELECT * FROM v2;
CREATE VIEW v3 AS SELECT t2.a,v1.a as b FROM t2,v1 where t2.a=v1.a;
CREATE OR REPLACE ALGORITHM = TEMPTABLE VIEW v2 AS SELECT * FROM t1;
--error ER_NON_UPDATABLE_TABLE
UPDATE v1 SET a = 10;
--error ER_NON_INSERTABLE_TABLE
REPLACE v1 SET a = 10;
--error ER_NON_INSERTABLE_TABLE
INSERT into v1 values (20);
--error ER_NON_UPDATABLE_TABLE
DELETE from v1;
--error ER_NON_UPDATABLE_TABLE
UPDATE v3 SET b= 10;
--error ER_NON_INSERTABLE_TABLE
REPLACE v3 SET b= 10;
--error ER_NON_INSERTABLE_TABLE
INSERT into v3(b) values (20);
--error ER_VIEW_DELETE_MERGE_VIEW
DELETE from v3 where b=20;
--error ER_VIEW_DELETE_MERGE_VIEW
DELETE from v3 where a=20;
--error ER_NON_UPDATABLE_TABLE
DELETE v1 from v1,t1 where v1.a=t1.a;
UPDATE v3 SET a = 10;
REPLACE v3 SET a = 11;
INSERT INTO v3(a) values (20);
select * from t1;
select * from t2;
CREATE OR REPLACE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM t2;
DELETE from v1 where a=11;
DELETE v1 from v1,t1 where v1.a=t1.a;
select * from t1;
select * from t2;
DROP VIEW v1,v2,v3;
DROP TABLE t1,t2;
--echo # -----------------------------------------------------------------
--echo # -- End of 5.2 tests.
--echo # -----------------------------------------------------------------
2011-02-01 04:33:32 +01:00
--echo #
--echo # Bug #59696 Optimizer does not use equalities for conditions over view
--echo #
CREATE TABLE t1 (a int NOT NULL);
INSERT INTO t1 VALUES
(9), (2), (8), (1), (3), (4), (2), (5),
(9), (2), (8), (1), (3), (4), (2), (5);
CREATE TABLE t2 (pk int PRIMARY KEY, c int NOT NULL);
INSERT INTO t2 VALUES
(9,90), (16, 160), (11,110), (1,10), (18,180), (2,20),
(14,140), (15, 150), (12,120), (3,30), (17,170), (19,190);
EXPLAIN EXTENDED
SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8;
FLUSH STATUS;
SELECT t1.a,t2.c FROM t1,t2 WHERE t2.pk = t1.a AND t2.pk > 8;
SHOW STATUS LIKE 'Handler_read_%';
CREATE VIEW v AS SELECT * FROM t2;
EXPLAIN EXTENDED
SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
FLUSH STATUS;
SELECT t1.a,v.c FROM t1,v WHERE v.pk = t1.a AND v.pk > 8;
SHOW STATUS LIKE 'Handler_read_%';
DROP VIEW v;
DROP TABLE t1, t2;
2011-02-08 00:19:03 +01:00
2011-02-06 05:57:03 +01:00
--echo #
--echo # Bug#702403: crash with multiple equalities and a view
--echo #
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (10);
CREATE TABLE t2 (pk int PRIMARY KEY, b int, INDEX idx (b));
INSERT INTO t2 VALUES (1,2), (3,4);
CREATE TABLE t3 (pk int PRIMARY KEY, b int, INDEX idx (b));
INSERT INTO t3 VALUES (1,2), (3,4);
CREATE VIEW v1 AS SELECT * FROM t1;
EXPLAIN
SELECT * FROM v1, t2, t3
WHERE t3.pk = v1.a AND t2.b = 1 AND t2.b = t3.pk AND v1.a BETWEEN 2 AND 5;
SELECT * FROM v1, t2, t3
WHERE t3.pk = v1.a AND t2.b = 1 AND t2.b = t3.pk AND v1.a BETWEEN 2 AND 5;
DROP VIEW v1;
DROP TABLE t1, t2, t3;
2011-02-08 00:19:03 +01:00
2011-04-27 04:58:41 +02:00
--echo #
--echo # Bug#717577: substitution for best field in a query over a view and
--echo # with OR in the WHERE condition
--echo #
create table t1 (a int, b int);
insert into t1 values (2,4), (1,3);
create table t2 (c int);
insert into t2 values (6), (4), (1), (3), (8), (3), (4), (2);
select * from t1,t2 where t2.c=t1.a and t2.c < 3 or t2.c=t1.b and t2.c >=4;
explain extended
select * from t1,t2 where t2.c=t1.a and t2.c < 3 or t2.c=t1.b and t2.c >=4;
create view v1 as select * from t2;
select * from t1,v1 where v1.c=t1.a and v1.c < 3 or v1.c=t1.b and v1.c >=4;
explain extended
select * from t1,v1 where v1.c=t1.a and v1.c < 3 or v1.c=t1.b and v1.c >=4;
create view v2 as select * from v1;
select * from t1,v2 where v2.c=t1.a and v2.c < 3 or v2.c=t1.b and v2.c >=4;
explain extended
select * from t1,v2 where v2.c=t1.a and v2.c < 3 or v2.c=t1.b and v2.c >=4;
create view v3 as select * from t1;
select * from v3,v2 where v2.c=v3.a and v2.c < 3 or v2.c=v3.b and v2.c >=4;
explain extended
select * from v3,v2 where v2.c=v3.a and v2.c < 3 or v2.c=v3.b and v2.c >=4;
drop view v1,v2,v3;
drop table t1,t2;
--echo #
--echo # Bug#724942: substitution of the constant into a view field
--echo #
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (2), (9), (9), (6), (5), (4), (7);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM v1 WHERE a > -1 OR a > 6 AND a = 3;
EXPLAIN EXTENDED
SELECT * FROM v1 WHERE a > -1 OR a > 6 AND a = 3;
SELECT * FROM v1 WHERE a > -1 OR a AND a = 0;
EXPLAIN EXTENDED
SELECT * FROM v1 WHERE a > -1 OR a AND a = 0;
CREATE VIEW v2 AS SELECT * FROM v1;
SELECT * FROM v2 WHERE a > -1 OR a AND a = 0;
EXPLAIN EXTENDED
SELECT * FROM v2 WHERE a > -1 OR a AND a = 0;
DROP VIEW v1,v2;
DROP TABLE t1;
CREATE TABLE t1 (a varchar(10), KEY (a)) ;
INSERT INTO t1 VALUES
('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'),('MM');
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM v1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV';
EXPLAIN EXTENDED
SELECT * FROM v1 WHERE a > 'JJ' OR a <> 0 AND a = 'VV';
SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV';
EXPLAIN EXTENDED
SELECT * FROM v1 WHERE a > 'JJ' OR a AND a = 'VV';
DROP VIEW v1;
DROP TABLE t1;
2011-05-20 03:28:38 +02:00
--echo #
--echo # Bug#777745: crash with equality propagation
--echo # over view fields
--echo #
CREATE TABLE t1 (a int NOT NULL ) ;
INSERT INTO t1 VALUES (2), (1);
CREATE TABLE t2 (a int NOT NULL , b int NOT NULL) ;
INSERT INTO t2 VALUES (2,20),(2,30);
CREATE VIEW v2 AS SELECT * FROM t2;
EXPLAIN
SELECT * FROM t1,v2
WHERE v2.a = t1.a AND v2.a = 2 AND v2.a IS NULL AND t1.a != 0;
SELECT * FROM t1,v2
WHERE v2.a = t1.a AND v2.a = 2 AND v2.a IS NULL AND t1.a != 0;
EXPLAIN
SELECT * FROM t1,v2
WHERE v2.a = t1.a AND v2.a = 2 AND v2.a+1 > 2 AND t1.a != 0;
SELECT * FROM t1,v2
WHERE v2.a = t1.a AND v2.a = 2 AND v2.a+1 > 2 AND t1.a != 0;
DROP VIEW v2;
DROP TABLE t1,t2;
2011-06-09 09:13:00 +02:00
--echo #
--echo # Bug#794038: crash with INSERT/UPDATE/DELETE
--echo # over a non-updatable view
--echo #
CREATE TABLE t1 (a int);
CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT * FROM t1;
CREATE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM v1;
CREATE ALGORITHM = TEMPTABLE VIEW v3 AS SELECT * FROM v2;
-- error ER_NON_INSERTABLE_TABLE
INSERT INTO v3 VALUES (1);
-- error ER_NON_UPDATABLE_TABLE
UPDATE v3 SET a=0;
-- error ER_NON_UPDATABLE_TABLE
DELETE FROM v3;
DROP VIEW v1,v2,v3;
DROP TABLE t1;
2011-06-22 03:00:58 +02:00
--echo #
--echo # Bug#798621: crash with a view string field equal
--echo # to a constant
--echo #
CREATE TABLE t1 (a varchar(32), b int) ;
INSERT INTO t1 VALUES ('j', NULL), ('c', 8), ('c', 1);
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE TABLE t2 (a varchar(32)) ;
INSERT INTO t2 VALUES ('j'), ('c');
SELECT * FROM v1 LEFT JOIN t2 ON t2.a = v1.a
WHERE v1.b = 1 OR v1.a = 'a' AND LENGTH(v1.a) >= v1.b;
EXPLAIN EXTENDED
SELECT * FROM v1 LEFT JOIN t2 ON t2.a = v1.a
WHERE v1.b = 1 OR v1.a = 'a' AND LENGTH(v1.a) >= v1.b;
DROP VIEW v1;
DROP TABLE t1,t2;
2011-06-24 23:38:53 +02:00
2011-06-25 06:18:20 +02:00
--echo # Bug#798625: duplicate of the previous one, but without crash
CREATE TABLE t1 (f1 int NOT NULL, f2 int, f3 int, f4 varchar(32), f5 int) ;
INSERT INTO t1 VALUES (20,5,2,'r', 0);
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT v1.f4 FROM v1
WHERE f1<>0 OR f2<>0 AND f4='v' AND (f2<>0 OR f3<>0 AND f5<>0 OR f4 LIKE '%b%');
EXPLAIN EXTENDED
SELECT v1.f4 FROM v1
WHERE f1<>0 OR f2<>0 AND f4='v' AND (f2<>0 OR f3<>0 AND f5<>0 OR f4 LIKE '%b%');
DROP VIEW v1;
DROP TABLE t1;
2011-06-24 23:38:53 +02:00
--echo #
--echo # Bug#798576: abort on a GROUP BY query over a view with left join
--echo # that can be converted to inner join
--echo #
CREATE TABLE t1 (a int NOT NULL , b int NOT NULL) ;
INSERT INTO t1 VALUES (214,0), (6,6), (6,0), (7,0);
CREATE TABLE t2 (b int) ;
INSERT INTO t2 VALUES (88), (78), (6);
CREATE ALGORITHM=MERGE VIEW v1 AS
SELECT t1.a, t2.b FROM (t2 LEFT JOIN t1 ON t2.b > t1.a) WHERE t1.b <= 0;
SELECT * FROM v1;
SELECT a, MIN(b) FROM v1 GROUP BY a;
DROP VIEW v1;
DROP TABLE t1,t2;
2011-07-11 19:56:48 +02:00
--echo #
--echo # LP bug #793386: unexpected 'Duplicate column name ''' error
--echo # at the second execution of a PS using a view
--echo #
CREATE TABLE t1 (f1 int, f2 int, f3 int, f4 int);
CREATE VIEW v1 AS
SELECT t.f1, t.f2, s.f3, s.f4 FROM t1 t, t1 s
WHERE t.f4 >= s.f2 AND s.f3 < 0;
PREPARE stmt1 FROM
"SELECT s.f1 AS f1, s.f2 AS f2, s.f3 AS f3, t.f4 AS f4
FROM v1 AS t LEFT JOIN v1 AS s ON t.f4=s.f4 WHERE t.f2 <> 1225";
EXECUTE stmt1;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
2011-08-12 05:24:32 +02:00
DROP VIEW v1;
DROP TABLE t1;
2011-07-21 22:37:40 +02:00
--echo #
--echo # LP BUG#806071 (2 views with ORDER BY)
--echo #
CREATE TABLE t1 (f1 int);
INSERT INTO t1 VALUES (1),(1);
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT f1 FROM t1;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT f1 FROM v1 ORDER BY f1;
SELECT * FROM v2 AS a1, v2 AS a2;
EXPLAIN EXTENDED SELECT * FROM v2 AS a1, v2 AS a2;
2011-08-12 05:24:32 +02:00
DROP VIEW v1, v2;
DROP TABLE t1;
--echo #
--echo # LP bug #823189: dependent subquery with RIGHT JOIN
--echo # referencing view in WHERE
--echo #
CREATE TABLE t1 (a varchar(32));
INSERT INTO t1 VALUES ('y'), ('w');
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (10);
CREATE TABLE t3 (a varchar(32), b int);
CREATE TABLE t4 (a varchar(32));
INSERT INTO t4 VALUES ('y'), ('w');
CREATE VIEW v1 AS SELECT * FROM t1;
EXPLAIN EXTENDED
SELECT * FROM t1, t2
WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a)
WHERE t4.a >= t1.a);
SELECT * FROM t1, t2
WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a)
WHERE t4.a >= t1.a);
EXPLAIN EXTENDED
SELECT * FROM v1, t2
WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a)
WHERE t4.a >= v1.a);
SELECT * FROM v1, t2
WHERE t2.a NOT IN (SELECT t3.b FROM t3 RIGHT JOIN t4 ON (t4.a = t3.a)
WHERE t4.a >= v1.a);
DROP VIEW v1;
DROP TABLE t1,t2,t3,t4;
2011-09-08 21:24:47 +02:00
2012-10-02 04:04:17 +02:00
--echo #
--echo # LP bug #823237: dependent subquery with LEFT JOIN
--echo # referencing view in WHERE
--echo # (duplicate of LP bug #823189)
--echo #
CREATE TABLE t1 (a int);
CREATE TABLE t2 ( b int, d int, e int);
INSERT INTO t2 VALUES (7,8,0);
CREATE TABLE t3 ( c int);
INSERT INTO t3 VALUES (0);
CREATE TABLE t4 (a int, b int, c int);
INSERT INTO t4 VALUES (93,1,0), (95,NULL,0);
CREATE VIEW v4 AS SELECT * FROM t4;
EXPLAIN EXTENDED
SELECT * FROM t3 , t4
WHERE t4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d )
WHERE t2.b > t4.b);
SELECT * FROM t3 , t4
WHERE t4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d )
WHERE t2.b > t4.b);
EXPLAIN EXTENDED
SELECT * FROM t3, v4
WHERE v4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d )
WHERE t2.b > v4.b);
SELECT * FROM t3, v4
WHERE v4.c <= (SELECT t2.e FROM t2 LEFT JOIN t1 ON ( t1.a = t2.d )
WHERE t2.b > v4.b);
DROP VIEW v4;
DROP TABLE t1,t2,t3,t4;
2011-09-08 21:24:47 +02:00
--echo #
--echo # BUG#833600: Wrong result with view + outer join + uncorrelated subquery (non-semijoin)
--echo #
CREATE TABLE t1 ( a int, b int );
INSERT INTO t1 VALUES (0,0),(0,0);
CREATE TABLE t2 ( a int, b int );
INSERT IGNORE INTO t2 VALUES (1,0),(1,0);
CREATE TABLE t3 ( b int );
INSERT IGNORE INTO t3 VALUES (0),(0);
CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ;
SELECT * FROM t1 RIGHT JOIN v2 ON ( v2.a = t1.a ) WHERE v2.b IN ( SELECT b FROM t3 ) AND t1.b IS NULL ;
DROP VIEW v2;
DROP TABLE t1, t2, t3;
2011-12-15 09:21:15 +01:00
2012-04-07 00:08:09 +02:00
--echo #
--echo # BUG#915222: Valgrind complains or crashes with INSERT SELECT
--echo # within a trigger that uses a view
--echo #
CREATE TABLE t1 (a char(1));
CREATE TABLE t2 (d int, e char(1));
INSERT INTO t2 VALUES (13,'z');
CREATE TRIGGER tr AFTER UPDATE ON t2
FOR EACH ROW
REPLACE INTO t3
SELECT f, a AS alias FROM t3, v;
CREATE TABLE t3 (f int, g char(8));
CREATE VIEW v AS SELECT a, e FROM t2, t1;
UPDATE t2 SET d=7;
UPDATE t2 SET d=7;
UPDATE t2 SET d=7;
UPDATE t2 SET d=7;
DROP TRIGGER tr;
DROP VIEW v;
DROP TABLE t1,t2,t3;
2012-04-07 11:29:04 +02:00
--echo #
--echo # BUG#972943: Assertion failure with INSERT SELECT within a trigger
--echo # that uses derived table and materialized view
--echo #
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (1,0), (2,8);
CREATE ALGORITHM=TEMPTABLE VIEW v1
AS SELECT * FROM t1;
CREATE TABLE t2 (c int);
CREATE TABLE t3 (d int, e int);
CREATE TRIGGER tr BEFORE INSERT ON t2 FOR EACH ROW
INSERT INTO t3
SELECT t1.*
FROM (SELECT * FROM t1 WHERE b IN (SELECT b FROM v1)) AS alias1, t1
WHERE t1.a = 3 OR t1.a > 5;
INSERT INTO t2 VALUES (1);
DROP TRIGGER tr;
DROP VIEW v1;
DROP TABLE t1,t2,t3;
2012-06-26 20:43:34 +02:00
--echo #
--echo # LP bug#1007622 Server crashes in handler::increment_statistics on
--echo # inserting into a view over a view
--echo #
CREATE TABLE t1 (a INT);
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.* FROM t1 AS a1, t1 AS a2;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1;
INSERT INTO v2 (a) VALUES (1) ;
select * from t1;
drop view v2,v1;
drop table t1;
2012-09-05 22:23:58 +02:00
--echo #
--echo # MDEV-486 LP BUG#1010116 Incorrect query results in
--echo # view and derived tables
--echo #
SELECT
`Derived1`.`id`,
`Derived2`.`Val1`
FROM (select 30631 as `id`) AS `Derived1` LEFT OUTER JOIN (SELECT
2 as `id`,
1 AS `Val1`
FROM (select 30631 as `id`) AS `Derived3`) AS `Derived2` ON `Derived1`.`id` = `Derived2`.`id`;
create table t1 ( id int );
insert into t1 values (30631);
create table t2 ( id int );
insert into t2 values (30631);
create algorithm=MERGE view v2 as select 2 as id, 1 as val1 from t2;
select t1.*, v2.* from t1 left join v2 on t1.id = v2.id;
drop view v2;
drop table t1,t2;
create table t1 ( id int );
insert into t1 values (30631);
create table t2 ( id int );
insert into t2 values (30631);
create algorithm=MERGE view v2 as select 2 as id, id is null as bbb, id as iddqd, 1 as val1 from t2;
select t1.*, v2.* from t1 left join v2 on t1.id = v2.id;
drop view v2;
drop table t1,t2;
2012-10-05 11:26:55 +02:00
2012-12-05 20:06:00 +01:00
--echo #
--echo # MDEV-3914: Wrong result (NULLs instead of real values)
--echo # with INNER and RIGHT JOIN in a FROM subquery, derived_merge=on
--echo # (fix of above MDEV-486 fix)
--echo #
SET @save_optimizer_switch_MDEV_3914=@@optimizer_switch;
SET optimizer_switch = 'derived_merge=on';
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (3),(4);
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
INSERT INTO t3 VALUES (5),(6);
SELECT * FROM ( SELECT c FROM ( t1 INNER JOIN t2 ) RIGHT JOIN t3 ON a = c ) AS alias;
SET optimizer_switch = 'derived_merge=off';
SELECT * FROM ( SELECT c FROM ( t1 INNER JOIN t2 ) RIGHT JOIN t3 ON a = c ) AS alias;
SET optimizer_switch=@save_optimizer_switch_MDEV_3914;
drop table t1,t2,t3;
2012-10-05 11:26:55 +02:00
--echo #
--echo # MDEV-589 (LP BUG#1007647) :
--echo # Assertion `vcol_table == 0 || vcol_table == table' failed in
--echo # fill_record(THD*, List<Item>&, List<Item>&, bool)
--echo #
CREATE TABLE t1 (f1 INT, f2 INT);
CREATE TABLE t2 (f1 INT, f2 INT);
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT a1.f1, a2.f2 FROM t1 AS a1, t1 AS a2;
CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM v1;
CREATE ALGORITHM=MERGE VIEW v3 AS SELECT a1.f1, a2.f2 FROM t1 AS a1, t2 AS a2;
CREATE ALGORITHM=MERGE VIEW v4 AS SELECT * FROM v3;
--error ER_VIEW_MULTIUPDATE
INSERT INTO v3 (f1, f2) VALUES (1, 2);
--error ER_VIEW_MULTIUPDATE
INSERT INTO v1 (f1, f2) VALUES (1, 2);
--error ER_VIEW_MULTIUPDATE
INSERT INTO v4 (f1, f2) VALUES (1, 2);
--error ER_VIEW_MULTIUPDATE
INSERT INTO v2 (f1, f2) VALUES (1, 2);
drop view v4,v3,v2,v1;
drop table t1,t2;
2012-10-10 21:42:50 +02:00
--echo #
--echo # MDEV-3799 fix of above bugfix (MDEV-589)
--echo # Wrong result (NULLs instead of real values) with RIGHT JOIN
--echo # in a FROM subquery and derived_merge=on
--echo #
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (4),(6);
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
INSERT INTO t2 VALUES (7),(8);
SELECT * FROM (
SELECT * FROM t1 RIGHT JOIN t2 ON f1 = f2
) AS alias;
SELECT * FROM (
SELECT * FROM t2 LEFT JOIN t1 ON f1 = f2
) AS alias;
drop tables t1,t2;
2012-12-28 13:41:46 +01:00
--echo #
--echo # MDEV-3876 Wrong result (extra rows) with ALL subquery
--echo # from a MERGE view (duplicate of MDEV-3873)
--echo #
CREATE TABLE t1 (a INT NOT NULL) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT NOT NULL) ENGINE=MyISAM;
INSERT INTO t2 VALUES (1),(3);
CREATE OR REPLACE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2;
SELECT a FROM t1 AS alias
WHERE a >= ALL (
SELECT b FROM t1 LEFT JOIN v1 ON (a = b)
WHERE a = alias.a );
drop view v1;
drop table t1,t2;
2013-06-06 22:33:40 +02:00
--echo #
--echo # MDEV-4593: p_s: crash in simplify_joins with delete using subselect
--echo # from view
--echo #
create table `t1`(`a` int);
create table `t2`(`a` int);
create or replace view `v1` as select `a` from `t1`;
prepare s from "delete from `t2` order by (select 1 from `v1`)";
execute s;
deallocate prepare s;
drop view v1;
drop tables t1,t2;
2013-10-11 14:57:19 +02:00
--echo #
--echo # MDEV-5034 (duplicate of MDEV-5107):
--echo # Left Join Yields All Nulls Instead of Appropriate Matches
--echo #
--echo # test #1
CREATE TABLE t1 (state VARCHAR(32), INDEX(state));
INSERT INTO t1 VALUES ('Indiana'),('Vermont');
CREATE TABLE t2 (state VARCHAR(32));
INSERT INTO t2 VALUES ('Hawaii'),('Oregon'),('Vermont');
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT t1.* FROM t2, t1;
SELECT * FROM t1 AS outer_t1 LEFT JOIN v1 AS joined_t1
ON (joined_t1.state = outer_t1.state AND joined_t1.state IN ( SELECT 'Vermont' UNION SELECT 'Florida' ) );
SELECT * FROM t1 AS outer_t1 LEFT JOIN (SELECT t1.* FROM t2, t1) AS joined_t1 ON (joined_t1.state = outer_t1.state AND joined_t1.state IN ( SELECT 'Vermont' UNION SELECT 'Florida' ) );
drop view v1;
drop table t1, t2;
--echo # test #1
CREATE TABLE t1 (a INT, b VARCHAR(1), INDEX(b,a));
INSERT INTO t1 VALUES (4,'p'),(1,'q'),(9,'w');
CREATE TABLE t2 (c VARCHAR(1), INDEX(c));
INSERT INTO t2 VALUES ('q'),('a');
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT t1a.* FROM t1, t1 AS t1a;
SELECT * FROM t2 LEFT JOIN v1 ON ( c=b AND a IN ( 1,6 ) );
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT t1a.* FROM t1, t1 AS t1a;
SELECT * FROM t2 LEFT JOIN v1 ON ( c=b AND a IN ( 1,6 ) );
drop view v1;
drop table t1,t2;
2013-11-11 16:28:14 +01:00
--echo #
--echo # MDEV-5153: Server crashes in Item_ref::fix_fields on 2nd execution
--echo # of PS with LEFT JOIN and MERGE view or SELECT SQ
--echo #
CREATE TABLE t1 (i1 INT, c1 VARCHAR(6)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
CREATE TABLE t2 (c2 VARCHAR(6)) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('foobar'),('qux');
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1 WHERE ( c1 ) IN ( SELECT c2 FROM t2 ) AND i1 <= 2 ;
PREPARE stmt FROM 'SELECT * FROM t1 LEFT JOIN v1 ON (v1.i1 = t1.i1)';
EXECUTE stmt;
EXECUTE stmt;
drop view v1;
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1 WHERE ( c1, c1 ) IN ( SELECT c2, c2 FROM t2 ) AND i1 <= 2 ;
EXECUTE stmt;
EXECUTE stmt;
deallocate prepare stmt;
drop view v1;
drop table t1,t2;
2013-12-18 14:59:51 +01:00
#
# MDEV-5414: RAND() in a subselect : different behavior in MariaDB and MySQL
#
create table t1 (a int);
insert into t1 values (1),(2);
create view v1 (a,r) as select a,rand() from t1;
create table t2 select a, r as r1, r as r2, r as r3 from v1;
select a, r1 = r2, r2 = r3 from t2;
drop view v1;
drop table t1,t2;
2014-01-13 20:30:42 +01:00
--echo #
--echo # MDEV-5515: 2nd execution of a prepared statement returns wrong results
--echo #
CREATE TABLE t1 (i1 INT, j1 INT NOT NULL, PRIMARY KEY (i1));
INSERT INTO t1 VALUES (30,300),(40,400);
CREATE TABLE t2 (i2 INT);
INSERT INTO t2 VALUES (50),(60);
CREATE TABLE t3 (c3 VARCHAR(20), i3 INT);
INSERT INTO t3 VALUES ('a',10),('b',2);
CREATE TABLE t4 (i4 INT);
INSERT INTO t4 VALUES (1),(2);
DROP VIEW IF EXISTS v1;
CREATE VIEW v1 AS select coalesce(j1,i3) AS v1_field1 from t2 join t3 left join t1 on ( i1 = i2 );
CREATE VIEW v2 AS select v1_field1 from t4 join v1;
prepare my_stmt from "select v1_field1 from v2";
execute my_stmt;
execute my_stmt;
deallocate prepare my_stmt;
DROP VIEW v1,v2;
DROP TABLE t1,t2,t3,t4;
2014-03-12 11:34:16 +01:00
--echo #
--echo #MDEV-5717: Server crash with insert statement containing DEFAULT into
--echo #view
--echo #
CREATE TABLE t1 (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`test` tinyint(3) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
);
CREATE VIEW v1 AS (select t1.id AS id, t1.test AS test from t1);
INSERT INTO v1 SET test = DEFAULT;
select * from v1;
drop view v1;
drop table t1;
2014-05-01 16:19:17 +02:00
--echo #
--echo # MDEV-5981: name resolution issues with views and multi-update
--echo # in ps-protocol
--echo #
create table t1 (id1 int primary key, val1 varchar(20));
insert into t1 values (1, 'test1');
create table t2 (id2 int primary key, val2 varchar(20));
insert into t2 values (1, 'test2');
create algorithm=merge view v1 as select id1 as id1v1, val1 as val1v1 from t1;
create algorithm=merge view v2 as
select t2.id2 as id2v2, t2.val2 as val2v2
from t2, v1
where t2.id2 = v1.id1v1;
prepare stmt1 from "update v2 set val2v2 = 'test19' where 1 = id2v2";
execute stmt1;
deallocate prepare stmt1;
drop view v1,v2;
drop table t1,t2;
2012-02-03 12:01:05 +01:00
--echo # -----------------------------------------------------------------
--echo # -- End of 5.3 tests.
--echo # -----------------------------------------------------------------
2011-12-15 09:21:15 +01:00
SET optimizer_switch=@save_optimizer_switch;