Commit 2db17e66 authored by Aleksey Midenkov's avatar Aleksey Midenkov

Parser: versioned JOIN fix

Moved opt_for_system_time_clause from table identifier (which binds
it to single table) to table expression.
parent 5c4473dc
...@@ -2278,6 +2278,7 @@ void st_select_lex::init_select() ...@@ -2278,6 +2278,7 @@ void st_select_lex::init_select()
with_dep= 0; with_dep= 0;
join= 0; join= 0;
lock_type= TL_READ_DEFAULT; lock_type= TL_READ_DEFAULT;
vers_conditions.empty();
} }
/* /*
......
...@@ -991,6 +991,9 @@ class st_select_lex: public st_select_lex_node ...@@ -991,6 +991,9 @@ class st_select_lex: public st_select_lex_node
/* it is for correct printing SELECT options */ /* it is for correct printing SELECT options */
thr_lock_type lock_type; thr_lock_type lock_type;
/* System Versioning conditions */
vers_select_conds_t vers_conditions;
void init_query(); void init_query();
void init_select(); void init_select();
st_select_lex_unit* master_unit() { return (st_select_lex_unit*) master; } st_select_lex_unit* master_unit() { return (st_select_lex_unit*) master; }
......
...@@ -688,11 +688,6 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se ...@@ -688,11 +688,6 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se
{ {
if (table->table && table->table->versioned()) if (table->table && table->table->versioned())
versioned_tables++; versioned_tables++;
else if (table->system_versioning.type != FOR_SYSTEM_TIME_UNSPECIFIED)
{
my_error(ER_TABLE_DOESNT_SUPPORT_SYSTEM_VERSIONING, MYF(0), table->table_name);
DBUG_RETURN(-1);
}
} }
if (versioned_tables == 0) if (versioned_tables == 0)
...@@ -746,7 +741,7 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se ...@@ -746,7 +741,7 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se
} }
Item *cond1= 0, *cond2= 0, *curr= 0; Item *cond1= 0, *cond2= 0, *curr= 0;
switch (table->system_versioning.type) switch (select_lex->vers_conditions.type)
{ {
case FOR_SYSTEM_TIME_UNSPECIFIED: case FOR_SYSTEM_TIME_UNSPECIFIED:
if (table->table->versioned_by_sql()) if (table->table->versioned_by_sql())
...@@ -764,21 +759,21 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se ...@@ -764,21 +759,21 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se
break; break;
case FOR_SYSTEM_TIME_AS_OF: case FOR_SYSTEM_TIME_AS_OF:
cond1= new (thd->mem_root) Item_func_le(thd, row_start, cond1= new (thd->mem_root) Item_func_le(thd, row_start,
table->system_versioning.start); select_lex->vers_conditions.start);
cond2= new (thd->mem_root) Item_func_gt(thd, row_end, cond2= new (thd->mem_root) Item_func_gt(thd, row_end,
table->system_versioning.start); select_lex->vers_conditions.start);
break; break;
case FOR_SYSTEM_TIME_FROM_TO: case FOR_SYSTEM_TIME_FROM_TO:
cond1= new (thd->mem_root) Item_func_lt(thd, row_start, cond1= new (thd->mem_root) Item_func_lt(thd, row_start,
table->system_versioning.end); select_lex->vers_conditions.end);
cond2= new (thd->mem_root) Item_func_ge(thd, row_end, cond2= new (thd->mem_root) Item_func_ge(thd, row_end,
table->system_versioning.start); select_lex->vers_conditions.start);
break; break;
case FOR_SYSTEM_TIME_BETWEEN: case FOR_SYSTEM_TIME_BETWEEN:
cond1= new (thd->mem_root) Item_func_le(thd, row_start, cond1= new (thd->mem_root) Item_func_le(thd, row_start,
table->system_versioning.end); select_lex->vers_conditions.end);
cond2= new (thd->mem_root) Item_func_ge(thd, row_end, cond2= new (thd->mem_root) Item_func_ge(thd, row_end,
table->system_versioning.start); select_lex->vers_conditions.start);
break; break;
default: default:
DBUG_ASSERT(0); DBUG_ASSERT(0);
...@@ -797,10 +792,10 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se ...@@ -797,10 +792,10 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **conds, SELECT_LEX *se
else else
thd->change_item_tree(conds, cond1); thd->change_item_tree(conds, cond1);
table->system_versioning.is_moved_to_where= true; table->vers_moved_to_where= true;
} }
} } // if (... table->table->versioned())
} } // for (table= tables; ...)
if (arena) if (arena)
{ {
...@@ -24935,29 +24930,30 @@ bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) ...@@ -24935,29 +24930,30 @@ bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
void TABLE_LIST::print_system_versioning(THD *thd, table_map eliminated_tables, void TABLE_LIST::print_system_versioning(THD *thd, table_map eliminated_tables,
String *str, enum_query_type query_type) String *str, enum_query_type query_type)
{ {
if (system_versioning.is_moved_to_where) if (vers_moved_to_where)
return; return;
DBUG_ASSERT(select_lex);
// system versioning // system versioning
if (system_versioning.type != FOR_SYSTEM_TIME_UNSPECIFIED) if (select_lex->vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED)
{ {
switch (system_versioning.type) switch (select_lex->vers_conditions.type)
{ {
case FOR_SYSTEM_TIME_AS_OF: case FOR_SYSTEM_TIME_AS_OF:
str->append(STRING_WITH_LEN(" for system_time as of ")); str->append(STRING_WITH_LEN(" for system_time as of "));
system_versioning.start->print(str, query_type); select_lex->vers_conditions.start->print(str, query_type);
break; break;
case FOR_SYSTEM_TIME_FROM_TO: case FOR_SYSTEM_TIME_FROM_TO:
str->append(STRING_WITH_LEN(" for system_time from timestamp ")); str->append(STRING_WITH_LEN(" for system_time from timestamp "));
system_versioning.start->print(str, query_type); select_lex->vers_conditions.start->print(str, query_type);
str->append(STRING_WITH_LEN(" to ")); str->append(STRING_WITH_LEN(" to "));
system_versioning.end->print(str, query_type); select_lex->vers_conditions.end->print(str, query_type);
break; break;
case FOR_SYSTEM_TIME_BETWEEN: case FOR_SYSTEM_TIME_BETWEEN:
str->append(STRING_WITH_LEN(" for system_time between timestamp ")); str->append(STRING_WITH_LEN(" for system_time between timestamp "));
system_versioning.start->print(str, query_type); select_lex->vers_conditions.start->print(str, query_type);
str->append(STRING_WITH_LEN(" and ")); str->append(STRING_WITH_LEN(" and "));
system_versioning.end->print(str, query_type); select_lex->vers_conditions.end->print(str, query_type);
break; break;
default: default:
DBUG_ASSERT(0); DBUG_ASSERT(0);
......
...@@ -758,7 +758,6 @@ Virtual_column_info *add_virtual_expression(THD *thd, Item *expr) ...@@ -758,7 +758,6 @@ Virtual_column_info *add_virtual_expression(THD *thd, Item *expr)
uint sp_instr_addr; uint sp_instr_addr;
/* structs */ /* structs */
system_versioning_for_select system_versioning;
LEX_STRING lex_str; LEX_STRING lex_str;
LEX_SYMBOL symbol; LEX_SYMBOL symbol;
Lex_string_with_metadata_st lex_string_with_metadata; Lex_string_with_metadata_st lex_string_with_metadata;
...@@ -1954,7 +1953,6 @@ END_OF_INPUT ...@@ -1954,7 +1953,6 @@ END_OF_INPUT
%type <NONE> window_frame_extent; %type <NONE> window_frame_extent;
%type <frame_exclusion> opt_window_frame_exclusion; %type <frame_exclusion> opt_window_frame_exclusion;
%type <window_frame_bound> window_frame_start window_frame_bound; %type <window_frame_bound> window_frame_start window_frame_bound;
%type <system_versioning> opt_for_system_time_clause;
%type <NONE> %type <NONE>
'-' '+' '*' '/' '%' '(' ')' '-' '+' '*' '/' '%' '(' ')'
...@@ -8628,6 +8626,7 @@ table_expression: ...@@ -8628,6 +8626,7 @@ table_expression:
opt_group_clause opt_group_clause
opt_having_clause opt_having_clause
opt_window_clause opt_window_clause
opt_for_system_time_clause
; ;
opt_table_expression: opt_table_expression:
...@@ -8664,14 +8663,12 @@ select_options: ...@@ -8664,14 +8663,12 @@ select_options:
opt_for_system_time_clause: opt_for_system_time_clause:
/* empty */ /* empty */
{ {}
$$.init();
}
| FOR_SYSTEM_TIME_SYM | FOR_SYSTEM_TIME_SYM
AS OF_SYM AS OF_SYM
TIMESTAMP simple_expr TIMESTAMP simple_expr
{ {
$$.init(FOR_SYSTEM_TIME_AS_OF, $5); Lex->current_select->vers_conditions.init(FOR_SYSTEM_TIME_AS_OF, $5);
} }
| FOR_SYSTEM_TIME_SYM | FOR_SYSTEM_TIME_SYM
AS OF_SYM AS OF_SYM
...@@ -8680,7 +8677,7 @@ opt_for_system_time_clause: ...@@ -8680,7 +8677,7 @@ opt_for_system_time_clause:
Item *item= new (thd->mem_root) Item_func_now_local(thd, 6); Item *item= new (thd->mem_root) Item_func_now_local(thd, 6);
if (item == NULL) if (item == NULL)
MYSQL_YYABORT; MYSQL_YYABORT;
$$.init(FOR_SYSTEM_TIME_AS_OF, item); Lex->current_select->vers_conditions.init(FOR_SYSTEM_TIME_AS_OF, item);
} }
| FOR_SYSTEM_TIME_SYM | FOR_SYSTEM_TIME_SYM
FROM FROM
...@@ -8688,7 +8685,7 @@ opt_for_system_time_clause: ...@@ -8688,7 +8685,7 @@ opt_for_system_time_clause:
TO_SYM TO_SYM
TIMESTAMP simple_expr TIMESTAMP simple_expr
{ {
$$.init(FOR_SYSTEM_TIME_FROM_TO, $4, $7); Lex->current_select->vers_conditions.init(FOR_SYSTEM_TIME_FROM_TO, $4, $7);
} }
| FOR_SYSTEM_TIME_SYM | FOR_SYSTEM_TIME_SYM
BETWEEN_SYM BETWEEN_SYM
...@@ -8696,7 +8693,7 @@ opt_for_system_time_clause: ...@@ -8696,7 +8693,7 @@ opt_for_system_time_clause:
AND_SYM AND_SYM
TIMESTAMP simple_expr TIMESTAMP simple_expr
{ {
$$.init(FOR_SYSTEM_TIME_BETWEEN, $4, $7); Lex->current_select->vers_conditions.init(FOR_SYSTEM_TIME_BETWEEN, $4, $7);
} }
; ;
...@@ -11107,7 +11104,7 @@ table_primary_ident: ...@@ -11107,7 +11104,7 @@ table_primary_ident:
SELECT_LEX *sel= Select; SELECT_LEX *sel= Select;
sel->table_join_options= 0; sel->table_join_options= 0;
} }
table_ident opt_use_partition opt_table_alias opt_key_definition opt_for_system_time_clause table_ident opt_use_partition opt_table_alias opt_key_definition
{ {
if (!($$= Select->add_table_to_list(thd, $2, $4, if (!($$= Select->add_table_to_list(thd, $2, $4,
Select->get_table_join_options(), Select->get_table_join_options(),
...@@ -11117,7 +11114,6 @@ table_primary_ident: ...@@ -11117,7 +11114,6 @@ table_primary_ident:
$3))) $3)))
MYSQL_YYABORT; MYSQL_YYABORT;
Select->add_joined_table($$); Select->add_joined_table($$);
$$->system_versioning= $6;
} }
; ;
......
...@@ -1814,26 +1814,32 @@ class Item_in_subselect; ...@@ -1814,26 +1814,32 @@ class Item_in_subselect;
enum for_system_time_type enum for_system_time_type
{ {
FOR_SYSTEM_TIME_UNSPECIFIED, FOR_SYSTEM_TIME_AS_OF, FOR_SYSTEM_TIME_UNSPECIFIED = 0,
FOR_SYSTEM_TIME_FROM_TO, FOR_SYSTEM_TIME_BETWEEN FOR_SYSTEM_TIME_AS_OF,
FOR_SYSTEM_TIME_FROM_TO,
FOR_SYSTEM_TIME_BETWEEN
}; };
/** System versioning support. */ /** System versioning support. */
struct system_versioning_for_select struct vers_select_conds_t
{ {
enum for_system_time_type type; enum for_system_time_type type;
Item *start, *end; Item *start, *end;
bool is_moved_to_where;
void empty()
{
type= FOR_SYSTEM_TIME_UNSPECIFIED;
start= end= NULL;
}
void init( void init(
const enum for_system_time_type t=FOR_SYSTEM_TIME_UNSPECIFIED, const enum for_system_time_type t,
Item * const s=NULL, Item * const s,
Item * const e=NULL) Item * const e= NULL)
{ {
type= t; type= t;
start= s; start= s;
end= e; end= e;
is_moved_to_where= false;
} }
}; };
...@@ -2293,8 +2299,8 @@ struct TABLE_LIST ...@@ -2293,8 +2299,8 @@ struct TABLE_LIST
TABLE_LIST *first_leaf_for_name_resolution(); TABLE_LIST *first_leaf_for_name_resolution();
TABLE_LIST *last_leaf_for_name_resolution(); TABLE_LIST *last_leaf_for_name_resolution();
/** System versioning support. */ /* System Versioning */
system_versioning_for_select system_versioning; bool vers_moved_to_where;
/** /**
@brief @brief
......
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