Skip to content

Commit d0f5e56

Browse files
committed
MDEV-14785 SYSTEM_INVISIBLE behaviour not consistent
Hide INVISIBLE_SYSTEM columns from writes and from fix_vcol_expr().
1 parent 34ee747 commit d0f5e56

File tree

5 files changed

+159
-12
lines changed

5 files changed

+159
-12
lines changed

mysql-test/r/invisible_field_debug.result

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
set @old_debug= @@debug_dbug;
2+
create table t_tmp(a int, b int);
23
set debug_dbug= "+d,test_pseudo_invisible";
34
create table t1(a int);
45
set debug_dbug=@old_debug;
6+
insert into t1 values(1);
57
desc t1;
68
Field Type Null Key Default Extra
79
a int(11) YES NULL
@@ -10,14 +12,76 @@ Table Create Table
1012
t1 CREATE TABLE `t1` (
1113
`a` int(11) DEFAULT NULL
1214
) ENGINE=MyISAM DEFAULT CHARSET=latin1
13-
insert into t1 values(1);
15+
select a , invisible from t1;
16+
a invisible
17+
1 9
18+
insert into t1(a, invisible) values(99,99);
19+
ERROR 42S22: Unknown column 'invisible' in 'field list'
20+
insert into t1(invisible) values(99);
21+
ERROR 42S22: Unknown column 'invisible' in 'field list'
22+
insert into t_tmp select a, invisible from t1;
23+
insert into t1 select * from t_tmp;
24+
ERROR 21S01: Column count doesn't match value count at row 1
25+
insert into t1(a,invisible) select * from t_tmp;
26+
ERROR 42S22: Unknown column 'invisible' in 'field list'
27+
select a , invisible from t1;
28+
a invisible
29+
1 9
30+
insert into t1 values (5), (invisible+1);
31+
select a , invisible from t1;
32+
a invisible
33+
1 9
34+
5 9
35+
10 9
36+
delete from t1 where a > 1;
37+
update t1 set a = invisible where a=1;
38+
select a , invisible from t1;
39+
a invisible
40+
9 9
41+
update t1 set a = (select invisible+100 from t1 limit 1) where a=(select a from t1 limit 1);
42+
select a , invisible from t1;
43+
a invisible
44+
109 9
45+
update t1 set invisible = 23 where a=(select a from t1 limit 1);
46+
ERROR 42S22: Unknown column 'invisible' in 'field list'
47+
update t1 set invisible = 101 where a=(select a from t1 limit 1);
48+
ERROR 42S22: Unknown column 'invisible' in 'field list'
49+
update t1 set invisible = (select invisible+100 from t1 limit 1) where a=(select invisible from t1 limit 1);
50+
ERROR 42S22: Unknown column 'invisible' in 'field list'
51+
select a , invisible from t1;
52+
a invisible
53+
109 9
54+
set @a=12;
55+
update t1 set invisible = (select @a from dual) where a=(select a from t1 limit 1);
56+
ERROR 42S22: Unknown column 'invisible' in 'field list'
57+
select a , invisible from t1;
58+
a invisible
59+
109 9
60+
update t1 set invisible = (select invisible+100 from t1 limit 1) where a=(select a from t1 limit 1);
61+
ERROR 42S22: Unknown column 'invisible' in 'field list'
62+
select a , invisible from t1;
63+
a invisible
64+
109 9
65+
set @a=(select invisible from t1 limit 1);
66+
select @a from dual;
67+
@a
68+
9
69+
alter table t1 add constraint a check (invisible > 2);
70+
ERROR 42S22: Unknown column 'invisible' in 'CHECK'
71+
set debug_dbug= "+d,test_pseudo_invisible";
72+
create table t2(a int, b int as (invisible +2) virtual);
73+
ERROR 42S22: Unknown column 'invisible' in 'GENERATED ALWAYS AS'
74+
create table t2(a int , b int);
75+
insert into t2 values(2,2);
76+
insert into t2 select a, invisible from t1;
77+
set debug_dbug=@old_debug;
1478
select * from t1;
1579
a
16-
1
80+
109
1781
select invisible ,a from t1;
1882
invisible a
19-
9 1
20-
drop table t1;
83+
9 109
84+
drop table t1,t2,t_tmp;
2185
set debug_dbug= "+d,test_completely_invisible";
2286
create table t1(a int);
2387
set debug_dbug=@old_debug;
@@ -107,9 +171,18 @@ a invisible2
107171
select invisible ,a from t1;
108172
invisible a
109173
9 1
174+
create trigger trg before insert on t1 for each row set new.invisible=1;
175+
ERROR 42S22: Unknown column 'invisible' in 'NEW'
176+
create trigger trg before insert on t1 for each row set @a:=new.invisible;
110177
drop table t1;
111178
set debug_dbug= "+d,test_completely_invisible";
112179
create table t1(a int);
180+
set debug_dbug=@old_debug;
181+
create trigger trg before insert on t1 for each row set new.invisible=1;
182+
ERROR 42S22: Unknown column 'invisible' in 'NEW'
183+
create trigger trg before insert on t1 for each row set @a:=new.invisible;
184+
ERROR 42S22: Unknown column 'invisible' in 'NEW'
185+
set debug_dbug= "+d,test_completely_invisible";
113186
desc t1;
114187
Field Type Null Key Default Extra
115188
a int(11) YES NULL
@@ -152,7 +225,6 @@ select invisible1, invisible ,a from t1;
152225
invisible1 invisible a
153226
9 NULL 1
154227
ALTER table t1 add hid int default 2;
155-
set debug_dbug= "+d,test_completely_invisible";
156228
select * from t1;
157229
a invisible hid
158230
1 NULL 2

