2023-11-20 08:32:44 +00:00

504 lines
20 KiB
Plaintext

drop database if exists view;
create database view;
use view;
set character_set_client = 45;
drop table if exists t1;
drop view if exists v, vv;
create table t1(c1 int, c2 int);
create view v as select c1, c2 from t1;
create view vv as select c1 from v;
select c1, c2 from v;
c1 c2
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1, c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table t1;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1, c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
create table t1(c1 int);
select c1 from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2 from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1, c2 from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select 1 as a from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v, vv;
create table t1(c1 int, c2 int);
create view v as select c1, c2 from t1;
create view vv as select c2 from v;
select c1, c2 from v;
c1 c2
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1, c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table t1;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1, c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
create table t1(c1 int);
select c1 from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2 from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1, c2 from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2, c1 from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select 1 as a from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1,t2;
drop view if exists v,vv;
create table t1(c1 int ,c2 int);
create table t2(c1 int ,c2 int);
create view v as select c1, c2 from t1;
create view vv as select c1 from v;
alter table t1 drop column c2;
select * from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select v.* from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select * from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select vv.* from vv;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1,t2;
drop view if exists v;
create table t1(c1 int,c2 int);
create table t2(c1 int,c2 int);
create view v as select c1, c2 from t1;
alter table t1 drop column c2;
select v.c1 from v join t2 on v.c1 = t2.c1;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select v.c1 from v join t2 on v.c2 = t2.c2;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select v.c1 from v join t2 using(c1);
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select v.c1 from v join t2 using(c2);
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1,t2;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select c1, c2 from t1;
select c1 from v where c2 = 1;
c1
select c1 from v where (select c2) = 1;
c1
alter table t1 drop column c2;
select c1 from v where c2 = 1;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1 from v where (select c2) = 1;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1,t2;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select c1, c2 from t1;
select c1 from v order by c2;
c1
select c1 from v order by (select c2);
c1
alter table t1 drop column c2;
select c1 from v order by c2;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1 from v order by (select c2);
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1,t2;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select c1, c2 from t1;
select c1 from v group by c2;
c1
select c1 from v group by (select c2);
c1
alter table t1 drop column c2;
select c1 from v group by c2;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c1 from v group by (select c2);
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
insert into t1 values(1,2),(2,3),(3,4);
create view v as select c1,c2 from t1 order by c2;
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
insert into t1 values(1,2),(2,3),(3,4);
create view v as select c1, -1 as c2 from t1 order by (select c2);
select c1 from v;
c1
1
2
3
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select c1,c2 from t1 where c2=1;
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
insert into t1 values(1,2),(2,3),(3,4);
create view v as select c1, -1 as c2 from t1 order by (select c2);
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select c1,sum(c2) from t1;
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
insert into t1 values(1,2),(2,3),(3,4),(4,5);
create view v as select c1,c2 from t1;
select * from v;
c1 c2
1 2
2 3
3 4
4 5
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select c2 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select * from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
alter table t1 add column c2 int default 100;
select * from v;
c1 c2
1 100
2 100
3 100
4 100
alter table t1 alter column c2 set default 200;
insert into t1(c1) values(5);
select * from v;
c1 c2
1 100
2 100
3 100
4 100
5 200
drop table if exists t1;
drop view if exists v;
create table t1(c1 int);
create view v as select c1 from t1;
desc v;
Field Type Null Key Default Extra
c1 int(11) YES NULL
drop table if exists t1,t2;
drop view if exists v;
create table t1(c1 int);
create table t2(c1 int);
create view v as (select c1 from t1) union (select c1 from t2);
desc v;
Field Type Null Key Default Extra
c1 int(11) YES NULL
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select c1,c2 from t1;
desc v;
Field Type Null Key Default Extra
c1 int(11) YES NULL
c2 int(11) YES NULL
alter table t1 drop column c2;
desc v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v,vv;
create table t1(c1 int,c2 int);
create view v as select c1,c2 from t1;
create view vv as select c1,c2 from v;
alter table t1 drop column c2;
desc v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
desc vv;
ERROR 42S22: View 'view.vv' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v,vv;
create table t1(c1 int,c2 int);
create view v as select c1,c2 from t1;
create view vv as select c1,c2 from v;
create or replace view v as select c1 from t1;
desc v;
Field Type Null Key Default Extra
c1 int(11) YES NULL
desc vv;
ERROR 42S22: View 'view.vv' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
create or replace view vv as select c1 from v;
desc vv;
Field Type Null Key Default Extra
c1 int(11) NO
drop table if exists t1,t2,t3,t4;
drop view if exists v,vv;
create table t1(c1 int,c2 int);
create table t2(c1 int,c2 int);
create table t3(c1 int,c2 int);
create table t4(c1 int,c2 int);
create view v as ((select * from t1) union (select c1,c2 from t2)) union (select * from t3);
desc v;
Field Type Null Key Default Extra
c1 int(11) YES NULL
c2 int(11) YES NULL
create view vv as (select * from v) union (select * from t4);
desc vv;
Field Type Null Key Default Extra
c1 int(11) NO
c2 int(11) NO
drop table if exists t1,t2;
drop view if exists v;
create table t1(c1 int,c2 int);
create table t2(c1 int,c2 int);
create view v as select c1,c2 from t1;
select (select c2 from v limit 1) from t2;
(select c2 from v limit 1)
alter table t1 drop column c2;
select (select c2 from v limit 1) from t2;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select (select c3 from v limit 1) from t2;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
alter table t2 add column c3 int;
select (select c3 from v limit 1) from t2;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists t1;
drop table if exists v1,v2,v3;
drop view if exists v1,v2,v3;
create table t1(c1 int);
create view v1 as select * from t1;
create view v2 as select * from v1;
create view v3 as select * from v2;
drop table t1;
rename table v3 to t1;
select * from v1;
ERROR 42S02: 'view.v1' contains view recursion
select * from v2;
ERROR 42S02: 'view.v2' contains view recursion
select * from v3;
ERROR 42S02: Table 'view.v3' doesn't exist
drop table if exists t1,t2;
drop view if exists t1,t2;
drop table if exists v1,v2,v3;
drop view if exists v1,v2,v3;
create table t1(c1 int);
create table t2(c1 int);
create view v1 as select * from t1;
create view v2 as select * from t2;
create view v3 as select v1.c1 as v1c1, v2.c1 as v2c1 from v1,v2;
drop table t2;
rename table v3 to t2;
select * from t2;
ERROR 42S02: 'view.t2' contains view recursion
select * from v2;
ERROR 42S02: 'view.v2' contains view recursion
drop table if exists t1,t2;
drop view if exists t1,t2;
drop table if exists v1,v2;
drop view if exists v1,v2;
create table t1(c1 int);
create table t2(c1 int);
create view v1 as select * from t1;
create view v2 as select (select c1 from v1 limit 1) from t2;
drop table t1;
rename table v2 to t1;
select * from t1;
ERROR 42S02: 'view.t1' contains view recursion
select * from v1;
ERROR 42S02: 'view.v1' contains view recursion
drop table if exists t1;
drop view if exists t1;
drop table if exists v1,v2,v3,v4;
drop view if exists v1,v2,v3,v4;
create table t1(c1 int);
create view v1 as select * from t1;
create view v2 as select * from v1;
create view v3 as select * from v2;
create view v4 as select * from v2;
drop view v1;
rename table v4 to v1;
select * from v1;
ERROR 42S02: 'view.v1' contains view recursion
select * from v2;
ERROR 42S02: 'view.v2' contains view recursion
select * from v3;
ERROR 42S02: 'view.v2' contains view recursion
SET optimizer_switch = (SELECT variable_value FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'optimizer_switch');
ERROR 0A000: subqueries or stored function calls here not supported
drop table if exists t1,t2;
drop view if exists v1;
create table t1(c1 int,c2 int);
create table t2(c1 int,c2 int);
insert into t1(c1,c2) values(1,2),(2,3);
create view v1 as select * from t1;
insert into t2(c1,c2) select * from v1;
select * from t2;
c1 c2
1 2
2 3
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select * from t1;
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
show warnings;
Level Code Message
Error 1356 View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
create view v as select * from t1;
alter table t1 drop column c2;
select c1 from v;
ERROR 42S22: View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
show warnings;
Level Code Message
Error 1356 View 'view.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop table if exists t1;
drop view if exists v;
create table t1(c1 int,c2 int);
insert into t1 values(1, 1);
create view v as select * from t1 where not exists(select * from t1 where c1>0);
show create view v;
View Create View character_set_client collation_connection
v CREATE VIEW `v` AS select `view`.`t1`.`c1` AS `c1`,`view`.`t1`.`c2` AS `c2` from `view`.`t1` where not exists((select `t1`.`c1`,`t1`.`c2` from `view`.`t1` `t1` where (`t1`.`c1` > 0))) utf8mb4 utf8mb4_general_ci
select * from v;
c1 c2
create view xy as select 123 from dual where not exists (select 1 from dual) limit 1;
select * from xy;
123
drop table if exists t1;
drop table if exists t2;
drop view if exists v;
create table t1 (k int primary key, v1 int, v2 int);
create table t2 (k int primary key, v1 char(1), v2 varchar(10));
create view v as select k, v1, v2 from t1 union select k, v1, v2 from t2;
show create view v;
View Create View character_set_client collation_connection
v CREATE VIEW `v` AS (select `view`.`t1`.`k` AS `k`,`view`.`t1`.`v1` AS `v1`,`view`.`t1`.`v2` AS `v2` from `view`.`t1`) union (select `view`.`t2`.`k` AS `k`,`view`.`t2`.`v1` AS `v1`,`view`.`t2`.`v2` AS `v2` from `view`.`t2`) utf8mb4 utf8mb4_general_ci
select * from v;
k v1 v2
drop table if exists t1;
drop view if exists v;
create table t1 (k int, v int);
create view v as (select k, v from t1) union (select 1, 1 from t1);
show create view v;
View Create View character_set_client collation_connection
v CREATE VIEW `v` AS (select `view`.`t1`.`k` AS `k`,`view`.`t1`.`v` AS `v` from `view`.`t1`) union (select 1 AS `1`,1 AS `1` from `view`.`t1` `t1`) utf8mb4 utf8mb4_general_ci
drop table if exists t1;
drop table if exists t2;
CREATE TABLE `t11` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, PRIMARY KEY (`a`) );
CREATE TABLE `t21` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, PRIMARY KEY (`a`) );
explain extended_noaddr select t3.* from (select t11.a as X, t21.a as Y from t11 left join t21 on t11.a = t21.a) as t3 where t3.y is not null and t3.x > 10;
Query Plan
==================================================
|ID|OPERATOR |NAME|EST.ROWS|EST.TIME(us)|
--------------------------------------------------
|0 |MERGE JOIN | |1 |5 |
|1 |├─TABLE RANGE SCAN|t11 |1 |3 |
|2 |└─TABLE RANGE SCAN|t21 |1 |3 |
==================================================
Outputs & filters:
-------------------------------------
0 - output([t11.a], [t21.a]), filter(nil), rowset=16
equal_conds([t11.a = t21.a]), other_conds(nil)
merge_directions([ASC])
1 - output([t11.a]), filter(nil), rowset=16
access([t11.a]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([t11.a]), range(10 ; MAX),
range_cond([t11.a > 10])
2 - output([t21.a]), filter(nil), rowset=16
access([t21.a]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([t21.a]), range(10 ; MAX),
range_cond([t21.a > 10])
Used Hint:
-------------------------------------
/*+
*/
Qb name trace:
-------------------------------------
stmt_id:0, stmt_type:T_EXPLAIN
stmt_id:1, SEL$1 > SEL$CFEA49FE > SEL$A7A036C9 > SEL$AC33F27C > SEL$21AFC505
stmt_id:2, SEL$2
Outline Data:
-------------------------------------
/*+
BEGIN_OUTLINE_DATA
LEADING(@"SEL$21AFC505" ("view"."t11"@"SEL$2" "view"."t21"@"SEL$2"))
USE_MERGE(@"SEL$21AFC505" "view"."t21"@"SEL$2")
FULL(@"SEL$21AFC505" "view"."t11"@"SEL$2")
FULL(@"SEL$21AFC505" "view"."t21"@"SEL$2")
MERGE(@"SEL$2" > "SEL$1")
OUTER_TO_INNER(@"SEL$CFEA49FE")
PRED_DEDUCE(@"SEL$A7A036C9")
SIMPLIFY_EXPR(@"SEL$AC33F27C")
OPTIMIZER_FEATURES_ENABLE('4.0.0.0')
END_OUTLINE_DATA
*/
Optimization Info:
-------------------------------------
t11:
table_rows:1
physical_range_rows:1
logical_range_rows:1
index_back_rows:0
output_rows:1
table_dop:1
dop_method:Table DOP
avaiable_index_name:[t11]
stats version:0
dynamic sampling level:1
t21:
table_rows:1
physical_range_rows:1
logical_range_rows:1
index_back_rows:0
output_rows:1
table_dop:1
dop_method:Table DOP
avaiable_index_name:[t21]
stats version:0
dynamic sampling level:1
Plan Type:
LOCAL
Note:
Degree of Parallelisim is 1 because of table property
Expr Constraints:
1 result is TRUE
drop database if exists view;