From 17745222a1a1dbc72ecbe5a9c0ca0daeacc675a8 Mon Sep 17 00:00:00 2001 From: kevg Date: Sun, 5 Mar 2017 23:51:02 +0300 Subject: [PATCH] SQL: incorrect check on specific JOIN query [fixes #145] --- mysql-test/suite/versioning/r/select.result | 3 +++ mysql-test/suite/versioning/t/select.test | 3 +++ sql/sql_base.cc | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/versioning/r/select.result b/mysql-test/suite/versioning/r/select.result index 72f8e0424d6..4258f84b16e 100644 --- a/mysql-test/suite/versioning/r/select.result +++ b/mysql-test/suite/versioning/r/select.result @@ -406,6 +406,9 @@ create or replace table t1 (x int) with system versioning; insert into t1 values (1); select * from t1 for system_time all for update; ERROR HY000: Wrong parameters for `FOR SYSTEM_TIME query`: write-locking of historic rows +create or replace table t1 (a int not null auto_increment primary key) with system versioning; +select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1; +a drop table t1; 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 ca3f8d2b3b7..9af249c1056 100644 --- a/mysql-test/suite/versioning/t/select.test +++ b/mysql-test/suite/versioning/t/select.test @@ -131,6 +131,9 @@ insert into t1 values (1); --error ER_VERS_WRONG_PARAMS select * from t1 for system_time all for update; +create or replace table t1 (a int not null auto_increment primary key) with system versioning; +select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1; + drop table t1; call verify_vtq; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 02adbb656c1..e8ec8104f8b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6420,8 +6420,9 @@ 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 (cur_nj_col_2->is_common || - (found && (!using_fields || is_using_column_1))) + if ((!it_1.field() || !it_1.field()->vers_sys_field()) && + (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;