diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2017-12-14 13:43:37 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2017-12-14 13:43:37 +0300 |
commit | 2e3b580ba4bcb830a87ca969e77a6392eca9e615 (patch) | |
tree | b0730b20e8446c2bd53f7307fc2607f41362149b /sql/sql_select.cc | |
parent | eab471260b4576fc7b6e367fccf549816682a89e (diff) | |
download | mariadb-git-2e3b580ba4bcb830a87ca969e77a6392eca9e615.tar.gz |
SQL: inner/outer system_time consistency [fixes #384]
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 194bc29a472..cd6c7877354 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -797,17 +797,23 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr } } - SELECT_LEX *outer_slex= next_select_in_list(); - // propagate derived conditions to outer SELECT_LEX - if (outer_slex && vers_check_clash) + // find outer system_time + SELECT_LEX *outer_slex= outer_select(); + TABLE_LIST* outer_table= NULL; + + if (outer_slex) { - for (table= outer_slex->table_list.first; table; table= table->next_local) + TABLE_LIST* derived= master_unit()->derived; + // inner SELECT may not be a derived table (derived == NULL) + while (derived && outer_slex && !derived->vers_conditions) { - if (table->vers_conditions && !is_linkage_set()) - { - my_error(ER_VERS_SYSTEM_TIME_CLASH, MYF(0), table->alias); - DBUG_RETURN(-1); - } + derived= outer_slex->master_unit()->derived; + outer_slex= outer_slex->outer_select(); + } + if (derived && outer_slex) + { + DBUG_ASSERT(derived->vers_conditions); + outer_table= derived; } } @@ -821,20 +827,17 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr vers_select_conds_t &vers_conditions= table->vers_conditions; - // propagate system_time from nearest outer SELECT_LEX - if (!vers_conditions && outer_slex) + if (outer_table && table != outer_table) // inner table may be outer in recursive CTE { - TABLE_LIST* derived= master_unit()->derived; - // inner SELECT may not be a derived table (derived == NULL) - while (derived && outer_slex && !derived->vers_conditions) + if (vers_conditions) { - derived= outer_slex->master_unit()->derived; - outer_slex= outer_slex->next_select_in_list(); + my_error(ER_VERS_SYSTEM_TIME_CLASH, MYF(0), outer_table->alias); + DBUG_RETURN(-1); } - if (derived && outer_slex) + else { - DBUG_ASSERT(derived->vers_conditions); - vers_conditions= derived->vers_conditions; + // propagate system_time from nearest outer SELECT_LEX + vers_conditions= outer_table->vers_conditions; } } @@ -1022,6 +1025,9 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr this->where= *dst_cond; this->where->top_level_item(); } + + if (outer_table) + outer_table->vers_conditions.type= FOR_SYSTEM_TIME_ALL; } DBUG_RETURN(0); |