| 1 |
SET @@session.default_storage_engine = 'InnoDB'; |
| 2 |
SET @save_innodb_stats_persistent=@@GLOBAL.innodb_stats_persistent; |
| 3 |
SET GLOBAL innodb_stats_persistent=0; |
| 4 |
create table t1 (a int not null, |
| 5 |
b int as (-a), |
| 6 |
c int as (-a) persistent); |
| 7 |
insert into t1 (a) values (1), (1), (2), (2), (3); |
| 8 |
create view v1 (d,e) as select abs(b), abs(c) from t1; |
| 9 |
select d,e from v1; |
| 10 |
d e |
| 11 |
1 1 |
| 12 |
1 1 |
| 13 |
2 2 |
| 14 |
2 2 |
| 15 |
3 3 |
| 16 |
select is_updatable from information_schema.views where table_name='v1'; |
| 17 |
is_updatable |
| 18 |
NO |
| 19 |
explain extended select d,e from v1; |
| 20 |
id select_type table type possible_keys key key_len ref rows filtered Extra |
| 21 |
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 |
| 22 |
Warnings: |
| 23 |
Note 1003 select abs(`test`.`t1`.`b`) AS `d`,abs(`test`.`t1`.`c`) AS `e` from `test`.`t1` |
| 24 |
create algorithm=temptable view v2 (d,e) as select abs(b), abs(c) from t1; |
| 25 |
show create view v2; |
| 26 |
View Create View character_set_client collation_connection |
| 27 |
v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select abs(`t1`.`b`) AS `d`,abs(`t1`.`c`) AS `e` from `t1` latin1 latin1_swedish_ci |
| 28 |
select d,e from v2; |
| 29 |
d e |
| 30 |
1 1 |
| 31 |
1 1 |
| 32 |
2 2 |
| 33 |
2 2 |
| 34 |
3 3 |
| 35 |
explain extended select d,e from v2; |
| 36 |
id select_type table type possible_keys key key_len ref rows filtered Extra |
| 37 |
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5 100.00 |
| 38 |
2 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 |
| 39 |
Warnings: |
| 40 |
Note 1003 /* select#1 */ select `v2`.`d` AS `d`,`v2`.`e` AS `e` from `test`.`v2` |
| 41 |
create view v3 (d,e) as select d*2, e*2 from v1; |
| 42 |
select * from v3; |
| 43 |
d e |
| 44 |
2 2 |
| 45 |
2 2 |
| 46 |
4 4 |
| 47 |
4 4 |
| 48 |
6 6 |
| 49 |
explain extended select * from v3; |
| 50 |
id select_type table type possible_keys key key_len ref rows filtered Extra |
| 51 |
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 |
| 52 |
Warnings: |
| 53 |
Note 1003 select abs(`test`.`t1`.`b`) * 2 AS `d`,abs(`test`.`t1`.`c`) * 2 AS `e` from `test`.`t1` |
| 54 |
drop view v1,v2,v3; |
| 55 |
drop table t1; |
| 56 |
create table t1 (a int not null, |
| 57 |
b int as (-a), |
| 58 |
c int as (-a) persistent); |
| 59 |
insert into t1 (a) values (1), (2), (3), (1), (2), (3); |
| 60 |
create view v1 as select distinct b from t1; |
| 61 |
select * from v1; |
| 62 |
b |
| 63 |
-1 |
| 64 |
-2 |
| 65 |
-3 |
| 66 |
explain select * from v1; |
| 67 |
id select_type table type possible_keys key key_len ref rows Extra |
| 68 |
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 6 |
| 69 |
2 DERIVED t1 ALL NULL NULL NULL NULL 6 Using temporary |
| 70 |
select * from t1; |
| 71 |
a b c |
| 72 |
1 -1 -1 |
| 73 |
2 -2 -2 |
| 74 |
3 -3 -3 |
| 75 |
1 -1 -1 |
| 76 |
2 -2 -2 |
| 77 |
3 -3 -3 |
| 78 |
drop view v1; |
| 79 |
create view v1 as select distinct c from t1; |
| 80 |
select * from v1; |
| 81 |
c |
| 82 |
-1 |
| 83 |
-2 |
| 84 |
-3 |
| 85 |
explain select * from v1; |
| 86 |
id select_type table type possible_keys key key_len ref rows Extra |
| 87 |
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 6 |
| 88 |
2 DERIVED t1 ALL NULL NULL NULL NULL 6 Using temporary |
| 89 |
select * from t1; |
| 90 |
a b c |
| 91 |
1 -1 -1 |
| 92 |
2 -2 -2 |
| 93 |
3 -3 -3 |
| 94 |
1 -1 -1 |
| 95 |
2 -2 -2 |
| 96 |
3 -3 -3 |
| 97 |
drop view v1; |
| 98 |
drop table t1; |
| 99 |
create table t1 (a int not null, |
| 100 |
b int as (-a), |
| 101 |
c int as (-a) persistent); |
| 102 |
insert into t1 (a) values (1), (2), (3), (4); |
| 103 |
create view v1 as select b+1 from t1 order by 1 desc limit 2; |
| 104 |
select * from v1; |
| 105 |
b+1 |
| 106 |
0 |
| 107 |
-1 |
| 108 |
MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1. |
| 109 |
MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed |
| 110 |
explain select * from v1; |
| 111 |
id select_type table type possible_keys key key_len ref rows Extra |
| 112 |
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 |
| 113 |
2 DERIVED t1 ALL NULL NULL NULL NULL 4 Using filesort |
| 114 |
drop view v1; |
| 115 |
create view v1 as select c+1 from t1 order by 1 desc limit 2; |
| 116 |
select * from v1; |
| 117 |
c+1 |
| 118 |
0 |
| 119 |
-1 |
| 120 |
MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1. |
| 121 |
MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed |
| 122 |
explain select * from v1; |
| 123 |
id select_type table type possible_keys key key_len ref rows Extra |
| 124 |
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 |
| 125 |
2 DERIVED t1 ALL NULL NULL NULL NULL 4 Using filesort |
| 126 |
drop view v1; |
| 127 |
drop table t1; |
| 128 |
create table t1 (a int, |
| 129 |
b int, |
| 130 |
c int as (-a), |
| 131 |
d int as (-a) persistent, |
| 132 |
primary key(a)); |
| 133 |
insert into t1 (a,b) values (10,2), (20,3), (30,4), (40,5), (50,10); |
| 134 |
create view v1 (a,e,f,g) as select a, b+1,c+1,d+1 from t1; |
| 135 |
update v1 set a=a+e; |
| 136 |
select * from v1; |
| 137 |
a e f g |
| 138 |
13 3 -12 -12 |
| 139 |
24 4 -23 -23 |
| 140 |
35 5 -34 -34 |
| 141 |
46 6 -45 -45 |
| 142 |
61 11 -60 -60 |
| 143 |
select * from t1; |
| 144 |
a b c d |
| 145 |
13 2 -13 -13 |
| 146 |
24 3 -24 -24 |
| 147 |
35 4 -35 -35 |
| 148 |
46 5 -46 -46 |
| 149 |
61 10 -61 -61 |
| 150 |
delete from v1; |
| 151 |
select * from v1; |
| 152 |
a e f g |
| 153 |
select * from t1; |
| 154 |
a b c d |
| 155 |
insert into v1 (a,e) values (60,15); |
| 156 |
ERROR HY000: The target table v1 of the INSERT is not insertable-into |
| 157 |
drop table t1; |
| 158 |
drop view v1; |
| 159 |
SET @save_optimizer_switch=@@optimizer_switch; |
| 160 |
SET optimizer_switch='outer_join_with_cache=off'; |
| 161 |
create table t1 (a int, |
| 162 |
b int as (-a), |
| 163 |
c int as (-a) persistent, |
| 164 |
primary key(a)); |
| 165 |
insert into t1 (a) values (1), (2), (3); |
| 166 |
create view v1 (x,y,z) as select a,b,c from t1 where b < -1; |
| 167 |
select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.b= v1.y); |
| 168 |
a x y z |
| 169 |
1 NULL NULL NULL |
| 170 |
2 2 -2 -2 |
| 171 |
3 3 -3 -3 |
| 172 |
drop view v1; |
| 173 |
create view v1 (x,y,z) as select a,b,c from t1 where c < -1; |
| 174 |
select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.c= v1.z); |
| 175 |
a x y z |
| 176 |
1 NULL NULL NULL |
| 177 |
2 2 -2 -2 |
| 178 |
3 3 -3 -3 |
| 179 |
drop view v1; |
| 180 |
drop table t1; |
| 181 |
SET optimizer_switch=@save_optimizer_switch; |
| 182 |
create table t1 (a1 int, |
| 183 |
b1 int as (-a1), |
| 184 |
c1 int as (-a1) persistent); |
| 185 |
create table t2 (a2 int, |
| 186 |
b2 int as (-a2), |
| 187 |
c2 int as (-a2) persistent); |
| 188 |
insert into t1 (a1) values (1), (2); |
| 189 |
insert into t2 (a2) values (2), (3); |
| 190 |
create view v1 as select * from t1,t2 union all select * from t1,t2; |
| 191 |
select * from v1; |
| 192 |
a1 b1 c1 a2 b2 c2 |
| 193 |
1 -1 -1 2 -2 -2 |
| 194 |
2 -2 -2 2 -2 -2 |
| 195 |
1 -1 -1 3 -3 -3 |
| 196 |
2 -2 -2 3 -3 -3 |
| 197 |
1 -1 -1 2 -2 -2 |
| 198 |
2 -2 -2 2 -2 -2 |
| 199 |
1 -1 -1 3 -3 -3 |
| 200 |
2 -2 -2 3 -3 -3 |
| 201 |
drop view v1; |
| 202 |
drop table t1, t2; |
| 203 |
create table t1 (a int, |
| 204 |
b int as (-a), |
| 205 |
c int as (-a) persistent); |
| 206 |
create table t2 like t1; |
| 207 |
create view v1 as select a,b,c from t1; |
| 208 |
create view v2 as select a,b,c from t2 where b in (select b from v1); |
| 209 |
show create view v2; |
| 210 |
View Create View character_set_client collation_connection |
| 211 |
v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a`,`t2`.`b` AS `b`,`t2`.`c` AS `c` from `t2` where `t2`.`b` in (select `v1`.`b` from `v1`) latin1 latin1_swedish_ci |
| 212 |
drop view v2, v1; |
| 213 |
drop table t1, t2; |
| 214 |
create table t1 (a int, |
| 215 |
b int as (-a), |
| 216 |
c int as (-a) persistent); |
| 217 |
insert into t1 (a) values (1),(1),(2),(2),(3),(3); |
| 218 |
create view v1 as select b from t1; |
| 219 |
select distinct b from v1; |
| 220 |
b |
| 221 |
-1 |
| 222 |
-2 |
| 223 |
-3 |
| 224 |
select distinct b from v1 limit 2; |
| 225 |
b |
| 226 |
-1 |
| 227 |
-2 |
| 228 |
select distinct b from t1 limit 2; |
| 229 |
b |
| 230 |
-1 |
| 231 |
-2 |
| 232 |
prepare stmt1 from "select distinct b from v1 limit 2"; |
| 233 |
execute stmt1; |
| 234 |
b |
| 235 |
-1 |
| 236 |
-2 |
| 237 |
execute stmt1; |
| 238 |
b |
| 239 |
-1 |
| 240 |
-2 |
| 241 |
deallocate prepare stmt1; |
| 242 |
drop view v1; |
| 243 |
create view v1 as select c from t1; |
| 244 |
select distinct c from v1; |
| 245 |
c |
| 246 |
-1 |
| 247 |
-2 |
| 248 |
-3 |
| 249 |
select distinct c from v1 limit 2; |
| 250 |
c |
| 251 |
-1 |
| 252 |
-2 |
| 253 |
select distinct c from t1 limit 2; |
| 254 |
c |
| 255 |
-1 |
| 256 |
-2 |
| 257 |
prepare stmt1 from "select distinct c from v1 limit 2"; |
| 258 |
execute stmt1; |
| 259 |
c |
| 260 |
-1 |
| 261 |
-2 |
| 262 |
execute stmt1; |
| 263 |
c |
| 264 |
-1 |
| 265 |
-2 |
| 266 |
deallocate prepare stmt1; |
| 267 |
drop view v1; |
| 268 |
drop table t1; |
| 269 |
create table t1 (a int, |
| 270 |
b int as (-a), |
| 271 |
c int as (-a) persistent); |
| 272 |
create view v1 as select * from t1 where b > -2 && c >-2 with check option; |
| 273 |
insert into v1 (a) values (1); |
| 274 |
insert into v1 (a) values (3); |
| 275 |
ERROR 44000: CHECK OPTION failed `test`.`v1` |
| 276 |
insert ignore into v1 (a) values (2),(3),(0); |
| 277 |
Warnings: |
| 278 |
Warning 1369 CHECK OPTION failed `test`.`v1` |
| 279 |
Warning 1369 CHECK OPTION failed `test`.`v1` |
| 280 |
select * from t1; |
| 281 |
a b c |
| 282 |
1 -1 -1 |
| 283 |
0 0 0 |
| 284 |
drop view v1; |
| 285 |
drop table t1; |
| 286 |
SET GLOBAL innodb_stats_persistent=@save_innodb_stats_persistent; |