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

This commit is contained in:
Alexander Barkov 2017-07-12 11:57:47 +04:00
parent 31b3511849
commit 7c3df72d0a
14 changed files with 110 additions and 76 deletions

View File

@ -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_SLOW_STATEMENTS;
sphead->m_flags|= sp_head::LOG_GENERAL_LOG; 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->set_creation_ctx(creation_ctx);
sphead->optimize(); sphead->optimize();

View File

@ -818,6 +818,8 @@ public:
{ return store(ls->str, ls->length, cs); } { return store(ls->str, ls->length, cs); }
int store(const LEX_CSTRING *ls, CHARSET_INFO *cs) int store(const LEX_CSTRING *ls, CHARSET_INFO *cs)
{ return store(ls->str, ls->length, 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 double val_real(void)=0;
virtual longlong val_int(void)=0; virtual longlong val_int(void)=0;
virtual bool val_bool(void)= 0; virtual bool val_bool(void)= 0;

View File

@ -6316,7 +6316,7 @@ Item_func_sp::init_result_field(THD *thd)
bool Item_func_sp::is_expensive() bool Item_func_sp::is_expensive()
{ {
return !m_sp->m_chistics->detistic || return !m_sp->detistic() ||
current_thd->locked_tables_mode < LTM_LOCK_TABLES; current_thd->locked_tables_mode < LTM_LOCK_TABLES;
} }
@ -6390,8 +6390,8 @@ Item_func_sp::execute_impl(THD *thd)
Sub_statement_state statement_state; Sub_statement_state statement_state;
Security_context *save_security_ctx= thd->security_ctx; Security_context *save_security_ctx= thd->security_ctx;
enum enum_sp_data_access access= enum enum_sp_data_access access=
(m_sp->m_chistics->daccess == SP_DEFAULT_ACCESS) ? (m_sp->daccess() == SP_DEFAULT_ACCESS) ?
SP_DEFAULT_ACCESS_MAPPING : m_sp->m_chistics->daccess; SP_DEFAULT_ACCESS_MAPPING : m_sp->daccess();
DBUG_ENTER("Item_func_sp::execute_impl"); DBUG_ENTER("Item_func_sp::execute_impl");
@ -6408,7 +6408,7 @@ Item_func_sp::execute_impl(THD *thd)
statement-based replication (SBR) is active. 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) && (access == SP_CONTAINS_SQL || access == SP_MODIFIES_SQL_DATA) &&
(mysql_bin_log.is_open() && (mysql_bin_log.is_open() &&
thd->variables.binlog_format == BINLOG_FORMAT_STMT)) 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 */ #endif /* ! NO_EMBEDDED_ACCESS_CHECKS */
} }
if (!m_sp->m_chistics->detistic) if (!m_sp->detistic())
{ {
used_tables_cache |= RAND_TABLE_BIT; used_tables_cache |= RAND_TABLE_BIT;
const_item_cache= FALSE; const_item_cache= FALSE;
@ -6604,7 +6604,7 @@ void Item_func_sp::update_used_tables()
{ {
Item_func::update_used_tables(); Item_func::update_used_tables();
if (!m_sp->m_chistics->detistic) if (!m_sp->detistic())
{ {
used_tables_cache |= RAND_TABLE_BIT; used_tables_cache |= RAND_TABLE_BIT;
const_item_cache= FALSE; const_item_cache= FALSE;

View File

@ -487,9 +487,8 @@ db_find_routine_aux(THD *thd, stored_procedure_type type, const sp_name *name,
*/ */
if (name->m_name.length > table->field[1]->field_length) if (name->m_name.length > table->field[1]->field_length)
DBUG_RETURN(SP_KEY_NOT_FOUND); DBUG_RETURN(SP_KEY_NOT_FOUND);
table->field[0]->store(name->m_db.str, name->m_db.length, &my_charset_bin); table->field[0]->store(name->m_db, &my_charset_bin);
table->field[1]->store(name->m_name.str, name->m_name.length, table->field[1]->store(name->m_name, &my_charset_bin);
&my_charset_bin);
table->field[2]->store((longlong) type, TRUE); table->field[2]->store((longlong) type, TRUE);
key_copy(key, table->record[0], table->key_info, key_copy(key, table->record[0], table->key_info,
table->key_info->key_length); table->key_info->key_length);
@ -533,7 +532,7 @@ db_find_routine(THD *thd, stored_procedure_type type, const sp_name *name,
const char *definer; const char *definer;
longlong created; longlong created;
longlong modified; longlong modified;
st_sp_chistics chistics; Sp_chistics chistics;
char *ptr; char *ptr;
uint length; uint length;
char buff[65]; char buff[65];
@ -567,7 +566,6 @@ db_find_routine(THD *thd, stored_procedure_type type, const sp_name *name,
goto done; goto done;
} }
bzero((char *)&chistics, sizeof(chistics));
if ((ptr= get_field(thd->mem_root, if ((ptr= get_field(thd->mem_root,
table->field[MYSQL_PROC_FIELD_ACCESS])) == NULL) table->field[MYSQL_PROC_FIELD_ACCESS])) == NULL)
{ {
@ -849,7 +847,7 @@ db_load_routine(THD *thd, stored_procedure_type type,
params, strlen(params), params, strlen(params),
returns, strlen(returns), returns, strlen(returns),
body, strlen(body), body, strlen(body),
&chistics, definer_user_name, definer_host_name, chistics, definer_user_name, definer_host_name,
sql_mode)) sql_mode))
{ {
ret= SP_INTERNAL_ERROR; ret= SP_INTERNAL_ERROR;
@ -902,7 +900,7 @@ db_load_routine(THD *thd, stored_procedure_type type,
} }
(*sphp)->set_definer(definer_user_name, definer_host_name); (*sphp)->set_definer(definer_user_name, definer_host_name);
(*sphp)->set_info(created, modified, &chistics, sql_mode); (*sphp)->set_info(created, modified, chistics, sql_mode);
(*sphp)->set_creation_ctx(creation_ctx); (*sphp)->set_creation_ctx(creation_ctx);
(*sphp)->optimize(); (*sphp)->optimize();
/* /*
@ -1139,11 +1137,11 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
store_failed= store_failed=
table->field[MYSQL_PROC_FIELD_DB]-> table->field[MYSQL_PROC_FIELD_DB]->
store(sp->m_db.str, sp->m_db.length, system_charset_info); store(sp->m_db, system_charset_info);
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_NAME]-> table->field[MYSQL_PROC_FIELD_NAME]->
store(sp->m_name.str, sp->m_name.length, system_charset_info); store(sp->m_name, system_charset_info);
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_MYSQL_TYPE]-> table->field[MYSQL_PROC_MYSQL_TYPE]->
@ -1151,29 +1149,29 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_SPECIFIC_NAME]-> table->field[MYSQL_PROC_FIELD_SPECIFIC_NAME]->
store(sp->m_name.str, sp->m_name.length, system_charset_info); store(sp->m_name, system_charset_info);
if (sp->m_chistics->daccess != SP_DEFAULT_ACCESS) if (sp->daccess() != SP_DEFAULT_ACCESS)
{ {
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_ACCESS]-> table->field[MYSQL_PROC_FIELD_ACCESS]->
store((longlong)sp->m_chistics->daccess, TRUE); store((longlong)sp->daccess(), TRUE);
} }
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_DETERMINISTIC]-> table->field[MYSQL_PROC_FIELD_DETERMINISTIC]->
store((longlong)(sp->m_chistics->detistic ? 1 : 2), TRUE); store((longlong)(sp->detistic() ? 1 : 2), TRUE);
if (sp->m_chistics->suid != SP_IS_DEFAULT_SUID) if (sp->suid() != SP_IS_DEFAULT_SUID)
{ {
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]-> table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
store((longlong)sp->m_chistics->suid, TRUE); store((longlong)sp->suid(), TRUE);
} }
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_PARAM_LIST]-> table->field[MYSQL_PROC_FIELD_PARAM_LIST]->
store(sp->m_params.str, sp->m_params.length, system_charset_info); store(sp->m_params, system_charset_info);
if (sp->m_type == TYPE_ENUM_FUNCTION) if (sp->m_type == TYPE_ENUM_FUNCTION)
{ {
@ -1186,11 +1184,11 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_BODY]-> table->field[MYSQL_PROC_FIELD_BODY]->
store(sp->m_body.str, sp->m_body.length, system_charset_info); store(sp->m_body, system_charset_info);
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_DEFINER]-> table->field[MYSQL_PROC_FIELD_DEFINER]->
store(definer.str, definer.length, system_charset_info); store(definer, system_charset_info);
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_CREATED])->set_time(); ((Field_timestamp *)table->field[MYSQL_PROC_FIELD_CREATED])->set_time();
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time(); ((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time();
@ -1199,26 +1197,25 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
table->field[MYSQL_PROC_FIELD_SQL_MODE]-> table->field[MYSQL_PROC_FIELD_SQL_MODE]->
store((longlong)saved_mode, TRUE); store((longlong)saved_mode, TRUE);
if (sp->m_chistics->comment.str) if (sp->comment().str)
{ {
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_COMMENT]-> table->field[MYSQL_PROC_FIELD_COMMENT]->
store(sp->m_chistics->comment.str, sp->m_chistics->comment.length, store(sp->comment(), system_charset_info);
system_charset_info);
} }
if ((sp->m_type == TYPE_ENUM_FUNCTION) && if ((sp->m_type == TYPE_ENUM_FUNCTION) &&
!trust_function_creators && mysql_bin_log.is_open()) !trust_function_creators && mysql_bin_log.is_open())
{ {
if (!sp->m_chistics->detistic) if (!sp->detistic())
{ {
/* /*
Note that this test is not perfect; one could use Note that this test is not perfect; one could use
a non-deterministic read-only function in an update statement. a non-deterministic read-only function in an update statement.
*/ */
enum enum_sp_data_access access= enum enum_sp_data_access access=
(sp->m_chistics->daccess == SP_DEFAULT_ACCESS) ? (sp->daccess() == SP_DEFAULT_ACCESS) ?
SP_DEFAULT_ACCESS_MAPPING : sp->m_chistics->daccess; SP_DEFAULT_ACCESS_MAPPING : sp->daccess();
if (access == SP_CONTAINS_SQL || if (access == SP_CONTAINS_SQL ||
access == SP_MODIFIES_SQL_DATA) access == SP_MODIFIES_SQL_DATA)
{ {
@ -1255,7 +1252,7 @@ sp_create_routine(THD *thd, stored_procedure_type type, sp_head *sp)
table->field[MYSQL_PROC_FIELD_BODY_UTF8]->set_notnull(); table->field[MYSQL_PROC_FIELD_BODY_UTF8]->set_notnull();
store_failed= store_failed || store_failed= store_failed ||
table->field[MYSQL_PROC_FIELD_BODY_UTF8]->store( table->field[MYSQL_PROC_FIELD_BODY_UTF8]->store(
sp->m_body_utf8.str, sp->m_body_utf8.length, system_charset_info); sp->m_body_utf8, system_charset_info);
if (store_failed) if (store_failed)
{ {
@ -1291,7 +1288,7 @@ log:
sp->m_params.str, sp->m_params.length, sp->m_params.str, sp->m_params.length,
retstr.ptr(), retstr.length(), retstr.ptr(), retstr.length(),
sp->m_body.str, sp->m_body.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), &(thd->lex->definer->host),
saved_mode)) saved_mode))
{ {
@ -1448,8 +1445,7 @@ sp_update_routine(THD *thd, stored_procedure_type type, const sp_name *name,
table->field[MYSQL_PROC_FIELD_ACCESS]-> table->field[MYSQL_PROC_FIELD_ACCESS]->
store((longlong)chistics->daccess, TRUE); store((longlong)chistics->daccess, TRUE);
if (chistics->comment.str) if (chistics->comment.str)
table->field[MYSQL_PROC_FIELD_COMMENT]->store(chistics->comment.str, table->field[MYSQL_PROC_FIELD_COMMENT]->store(chistics->comment,
chistics->comment.length,
system_charset_info); system_charset_info);
if ((ret= table->file->ha_update_row(table->record[1],table->record[0])) && if ((ret= table->file->ha_update_row(table->record[1],table->record[0])) &&
ret != HA_ERR_RECORD_IS_THE_SAME) ret != HA_ERR_RECORD_IS_THE_SAME)
@ -1792,7 +1788,7 @@ sp_find_routine(THD *thd, stored_procedure_type type, const sp_name *name,
} }
if (db_load_routine(thd, type, name, &new_sp, if (db_load_routine(thd, type, name, &new_sp,
sp->m_sql_mode, sp->m_params.str, returns, sp->m_sql_mode, sp->m_params.str, returns,
sp->m_body.str, *sp->m_chistics, sp->m_body.str, sp->chistics(),
&sp->m_definer.user, &sp->m_definer.host, &sp->m_definer.user, &sp->m_definer.host,
sp->m_created, sp->m_modified, sp->m_created, sp->m_modified,
sp->get_creation_ctx()) == SP_OK) sp->get_creation_ctx()) == SP_OK)
@ -2201,7 +2197,7 @@ show_create_sp(THD *thd, String *buf,
const char *params, ulong paramslen, const char *params, ulong paramslen,
const char *returns, ulong returnslen, const char *returns, ulong returnslen,
const char *body, ulong bodylen, const char *body, ulong bodylen,
const st_sp_chistics *chistics, const st_sp_chistics &chistics,
const LEX_CSTRING *definer_user, const LEX_CSTRING *definer_user,
const LEX_CSTRING *definer_host, const LEX_CSTRING *definer_host,
sql_mode_t sql_mode) sql_mode_t sql_mode)
@ -2209,7 +2205,7 @@ show_create_sp(THD *thd, String *buf,
sql_mode_t old_sql_mode= thd->variables.sql_mode; sql_mode_t old_sql_mode= thd->variables.sql_mode;
/* Make some room to begin with */ /* Make some room to begin with */
if (buf->alloc(100 + dblen + 1 + namelen + paramslen + returnslen + bodylen + if (buf->alloc(100 + dblen + 1 + namelen + paramslen + returnslen + bodylen +
chistics->comment.length + 10 /* length of " DEFINER= "*/ + chistics.comment.length + 10 /* length of " DEFINER= "*/ +
USER_HOST_BUFF_SIZE)) USER_HOST_BUFF_SIZE))
return FALSE; return FALSE;
@ -2243,7 +2239,7 @@ show_create_sp(THD *thd, String *buf,
buf->append(returns, returnslen); buf->append(returns, returnslen);
} }
buf->append('\n'); buf->append('\n');
switch (chistics->daccess) { switch (chistics.daccess) {
case SP_NO_SQL: case SP_NO_SQL:
buf->append(STRING_WITH_LEN(" NO SQL\n")); buf->append(STRING_WITH_LEN(" NO SQL\n"));
break; break;
@ -2258,14 +2254,14 @@ show_create_sp(THD *thd, String *buf,
/* Do nothing */ /* Do nothing */
break; break;
} }
if (chistics->detistic) if (chistics.detistic)
buf->append(STRING_WITH_LEN(" DETERMINISTIC\n")); buf->append(STRING_WITH_LEN(" DETERMINISTIC\n"));
if (chistics->suid == SP_IS_NOT_SUID) if (chistics.suid == SP_IS_NOT_SUID)
buf->append(STRING_WITH_LEN(" SQL SECURITY INVOKER\n")); buf->append(STRING_WITH_LEN(" SQL SECURITY INVOKER\n"));
if (chistics->comment.length) if (chistics.comment.length)
{ {
buf->append(STRING_WITH_LEN(" COMMENT ")); buf->append(STRING_WITH_LEN(" COMMENT "));
append_unescaped(buf, chistics->comment.str, chistics->comment.length); append_unescaped(buf, chistics.comment.str, chistics.comment.length);
buf->append('\n'); buf->append('\n');
} }
buf->append(body, bodylen); buf->append(body, bodylen);
@ -2303,7 +2299,6 @@ sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db,
{ {
const char *sp_body; const char *sp_body;
String defstr; String defstr;
struct st_sp_chistics sp_chistics;
const LEX_CSTRING definer_user= {STRING_WITH_LEN("")}; const LEX_CSTRING definer_user= {STRING_WITH_LEN("")};
const LEX_CSTRING definer_host= {STRING_WITH_LEN("")}; const LEX_CSTRING definer_host= {STRING_WITH_LEN("")};
LEX_CSTRING sp_db_str; LEX_CSTRING sp_db_str;
@ -2326,7 +2321,6 @@ sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db,
Stored_program_creation_ctx *creation_ctx= Stored_program_creation_ctx *creation_ctx=
Stored_routine_creation_ctx::load_from_db(thd, &sp_name_obj, proc_table); Stored_routine_creation_ctx::load_from_db(thd, &sp_name_obj, proc_table);
sp_body= (type == TYPE_ENUM_FUNCTION ? "RETURN NULL" : "BEGIN END"); sp_body= (type == TYPE_ENUM_FUNCTION ? "RETURN NULL" : "BEGIN END");
bzero((char*) &sp_chistics, sizeof(sp_chistics));
defstr.set_charset(creation_ctx->get_client_cs()); defstr.set_charset(creation_ctx->get_client_cs());
if (!show_create_sp(thd, &defstr, type, if (!show_create_sp(thd, &defstr, type,
sp_db_str.str, sp_db_str.length, sp_db_str.str, sp_db_str.length,
@ -2334,7 +2328,7 @@ sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db,
params, strlen(params), params, strlen(params),
returns, strlen(returns), returns, strlen(returns),
sp_body, strlen(sp_body), sp_body, strlen(sp_body),
&sp_chistics, &definer_user, &definer_host, sql_mode)) Sp_chistics(), &definer_user, &definer_host, sql_mode))
return 0; return 0;
thd->lex= &newlex; thd->lex= &newlex;

View File

@ -240,7 +240,7 @@ bool show_create_sp(THD *thd, String *buf,
const char *params, ulong paramslen, const char *params, ulong paramslen,
const char *returns, ulong returnslen, const char *returns, ulong returnslen,
const char *body, ulong bodylen, const char *body, ulong bodylen,
const st_sp_chistics *chistics, const st_sp_chistics &chistics,
const LEX_CSTRING *definer_user, const LEX_CSTRING *definer_user,
const LEX_CSTRING *definer_host, const LEX_CSTRING *definer_host,
sql_mode_t sql_mode); sql_mode_t sql_mode);

View File

@ -559,6 +559,8 @@ sp_head::sp_head(stored_procedure_type type)
m_sp_cache_version(0), m_sp_cache_version(0),
m_creation_ctx(0), m_creation_ctx(0),
unsafe_flags(0), unsafe_flags(0),
m_created(0),
m_modified(0),
m_recursion_level(0), m_recursion_level(0),
m_next_cached_sp(0), m_next_cached_sp(0),
m_param_begin(NULL), m_param_begin(NULL),
@ -1408,7 +1410,7 @@ set_routine_security_ctx(THD *thd, sp_head *sp, bool is_proc,
Security_context **save_ctx) Security_context **save_ctx)
{ {
*save_ctx= 0; *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_security_ctx.change_security_context(thd, &sp->m_definer.user,
&sp->m_definer.host, &sp->m_definer.host,
&sp->m_db, &sp->m_db,
@ -1520,7 +1522,7 @@ sp_head::execute_trigger(THD *thd,
Security_context *save_ctx= NULL; 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_security_ctx.change_security_context(thd,
&m_definer.user, &m_definer.user,
&m_definer.host, &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 void
sp_head::set_info(longlong created, longlong modified, 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_created= created;
m_modified= modified; m_modified= modified;
m_chistics= (st_sp_chistics *) memdup_root(mem_root, (char*) chistics, set_chistics(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);
m_sql_mode= sql_mode; m_sql_mode= sql_mode;
} }

View File

@ -179,7 +179,15 @@ public:
Column_definition m_return_field_def; /**< This is used for FUNCTIONs only. */ Column_definition m_return_field_def; /**< This is used for FUNCTIONs only. */
const char *m_tmp_query; ///< Temporary pointer to sub query string 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 sql_mode_t m_sql_mode; ///< For SHOW CREATE and execution
bool m_explicit_name; /**< Prepend the db name? */ bool m_explicit_name; /**< Prepend the db name? */
LEX_CSTRING m_qname; ///< db.name LEX_CSTRING m_qname; ///< db.name
@ -189,6 +197,12 @@ public:
LEX_CSTRING m_defstr; LEX_CSTRING m_defstr;
AUTHID m_definer; 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? Is this routine being executed?
*/ */
@ -671,8 +685,9 @@ public:
m_flags|= sp_head::HAS_COLUMN_TYPE_REFS; m_flags|= sp_head::HAS_COLUMN_TYPE_REFS;
} }
void set_chistics(const st_sp_chistics &chistics);
void set_info(longlong created, longlong modified, 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 char *definer, uint definerlen);
void set_definer(const LEX_CSTRING *user_name, const LEX_CSTRING *host_name) void set_definer(const LEX_CSTRING *user_name, const LEX_CSTRING *host_name)

View File

@ -5831,10 +5831,9 @@ sp_head *LEX::make_sp_head(THD *thd, sp_name *name,
sp->init(this); sp->init(this);
if (name) if (name)
sp->init_sp_name(thd, name); sp->init_sp_name(thd, name);
sp->m_chistics= &sp_chistics;
sphead= sp; sphead= sp;
} }
bzero(&sp_chistics, sizeof(sp_chistics)); sp_chistics.init();
return sp; return sp;
} }
@ -6124,7 +6123,7 @@ bool LEX::maybe_start_compound_statement(THD *thd)
{ {
if (!make_sp_head(thd, NULL, TYPE_ENUM_PROCEDURE)) if (!make_sp_head(thd, NULL, TYPE_ENUM_PROCEDURE))
return true; 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()); sphead->set_body_start(thd, thd->m_parser_state->m_lip.get_cpp_ptr());
} }
return false; return false;

View File

@ -1285,9 +1285,17 @@ struct st_sp_chistics
enum enum_sp_suid_behaviour suid; enum enum_sp_suid_behaviour suid;
bool detistic; bool detistic;
enum enum_sp_data_access daccess; 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 struct st_trg_chistics: public st_trg_execution_order
{ {

View File

@ -2710,7 +2710,7 @@ bool sp_process_definer(THD *thd)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
if (thd->slave_thread && lex->sphead) if (thd->slave_thread && lex->sphead)
lex->sphead->m_chistics->suid= SP_IS_NOT_SUID; lex->sphead->set_suid(SP_IS_NOT_SUID);
} }
else else
{ {

View File

@ -663,7 +663,7 @@ static void build_trig_stmt_query(THD *thd, TABLE_LIST *tables,
if (lex->create_info.or_replace()) if (lex->create_info.or_replace())
stmt_query->append(STRING_WITH_LEN("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 */ /* SUID trigger */
lex->definer->set_lex_string(trg_definer, trg_definer_holder); 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(); lex.set_trg_event_type_for_tables();
if (lex.sphead) 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) if (unlikely(!(trigger= (new (&table->mem_root)
Trigger(trigger_list, lex.sphead))))) Trigger(trigger_list, lex.sphead)))))
@ -1489,7 +1489,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
continue; continue;
} }
sp->set_info(0, 0, &lex.sp_chistics, sql_mode); sp->m_sql_mode= sql_mode;
sp->set_creation_ctx(creation_ctx); sp->set_creation_ctx(creation_ctx);
if (!trg_definer || !trg_definer->length) 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. authorization of the invoker.
*/ */
sp->m_chistics->suid= SP_IS_NOT_SUID; sp->set_suid(SP_IS_NOT_SUID);
} }
else else
{ {
@ -1691,7 +1691,7 @@ void Trigger::get_trigger_info(LEX_CSTRING *trigger_stmt,
} }
*trigger_body= body->m_body_utf8; *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; *definer= empty_lex_str;
} }

View File

@ -2950,7 +2950,6 @@ ev_sql_stmt:
TYPE_ENUM_PROCEDURE)) TYPE_ENUM_PROCEDURE))
MYSQL_YYABORT; MYSQL_YYABORT;
lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
lex->sphead->set_body_start(thd, lip->get_cpp_ptr()); lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
} }
sp_proc_stmt sp_proc_stmt
@ -7230,7 +7229,7 @@ alter:
if (lex->sphead) if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE")); 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 sp_a_chistics
{ {
@ -7245,7 +7244,7 @@ alter:
if (lex->sphead) if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION")); 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 sp_a_chistics
{ {
@ -16674,6 +16673,7 @@ sf_tail:
LEX *lex= thd->lex; LEX *lex= thd->lex;
Lex_input_stream *lip= YYLIP; Lex_input_stream *lip= YYLIP;
lex->sphead->set_chistics(lex->sp_chistics);
lex->sphead->set_body_start(thd, lip->get_cpp_tok_start()); lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
} }
sp_proc_stmt_in_returns_clause sp_proc_stmt_in_returns_clause
@ -16705,6 +16705,7 @@ sp_tail:
sp_parenthesized_pdparam_list sp_parenthesized_pdparam_list
sp_c_chistics sp_c_chistics
{ {
Lex->sphead->set_chistics(Lex->sp_chistics);
Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
} }
sp_proc_stmt sp_proc_stmt

View File

@ -2391,7 +2391,6 @@ ev_sql_stmt:
TYPE_ENUM_PROCEDURE)) TYPE_ENUM_PROCEDURE))
MYSQL_YYABORT; MYSQL_YYABORT;
lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
lex->sphead->set_body_start(thd, lip->get_cpp_ptr()); lex->sphead->set_body_start(thd, lip->get_cpp_ptr());
} }
sp_proc_stmt sp_proc_stmt
@ -7211,7 +7210,7 @@ alter:
if (lex->sphead) if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "PROCEDURE")); 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 sp_a_chistics
{ {
@ -7226,7 +7225,7 @@ alter:
if (lex->sphead) if (lex->sphead)
my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION")); 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 sp_a_chistics
{ {
@ -16913,6 +16912,7 @@ sf_tail:
LEX *lex= thd->lex; LEX *lex= thd->lex;
Lex_input_stream *lip= YYLIP; Lex_input_stream *lip= YYLIP;
lex->sphead->set_chistics(lex->sp_chistics);
lex->sphead->set_body_start(thd, lip->get_cpp_tok_start()); lex->sphead->set_body_start(thd, lip->get_cpp_tok_start());
} }
sp_tail_is sp_tail_is
@ -16947,6 +16947,7 @@ sp_tail:
opt_sp_parenthesized_pdparam_list opt_sp_parenthesized_pdparam_list
sp_c_chistics sp_c_chistics
{ {
Lex->sphead->set_chistics(Lex->sp_chistics);
Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start()); Lex->sphead->set_body_start(thd, YYLIP->get_cpp_tok_start());
} }
sp_tail_is sp_tail_is

View File

@ -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, sp->m_params.str, sp->m_params.length,
retstr.c_ptr(), retstr.length(), retstr.c_ptr(), retstr.length(),
sp->m_body.str, sp->m_body.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), &(thd->lex->definer->host),
saved_mode)) saved_mode))
{ {