Commit dc4ef66f authored by kevg's avatar kevg Committed by Aleksey Midenkov

SQL: optimize FOR SYSTEM_TIME ALL queries [closes #85]

parent 1dc02136
...@@ -676,11 +676,9 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s ...@@ -676,11 +676,9 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s
TABLE_LIST *table; TABLE_LIST *table;
int versioned_tables= 0; int versioned_tables= 0;
Query_arena *arena= 0, backup; Query_arena *arena= 0, backup;
bool is_prepare= thd->stmt_arena->is_stmt_prepare();
if (!thd->stmt_arena->is_conventional() if (!thd->stmt_arena->is_conventional() &&
&& !is_prepare !thd->stmt_arena->is_stmt_prepare() && !thd->stmt_arena->is_sp_execute())
&& !thd->stmt_arena->is_sp_execute())
{ {
// statement is already prepared // statement is already prepared
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -702,6 +700,11 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s ...@@ -702,6 +700,11 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s
DBUG_RETURN(0); DBUG_RETURN(0);
} }
if (slex->vers_conditions.type == FOR_SYSTEM_TIME_ALL)
{
DBUG_RETURN(0);
}
/* For prepared statements we create items on statement arena, /* For prepared statements we create items on statement arena,
because they must outlive execution phase for multiple executions. */ because they must outlive execution phase for multiple executions. */
arena= thd->activate_stmt_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
......
...@@ -8749,13 +8749,7 @@ opt_for_system_time_clause: ...@@ -8749,13 +8749,7 @@ opt_for_system_time_clause:
} }
| FOR_SYSTEM_TIME_SYM ALL | FOR_SYSTEM_TIME_SYM ALL
{ {
static MYSQL_TIME min= { TIMESTAMP_MIN_YEAR, 1, 1, 0, 0, 0, 0, false, MYSQL_TIMESTAMP_DATETIME }; Lex->current_select->vers_conditions.init(FOR_SYSTEM_TIME_ALL, UNIT_TIMESTAMP);
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);
} }
| FOR_SYSTEM_TIME_SYM | FOR_SYSTEM_TIME_SYM
FROM FROM
......
...@@ -1817,7 +1817,8 @@ enum vers_range_type_t ...@@ -1817,7 +1817,8 @@ enum vers_range_type_t
FOR_SYSTEM_TIME_UNSPECIFIED = 0, FOR_SYSTEM_TIME_UNSPECIFIED = 0,
FOR_SYSTEM_TIME_AS_OF, FOR_SYSTEM_TIME_AS_OF,
FOR_SYSTEM_TIME_FROM_TO, FOR_SYSTEM_TIME_FROM_TO,
FOR_SYSTEM_TIME_BETWEEN FOR_SYSTEM_TIME_BETWEEN,
FOR_SYSTEM_TIME_ALL
}; };
enum vers_range_unit_t enum vers_range_unit_t
...@@ -1843,7 +1844,7 @@ struct vers_select_conds_t ...@@ -1843,7 +1844,7 @@ struct vers_select_conds_t
void init( void init(
vers_range_type_t t, vers_range_type_t t,
vers_range_unit_t u, vers_range_unit_t u,
Item * s, Item * s= NULL,
Item * e= NULL) Item * e= NULL)
{ {
type= t; type= t;
......
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