From e8ae9f1ae9e361c41148f32f9efbae49ccadff19 Mon Sep 17 00:00:00 2001 From: kevg Date: Thu, 23 Mar 2017 16:14:19 +0300 Subject: [PATCH] SQL: VIEW NATURAL JOIN TABLE [fixes #161] --- mysql-test/suite/versioning/r/select.result | 28 ++++++++++++++++++++- mysql-test/suite/versioning/t/select.test | 14 ++++++++++- sql/sql_base.cc | 9 +++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/versioning/r/select.result b/mysql-test/suite/versioning/r/select.result index 86a56fe05a0..167d1c8ff9a 100644 --- a/mysql-test/suite/versioning/r/select.result +++ b/mysql-test/suite/versioning/r/select.result @@ -390,8 +390,32 @@ a1 a2 2 1 1 2 2 2 +create or replace table t1(a1 int) with system versioning; +create or replace table t2(a2 int) with system versioning; +insert into t1 values(1),(2); +insert into t2 values(1),(2); +create or replace view v1 as select a1 from t1; +select * from v1 natural join t2; +a1 a2 +1 1 +2 1 +1 2 +2 2 +select * from v1 natural left join t2; +a1 a2 +1 1 +2 1 +1 2 +2 2 +select * from v1 natural right join t2; +a2 a1 +1 1 +2 1 +1 2 +2 2 +drop view v1; drop table t1, t2; -call innodb_verify_vtq(19); +call innodb_verify_vtq(21); No A B C D 1 1 1 1 1 2 1 1 1 1 @@ -412,6 +436,8 @@ No A B C D 17 1 1 1 1 18 1 1 1 1 19 1 1 1 1 +20 1 1 1 1 +21 1 1 1 1 drop procedure test_01; drop procedure test_02; drop procedure verify_vtq; diff --git a/mysql-test/suite/versioning/t/select.test b/mysql-test/suite/versioning/t/select.test index 115706f9130..35cbc068070 100644 --- a/mysql-test/suite/versioning/t/select.test +++ b/mysql-test/suite/versioning/t/select.test @@ -173,9 +173,21 @@ insert into t1 values(1),(2); insert into t2 values(1),(2); select * from t1 for system_time all natural left join t2 for system_time all; +# natural join of a view and table +create or replace table t1(a1 int) with system versioning; +create or replace table t2(a2 int) with system versioning; +insert into t1 values(1),(2); +insert into t2 values(1),(2); +create or replace view v1 as select a1 from t1; + +select * from v1 natural join t2; +select * from v1 natural left join t2; +select * from v1 natural right join t2; + +drop view v1; drop table t1, t2; -call innodb_verify_vtq(19); +call innodb_verify_vtq(21); drop procedure test_01; drop procedure test_02; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 14bc741057b..2ca2c9141f3 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6383,6 +6383,15 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, if (nj_col_1->field() && nj_col_1->field()->vers_sys_field()) continue; + if (table_ref_1->is_view() && table_ref_1->table->versioned()) + { + Item *item= nj_col_1->view_field->item; + DBUG_ASSERT(item->type() == Item::FIELD_ITEM); + Item_field *item_field= (Item_field *)item; + if (item_field->field->vers_sys_field()) + continue; + } + field_name_1= nj_col_1->name(); is_using_column_1= using_fields && test_if_string_in_list(field_name_1, using_fields);