Commit 7838d468 authored by unknown's avatar unknown

WL#1034

make more independent of SP


sql/event.cc:
  use own routine - export it
sql/event_priv.h:
  export these two
sql/event_timed.cc:
  use own routine, don't rely on SP
sql/sp.cc:
  revert changes to SP
sql/sp.h:
  revert changes to SP
sql/sql_show.cc:
  rever changes to SP
parent 70856a0d
...@@ -208,7 +208,7 @@ TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type) ...@@ -208,7 +208,7 @@ TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type)
SP_KEY_NOT_FOUND- No routine with given name SP_KEY_NOT_FOUND- No routine with given name
*/ */
static int int
evex_db_find_routine_aux(THD *thd, const LEX_STRING dbname, evex_db_find_routine_aux(THD *thd, const LEX_STRING dbname,
const LEX_STRING rname, TABLE *table) const LEX_STRING rname, TABLE *table)
{ {
...@@ -871,7 +871,7 @@ evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists) ...@@ -871,7 +871,7 @@ evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists)
if (!(table= evex_open_event_table(thd, TL_WRITE))) if (!(table= evex_open_event_table(thd, TL_WRITE)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
ret= sp_db_find_routine_aux(thd, 0/*notype*/, et->m_db, et->m_name, table); ret= evex_db_find_routine_aux(thd, et->m_db, et->m_name, table);
if (ret == EVEX_OK) if (ret == EVEX_OK)
{ {
......
...@@ -51,6 +51,10 @@ extern pthread_mutex_t LOCK_event_arrays, ...@@ -51,6 +51,10 @@ extern pthread_mutex_t LOCK_event_arrays,
int int
my_time_compare(TIME *a, TIME *b); my_time_compare(TIME *a, TIME *b);
int
TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type); evex_db_find_routine_aux(THD *thd, const LEX_STRING dbname,
const LEX_STRING rname, TABLE *table);
TABLE *
evex_open_event_table(THD *thd, enum thr_lock_type lock_type);
#endif /* _EVENT_PRIV_H_ */ #endif /* _EVENT_PRIV_H_ */
...@@ -722,7 +722,7 @@ event_timed::update_fields(THD *thd) ...@@ -722,7 +722,7 @@ event_timed::update_fields(THD *thd)
if (!(table= evex_open_event_table(thd, TL_WRITE))) if (!(table= evex_open_event_table(thd, TL_WRITE)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
if ((ret= sp_db_find_routine_aux(thd, 0/*notype*/, m_db, m_name, table))) if ((ret= evex_db_find_routine_aux(thd, m_db, m_name, table)))
goto done; goto done;
store_record(table,record[1]); store_record(table,record[1]);
......
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
#include "sp_cache.h" #include "sp_cache.h"
#include "sql_trigger.h" #include "sql_trigger.h"
#define SP_OPEN_TABLE_FOR_UPDATE() \
open_proc_type_table_for_update(thd, "proc", &mysql_proc_table_exists)
static bool static bool
create_string(THD *thd, String *buf, create_string(THD *thd, String *buf,
int sp_type, int sp_type,
...@@ -71,7 +68,7 @@ bool mysql_proc_table_exists= 1; ...@@ -71,7 +68,7 @@ bool mysql_proc_table_exists= 1;
/* /*
Close mysql.proc, opened with open_proc_type_table_for_read(). Close mysql.proc, opened with open_proc_table_for_read().
SYNOPSIS SYNOPSIS
close_proc_table() close_proc_table()
...@@ -89,16 +86,14 @@ void close_proc_table(THD *thd, Open_tables_state *backup) ...@@ -89,16 +86,14 @@ void close_proc_table(THD *thd, Open_tables_state *backup)
/* /*
Open table which has key structure like of mysql.proc for read. Open the mysql.proc table for read.
SYNOPSIS SYNOPSIS
open_proc_type_table_for_read() open_proc_table_for_read()
thd Thread context thd Thread context
backup Pointer to Open_tables_state instance where information about backup Pointer to Open_tables_state instance where information about
currently open tables will be saved, and from which will be currently open tables will be saved, and from which will be
restored when we will end work with mysql.proc. restored when we will end work with mysql.proc.
tname Table name having primary key structure like mysql.proc
table_exists Ptr to boolean to set whether the system table exists or not
NOTES NOTES
Thanks to restrictions which we put on opening and locking of Thanks to restrictions which we put on opening and locking of
...@@ -109,11 +104,10 @@ void close_proc_table(THD *thd, Open_tables_state *backup) ...@@ -109,11 +104,10 @@ void close_proc_table(THD *thd, Open_tables_state *backup)
RETURN RETURN
0 Error 0 Error
# Pointer to TABLE object of tname # Pointer to TABLE object of mysql.proc
*/ */
TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup, TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
const char *tname, bool *table_exists)
{ {
TABLE_LIST tables; TABLE_LIST tables;
TABLE *table; TABLE *table;
...@@ -121,22 +115,22 @@ TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup, ...@@ -121,22 +115,22 @@ TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup,
DBUG_ENTER("open_proc_table"); DBUG_ENTER("open_proc_table");
/* /*
Speed up things if the table doesn't exists. *table_exists Speed up things if mysql.proc doesn't exists. mysql_proc_table_exists
is set when we create or read stored procedure or on flush privileges. is set when we create or read stored procedure or on flush privileges.
*/ */
if (!*table_exists) if (!mysql_proc_table_exists)
DBUG_RETURN(0); DBUG_RETURN(0);
thd->reset_n_backup_open_tables_state(backup); thd->reset_n_backup_open_tables_state(backup);
bzero((char*) &tables, sizeof(tables)); bzero((char*) &tables, sizeof(tables));
tables.db= (char*) "mysql"; tables.db= (char*) "mysql";
tables.table_name= tables.alias= (char*) tname; tables.table_name= tables.alias= (char*)"proc";
if (!(table= open_table(thd, &tables, thd->mem_root, &not_used, if (!(table= open_table(thd, &tables, thd->mem_root, &not_used,
MYSQL_LOCK_IGNORE_FLUSH))) MYSQL_LOCK_IGNORE_FLUSH)))
{ {
thd->restore_backup_open_tables_state(backup); thd->restore_backup_open_tables_state(backup);
*table_exists= 0; mysql_proc_table_exists= 0;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -158,13 +152,11 @@ TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup, ...@@ -158,13 +152,11 @@ TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup,
/* /*
Open table with primary key struct like mysql.proc for update. Open the mysql.proc table for update.
SYNOPSIS SYNOPSIS
open_proc_type_table_for_update() open_proc_table_for_update()
thd Thread context thd Thread context
tname Table name with primary key structure like mysql.proc
table_exists Ptr to boolean to set whether the system table exists or not
NOTES NOTES
Table opened with this call should closed using close_thread_tables(). Table opened with this call should closed using close_thread_tables().
...@@ -174,8 +166,7 @@ TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup, ...@@ -174,8 +166,7 @@ TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup,
# Pointer to TABLE object of mysql.proc # Pointer to TABLE object of mysql.proc
*/ */
TABLE *open_proc_type_table_for_update(THD *thd, const char *tname, static TABLE *open_proc_table_for_update(THD *thd)
bool *table_exists)
{ {
TABLE_LIST tables; TABLE_LIST tables;
TABLE *table; TABLE *table;
...@@ -183,7 +174,7 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname, ...@@ -183,7 +174,7 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname,
bzero((char*) &tables, sizeof(tables)); bzero((char*) &tables, sizeof(tables));
tables.db= (char*) "mysql"; tables.db= (char*) "mysql";
tables.table_name= tables.alias= (char*) tname; tables.table_name= tables.alias= (char*)"proc";
tables.lock_type= TL_WRITE; tables.lock_type= TL_WRITE;
table= open_ltable(thd, &tables, TL_WRITE); table= open_ltable(thd, &tables, TL_WRITE);
...@@ -195,7 +186,7 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname, ...@@ -195,7 +186,7 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname,
transient. transient.
*/ */
if (!(thd->locked_tables || thd->prelocked_mode) || table) if (!(thd->locked_tables || thd->prelocked_mode) || table)
*table_exists= test(table); mysql_proc_table_exists= test(table);
DBUG_RETURN(table); DBUG_RETURN(table);
} }
...@@ -205,11 +196,10 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname, ...@@ -205,11 +196,10 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname,
Find row in open mysql.proc table representing stored routine. Find row in open mysql.proc table representing stored routine.
SYNOPSIS SYNOPSIS
sp_db_find_routine_aux() db_find_routine_aux()
thd Thread context thd Thread context
type Type of routine to find (function or procedure) type Type of routine to find (function or procedure)
dbname Name of routine's database name Name of routine
rname Name of the routine inside the db
table TABLE object for open mysql.proc table. table TABLE object for open mysql.proc table.
RETURN VALUE RETURN VALUE
...@@ -217,14 +207,13 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname, ...@@ -217,14 +207,13 @@ TABLE *open_proc_type_table_for_update(THD *thd, const char *tname,
SP_KEY_NOT_FOUND- No routine with given name SP_KEY_NOT_FOUND- No routine with given name
*/ */
int static int
sp_db_find_routine_aux(THD *thd, int type, const LEX_STRING dbname, db_find_routine_aux(THD *thd, int type, sp_name *name, TABLE *table)
const LEX_STRING rname, TABLE *table)
{ {
byte key[MAX_KEY_LENGTH]; // db, name, optional key length type byte key[MAX_KEY_LENGTH]; // db, name, optional key length type
DBUG_ENTER("sp_db_find_routine_aux"); DBUG_ENTER("db_find_routine_aux");
DBUG_PRINT("enter", ("type: %d name: %.*s", DBUG_PRINT("enter", ("type: %d name: %.*s",
type, rname.length, rname.str)); type, name->m_name.length, name->m_name.str));
/* /*
Create key to find row. We have to use field->store() to be able to Create key to find row. We have to use field->store() to be able to
...@@ -233,10 +222,11 @@ sp_db_find_routine_aux(THD *thd, int type, const LEX_STRING dbname, ...@@ -233,10 +222,11 @@ sp_db_find_routine_aux(THD *thd, int type, const LEX_STRING dbname,
'db', 'name' and 'type' and the first key is the primary key over the 'db', 'name' and 'type' and the first key is the primary key over the
same fields. same fields.
*/ */
if (rname.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(dbname.str, dbname.length, &my_charset_bin); table->field[0]->store(name->m_db.str, name->m_db.length, &my_charset_bin);
table->field[1]->store(rname.str, rname.length, &my_charset_bin); table->field[1]->store(name->m_name.str, name->m_name.length,
&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);
...@@ -293,12 +283,10 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp) ...@@ -293,12 +283,10 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
type, name->m_name.length, name->m_name.str)); type, name->m_name.length, name->m_name.str));
*sphp= 0; // In case of errors *sphp= 0; // In case of errors
if (!(table= open_proc_type_table_for_read(thd,&open_tables_state_backup, if (!(table= open_proc_table_for_read(thd, &open_tables_state_backup)))
"proc", &mysql_proc_table_exists)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
if ((ret= sp_db_find_routine_aux(thd, type, name->m_db, name->m_name, if ((ret= db_find_routine_aux(thd, type, name, table)) != SP_OK)
table)) != SP_OK)
goto done; goto done;
if (table->s->fields != MYSQL_PROC_FIELD_COUNT) if (table->s->fields != MYSQL_PROC_FIELD_COUNT)
...@@ -505,7 +493,7 @@ db_create_routine(THD *thd, int type, sp_head *sp) ...@@ -505,7 +493,7 @@ db_create_routine(THD *thd, int type, sp_head *sp)
goto done; goto done;
} }
if (!(table= SP_OPEN_TABLE_FOR_UPDATE())) if (!(table= open_proc_table_for_update(thd)))
ret= SP_OPEN_TABLE_FAILED; ret= SP_OPEN_TABLE_FAILED;
else else
{ {
...@@ -626,10 +614,9 @@ db_drop_routine(THD *thd, int type, sp_name *name) ...@@ -626,10 +614,9 @@ db_drop_routine(THD *thd, int type, sp_name *name)
DBUG_PRINT("enter", ("type: %d name: %.*s", DBUG_PRINT("enter", ("type: %d name: %.*s",
type, name->m_name.length, name->m_name.str)); type, name->m_name.length, name->m_name.str));
if (!(table= SP_OPEN_TABLE_FOR_UPDATE())) if (!(table= open_proc_table_for_update(thd)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
if ((ret= sp_db_find_routine_aux(thd, type, name->m_db, name->m_name, if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
table)) == SP_OK)
{ {
if (table->file->delete_row(table->record[0])) if (table->file->delete_row(table->record[0]))
ret= SP_DELETE_ROW_FAILED; ret= SP_DELETE_ROW_FAILED;
...@@ -649,10 +636,9 @@ db_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics) ...@@ -649,10 +636,9 @@ db_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
DBUG_PRINT("enter", ("type: %d name: %.*s", DBUG_PRINT("enter", ("type: %d name: %.*s",
type, name->m_name.length, name->m_name.str)); type, name->m_name.length, name->m_name.str));
if (!(table= SP_OPEN_TABLE_FOR_UPDATE())) if (!(table= open_proc_table_for_update(thd)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
if ((ret= sp_db_find_routine_aux(thd, type, name->m_db, name->m_name, if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
table)) == SP_OK)
{ {
store_record(table,record[1]); store_record(table,record[1]);
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET; table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
...@@ -874,7 +860,7 @@ sp_drop_db_routines(THD *thd, char *db) ...@@ -874,7 +860,7 @@ sp_drop_db_routines(THD *thd, char *db)
keylen= sizeof(key); keylen= sizeof(key);
ret= SP_OPEN_TABLE_FAILED; ret= SP_OPEN_TABLE_FAILED;
if (!(table= SP_OPEN_TABLE_FOR_UPDATE())) if (!(table= open_proc_table_for_update(thd)))
goto err; goto err;
ret= SP_OK; ret= SP_OK;
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
#define SP_BAD_IDENTIFIER -9 #define SP_BAD_IDENTIFIER -9
#define SP_BODY_TOO_LONG -10 #define SP_BODY_TOO_LONG -10
extern bool mysql_proc_table_exists;
/* Drop all routines in database 'db' */ /* Drop all routines in database 'db' */
int int
sp_drop_db_routines(THD *thd, char *db); sp_drop_db_routines(THD *thd, char *db);
...@@ -99,17 +97,9 @@ extern "C" byte* sp_sroutine_key(const byte *ptr, uint *plen, my_bool first); ...@@ -99,17 +97,9 @@ extern "C" byte* sp_sroutine_key(const byte *ptr, uint *plen, my_bool first);
Routines which allow open/lock and close mysql.proc table even when Routines which allow open/lock and close mysql.proc table even when
we already have some tables open and locked. we already have some tables open and locked.
*/ */
TABLE *open_proc_type_table_for_read(THD *thd, Open_tables_state *backup, TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup);
const char *tname, bool *table_exists);
TABLE *open_proc_type_table_for_update(THD *thd, const char *tname,
bool *table_exists);
void close_proc_table(THD *thd, Open_tables_state *backup); void close_proc_table(THD *thd, Open_tables_state *backup);
int
sp_db_find_routine_aux(THD *thd, int type, const LEX_STRING dbname,
const LEX_STRING rname, TABLE *table);
// //
// Utilities... // Utilities...
// //
......
...@@ -2931,9 +2931,7 @@ int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -2931,9 +2931,7 @@ int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond)
proc_tables.table_name_length= 4; proc_tables.table_name_length= 4;
proc_tables.lock_type= TL_READ; proc_tables.lock_type= TL_READ;
full_access= !check_table_access(thd, SELECT_ACL, &proc_tables, 1); full_access= !check_table_access(thd, SELECT_ACL, &proc_tables, 1);
if (!(proc_table= open_proc_type_table_for_read(thd, &open_tables_state_backup, if (!(proc_table= open_proc_table_for_read(thd, &open_tables_state_backup)))
"proc",
&mysql_proc_table_exists)))
{ {
DBUG_RETURN(1); DBUG_RETURN(1);
} }
......
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