mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
SQL(misc): Query_arena_stmt RAII
This commit is contained in:
@ -7425,3 +7425,16 @@ bool Discrete_intervals_list::append(Discrete_interval *new_interval)
|
||||
}
|
||||
|
||||
#endif /* !defined(MYSQL_CLIENT) */
|
||||
|
||||
|
||||
Query_arena_stmt::Query_arena_stmt(THD *_thd) :
|
||||
thd(_thd)
|
||||
{
|
||||
arena= thd->activate_stmt_arena_if_needed(&backup);
|
||||
}
|
||||
|
||||
Query_arena_stmt::~Query_arena_stmt()
|
||||
{
|
||||
if (arena)
|
||||
thd->restore_active_arena(arena, &backup);
|
||||
}
|
||||
|
@ -1024,6 +1024,22 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class Query_arena_stmt
|
||||
{
|
||||
THD *thd;
|
||||
Query_arena backup;
|
||||
Query_arena *arena;
|
||||
|
||||
public:
|
||||
Query_arena_stmt(THD *_thd);
|
||||
~Query_arena_stmt();
|
||||
bool arena_replaced()
|
||||
{
|
||||
return arena != NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Server_side_cursor;
|
||||
|
||||
/**
|
||||
|
@ -723,14 +723,11 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
|
||||
TABLE_SHARE *s= tl->table->s;
|
||||
const char *db= tl->db;
|
||||
const char *alias= tl->alias;
|
||||
Query_arena backup;
|
||||
Query_arena *arena= thd->activate_stmt_arena_if_needed(&backup);
|
||||
Query_arena_stmt on_stmt_arena(thd);
|
||||
sl->item_list.push_back(new (thd->mem_root) Item_field(
|
||||
thd, &sl->context, db, alias, s->vers_start_field()->field_name));
|
||||
sl->item_list.push_back(new (thd->mem_root) Item_field(
|
||||
thd, &sl->context, db, alias, s->vers_end_field()->field_name));
|
||||
if (arena)
|
||||
thd->restore_active_arena(arena, &backup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -695,7 +695,6 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
TABLE_LIST *table;
|
||||
int versioned_tables= 0;
|
||||
int slex_conds_used= 0;
|
||||
Query_arena *arena= 0, backup;
|
||||
|
||||
if (!thd->stmt_arena->is_conventional() &&
|
||||
!thd->stmt_arena->is_stmt_prepare() && !thd->stmt_arena->is_sp_execute())
|
||||
@ -727,7 +726,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
|
||||
/* 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);
|
||||
Query_arena_stmt on_stmt_arena(thd);
|
||||
|
||||
if (slex->saved_where)
|
||||
{
|
||||
@ -798,8 +797,6 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
case TL_WRITE:
|
||||
case TL_WRITE_ONLY:
|
||||
my_error(ER_VERS_WRONG_PARAMS, MYF(0), "FOR SYSTEM_TIME query", "write-locking of historic rows");
|
||||
if (arena)
|
||||
thd->restore_active_arena(arena, &backup);
|
||||
DBUG_RETURN(-1);
|
||||
default:
|
||||
break;
|
||||
@ -969,7 +966,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
cond2,
|
||||
cond1));
|
||||
|
||||
if (arena)
|
||||
if (on_stmt_arena.arena_replaced())
|
||||
*dst_cond= cond1;
|
||||
else
|
||||
thd->change_item_tree(dst_cond, cond1);
|
||||
@ -977,9 +974,6 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
|
||||
} // if (... table->table->versioned())
|
||||
} // for (table= tables; ...)
|
||||
|
||||
if (arena)
|
||||
thd->restore_active_arena(arena, &backup);
|
||||
|
||||
if (!slex_conds_used && slex->vers_conditions)
|
||||
{
|
||||
my_error(ER_VERS_WRONG_QUERY, MYF(0), "unused `QUERY FOR SYSTEM_TIME` clause!");
|
||||
|
Reference in New Issue
Block a user