Commit 59ca71d4 authored by Sergei Golubchik's avatar Sergei Golubchik

INVISIBLE columns in USING and NATURAL JOIN

* don't disclose INVISIBLE_FULL columns in USING and NATURAL JOIN
* other INVISIBLE columns must me mentioned by name in USING,
  they are hidden from NATURAL JOIN
parent 7a42f28e
...@@ -540,3 +540,14 @@ select a,b from t2; ...@@ -540,3 +540,14 @@ select a,b from t2;
a b a b
12 1 12 1
drop table t1,t2; drop table t1,t2;
create table t1 (a int invisible, b int, c int);
create table t2 (a int, b int, d int);
insert t1 (a,b,c) values (0,2,3), (10, 20, 30);
insert t2 (a,b,d) values (1,2,4), (10, 30, 40);
select * from t1 join t2 using (a);
b c b d
20 30 30 40
select * from t1 natural join t2;
b c a d
2 3 1 4
drop table t1, t2;
...@@ -40,7 +40,21 @@ select invisible ,a from t1; ...@@ -40,7 +40,21 @@ select invisible ,a from t1;
invisible a invisible a
9 1 9 1
set debug_dbug=@old_debug; set debug_dbug=@old_debug;
drop table t1; create table t2 (invisible int);
select * from t1 join t2 using (invisible);
ERROR 42S22: Unknown column 'invisible' in 'from clause'
select * from t2 join t1 using (invisible);
ERROR 42S22: Unknown column 'invisible' in 'from clause'
insert t2 values (8),(9);
select * from t1 natural join t2;
a invisible
1 8
1 9
select * from t2 natural join t1;
invisible a
8 1
9 1
drop table t1, t2;
set debug_dbug= "+d,test_pseudo_invisible"; set debug_dbug= "+d,test_pseudo_invisible";
create table t1(a int); create table t1(a int);
set debug_dbug=@old_debug; set debug_dbug=@old_debug;
......
...@@ -226,4 +226,15 @@ insert into t1 values(1); ...@@ -226,4 +226,15 @@ insert into t1 values(1);
select a,b from t1; select a,b from t1;
insert into t2 values(1); insert into t2 values(1);
select a,b from t2; select a,b from t2;
drop table t1,t2; drop table t1,t2;
\ No newline at end of file
#
# natural join and using
#
create table t1 (a int invisible, b int, c int);
create table t2 (a int, b int, d int);
insert t1 (a,b,c) values (0,2,3), (10, 20, 30);
insert t2 (a,b,d) values (1,2,4), (10, 30, 40);
select * from t1 join t2 using (a);
select * from t1 natural join t2;
drop table t1, t2;
...@@ -30,7 +30,17 @@ set debug_dbug= "+d,test_completely_invisible"; ...@@ -30,7 +30,17 @@ set debug_dbug= "+d,test_completely_invisible";
select invisible ,a from t1; select invisible ,a from t1;
set debug_dbug=@old_debug; set debug_dbug=@old_debug;
drop table t1; create table t2 (invisible int);
--error ER_BAD_FIELD_ERROR
select * from t1 join t2 using (invisible);
--error ER_BAD_FIELD_ERROR
select * from t2 join t1 using (invisible);
insert t2 values (8),(9);
select * from t1 natural join t2;
select * from t2 natural join t1;
drop table t1, t2;
##TEST for Alter table for invisibleness level 2 ##TEST for Alter table for invisibleness level 2
......
...@@ -6515,6 +6515,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, ...@@ -6515,6 +6515,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
bool result= TRUE; bool result= TRUE;
bool first_outer_loop= TRUE; bool first_outer_loop= TRUE;
Field *field_1, *field_2; Field *field_1, *field_2;
field_visibility_t field_1_invisible, field_2_invisible;
/* /*
Leaf table references to which new natural join columns are added Leaf table references to which new natural join columns are added
if the leaves are != NULL. if the leaves are != NULL.
...@@ -6543,7 +6544,9 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, ...@@ -6543,7 +6544,9 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
goto err; goto err;
field_1= nj_col_1->field(); field_1= nj_col_1->field();
if (nj_col_1->field() && nj_col_1->field()->vers_sys_field()) field_1_invisible= field_1 ? field_1->invisible : VISIBLE;
if (field_1_invisible == INVISIBLE_FULL)
continue; continue;
field_name_1= nj_col_1->name(); field_name_1= nj_col_1->name();
...@@ -6553,6 +6556,9 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, ...@@ -6553,6 +6556,9 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
nj_col_1->safe_table_name(), nj_col_1->safe_table_name(),
field_name_1->str)); field_name_1->str));
if (field_1_invisible && !is_using_column_1)
continue;
/* /*
Find a field with the same name in table_ref_2. Find a field with the same name in table_ref_2.
...@@ -6569,6 +6575,11 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, ...@@ -6569,6 +6575,11 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
goto err; goto err;
field_2= cur_nj_col_2->field(); field_2= cur_nj_col_2->field();
field_2_invisible= field_2 ? field_2->invisible : VISIBLE;
if (field_2_invisible == INVISIBLE_FULL)
continue;
cur_field_name_2= cur_nj_col_2->name(); cur_field_name_2= cur_nj_col_2->name();
DBUG_PRINT ("info", ("cur_field_name_2=%s.%s", DBUG_PRINT ("info", ("cur_field_name_2=%s.%s",
cur_nj_col_2->safe_table_name(), cur_nj_col_2->safe_table_name(),
...@@ -6594,7 +6605,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, ...@@ -6594,7 +6605,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1->str, thd->where); my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1->str, thd->where);
goto err; goto err;
} }
if (!using_fields || is_using_column_1) if ((!using_fields && !field_2_invisible) || is_using_column_1)
{ {
DBUG_ASSERT(nj_col_2 == NULL); DBUG_ASSERT(nj_col_2 == NULL);
nj_col_2= cur_nj_col_2; nj_col_2= cur_nj_col_2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment