diff --git a/mysql-test/suite/versioning/r/select.result b/mysql-test/suite/versioning/r/select.result index 229c470d408..9dc32249692 100644 --- a/mysql-test/suite/versioning/r/select.result +++ b/mysql-test/suite/versioning/r/select.result @@ -456,6 +456,16 @@ a b 1 2 select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp; a b +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); +select * from t1 for system_time all natural left join t2 for system_time all; +a1 a2 +1 1 +2 1 +1 2 +2 2 drop table t1, t2; call verify_vtq; No A B C D diff --git a/mysql-test/suite/versioning/t/select.test b/mysql-test/suite/versioning/t/select.test index d04d9fc914d..a535cd67e07 100644 --- a/mysql-test/suite/versioning/t/select.test +++ b/mysql-test/suite/versioning/t/select.test @@ -175,6 +175,12 @@ select * from (select * from t1 cross join t2) as tmp; select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2; select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp; +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); +select * from t1 for system_time all natural left join t2 for system_time all; + drop table t1, t2; call verify_vtq; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b0fe02aba69..14bc741057b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5350,7 +5350,7 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name, { if (!my_strcasecmp(system_charset_info, curr_nj_col->name(), name)) { - if (nj_col && !curr_nj_col->table_field->field->vers_sys_field()) + if (nj_col) { my_error(ER_NON_UNIQ_ERROR, MYF(0), name, thd->where); DBUG_RETURN(NULL); @@ -6379,6 +6379,10 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, bool is_using_column_1; if (!(nj_col_1= it_1.get_or_create_column_ref(thd, leaf_1))) goto err; + + if (nj_col_1->field() && nj_col_1->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); @@ -6420,9 +6424,8 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, if (!my_strcasecmp(system_charset_info, field_name_1, cur_field_name_2)) { DBUG_PRINT ("info", ("match c1.is_common=%d", nj_col_1->is_common)); - if ((!it_1.field() || !it_1.field()->vers_sys_field()) && - (cur_nj_col_2->is_common || - (found && (!using_fields || is_using_column_1)))) + if (cur_nj_col_2->is_common || + (found && (!using_fields || is_using_column_1))) { my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1, thd->where); goto err;