Below is the list of changes that have just been committed into a local
5.1 repository of alik. When alik does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-05-29 17:31:53+04:00, anozdrin@ibm. +5 -0
Refactoring patch:
1. Refactor sp_show_create_function() and sp_show_create_procedure()
into show_create_routine().
2. Code cleanup: eliminate proxy functions.
sql/sp.cc@stripped, 2007-05-29 17:31:49+04:00, anozdrin@ibm. +54 -160
Code cleanup: eliminate proxy functions.
sql/sp.h@stripped, 2007-05-29 17:31:49+04:00, anozdrin@ibm. +6 -23
Code cleanup: eliminate proxy functions.
sql/sp_head.cc@stripped, 2007-05-29 17:31:49+04:00, anozdrin@ibm. +65 -81
1. Refactor sp_show_create_function() and sp_show_create_procedure()
into show_create_routine().
2. Code cleanup: eliminate proxy functions.
sql/sp_head.h@stripped, 2007-05-29 17:31:49+04:00, anozdrin@ibm. +2 -5
1. Refactor sp_show_create_function() and sp_show_create_procedure()
into show_create_routine().
2. Code cleanup: eliminate proxy functions.
sql/sql_parse.cc@stripped, 2007-05-29 17:31:49+04:00, anozdrin@ibm. +23 -17
Code cleanup: use new functions.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: anozdrin
# Host: ibm.
# Root: /home/alik/Documents/MySQL/devel/5.1-rt-cs-3
--- 1.672/sql/sql_parse.cc 2007-05-28 15:29:56 +04:00
+++ 1.673/sql/sql_parse.cc 2007-05-29 17:31:49 +04:00
@@ -3928,11 +3928,15 @@
already puts on CREATE FUNCTION.
*/
/* Conditionally writes to binlog */
- if (lex->sql_command == SQLCOM_ALTER_PROCEDURE)
- sp_result= sp_update_procedure(thd, lex->spname,
- &lex->sp_chistics);
- else
- sp_result= sp_update_function(thd, lex->spname, &lex->sp_chistics);
+
+ int type= lex->sql_command == SQLCOM_ALTER_PROCEDURE ?
+ TYPE_ENUM_PROCEDURE :
+ TYPE_ENUM_FUNCTION;
+
+ sp_result= sp_update_routine(thd,
+ type,
+ lex->spname,
+ &lex->sp_chistics);
}
}
switch (sp_result)
@@ -3982,10 +3986,12 @@
}
#endif
/* Conditionally writes to binlog */
- if (lex->sql_command == SQLCOM_DROP_PROCEDURE)
- sp_result= sp_drop_procedure(thd, lex->spname);
- else
- sp_result= sp_drop_function(thd, lex->spname);
+
+ int type= lex->sql_command == SQLCOM_DROP_PROCEDURE ?
+ TYPE_ENUM_PROCEDURE :
+ TYPE_ENUM_FUNCTION;
+
+ sp_result= sp_drop_routine(thd, type, lex->spname);
}
else
{
@@ -4042,8 +4048,8 @@
}
case SQLCOM_SHOW_CREATE_PROC:
{
- if (sp_show_create_procedure(thd, lex->spname) != SP_OK)
- { /* We don't distinguish between errors for now */
+ if (sp_show_create_routine(thd, TYPE_ENUM_PROCEDURE, lex->spname))
+ {
my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
SP_COM_STRING(lex), lex->spname->m_name.str);
goto error;
@@ -4052,8 +4058,8 @@
}
case SQLCOM_SHOW_CREATE_FUNC:
{
- if (sp_show_create_function(thd, lex->spname) != SP_OK)
- { /* We don't distinguish between errors for now */
+ if (sp_show_create_routine(thd, TYPE_ENUM_FUNCTION, lex->spname))
+ {
my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
SP_COM_STRING(lex), lex->spname->m_name.str);
goto error;
@@ -4063,14 +4069,14 @@
#ifdef NOT_USED
case SQLCOM_SHOW_STATUS_PROC:
{
- res= sp_show_status_procedure(thd, (lex->wild ?
- lex->wild->ptr() : NullS));
+ res= sp_show_status_routine(thd, TYPE_ENUM_PROCEDURE,
+ (lex->wild ? lex->wild->ptr() : NullS));
break;
}
case SQLCOM_SHOW_STATUS_FUNC:
{
- res= sp_show_status_function(thd, (lex->wild ?
- lex->wild->ptr() : NullS));
+ res= sp_show_status_routine(thd, TYPE_ENUM_FUNCTION,
+ (lex->wild ? lex->wild->ptr() : NullS));
break;
}
#endif
--- 1.151/sql/sp.cc 2007-05-18 00:27:07 +04:00
+++ 1.152/sql/sp.cc 2007-05-29 17:31:49 +04:00
@@ -442,13 +442,13 @@
delete field;
}
-static int
-db_create_routine(THD *thd, int type, sp_head *sp)
+int
+sp_create_routine(THD *thd, int type, sp_head *sp)
{
int ret;
TABLE *table;
char definer[USER_HOST_BUFF_SIZE];
- DBUG_ENTER("db_create_routine");
+ DBUG_ENTER("sp_create_routine");
DBUG_PRINT("enter", ("type: %d name: %.*s",type,sp->m_name.length,
sp->m_name.str));
@@ -586,12 +586,12 @@
}
-static int
-db_drop_routine(THD *thd, int type, sp_name *name)
+int
+sp_drop_routine(THD *thd, int type, sp_name *name)
{
TABLE *table;
int ret;
- DBUG_ENTER("db_drop_routine");
+ DBUG_ENTER("sp_drop_routine");
DBUG_PRINT("enter", ("type: %d name: %.*s",
type, name->m_name.length, name->m_name.str));
@@ -618,6 +618,8 @@
thd->binlog_query(THD::MYSQL_QUERY_TYPE,
thd->query, thd->query_length, FALSE, FALSE);
}
+
+ sp_cache_invalidate();
}
close_thread_tables(thd);
@@ -625,12 +627,12 @@
}
-static int
-db_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
+int
+sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
{
TABLE *table;
int ret;
- DBUG_ENTER("db_update_routine");
+ DBUG_ENTER("sp_update_routine");
DBUG_PRINT("enter", ("type: %d name: %.*s",
type, name->m_name.length, name->m_name.str));
@@ -670,6 +672,8 @@
thd->binlog_query(THD::MYSQL_QUERY_TYPE,
thd->query, thd->query_length, FALSE, FALSE);
}
+
+ sp_cache_invalidate();
}
close_thread_tables(thd);
@@ -755,13 +759,13 @@
}
-static int
-db_show_routine_status(THD *thd, int type, const char *wild)
+int
+sp_show_status_routine(THD *thd, int type, const char *wild)
{
TABLE *table;
TABLE_LIST tables;
int res;
- DBUG_ENTER("db_show_routine_status");
+ DBUG_ENTER("sp_show_status_routine");
memset(&tables, 0, sizeof(tables));
tables.db= (char*)"mysql";
@@ -913,9 +917,44 @@
}
-/*****************************************************************************
- PROCEDURE
-******************************************************************************/
+bool
+sp_show_create_routine(THD *thd, int type, sp_name *name)
+{
+ bool err_status= TRUE;
+ sp_head *sp;
+ sp_cache *cache = type == TYPE_ENUM_PROCEDURE ?
+ thd->sp_proc_cache : thd->sp_func_cache;
+
+ DBUG_ENTER("sp_show_create_routine");
+ DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
+
+ DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
+ type == TYPE_ENUM_FUNCTION);
+
+ if (type == TYPE_ENUM_PROCEDURE)
+ {
+ /*
+ SHOW CREATE PROCEDURE may require two instances of one sp_head
+ object when SHOW CREATE PROCEDURE is called for the procedure that
+ is being executed. Basically, there is no actual recursion, so we
+ increase the recursion limit for this statement (kind of hack).
+
+ SHOW CREATE FUNCTION does not require this because SHOW CREATE
+ statements are prohibitted within stored functions.
+ */
+
+ thd->variables.max_sp_recursion_depth++;
+ }
+
+ if ((sp= sp_find_routine(thd, type, name, &cache, FALSE)))
+ err_status= sp->show_create_routine(thd, type);
+
+ if (type == TYPE_ENUM_PROCEDURE)
+ thd->variables.max_sp_recursion_depth--;
+
+ DBUG_RETURN(err_status);
+}
+
/*
Obtain object representing stored procedure/function by its name from
@@ -1106,151 +1145,6 @@
close_system_tables(thd, &open_tables_state_backup);
}
return ret;
-}
-
-
-int
-sp_create_procedure(THD *thd, sp_head *sp)
-{
- int ret;
- DBUG_ENTER("sp_create_procedure");
- DBUG_PRINT("enter", ("name: %.*s", sp->m_name.length, sp->m_name.str));
-
- ret= db_create_routine(thd, TYPE_ENUM_PROCEDURE, sp);
- DBUG_RETURN(ret);
-}
-
-
-int
-sp_drop_procedure(THD *thd, sp_name *name)
-{
- int ret;
- DBUG_ENTER("sp_drop_procedure");
- DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
-
- ret= db_drop_routine(thd, TYPE_ENUM_PROCEDURE, name);
- if (!ret)
- sp_cache_invalidate();
- DBUG_RETURN(ret);
-}
-
-
-int
-sp_update_procedure(THD *thd, sp_name *name, st_sp_chistics *chistics)
-{
- int ret;
- DBUG_ENTER("sp_update_procedure");
- DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
-
- ret= db_update_routine(thd, TYPE_ENUM_PROCEDURE, name, chistics);
- if (!ret)
- sp_cache_invalidate();
- DBUG_RETURN(ret);
-}
-
-
-int
-sp_show_create_procedure(THD *thd, sp_name *name)
-{
- int ret= SP_KEY_NOT_FOUND;
- sp_head *sp;
- DBUG_ENTER("sp_show_create_procedure");
- DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
-
- /*
- Increase the recursion limit for this statement. SHOW CREATE PROCEDURE
- does not do actual recursion.
- */
- thd->variables.max_sp_recursion_depth++;
- if ((sp= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name,
- &thd->sp_proc_cache, FALSE)))
- ret= sp->show_create_procedure(thd);
-
- thd->variables.max_sp_recursion_depth--;
- DBUG_RETURN(ret);
-}
-
-
-int
-sp_show_status_procedure(THD *thd, const char *wild)
-{
- int ret;
- DBUG_ENTER("sp_show_status_procedure");
-
- ret= db_show_routine_status(thd, TYPE_ENUM_PROCEDURE, wild);
- DBUG_RETURN(ret);
-}
-
-
-/*****************************************************************************
- FUNCTION
-******************************************************************************/
-
-int
-sp_create_function(THD *thd, sp_head *sp)
-{
- int ret;
- DBUG_ENTER("sp_create_function");
- DBUG_PRINT("enter", ("name: %.*s", sp->m_name.length, sp->m_name.str));
-
- ret= db_create_routine(thd, TYPE_ENUM_FUNCTION, sp);
- DBUG_RETURN(ret);
-}
-
-
-int
-sp_drop_function(THD *thd, sp_name *name)
-{
- int ret;
- DBUG_ENTER("sp_drop_function");
- DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
-
- ret= db_drop_routine(thd, TYPE_ENUM_FUNCTION, name);
- if (!ret)
- sp_cache_invalidate();
- DBUG_RETURN(ret);
-}
-
-
-int
-sp_update_function(THD *thd, sp_name *name, st_sp_chistics *chistics)
-{
- int ret;
- DBUG_ENTER("sp_update_procedure");
- DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
-
- ret= db_update_routine(thd, TYPE_ENUM_FUNCTION, name, chistics);
- if (!ret)
- sp_cache_invalidate();
- DBUG_RETURN(ret);
-}
-
-
-int
-sp_show_create_function(THD *thd, sp_name *name)
-{
- sp_head *sp;
- DBUG_ENTER("sp_show_create_function");
- DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
-
- if ((sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, name,
- &thd->sp_func_cache, FALSE)))
- {
- int ret= sp->show_create_function(thd);
-
- DBUG_RETURN(ret);
- }
- DBUG_RETURN(SP_KEY_NOT_FOUND);
-}
-
-
-int
-sp_show_status_function(THD *thd, const char *wild)
-{
- int ret;
- DBUG_ENTER("sp_show_status_function");
- ret= db_show_routine_status(thd, TYPE_ENUM_FUNCTION, wild);
- DBUG_RETURN(ret);
}
--- 1.38/sql/sp.h 2007-03-09 13:12:26 +03:00
+++ 1.39/sql/sp.h 2007-05-29 17:31:49 +04:00
@@ -44,37 +44,20 @@
int
sp_routine_exists_in_table(THD *thd, int type, sp_name *name);
-int
-sp_create_procedure(THD *thd, sp_head *sp);
-
-int
-sp_drop_procedure(THD *thd, sp_name *name);
-
+bool
+sp_show_create_routine(THD *thd, int type, sp_name *name);
int
-sp_update_procedure(THD *thd, sp_name *name, st_sp_chistics *chistics);
+sp_show_status_routine(THD *thd, int type, const char *wild);
int
-sp_show_create_procedure(THD *thd, sp_name *name);
+sp_create_routine(THD *thd, int type, sp_head *sp);
int
-sp_show_status_procedure(THD *thd, const char *wild);
+sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics);
int
-sp_create_function(THD *thd, sp_head *sp);
-
-int
-sp_drop_function(THD *thd, sp_name *name);
-
-int
-sp_update_function(THD *thd, sp_name *name, st_sp_chistics *chistics);
-
-int
-sp_show_create_function(THD *thd, sp_name *name);
-
-int
-sp_show_status_function(THD *thd, const char *wild);
-
+sp_drop_routine(THD *thd, int type, sp_name *name);
/*
Procedures for pre-caching of stored routines and building table list
--- 1.271/sql/sp_head.cc 2007-05-16 10:13:51 +04:00
+++ 1.272/sql/sp_head.cc 2007-05-29 17:31:49 +04:00
@@ -637,17 +637,10 @@
sp_head::create(THD *thd)
{
DBUG_ENTER("sp_head::create");
- int ret;
-
DBUG_PRINT("info", ("type: %d name: %s params: %s body: %s",
m_type, m_name.str, m_params.str, m_body.str));
- if (m_type == TYPE_ENUM_FUNCTION)
- ret= sp_create_function(thd, this);
- else
- ret= sp_create_procedure(thd, this);
-
- DBUG_RETURN(ret);
+ DBUG_RETURN(sp_create_routine(thd, m_type, this));
}
sp_head::~sp_head()
@@ -2104,49 +2097,82 @@
}
-int
-sp_head::show_create_procedure(THD *thd)
+bool
+sp_head::show_create_routine(THD *thd, int type)
{
- Protocol *protocol= thd->protocol;
- char buff[2048];
- String buffer(buff, sizeof(buff), system_charset_info);
- int res;
- List<Item> field_list;
+ const char *col1_caption= type == TYPE_ENUM_PROCEDURE ?
+ "Procedure" : "Function";
+
+ const char *col3_caption= type == TYPE_ENUM_PROCEDURE ?
+ "Create Procedure" : "Create Function";
+
+ bool err_status;
+
+ Protocol *p= thd->protocol;
+ List<Item> fields;
+
LEX_STRING sql_mode;
+
bool full_access;
- DBUG_ENTER("sp_head::show_create_procedure");
- DBUG_PRINT("info", ("procedure %s", m_name.str));
+
+ DBUG_ENTER("sp_head::show_create_routine");
+ DBUG_PRINT("info", ("routine %s", m_name.str));
+
+ DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
+ type == TYPE_ENUM_FUNCTION);
if (check_show_routine_access(thd, this, &full_access))
- DBUG_RETURN(1);
+ DBUG_RETURN(TRUE);
+
+ sys_var_thd_sql_mode::symbolic_mode_representation(
+ thd, m_sql_mode, &sql_mode);
+
+ /* Send header. */
+
+ fields.push_back(new Item_empty_string(col1_caption, NAME_LEN));
+ fields.push_back(new Item_empty_string("sql_mode", sql_mode.length));
+
+ {
+ /*
+ NOTE: SQL statement field must be not less than 1024 in order not to
+ confuse old clients.
+ */
+
+ Item_empty_string *stmt_fld=
+ new Item_empty_string(col3_caption,
+ max(m_defstr.length, 1024));
+
+ stmt_fld->maybe_null= TRUE;
+
+ fields.push_back(stmt_fld);
+ }
+
+ if (p->send_fields(&fields, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
+ DBUG_RETURN(TRUE);
+
+ /* Send data. */
+
+ p->prepare_for_resend();
+
+ p->store(m_name.str, m_name.length, system_charset_info);
+ p->store(sql_mode.str, sql_mode.length, system_charset_info);
- sys_var_thd_sql_mode::symbolic_mode_representation(thd, m_sql_mode,
- &sql_mode);
- field_list.push_back(new Item_empty_string("Procedure", NAME_CHAR_LEN));
- field_list.push_back(new Item_empty_string("sql_mode", sql_mode.length));
- // 1024 is for not to confuse old clients
- Item_empty_string *definition=
- new Item_empty_string("Create Procedure", max(buffer.length(),1024));
- definition->maybe_null= TRUE;
- field_list.push_back(definition);
-
- if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
- Protocol::SEND_EOF))
- DBUG_RETURN(1);
- protocol->prepare_for_resend();
- protocol->store(m_name.str, m_name.length, system_charset_info);
- protocol->store((char*) sql_mode.str, sql_mode.length, system_charset_info);
if (full_access)
- protocol->store(m_defstr.str, m_defstr.length, system_charset_info);
+ p->store(m_defstr.str, m_defstr.length, &my_charset_bin);
else
- protocol->store_null();
- res= protocol->write();
- send_eof(thd);
+ p->store_null();
+
+ err_status= p->write();
- DBUG_RETURN(res);
+ if (!err_status)
+ send_eof(thd);
+
+ DBUG_RETURN(err_status);
}
+
+
/*
Add instruction to SP
@@ -2167,48 +2193,6 @@
*/
instr->mem_root= &main_mem_root;
insert_dynamic(&m_instr, (gptr)&instr);
-}
-
-
-int
-sp_head::show_create_function(THD *thd)
-{
- Protocol *protocol= thd->protocol;
- char buff[2048];
- String buffer(buff, sizeof(buff), system_charset_info);
- int res;
- List<Item> field_list;
- LEX_STRING sql_mode;
- bool full_access;
- DBUG_ENTER("sp_head::show_create_function");
- DBUG_PRINT("info", ("procedure %s", m_name.str));
-
- if (check_show_routine_access(thd, this, &full_access))
- DBUG_RETURN(1);
-
- sys_var_thd_sql_mode::symbolic_mode_representation(thd, m_sql_mode,
- &sql_mode);
- field_list.push_back(new Item_empty_string("Function",NAME_CHAR_LEN));
- field_list.push_back(new Item_empty_string("sql_mode", sql_mode.length));
- Item_empty_string *definition=
- new Item_empty_string("Create Function", max(buffer.length(),1024));
- definition->maybe_null= TRUE;
- field_list.push_back(definition);
-
- if (protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(1);
- protocol->prepare_for_resend();
- protocol->store(m_name.str, m_name.length, system_charset_info);
- protocol->store(sql_mode.str, sql_mode.length, system_charset_info);
- if (full_access)
- protocol->store(m_defstr.str, m_defstr.length, system_charset_info);
- else
- protocol->store_null();
- res= protocol->write();
- send_eof(thd);
-
- DBUG_RETURN(res);
}
--- 1.106/sql/sp_head.h 2007-05-07 12:26:17 +04:00
+++ 1.107/sql/sp_head.h 2007-05-29 17:31:49 +04:00
@@ -225,11 +225,8 @@
bool
execute_procedure(THD *thd, List<Item> *args);
- int
- show_create_procedure(THD *thd);
-
- int
- show_create_function(THD *thd);
+ bool
+ show_create_routine(THD *thd, int type);
void
add_instr(sp_instr *instr);
| Thread |
|---|
| • bk commit into 5.1 tree (anozdrin:1.2523) | Alexander Nozdrin | 29 May |