Commit 7c3df72d authored by Alexander Barkov's avatar Alexander Barkov

MDEV-13298 Change sp_head::m_chistics from a pointer to a structure

parent 31b35118
......@@ -1426,7 +1426,13 @@ Event_job_data::execute(THD *thd, bool drop)
sphead->m_flags|= sp_head::LOG_SLOW_STATEMENTS;
sphead->m_flags|= sp_head::LOG_GENERAL_LOG;
sphead->set_info(0, 0, &thd->lex->sp_chistics, sql_mode);
/*
construct_sp_sql() + parse_sql() set suid to SP_IS_NOT_SUID,
because we have the security context already set to the event
definer here. See more comments in construct_sp_sql().
*/
DBUG_ASSERT(sphead->suid() == SP_IS_NOT_SUID);
sphead->m_sql_mode= sql_mode;
sphead->set_creation_ctx(creation_ctx);
sphead->optimize();
......
......@@ -818,6 +818,8 @@ class Field: public Value_source
{ return store(ls->str, ls->length, cs); }
int store(const LEX_CSTRING *ls, CHARSET_INFO *cs)
{ return store(ls->str, ls->length, cs); }
int store(const LEX_CSTRING &ls, CHARSET_INFO *cs)
{ return store(ls.str, ls.length, cs); }
virtual double val_real(void)=0;
virtual longlong val_int(void)=0;
virtual bool val_bool(void)= 0;
......
......@@ -6316,7 +6316,7 @@ Item_func_sp::init_result_field(THD *thd)
bool Item_func_sp::is_expensive()
{
return !m_sp->m_chistics->detistic ||
return !m_sp->detistic() ||
current_thd->locked_tables_mode < LTM_LOCK_TABLES;
}
......@@ -6390,8 +6390,8 @@ Item_func_sp::execute_impl(THD *thd)
Sub_statement_state statement_state;
Security_context *save_security_ctx= thd->security_ctx;
enum enum_sp_data_access access=
(m_sp->m_chistics->daccess == SP_DEFAULT_ACCESS) ?
SP_DEFAULT_ACCESS_MAPPING : m_sp->m_chistics->daccess;
(m_sp->daccess() == SP_DEFAULT_ACCESS) ?
SP_DEFAULT_ACCESS_MAPPING : m_sp->daccess();
DBUG_ENTER("Item_func_sp::execute_impl");
......@@ -6408,7 +6408,7 @@ Item_func_sp::execute_impl(THD *thd)
statement-based replication (SBR) is active.
*/
if (!m_sp->m_chistics->detistic && !trust_function_creators &&
if (!m_sp->detistic() && !trust_function_creators &&
(access == SP_CONTAINS_SQL || access == SP_MODIFIES_SQL_DATA) &&
(mysql_bin_log.is_open() &&
thd->variables.binlog_format == BINLOG_FORMAT_STMT))
......@@ -6590,7 +6590,7 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
#endif /* ! NO_EMBEDDED_ACCESS_CHECKS */
}
if (!m_sp->m_chistics->detistic)
if (!m_sp->detistic())
{
used_tables_cache |= RAND_TABLE_BIT;
const_item_cache= FALSE;
......@@ -6604,7 +6604,7 @@ void Item_func_sp::update_used_tables()
{
Item_func::update_used_tables();
if (!m_sp->m_chistics->detistic)
if (!m_sp->detistic())
{
used_tables_cache |= RAND_TABLE_BIT;
const_item_cache= FALSE;
......
This diff is collapsed.
......@@ -240,7 +240,7 @@ bool show_create_sp(THD *thd, String *buf,
const char *params, ulong paramslen,
const char *returns, ulong returnslen,
const char *body, ulong bodylen,
const st_sp_chistics *chistics,
const st_sp_chistics &chistics,
const LEX_CSTRING *definer_user,
const LEX_CSTRING *definer_host,
sql_mode_t sql_mode);
......
......@@ -559,6 +559,8 @@ sp_head::sp_head(stored_procedure_type type)
m_sp_cache_version(0),
m_creation_ctx(0),
unsafe_flags(0),
m_created(0),
m_modified(0),
m_recursion_level(0),
m_next_cached_sp(0),
m_param_begin(NULL),
......@@ -1408,7 +1410,7 @@ set_routine_security_ctx(THD *thd, sp_head *sp, bool is_proc,
Security_context **save_ctx)
{
*save_ctx= 0;
if (sp->m_chistics->suid != SP_IS_NOT_SUID &&
if (sp->suid() != SP_IS_NOT_SUID &&
sp->m_security_ctx.change_security_context(thd, &sp->m_definer.user,
&sp->m_definer.host,
&sp->m_db,
......@@ -1520,7 +1522,7 @@ sp_head::execute_trigger(THD *thd,
Security_context *save_ctx= NULL;
if (m_chistics->suid != SP_IS_NOT_SUID &&
if (suid() != SP_IS_NOT_SUID &&
m_security_ctx.change_security_context(thd,
&m_definer.user,
&m_definer.host,
......@@ -2432,20 +2434,26 @@ sp_head::sp_add_instr_cpush_for_cursors(THD *thd, sp_pcontext *pcontext)
}
void
sp_head::set_chistics(const st_sp_chistics &chistics)
{
m_chistics.set(chistics);
if (m_chistics.comment.length == 0)
m_chistics.comment.str= 0;
else
m_chistics.comment.str= strmake_root(mem_root,
m_chistics.comment.str,
m_chistics.comment.length);
}
void
sp_head::set_info(longlong created, longlong modified,
const st_sp_chistics *chistics, sql_mode_t sql_mode)
const st_sp_chistics &chistics, sql_mode_t sql_mode)
{
m_created= created;
m_modified= modified;
m_chistics= (st_sp_chistics *) memdup_root(mem_root, (char*) chistics,
sizeof(*chistics));
if (m_chistics->comment.length == 0)
m_chistics->comment.str= 0;
else
m_chistics->comment.str= strmake_root(mem_root,
m_chistics->comment.str,
m_chistics->comment.length);
set_chistics(chistics);
m_sql_mode= sql_mode;
}
......
......@@ -179,7 +179,15 @@ class sp_head :private Query_arena,
Column_definition m_return_field_def; /**< This is used for FUNCTIONs only. */
const char *m_tmp_query; ///< Temporary pointer to sub query string
st_sp_chistics *m_chistics;
private:
/*
Private to guarantee that m_chistics.comment is properly set to:
- a string which is alloced on this->mem_root
- or (NULL,0)
set_chistics() makes sure this.
*/
Sp_chistics m_chistics;
public:
sql_mode_t m_sql_mode; ///< For SHOW CREATE and execution
bool m_explicit_name; /**< Prepend the db name? */
LEX_CSTRING m_qname; ///< db.name
......@@ -189,6 +197,12 @@ class sp_head :private Query_arena,
LEX_CSTRING m_defstr;
AUTHID m_definer;
const st_sp_chistics &chistics() const { return m_chistics; }
const LEX_CSTRING &comment() const { return m_chistics.comment; }
void set_suid(enum_sp_suid_behaviour suid) { m_chistics.suid= suid; }
enum_sp_suid_behaviour suid() const { return m_chistics.suid; }
bool detistic() const { return m_chistics.detistic; }
enum_sp_data_access daccess() const { return m_chistics.daccess; }
/**
Is this routine being executed?
*/
......@@ -671,8 +685,9 @@ class sp_head :private Query_arena,
m_flags|= sp_head::HAS_COLUMN_TYPE_REFS;
}
void set_chistics(const st_sp_chistics &chistics);
void set_info(longlong created, longlong modified,
const st_sp_chistics *chistics, sql_mode_t sql_mode);
const st_sp_chistics &chistics, sql_mode_t sql_mode);
void set_definer(const char *definer, uint definerlen);
void set_definer(const LEX_CSTRING *user_name, const LEX_CSTRING *host_name)
......
......@@ -5831,10 +5831,9 @@ sp_head *LEX::make_sp_head(THD *thd, sp_name *name,
sp->init(this);
if (name)
sp->init_sp_name(thd, name);
sp->m_chistics= &sp_chistics;
sphead= sp;
}
bzero(&sp_chistics, sizeof(sp_chistics));
sp_chistics.init();
return sp;
}
......@@ -6124,7 +6123,7 @@ bool LEX::maybe_start_compound_statement(THD *thd)
{
if (!make_sp_head(thd, NULL, TYPE_ENUM_PROCEDURE))
return true;
sp_chistics.suid= SP_IS_NOT_SUID;
sphead->set_suid(SP_IS_NOT_SUID);
sphead->set_body_start(thd, thd->m_parser_state->m_lip.get_cpp_ptr());
}
return false;
......
......@@ -1285,9 +1285,17 @@ struct st_sp_chistics
enum enum_sp_suid_behaviour suid;
bool detistic;
enum enum_sp_data_access daccess;
void init() { bzero(this, sizeof(*this)); }
void set(const st_sp_chistics &other) { *this= other; }
};
class Sp_chistics: public st_sp_chistics
{
public:
Sp_chistics() { init(); }
};
struct st_trg_chistics: public st_trg_execution_order
{
......
......@@ -2710,7 +2710,7 @@ bool sp_process_definer(THD *thd)
DBUG_RETURN(TRUE);
if (thd->slave_thread && lex->sphead)
lex->sphead->m_chistics->suid= SP_IS_NOT_SUID;
lex->sphead->set_suid(SP_IS_NOT_SUID);
}
else
{
......
......@@ -663,7 +663,7 @@ static void build_trig_stmt_query(THD *thd, TABLE_LIST *tables,
if (lex->create_info.or_replace())
stmt_query->append(STRING_WITH_LEN("OR REPLACE "));
if (lex->sphead->m_chistics->suid != SP_IS_NOT_SUID)
if (lex->sphead->suid() != SP_IS_NOT_SUID)
{
/* SUID trigger */
lex->definer->set_lex_string(trg_definer, trg_definer_holder);
......@@ -1431,7 +1431,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
lex.set_trg_event_type_for_tables();
if (lex.sphead)
lex.sphead->set_info(0, 0, &lex.sp_chistics, sql_mode);
lex.sphead->m_sql_mode= sql_mode;
if (unlikely(!(trigger= (new (&table->mem_root)
Trigger(trigger_list, lex.sphead)))))
......@@ -1489,7 +1489,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
continue;
}
sp->set_info(0, 0, &lex.sp_chistics, sql_mode);
sp->m_sql_mode= sql_mode;
sp->set_creation_ctx(creation_ctx);
if (!trg_definer || !trg_definer->length)
......@@ -1519,7 +1519,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
authorization of the invoker.
*/
sp->m_chistics->suid= SP_IS_NOT_SUID;
sp->set_suid(SP_IS_NOT_SUID);
}
else
{
......@@ -1691,7 +1691,7 @@ void Trigger::get_trigger_info(LEX_CSTRING *trigger_stmt,
}
*trigger_body= body->m_body_utf8;
if (body->m_chistics->suid == SP_IS_NOT_SUID)
if (body->suid() == SP_IS_NOT_SUID)
{
*definer= empty_lex_str;
}
......
......@@ -2950,7 +2950,6 @@ ev_sql_stmt:
TYPE_ENUM_PROCEDURE))
MYSQL_YYABORT;
lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
}
sp_proc_stmt
......@@ -7230,7 +7229,7 @@ alter:
if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE"));
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
lex->sp_chistics.init();
}
sp_a_chistics
{
......@@ -7245,7 +7244,7 @@ alter:
if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"));
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
lex->sp_chistics.init();
}
sp_a_chistics
{
......@@ -16674,6 +16673,7 @@ sf_tail:
LEX *lex= thd->lex;
Lex_input_stream *lip= YYLIP;
lex->sphead->set_chistics(lex->sp_chistics);
lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
}
sp_proc_stmt_in_returns_clause
......@@ -16705,6 +16705,7 @@ sp_tail:
sp_parenthesized_pdparam_list
sp_c_chistics
{
Lex->sphead->set_chistics(Lex->sp_chistics);
Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
}
sp_proc_stmt
......
......@@ -2391,7 +2391,6 @@ ev_sql_stmt:
TYPE_ENUM_PROCEDURE))
MYSQL_YYABORT;
lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
}
sp_proc_stmt
......@@ -7211,7 +7210,7 @@ alter:
if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE"));
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
lex->sp_chistics.init();
}
sp_a_chistics
{
......@@ -7226,7 +7225,7 @@ alter:
if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION"));
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
lex->sp_chistics.init();
}
sp_a_chistics
{
......@@ -16913,6 +16912,7 @@ sf_tail:
LEX *lex= thd->lex;
Lex_input_stream *lip= YYLIP;
lex->sphead->set_chistics(lex->sp_chistics);
lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
}
sp_tail_is
......@@ -16947,6 +16947,7 @@ sp_tail:
opt_sp_parenthesized_pdparam_list
sp_c_chistics
{
Lex->sphead->set_chistics(Lex->sp_chistics);
Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
}
sp_tail_is
......
......@@ -2253,7 +2253,7 @@ static int wsrep_create_sp(THD *thd, uchar** buf, size_t* buf_len)
sp->m_params.str, sp->m_params.length,
retstr.c_ptr(), retstr.length(),
sp->m_body.str, sp->m_body.length,
sp->m_chistics, &(thd->lex->definer->user),
sp->chistics(), &(thd->lex->definer->user),
&(thd->lex->definer->host),
saved_mode))
{
......
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