mysql-test/suite/versioning/r/insert.result

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_ti
298298
x y current
299299
2 2 1
300300
1 1 0
301-
create or replace table t1 (x int) with system versioning engine innodb;
301+
create or replace table t1 (
302+
x int,
303+
row_start timestamp(6) as row start invisible,
304+
row_end timestamp(6) as row end invisible,
305+
period for system_time (row_start, row_end)
306+
) with system versioning;
302307
insert into t1 values (1), (2);
303308
insert into t1 (row_start) select row_end from t1;
304309
ERROR HY000: The value specified for generated column 'row_start' in table 't1' ignored

mysql-test/suite/versioning/t/insert.test

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ insert into t1 values (1, null);
202202
update t1 set x= x + 1;
203203
select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;
204204

205-
create or replace table t1 (x int) with system versioning engine innodb;
205+
create or replace table t1 (
206+
x int,
207+
row_start timestamp(6) as row start invisible,
208+
row_end timestamp(6) as row end invisible,
209+
period for system_time (row_start, row_end)
210+
) with system versioning;
206211
insert into t1 values (1), (2);
207212
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
208213
insert into t1 (row_start) select row_end from t1;

mysql-test/t/invisible_field_debug.test

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,67 @@
11
--source include/have_debug.inc
22
##TEST for invisible coloumn level 2
33
set @old_debug= @@debug_dbug;
4+
create table t_tmp(a int, b int);
45
set debug_dbug= "+d,test_pseudo_invisible";
56
create table t1(a int);
67
set debug_dbug=@old_debug;
7-
8+
insert into t1 values(1);
89
desc t1;
910
show create table t1;
10-
insert into t1 values(1);
11+
select a , invisible from t1;
12+
##field should not be resolved in fill_record
13+
--error ER_BAD_FIELD_ERROR
14+
insert into t1(a, invisible) values(99,99);
15+
--error ER_BAD_FIELD_ERROR
16+
insert into t1(invisible) values(99);
17+
insert into t_tmp select a, invisible from t1;
18+
--error ER_WRONG_VALUE_COUNT_ON_ROW
19+
insert into t1 select * from t_tmp;
20+
--error ER_BAD_FIELD_ERROR
21+
insert into t1(a,invisible) select * from t_tmp;
22+
23+
select a , invisible from t1;
24+
insert into t1 values (5), (invisible+1);
25+
select a , invisible from t1;
26+
delete from t1 where a > 1;
27+
28+
##Update
29+
update t1 set a = invisible where a=1;
30+
select a , invisible from t1;
31+
update t1 set a = (select invisible+100 from t1 limit 1) where a=(select a from t1 limit 1);
32+
select a , invisible from t1;
33+
34+
--error ER_BAD_FIELD_ERROR
35+
update t1 set invisible = 23 where a=(select a from t1 limit 1);
36+
--error ER_BAD_FIELD_ERROR
37+
update t1 set invisible = 101 where a=(select a from t1 limit 1);
38+
--error ER_BAD_FIELD_ERROR
39+
update t1 set invisible = (select invisible+100 from t1 limit 1) where a=(select invisible from t1 limit 1);
40+
select a , invisible from t1;
41+
##if changed then error
42+
set @a=12;
43+
--error ER_BAD_FIELD_ERROR
44+
update t1 set invisible = (select @a from dual) where a=(select a from t1 limit 1);
45+
select a , invisible from t1;
46+
--error ER_BAD_FIELD_ERROR
47+
update t1 set invisible = (select invisible+100 from t1 limit 1) where a=(select a from t1 limit 1);
48+
select a , invisible from t1;
49+
50+
##set
51+
set @a=(select invisible from t1 limit 1);
52+
select @a from dual;
53+
--error ER_BAD_FIELD_ERROR
54+
alter table t1 add constraint a check (invisible > 2);
55+
set debug_dbug= "+d,test_pseudo_invisible";
56+
--error ER_BAD_FIELD_ERROR
57+
create table t2(a int, b int as (invisible +2) virtual);
58+
create table t2(a int , b int);
59+
insert into t2 values(2,2);
60+
insert into t2 select a, invisible from t1;
61+
set debug_dbug=@old_debug;
1162
select * from t1;
1263
select invisible ,a from t1;
13-
drop table t1;
64+
drop table t1,t2,t_tmp;
1465

