Skip to content

Commit

Permalink
SQL: optimize FOR SYSTEM_TIME ALL queries [closes #85]
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgs authored and midenok committed Dec 11, 2016
1 parent dcb5b5f commit da5708f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
11 changes: 7 additions & 4 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,9 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s
TABLE_LIST *table;
int versioned_tables= 0;
Query_arena *arena= 0, backup;
bool is_prepare= thd->stmt_arena->is_stmt_prepare();

if (!thd->stmt_arena->is_conventional()
&& !is_prepare
&& !thd->stmt_arena->is_sp_execute())
if (!thd->stmt_arena->is_conventional() &&
!thd->stmt_arena->is_stmt_prepare() && !thd->stmt_arena->is_sp_execute())
{
// statement is already prepared
DBUG_RETURN(0);
Expand All @@ -702,6 +700,11 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s
DBUG_RETURN(0);
}

if (slex->vers_conditions.type == FOR_SYSTEM_TIME_ALL)
{
DBUG_RETURN(0);
}

/* For prepared statements we create items on statement arena,
because they must outlive execution phase for multiple executions. */
arena= thd->activate_stmt_arena_if_needed(&backup);
Expand Down
8 changes: 1 addition & 7 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -8772,13 +8772,7 @@ opt_for_system_time_clause:
}
| FOR_SYSTEM_TIME_SYM ALL
{
static MYSQL_TIME min= { TIMESTAMP_MIN_YEAR, 1, 1, 0, 0, 0, 0, false, MYSQL_TIMESTAMP_DATETIME };
static MYSQL_TIME max= { TIMESTAMP_MAX_YEAR, 12, 31, 23, 59, 59, 0, false, MYSQL_TIMESTAMP_DATETIME };
Item *t0= new (thd->mem_root) Item_datetime_literal(thd, &min);
Item *t1= new (thd->mem_root) Item_datetime_literal(thd, &max);
if (!t0 || !t1)
MYSQL_YYABORT;
Lex->current_select->vers_conditions.init(FOR_SYSTEM_TIME_BETWEEN, UNIT_TIMESTAMP, t0, t1);
Lex->current_select->vers_conditions.init(FOR_SYSTEM_TIME_ALL, UNIT_TIMESTAMP);
}
| FOR_SYSTEM_TIME_SYM
FROM
Expand Down
5 changes: 3 additions & 2 deletions sql/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,8 @@ enum vers_range_type_t
FOR_SYSTEM_TIME_UNSPECIFIED = 0,
FOR_SYSTEM_TIME_AS_OF,
FOR_SYSTEM_TIME_FROM_TO,
FOR_SYSTEM_TIME_BETWEEN
FOR_SYSTEM_TIME_BETWEEN,
FOR_SYSTEM_TIME_ALL
};

enum vers_range_unit_t
Expand All @@ -1823,7 +1824,7 @@ struct vers_select_conds_t
void init(
vers_range_type_t t,
vers_range_unit_t u,
Item * s,
Item * s= NULL,
Item * e= NULL)
{
type= t;
Expand Down

0 comments on commit da5708f

Please sign in to comment.