mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Bug#17204 "second CALL to procedure crashes Server"
Bug#18282 "INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views" This bug caused crashes or resulted in wrong data being returned when one tried to obtain information from I_S tables about views using stored functions. It was caused by the fact that we were using LEX representing statement which were doing select from I_S tables as active LEX when contents of I_S table were built. So state of this LEX both affected and was affected by open_tables() calls which happened during this process. This resulted in wrong behavior and in violations of some of invariants which caused crashes. This fix tries to solve this problem by properly saving/resetting and restoring part of LEX which affects and is affected by the process of opening tables and views in get_all_tables() routine. To simplify things we separated this part of LEX in a new class and made LEX its descendant.
This commit is contained in:
151
sql/sql_lex.h
151
sql/sql_lex.h
@@ -702,9 +702,95 @@ extern sys_var_long_ptr trg_new_row_fake_var;
|
||||
enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
|
||||
XA_SUSPEND, XA_FOR_MIGRATE};
|
||||
|
||||
|
||||
/*
|
||||
Class representing list of all tables used by statement.
|
||||
It also contains information about stored functions used by statement
|
||||
since during its execution we may have to add all tables used by its
|
||||
stored functions/triggers to this list in order to pre-open and lock
|
||||
them.
|
||||
|
||||
Also used by st_lex::reset_n_backup/restore_backup_query_tables_list()
|
||||
methods to save and restore this information.
|
||||
*/
|
||||
|
||||
class Query_tables_list
|
||||
{
|
||||
public:
|
||||
/* Global list of all tables used by this statement */
|
||||
TABLE_LIST *query_tables;
|
||||
/* Pointer to next_global member of last element in the previous list. */
|
||||
TABLE_LIST **query_tables_last;
|
||||
/*
|
||||
If non-0 then indicates that query requires prelocking and points to
|
||||
next_global member of last own element in query table list (i.e. last
|
||||
table which was not added to it as part of preparation to prelocking).
|
||||
0 - indicates that this query does not need prelocking.
|
||||
*/
|
||||
TABLE_LIST **query_tables_own_last;
|
||||
/* Set of stored routines called by statement. */
|
||||
HASH sroutines;
|
||||
/*
|
||||
List linking elements of 'sroutines' set. Allows you to add new elements
|
||||
to this set as you iterate through the list of existing elements.
|
||||
'sroutines_list_own_last' is pointer to ::next member of last element of
|
||||
this list which represents routine which is explicitly used by query.
|
||||
'sroutines_list_own_elements' number of explicitly used routines.
|
||||
We use these two members for restoring of 'sroutines_list' to the state
|
||||
in which it was right after query parsing.
|
||||
*/
|
||||
SQL_LIST sroutines_list;
|
||||
byte **sroutines_list_own_last;
|
||||
uint sroutines_list_own_elements;
|
||||
|
||||
/*
|
||||
These constructor and destructor serve for creation/destruction
|
||||
of Query_tables_list instances which are used as backup storage.
|
||||
*/
|
||||
Query_tables_list() {}
|
||||
~Query_tables_list() {}
|
||||
|
||||
/* Initializes (or resets) Query_tables_list object for "real" use. */
|
||||
void reset_query_tables_list(bool init);
|
||||
void destroy_query_tables_list();
|
||||
void set_query_tables_list(Query_tables_list *state)
|
||||
{
|
||||
*this= *state;
|
||||
}
|
||||
|
||||
void add_to_query_tables(TABLE_LIST *table)
|
||||
{
|
||||
*(table->prev_global= query_tables_last)= table;
|
||||
query_tables_last= &table->next_global;
|
||||
}
|
||||
bool requires_prelocking()
|
||||
{
|
||||
return test(query_tables_own_last);
|
||||
}
|
||||
void mark_as_requiring_prelocking(TABLE_LIST **tables_own_last)
|
||||
{
|
||||
query_tables_own_last= tables_own_last;
|
||||
}
|
||||
/* Return pointer to first not-own table in query-tables or 0 */
|
||||
TABLE_LIST* first_not_own_table()
|
||||
{
|
||||
return ( query_tables_own_last ? *query_tables_own_last : 0);
|
||||
}
|
||||
void chop_off_not_own_tables()
|
||||
{
|
||||
if (query_tables_own_last)
|
||||
{
|
||||
*query_tables_own_last= 0;
|
||||
query_tables_last= query_tables_own_last;
|
||||
query_tables_own_last= 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* The state of the lex parsing. This is saved in the THD struct */
|
||||
|
||||
typedef struct st_lex
|
||||
typedef struct st_lex : public Query_tables_list
|
||||
{
|
||||
uint yylineno,yytoklen; /* Simulate lex */
|
||||
LEX_YYSTYPE yylval;
|
||||
@@ -736,14 +822,6 @@ typedef struct st_lex
|
||||
gptr yacc_yyss,yacc_yyvs;
|
||||
THD *thd;
|
||||
CHARSET_INFO *charset;
|
||||
TABLE_LIST *query_tables; /* global list of all tables in this query */
|
||||
/*
|
||||
last element next_global of previous list (used only for list building
|
||||
during parsing and VIEW processing. This pointer could be invalid during
|
||||
processing of information schema tables(see get_schema_tables_result
|
||||
function)
|
||||
*/
|
||||
TABLE_LIST **query_tables_last;
|
||||
/* store original leaf_tables for INSERT SELECT and PS/SP */
|
||||
TABLE_LIST *leaf_tables_insert;
|
||||
/* Position (first character index) of SELECT of CREATE VIEW statement */
|
||||
@@ -876,20 +954,6 @@ typedef struct st_lex
|
||||
bool sp_lex_in_use; /* Keep track on lex usage in SPs for error handling */
|
||||
bool all_privileges;
|
||||
sp_pcontext *spcont;
|
||||
/* Set of stored routines called by statement. */
|
||||
HASH sroutines;
|
||||
/*
|
||||
List linking elements of 'sroutines' set. Allows you to add new elements
|
||||
to this set as you iterate through the list of existing elements.
|
||||
'sroutines_list_own_last' is pointer to ::next member of last element of
|
||||
this list which represents routine which is explicitly used by query.
|
||||
'sroutines_list_own_elements' number of explicitly used routines.
|
||||
We use these two members for restoring of 'sroutines_list' to the state
|
||||
in which it was right after query parsing.
|
||||
*/
|
||||
SQL_LIST sroutines_list;
|
||||
byte **sroutines_list_own_last;
|
||||
uint sroutines_list_own_elements;
|
||||
|
||||
st_sp_chistics sp_chistics;
|
||||
bool only_view; /* used for SHOW CREATE TABLE/VIEW */
|
||||
@@ -925,14 +989,6 @@ typedef struct st_lex
|
||||
*/
|
||||
const char *stmt_definition_begin;
|
||||
|
||||
/*
|
||||
If non-0 then indicates that query requires prelocking and points to
|
||||
next_global member of last own element in query table list (i.e. last
|
||||
table which was not added to it as part of preparation to prelocking).
|
||||
0 - indicates that this query does not need prelocking.
|
||||
*/
|
||||
TABLE_LIST **query_tables_own_last;
|
||||
|
||||
/*
|
||||
Pointers to part of LOAD DATA statement that should be rewritten
|
||||
during replication ("LOCAL 'filename' REPLACE INTO" part).
|
||||
@@ -945,7 +1001,7 @@ typedef struct st_lex
|
||||
|
||||
virtual ~st_lex()
|
||||
{
|
||||
hash_free(&sroutines);
|
||||
destroy_query_tables_list();
|
||||
}
|
||||
|
||||
inline void uncacheable(uint8 cause)
|
||||
@@ -970,11 +1026,6 @@ typedef struct st_lex
|
||||
TABLE_LIST *unlink_first_table(bool *link_to_local);
|
||||
void link_first_table_back(TABLE_LIST *first, bool link_to_local);
|
||||
void first_lists_tables_same();
|
||||
inline void add_to_query_tables(TABLE_LIST *table)
|
||||
{
|
||||
*(table->prev_global= query_tables_last)= table;
|
||||
query_tables_last= &table->next_global;
|
||||
}
|
||||
bool add_time_zone_tables_to_query_tables(THD *thd);
|
||||
|
||||
bool can_be_merged();
|
||||
@@ -1006,28 +1057,7 @@ typedef struct st_lex
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
inline bool requires_prelocking()
|
||||
{
|
||||
return test(query_tables_own_last);
|
||||
}
|
||||
inline void mark_as_requiring_prelocking(TABLE_LIST **tables_own_last)
|
||||
{
|
||||
query_tables_own_last= tables_own_last;
|
||||
}
|
||||
/* Return pointer to first not-own table in query-tables or 0 */
|
||||
TABLE_LIST* first_not_own_table()
|
||||
{
|
||||
return ( query_tables_own_last ? *query_tables_own_last : 0);
|
||||
}
|
||||
void chop_off_not_own_tables()
|
||||
{
|
||||
if (query_tables_own_last)
|
||||
{
|
||||
*query_tables_own_last= 0;
|
||||
query_tables_last= query_tables_own_last;
|
||||
query_tables_own_last= 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cleanup_after_one_table_open();
|
||||
|
||||
bool push_context(Name_resolution_context *context)
|
||||
@@ -1044,6 +1074,9 @@ typedef struct st_lex
|
||||
{
|
||||
return context_stack.head();
|
||||
}
|
||||
|
||||
void reset_n_backup_query_tables_list(Query_tables_list *backup);
|
||||
void restore_backup_query_tables_list(Query_tables_list *backup);
|
||||
} LEX;
|
||||
|
||||
struct st_lex_local: public st_lex
|
||||
|
||||
Reference in New Issue
Block a user