1566
##TEST for invisible coloumn level 3
1667

@@ -79,13 +130,24 @@ ALTER table t1 add invisible2 int default 2;
79130
select * from t1;
80131
select invisible ,a from t1;
81132

133+
--error ER_BAD_FIELD_ERROR
134+
create trigger trg before insert on t1 for each row set new.invisible=1;
135+
create trigger trg before insert on t1 for each row set @a:=new.invisible;
136+
82137
drop table t1;
83138

84139
##TEST for Alter table for invisibleness level 3
85140

86141
set debug_dbug= "+d,test_completely_invisible";
87142
create table t1(a int);
88143

144+
set debug_dbug=@old_debug;
145+
--error ER_BAD_FIELD_ERROR
146+
create trigger trg before insert on t1 for each row set new.invisible=1;
147+
--error ER_BAD_FIELD_ERROR
148+
create trigger trg before insert on t1 for each row set @a:=new.invisible;
149+
set debug_dbug= "+d,test_completely_invisible";
150+
89151
desc t1;
90152
insert into t1 values(1);
91153
select * from t1;
@@ -112,9 +174,7 @@ ALTER table t1 add invisible int;
112174
select * from t1;
113175
select invisible1, invisible ,a from t1;
114176

115-
#set debug_dbug=@old_debug;
116177
ALTER table t1 add hid int default 2;
117-
set debug_dbug= "+d,test_completely_invisible";
118178
select * from t1;
119179
select invisible ,a from t1;
120180

sql/sql_base.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5648,6 +5648,11 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length,
56485648
if (field->invisible == INVISIBLE_FULL &&
56495649
DBUG_EVALUATE_IF("test_completely_invisible", 0, 1))
56505650
DBUG_RETURN((Field*)0);
5651+
5652+
if (field->invisible == INVISIBLE_SYSTEM &&
5653+
thd->column_usage != MARK_COLUMNS_READ &&
5654+
thd->column_usage != COLUMNS_READ)
5655+
DBUG_RETURN((Field*)0);
56515656
}
56525657
else
56535658
{

0 commit comments

Comments
 (0)