mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
A preparatory patch to help adding JOIN::transform() and move one-time
query transformations to the PREPARE stage (prepared statements).
This commit is contained in:
@ -716,10 +716,6 @@ public:
|
|||||||
void cleanup();
|
void cleanup();
|
||||||
bool remove_dependence_processor(byte * arg);
|
bool remove_dependence_processor(byte * arg);
|
||||||
void print(String *str);
|
void print(String *str);
|
||||||
|
|
||||||
friend bool insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
|
|
||||||
const char *table_name, List_iterator<Item> *it,
|
|
||||||
bool any_privileges, bool allocate_view_names);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Item_equal;
|
class Item_equal;
|
||||||
|
@ -894,8 +894,7 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
|
|||||||
List<String> *index_list);
|
List<String> *index_list);
|
||||||
bool insert_fields(THD *thd,TABLE_LIST *tables,
|
bool insert_fields(THD *thd,TABLE_LIST *tables,
|
||||||
const char *db_name, const char *table_name,
|
const char *db_name, const char *table_name,
|
||||||
List_iterator<Item> *it, bool any_privileges,
|
List_iterator<Item> *it, bool any_privileges);
|
||||||
bool allocate_view_names);
|
|
||||||
bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds,
|
bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds,
|
||||||
TABLE_LIST **leaves, bool select_insert);
|
TABLE_LIST **leaves, bool select_insert);
|
||||||
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
|
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
|
||||||
|
@ -682,6 +682,7 @@ sp_head::execute(THD *thd)
|
|||||||
|
|
||||||
cleanup_items(thd->current_arena->free_list);
|
cleanup_items(thd->current_arena->free_list);
|
||||||
thd->current_arena= old_arena;
|
thd->current_arena= old_arena;
|
||||||
|
state= EXECUTED;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
DBUG_PRINT("info", ("ret=%d killed=%d query_error=%d",
|
DBUG_PRINT("info", ("ret=%d killed=%d query_error=%d",
|
||||||
|
@ -3051,7 +3051,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
|
|||||||
}
|
}
|
||||||
else if (insert_fields(thd,tables,((Item_field*) item)->db_name,
|
else if (insert_fields(thd,tables,((Item_field*) item)->db_name,
|
||||||
((Item_field*) item)->table_name, &it,
|
((Item_field*) item)->table_name, &it,
|
||||||
any_privileges, arena != 0))
|
any_privileges))
|
||||||
{
|
{
|
||||||
if (arena)
|
if (arena)
|
||||||
thd->restore_backup_item_arena(arena, &backup);
|
thd->restore_backup_item_arena(arena, &backup);
|
||||||
@ -3304,8 +3304,6 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
|
|||||||
any_privileges 0 If we should ensure that we have SELECT privileges
|
any_privileges 0 If we should ensure that we have SELECT privileges
|
||||||
for all columns
|
for all columns
|
||||||
1 If any privilege is ok
|
1 If any privilege is ok
|
||||||
allocate_view_names if true view names will be copied to current Query_arena
|
|
||||||
memory (made for SP/PS)
|
|
||||||
RETURN
|
RETURN
|
||||||
0 ok
|
0 ok
|
||||||
'it' is updated to point at last inserted
|
'it' is updated to point at last inserted
|
||||||
@ -3315,7 +3313,7 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
|
|||||||
bool
|
bool
|
||||||
insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
|
insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
|
||||||
const char *table_name, List_iterator<Item> *it,
|
const char *table_name, List_iterator<Item> *it,
|
||||||
bool any_privileges, bool allocate_view_names)
|
bool any_privileges)
|
||||||
{
|
{
|
||||||
/* allocate variables on stack to avoid pool alloaction */
|
/* allocate variables on stack to avoid pool alloaction */
|
||||||
Field_iterator_table table_iter;
|
Field_iterator_table table_iter;
|
||||||
@ -3506,25 +3504,6 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
|
|||||||
field->query_id=thd->query_id;
|
field->query_id=thd->query_id;
|
||||||
table->used_keys.intersect(field->part_of_key);
|
table->used_keys.intersect(field->part_of_key);
|
||||||
}
|
}
|
||||||
else if (allocate_view_names &&
|
|
||||||
thd->lex->current_select->first_execution)
|
|
||||||
{
|
|
||||||
Item_field *item;
|
|
||||||
if (alias_used)
|
|
||||||
item= new Item_field(0,
|
|
||||||
thd->strdup(tables->alias),
|
|
||||||
thd->strdup(field_name));
|
|
||||||
else
|
|
||||||
item= new Item_field(thd->strdup(tables->view_db.str),
|
|
||||||
thd->strdup(tables->view_name.str),
|
|
||||||
thd->strdup(field_name));
|
|
||||||
/*
|
|
||||||
during cleunup() this item will be put in list to replace
|
|
||||||
expression from VIEW
|
|
||||||
*/
|
|
||||||
thd->nocheck_register_item_tree_change(it->ref(), item,
|
|
||||||
thd->mem_root);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
All fields are used in case if usual tables (in case of view used
|
All fields are used in case if usual tables (in case of view used
|
||||||
|
@ -699,6 +699,8 @@ public:
|
|||||||
virtual ~Query_arena() {};
|
virtual ~Query_arena() {};
|
||||||
|
|
||||||
inline bool is_stmt_prepare() const { return state == INITIALIZED; }
|
inline bool is_stmt_prepare() const { return state == INITIALIZED; }
|
||||||
|
inline bool is_first_sp_execute() const
|
||||||
|
{ return state == INITIALIZED_FOR_SP; }
|
||||||
inline bool is_stmt_prepare_or_first_sp_execute() const
|
inline bool is_stmt_prepare_or_first_sp_execute() const
|
||||||
{ return (int)state < (int)PREPARED; }
|
{ return (int)state < (int)PREPARED; }
|
||||||
inline bool is_first_stmt_execute() const { return state == PREPARED; }
|
inline bool is_first_stmt_execute() const { return state == PREPARED; }
|
||||||
|
@ -422,7 +422,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insert_fields(thd, tables, tables->db, tables->alias, &it, 0, 0))
|
if (insert_fields(thd, tables, tables->db, tables->alias, &it, 0))
|
||||||
goto err0;
|
goto err0;
|
||||||
|
|
||||||
protocol->send_fields(&list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
|
protocol->send_fields(&list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
|
||||||
|
@ -530,7 +530,19 @@ public:
|
|||||||
query processing end even if we use temporary table
|
query processing end even if we use temporary table
|
||||||
*/
|
*/
|
||||||
bool subquery_in_having;
|
bool subquery_in_having;
|
||||||
bool first_execution; /* first execution in SP or PS */
|
/*
|
||||||
|
This variable is required to ensure proper work of subqueries and
|
||||||
|
stored procedures. Generally, one should use the states of
|
||||||
|
Query_arena to determine if it's a statement prepare or first
|
||||||
|
execution of a stored procedure. However, in case when there was an
|
||||||
|
error during the first execution of a stored procedure, the SP body
|
||||||
|
is not expelled from the SP cache. Therefore, a deeply nested
|
||||||
|
subquery might be left unoptimized. So we need this per-subquery
|
||||||
|
variable to inidicate the optimization/execution state of every
|
||||||
|
subquery. Prepared statements work OK in that regard, as in
|
||||||
|
case of an error during prepare the PS is not created.
|
||||||
|
*/
|
||||||
|
bool first_execution;
|
||||||
bool first_cond_optimization;
|
bool first_cond_optimization;
|
||||||
/* do not wrap view fields with Item_ref */
|
/* do not wrap view fields with Item_ref */
|
||||||
bool no_wrap_view_item;
|
bool no_wrap_view_item;
|
||||||
|
Reference in New Issue
Block a user