mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Parser, SQL: (0.4) TRANSACTION support in queries
Syntax extension: TIMESTAMP/TRANSACTION keyword can be used before FROM ... TO, BETWEEN ... AND. Example: SELECT * FROM t1 FOR SYSTEM_TIME TIMESTAMP FROM '1-1-1' TO NOW(); Closes #27
This commit is contained in:
@ -668,7 +668,7 @@ setup_without_group(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
}
|
||||
|
||||
static int
|
||||
setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *select_lex)
|
||||
setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *slex)
|
||||
{
|
||||
DBUG_ENTER("setup_for_system_time");
|
||||
|
||||
@ -698,11 +698,11 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LE
|
||||
because they must outlive execution phase for multiple executions. */
|
||||
arena= thd->activate_stmt_arena_if_needed(&backup);
|
||||
|
||||
if (select_lex->saved_where)
|
||||
if (slex->saved_where)
|
||||
{
|
||||
DBUG_ASSERT(thd->stmt_arena->is_sp_execute());
|
||||
/* 2. this copy_andor_structure() is also required by the same reason */
|
||||
*where_expr= select_lex->saved_where->copy_andor_structure(thd);
|
||||
*where_expr= slex->saved_where->copy_andor_structure(thd);
|
||||
}
|
||||
else if (thd->stmt_arena->is_sp_execute())
|
||||
{
|
||||
@ -711,7 +711,7 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LE
|
||||
else if (*where_expr) // SP executed first time (STMT_INITIALIZED_FOR_SP)
|
||||
/* 1. copy_andor_structure() is required since this andor tree
|
||||
is modified later (and on shorter arena) */
|
||||
select_lex->saved_where= (*where_expr)->copy_andor_structure(thd);
|
||||
slex->saved_where= (*where_expr)->copy_andor_structure(thd);
|
||||
}
|
||||
|
||||
/* We have to save also non-versioned on_expr since we may have
|
||||
@ -754,15 +754,23 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LE
|
||||
Field *fstart= table->table->vers_start_field();
|
||||
Field *fend= table->table->vers_end_field();
|
||||
|
||||
DBUG_ASSERT(select_lex->parent_lex);
|
||||
Name_resolution_context *context= select_lex->parent_lex->current_context();
|
||||
DBUG_ASSERT(slex->parent_lex);
|
||||
Name_resolution_context *context= slex->parent_lex->current_context();
|
||||
DBUG_ASSERT(context);
|
||||
|
||||
Item *row_start= new (thd->mem_root) Item_field(thd, context, fstart);
|
||||
Item *row_end= new (thd->mem_root) Item_field(thd, context, fend);
|
||||
Item *row_end2= row_end;
|
||||
|
||||
if (!table->table->versioned_by_sql())
|
||||
if (table->table->versioned_by_sql())
|
||||
{
|
||||
if (slex->vers_conditions.unit == UNIT_TRX_ID)
|
||||
{
|
||||
my_error(ER_VERS_TRX_ID_UNSUPPORTED, MYF(0), table->table_name);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
}
|
||||
else if (slex->vers_conditions.unit == UNIT_TIMESTAMP)
|
||||
{
|
||||
DBUG_ASSERT(table->table->s && table->table->s->db_plugin);
|
||||
row_start= new (thd->mem_root) Item_func_vtq_ts(
|
||||
@ -778,7 +786,7 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LE
|
||||
}
|
||||
|
||||
Item *cond1= 0, *cond2= 0, *curr= 0;
|
||||
switch (select_lex->vers_conditions.type)
|
||||
switch (slex->vers_conditions.type)
|
||||
{
|
||||
case FOR_SYSTEM_TIME_UNSPECIFIED:
|
||||
if (table->table->versioned_by_sql())
|
||||
@ -796,21 +804,21 @@ setup_for_system_time(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LE
|
||||
break;
|
||||
case FOR_SYSTEM_TIME_AS_OF:
|
||||
cond1= new (thd->mem_root) Item_func_le(thd, row_start,
|
||||
select_lex->vers_conditions.start);
|
||||
slex->vers_conditions.start);
|
||||
cond2= new (thd->mem_root) Item_func_gt(thd, row_end,
|
||||
select_lex->vers_conditions.start);
|
||||
slex->vers_conditions.start);
|
||||
break;
|
||||
case FOR_SYSTEM_TIME_FROM_TO:
|
||||
cond1= new (thd->mem_root) Item_func_lt(thd, row_start,
|
||||
select_lex->vers_conditions.end);
|
||||
slex->vers_conditions.end);
|
||||
cond2= new (thd->mem_root) Item_func_ge(thd, row_end,
|
||||
select_lex->vers_conditions.start);
|
||||
slex->vers_conditions.start);
|
||||
break;
|
||||
case FOR_SYSTEM_TIME_BETWEEN:
|
||||
cond1= new (thd->mem_root) Item_func_le(thd, row_start,
|
||||
select_lex->vers_conditions.end);
|
||||
slex->vers_conditions.end);
|
||||
cond2= new (thd->mem_root) Item_func_ge(thd, row_end,
|
||||
select_lex->vers_conditions.start);
|
||||
slex->vers_conditions.start);
|
||||
break;
|
||||
default:
|
||||
DBUG_ASSERT(0);
|
||||
|
Reference in New Issue
Block a user