2002-12-12 13:14:23 +01:00
|
|
|
/* Copyright (C) 2002 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2002-12-12 13:14:23 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include "sp.h"
|
|
|
|
#include "sp_head.h"
|
2003-07-03 15:58:37 +02:00
|
|
|
#include "sp_cache.h"
|
2005-07-09 19:51:59 +02:00
|
|
|
#include "sql_trigger.h"
|
2003-07-01 18:14:24 +02:00
|
|
|
|
2006-03-02 13:18:49 +01:00
|
|
|
#include <my_user.h>
|
|
|
|
|
2004-06-09 14:19:43 +02:00
|
|
|
static bool
|
|
|
|
create_string(THD *thd, String *buf,
|
2003-12-12 14:05:29 +01:00
|
|
|
int sp_type,
|
2008-05-16 01:13:24 +02:00
|
|
|
const char *db, ulong dblen,
|
2008-05-15 01:23:54 +02:00
|
|
|
const char *name, ulong namelen,
|
2003-12-12 14:05:29 +01:00
|
|
|
const char *params, ulong paramslen,
|
|
|
|
const char *returns, ulong returnslen,
|
|
|
|
const char *body, ulong bodylen,
|
2006-03-02 13:18:49 +01:00
|
|
|
st_sp_chistics *chistics,
|
|
|
|
const LEX_STRING *definer_user,
|
|
|
|
const LEX_STRING *definer_host);
|
2005-11-23 00:11:19 +01:00
|
|
|
static int
|
|
|
|
db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
|
|
|
|
ulong sql_mode, const char *params, const char *returns,
|
|
|
|
const char *body, st_sp_chistics &chistics,
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
const char *definer, longlong created, longlong modified,
|
|
|
|
Stored_program_creation_ctx *creation_ctx);
|
2003-12-12 14:05:29 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* DB storage of Stored PROCEDUREs and FUNCTIONs
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
enum
|
|
|
|
{
|
2003-12-16 19:14:10 +01:00
|
|
|
MYSQL_PROC_FIELD_DB = 0,
|
2003-12-12 14:05:29 +01:00
|
|
|
MYSQL_PROC_FIELD_NAME,
|
2006-12-02 02:26:52 +01:00
|
|
|
MYSQL_PROC_MYSQL_TYPE,
|
2003-12-12 14:05:29 +01:00
|
|
|
MYSQL_PROC_FIELD_SPECIFIC_NAME,
|
|
|
|
MYSQL_PROC_FIELD_LANGUAGE,
|
|
|
|
MYSQL_PROC_FIELD_ACCESS,
|
|
|
|
MYSQL_PROC_FIELD_DETERMINISTIC,
|
|
|
|
MYSQL_PROC_FIELD_SECURITY_TYPE,
|
|
|
|
MYSQL_PROC_FIELD_PARAM_LIST,
|
|
|
|
MYSQL_PROC_FIELD_RETURNS,
|
|
|
|
MYSQL_PROC_FIELD_BODY,
|
|
|
|
MYSQL_PROC_FIELD_DEFINER,
|
|
|
|
MYSQL_PROC_FIELD_CREATED,
|
|
|
|
MYSQL_PROC_FIELD_MODIFIED,
|
|
|
|
MYSQL_PROC_FIELD_SQL_MODE,
|
|
|
|
MYSQL_PROC_FIELD_COMMENT,
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
MYSQL_PROC_FIELD_CHARACTER_SET_CLIENT,
|
|
|
|
MYSQL_PROC_FIELD_COLLATION_CONNECTION,
|
|
|
|
MYSQL_PROC_FIELD_DB_COLLATION,
|
|
|
|
MYSQL_PROC_FIELD_BODY_UTF8,
|
2003-12-12 14:05:29 +01:00
|
|
|
MYSQL_PROC_FIELD_COUNT
|
|
|
|
};
|
2003-10-30 10:25:45 +01:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
Stored_routine_creation_ctx -- creation context of stored routines
|
|
|
|
(stored procedures and functions).
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Stored_routine_creation_ctx : public Stored_program_creation_ctx,
|
|
|
|
public Sql_alloc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static Stored_routine_creation_ctx *
|
2007-08-15 15:43:08 +02:00
|
|
|
load_from_db(THD *thd, const sp_name *name, TABLE *proc_tbl);
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual Stored_program_creation_ctx *clone(MEM_ROOT *mem_root)
|
|
|
|
{
|
|
|
|
return new (mem_root) Stored_routine_creation_ctx(m_client_cs,
|
|
|
|
m_connection_cl,
|
|
|
|
m_db_cl);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual Object_creation_ctx *create_backup_ctx(THD *thd) const
|
|
|
|
{
|
2007-08-13 15:11:25 +02:00
|
|
|
DBUG_ENTER("Stored_routine_creation_ctx::create_backup_ctx");
|
|
|
|
DBUG_RETURN(new Stored_routine_creation_ctx(thd));
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Stored_routine_creation_ctx(THD *thd)
|
|
|
|
: Stored_program_creation_ctx(thd)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Stored_routine_creation_ctx(CHARSET_INFO *client_cs,
|
|
|
|
CHARSET_INFO *connection_cl,
|
|
|
|
CHARSET_INFO *db_cl)
|
|
|
|
: Stored_program_creation_ctx(client_cs, connection_cl, db_cl)
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
Stored_routine_creation_ctx implementation.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
bool load_charset(MEM_ROOT *mem_root,
|
|
|
|
Field *field,
|
|
|
|
CHARSET_INFO *dflt_cs,
|
|
|
|
CHARSET_INFO **cs)
|
|
|
|
{
|
|
|
|
String cs_name;
|
|
|
|
|
|
|
|
if (get_field(mem_root, field, &cs_name))
|
|
|
|
{
|
|
|
|
*cs= dflt_cs;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cs= get_charset_by_csname(cs_name.c_ptr(), MY_CS_PRIMARY, MYF(0));
|
|
|
|
|
|
|
|
if (*cs == NULL)
|
|
|
|
{
|
|
|
|
*cs= dflt_cs;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
bool load_collation(MEM_ROOT *mem_root,
|
|
|
|
Field *field,
|
|
|
|
CHARSET_INFO *dflt_cl,
|
|
|
|
CHARSET_INFO **cl)
|
|
|
|
{
|
|
|
|
String cl_name;
|
|
|
|
|
|
|
|
if (get_field(mem_root, field, &cl_name))
|
|
|
|
{
|
|
|
|
*cl= dflt_cl;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cl= get_charset_by_name(cl_name.c_ptr(), MYF(0));
|
|
|
|
|
|
|
|
if (*cl == NULL)
|
|
|
|
{
|
|
|
|
*cl= dflt_cl;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
Stored_routine_creation_ctx *
|
|
|
|
Stored_routine_creation_ctx::load_from_db(THD *thd,
|
|
|
|
const sp_name *name,
|
|
|
|
TABLE *proc_tbl)
|
|
|
|
{
|
|
|
|
/* Load character set/collation attributes. */
|
|
|
|
|
|
|
|
CHARSET_INFO *client_cs;
|
|
|
|
CHARSET_INFO *connection_cl;
|
|
|
|
CHARSET_INFO *db_cl;
|
|
|
|
|
|
|
|
const char *db_name= thd->strmake(name->m_db.str, name->m_db.length);
|
|
|
|
const char *sr_name= thd->strmake(name->m_name.str, name->m_name.length);
|
|
|
|
|
|
|
|
bool invalid_creation_ctx= FALSE;
|
|
|
|
|
|
|
|
if (load_charset(thd->mem_root,
|
|
|
|
proc_tbl->field[MYSQL_PROC_FIELD_CHARACTER_SET_CLIENT],
|
|
|
|
thd->variables.character_set_client,
|
|
|
|
&client_cs))
|
|
|
|
{
|
|
|
|
sql_print_warning("Stored routine '%s'.'%s': invalid value "
|
|
|
|
"in column mysql.proc.character_set_client.",
|
|
|
|
(const char *) db_name,
|
|
|
|
(const char *) sr_name);
|
|
|
|
|
|
|
|
invalid_creation_ctx= TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_collation(thd->mem_root,
|
|
|
|
proc_tbl->field[MYSQL_PROC_FIELD_COLLATION_CONNECTION],
|
|
|
|
thd->variables.collation_connection,
|
|
|
|
&connection_cl))
|
|
|
|
{
|
|
|
|
sql_print_warning("Stored routine '%s'.'%s': invalid value "
|
|
|
|
"in column mysql.proc.collation_connection.",
|
|
|
|
(const char *) db_name,
|
|
|
|
(const char *) sr_name);
|
|
|
|
|
|
|
|
invalid_creation_ctx= TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_collation(thd->mem_root,
|
|
|
|
proc_tbl->field[MYSQL_PROC_FIELD_DB_COLLATION],
|
|
|
|
NULL,
|
|
|
|
&db_cl))
|
|
|
|
{
|
|
|
|
sql_print_warning("Stored routine '%s'.'%s': invalid value "
|
|
|
|
"in column mysql.proc.db_collation.",
|
|
|
|
(const char *) db_name,
|
|
|
|
(const char *) sr_name);
|
|
|
|
|
|
|
|
invalid_creation_ctx= TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invalid_creation_ctx)
|
|
|
|
{
|
|
|
|
push_warning_printf(thd,
|
|
|
|
MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
|
|
ER_SR_INVALID_CREATION_CTX,
|
|
|
|
ER(ER_SR_INVALID_CREATION_CTX),
|
|
|
|
(const char *) db_name,
|
|
|
|
(const char *) sr_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
If we failed to retrieve the database collation, load the default one
|
|
|
|
from the disk.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!db_cl)
|
|
|
|
db_cl= get_default_db_collation(thd, name->m_db.str);
|
|
|
|
|
|
|
|
/* Create the context. */
|
|
|
|
|
|
|
|
return new Stored_routine_creation_ctx(client_cs, connection_cl, db_cl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************/
|
2005-07-13 11:48:13 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-13 11:48:13 +02:00
|
|
|
Open the mysql.proc table for read.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread context
|
|
|
|
@param backup Pointer to Open_tables_state instance where information about
|
|
|
|
currently open tables will be saved, and from which will be
|
|
|
|
restored when we will end work with mysql.proc.
|
2005-07-13 11:48:13 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-07-13 11:48:13 +02:00
|
|
|
0 Error
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
\# Pointer to TABLE object of mysql.proc
|
2005-07-13 11:48:13 +02:00
|
|
|
*/
|
|
|
|
|
2005-08-08 15:46:06 +02:00
|
|
|
TABLE *open_proc_table_for_read(THD *thd, Open_tables_state *backup)
|
2005-07-13 11:48:13 +02:00
|
|
|
{
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
DBUG_ENTER("open_proc_table_for_read");
|
2003-03-02 19:17:41 +01:00
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
TABLE_LIST table;
|
|
|
|
bzero((char*) &table, sizeof(table));
|
|
|
|
table.db= (char*) "mysql";
|
|
|
|
table.table_name= table.alias= (char*)"proc";
|
|
|
|
table.lock_type= TL_READ;
|
2005-07-13 11:48:13 +02:00
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
if (!open_system_tables_for_read(thd, &table, backup))
|
|
|
|
DBUG_RETURN(table.table);
|
|
|
|
else
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-13 11:48:13 +02:00
|
|
|
Open the mysql.proc table for update.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread context
|
2005-07-13 11:48:13 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
2005-07-13 11:48:13 +02:00
|
|
|
Table opened with this call should closed using close_thread_tables().
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-07-13 11:48:13 +02:00
|
|
|
0 Error
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
\# Pointer to TABLE object of mysql.proc
|
2005-07-13 11:48:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static TABLE *open_proc_table_for_update(THD *thd)
|
|
|
|
{
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
DBUG_ENTER("open_proc_table_for_update");
|
2005-07-13 11:48:13 +02:00
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
TABLE_LIST table;
|
|
|
|
bzero((char*) &table, sizeof(table));
|
|
|
|
table.db= (char*) "mysql";
|
|
|
|
table.table_name= table.alias= (char*)"proc";
|
|
|
|
table.lock_type= TL_WRITE;
|
2005-07-13 11:48:13 +02:00
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
DBUG_RETURN(open_system_table_for_update(thd, &table));
|
2005-07-13 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-13 11:48:13 +02:00
|
|
|
Find row in open mysql.proc table representing stored routine.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread context
|
|
|
|
@param type Type of routine to find (function or procedure)
|
|
|
|
@param name Name of routine
|
|
|
|
@param table TABLE object for open mysql.proc table.
|
2005-07-13 11:48:13 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
SP_OK Routine found
|
|
|
|
@retval
|
|
|
|
SP_KEY_NOT_FOUND No routine with given name
|
2005-07-13 11:48:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
db_find_routine_aux(THD *thd, int type, sp_name *name, TABLE *table)
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
uchar key[MAX_KEY_LENGTH]; // db, name, optional key length type
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_ENTER("db_find_routine_aux");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",
|
|
|
|
type, (int) name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2005-04-04 15:43:25 +02:00
|
|
|
/*
|
|
|
|
Create key to find row. We have to use field->store() to be able to
|
|
|
|
handle VARCHAR and CHAR fields.
|
|
|
|
Assumption here is that the three first fields in the table are
|
|
|
|
'db', 'name' and 'type' and the first key is the primary key over the
|
|
|
|
same fields.
|
|
|
|
*/
|
2005-05-31 18:36:32 +02:00
|
|
|
if (name->m_name.length > table->field[1]->field_length)
|
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
2005-04-04 15:43:25 +02:00
|
|
|
table->field[0]->store(name->m_db.str, name->m_db.length, &my_charset_bin);
|
|
|
|
table->field[1]->store(name->m_name.str, name->m_name.length,
|
|
|
|
&my_charset_bin);
|
2005-09-14 00:41:44 +02:00
|
|
|
table->field[2]->store((longlong) type, TRUE);
|
2005-04-04 15:43:25 +02:00
|
|
|
key_copy(key, table->record[0], table->key_info,
|
|
|
|
table->key_info->key_length);
|
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
if (table->file->index_read_idx_map(table->record[0], 0, key, HA_WHOLE_KEY,
|
|
|
|
HA_READ_KEY_EXACT))
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(SP_OK);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-13 11:48:13 +02:00
|
|
|
Find routine definition in mysql.proc table and create corresponding
|
|
|
|
sp_head object for it.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread context
|
|
|
|
@param type Type of routine (TYPE_ENUM_PROCEDURE/...)
|
|
|
|
@param name Name of routine
|
|
|
|
@param sphp Out parameter in which pointer to created sp_head
|
|
|
|
object is returned (0 in case of error).
|
2005-07-13 11:48:13 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
2005-07-13 11:48:13 +02:00
|
|
|
This function may damage current LEX during execution, so it is good
|
|
|
|
idea to create temporary LEX and make it active before calling it.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
0 Success
|
|
|
|
@retval
|
|
|
|
non-0 Error (may be one of special codes like SP_KEY_NOT_FOUND)
|
2005-07-13 11:48:13 +02:00
|
|
|
*/
|
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
2004-02-17 17:36:53 +01:00
|
|
|
db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
2003-12-12 14:05:29 +01:00
|
|
|
const char *params, *returns, *body;
|
2003-02-21 17:37:05 +01:00
|
|
|
int ret;
|
2003-12-13 16:40:52 +01:00
|
|
|
const char *definer;
|
2003-05-06 18:09:20 +02:00
|
|
|
longlong created;
|
|
|
|
longlong modified;
|
2003-12-13 16:40:52 +01:00
|
|
|
st_sp_chistics chistics;
|
2003-05-06 18:09:20 +02:00
|
|
|
char *ptr;
|
|
|
|
uint length;
|
|
|
|
char buff[65];
|
2003-07-03 15:58:37 +02:00
|
|
|
String str(buff, sizeof(buff), &my_charset_bin);
|
2008-02-19 16:27:18 +01:00
|
|
|
bool saved_time_zone_used= thd->time_zone_used;
|
2008-02-07 11:47:39 +01:00
|
|
|
ulong sql_mode, saved_mode= thd->variables.sql_mode;
|
2005-08-08 15:46:06 +02:00
|
|
|
Open_tables_state open_tables_state_backup;
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
Stored_program_creation_ctx *creation_ctx;
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_find_routine");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
type, (int) name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
*sphp= 0; // In case of errors
|
2005-08-08 15:46:06 +02:00
|
|
|
if (!(table= open_proc_table_for_read(thd, &open_tables_state_backup)))
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
|
|
|
|
|
2008-02-07 11:47:39 +01:00
|
|
|
/* Reset sql_mode during data dictionary operations. */
|
|
|
|
thd->variables.sql_mode= 0;
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
if ((ret= db_find_routine_aux(thd, type, name, table)) != SP_OK)
|
2003-02-21 17:37:05 +01:00
|
|
|
goto done;
|
2003-10-30 10:25:45 +01:00
|
|
|
|
2007-07-25 16:38:52 +02:00
|
|
|
if (table->s->fields < MYSQL_PROC_FIELD_COUNT)
|
2003-10-30 10:25:45 +01:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-10-14 18:07:09 +02:00
|
|
|
bzero((char *)&chistics, sizeof(chistics));
|
2004-11-09 02:58:44 +01:00
|
|
|
if ((ptr= get_field(thd->mem_root,
|
2004-10-14 18:07:09 +02:00
|
|
|
table->field[MYSQL_PROC_FIELD_ACCESS])) == NULL)
|
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
switch (ptr[0]) {
|
|
|
|
case 'N':
|
|
|
|
chistics.daccess= SP_NO_SQL;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
chistics.daccess= SP_CONTAINS_SQL;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
chistics.daccess= SP_READS_SQL_DATA;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
chistics.daccess= SP_MODIFIES_SQL_DATA;
|
|
|
|
break;
|
|
|
|
default:
|
2005-05-05 14:20:53 +02:00
|
|
|
chistics.daccess= SP_DEFAULT_ACCESS_MAPPING;
|
2004-10-14 18:07:09 +02:00
|
|
|
}
|
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
if ((ptr= get_field(thd->mem_root,
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_DETERMINISTIC])) == NULL)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2003-12-13 16:40:52 +01:00
|
|
|
chistics.detistic= (ptr[0] == 'N' ? FALSE : TRUE);
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
if ((ptr= get_field(thd->mem_root,
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE])) == NULL)
|
2003-05-06 18:09:20 +02:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2004-10-14 18:07:09 +02:00
|
|
|
chistics.suid= (ptr[0] == 'I' ? SP_IS_NOT_SUID : SP_IS_SUID);
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
if ((params= get_field(thd->mem_root,
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_PARAM_LIST])) == NULL)
|
|
|
|
{
|
|
|
|
params= "";
|
|
|
|
}
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if (type == TYPE_ENUM_PROCEDURE)
|
|
|
|
returns= "";
|
2004-11-09 02:58:44 +01:00
|
|
|
else if ((returns= get_field(thd->mem_root,
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_RETURNS])) == NULL)
|
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
if ((body= get_field(thd->mem_root,
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_BODY])) == NULL)
|
2003-05-06 18:09:20 +02:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2003-12-12 14:05:29 +01:00
|
|
|
|
|
|
|
// Get additional information
|
2004-11-09 02:58:44 +01:00
|
|
|
if ((definer= get_field(thd->mem_root,
|
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_DEFINER])) == NULL)
|
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
modified= table->field[MYSQL_PROC_FIELD_MODIFIED]->val_int();
|
|
|
|
created= table->field[MYSQL_PROC_FIELD_CREATED]->val_int();
|
2003-05-06 18:09:20 +02:00
|
|
|
|
2003-12-21 01:07:45 +01:00
|
|
|
sql_mode= (ulong) table->field[MYSQL_PROC_FIELD_SQL_MODE]->val_int();
|
2003-12-11 12:23:50 +01:00
|
|
|
|
2003-10-30 10:25:45 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_COMMENT]->val_str(&str, &str);
|
|
|
|
|
2003-05-06 18:09:20 +02:00
|
|
|
ptr= 0;
|
2003-06-02 11:25:01 +02:00
|
|
|
if ((length= str.length()))
|
2003-12-12 14:05:29 +01:00
|
|
|
ptr= thd->strmake(str.ptr(), length);
|
2003-12-13 16:40:52 +01:00
|
|
|
chistics.comment.str= ptr;
|
|
|
|
chistics.comment.length= length;
|
2003-05-06 18:09:20 +02:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
creation_ctx= Stored_routine_creation_ctx::load_from_db(thd, name, table);
|
|
|
|
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
close_system_tables(thd, &open_tables_state_backup);
|
2005-07-13 11:48:13 +02:00
|
|
|
table= 0;
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
ret= db_load_routine(thd, type, name, sphp,
|
|
|
|
sql_mode, params, returns, body, chistics,
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
definer, created, modified, creation_ctx);
|
2005-11-23 00:11:19 +01:00
|
|
|
done:
|
2008-02-19 16:27:18 +01:00
|
|
|
/*
|
|
|
|
Restore the time zone flag as the timezone usage in proc table
|
|
|
|
does not affect replication.
|
|
|
|
*/
|
|
|
|
thd->time_zone_used= saved_time_zone_used;
|
2005-11-23 00:11:19 +01:00
|
|
|
if (table)
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
close_system_tables(thd, &open_tables_state_backup);
|
2008-02-07 11:47:39 +01:00
|
|
|
thd->variables.sql_mode= saved_mode;
|
2005-11-23 00:11:19 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
|
2008-02-04 19:39:55 +01:00
|
|
|
/**
|
|
|
|
Silence DEPRECATED SYNTAX warnings when loading a stored procedure
|
|
|
|
into the cache.
|
|
|
|
*/
|
|
|
|
struct Silence_deprecated_warning : public Internal_error_handler
|
|
|
|
{
|
|
|
|
public:
|
2009-09-10 11:18:29 +02:00
|
|
|
virtual bool handle_condition(THD *thd,
|
|
|
|
uint sql_errno,
|
|
|
|
const char* sqlstate,
|
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
|
|
|
const char* msg,
|
|
|
|
MYSQL_ERROR ** cond_hdl);
|
2008-02-04 19:39:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
2009-09-10 11:18:29 +02:00
|
|
|
Silence_deprecated_warning::handle_condition(
|
|
|
|
THD *,
|
|
|
|
uint sql_errno,
|
|
|
|
const char*,
|
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
|
|
|
const char*,
|
|
|
|
MYSQL_ERROR ** cond_hdl)
|
2008-02-04 19:39:55 +01:00
|
|
|
{
|
2009-09-10 11:18:29 +02:00
|
|
|
*cond_hdl= NULL;
|
2008-02-04 19:39:55 +01:00
|
|
|
if (sql_errno == ER_WARN_DEPRECATED_SYNTAX &&
|
|
|
|
level == MYSQL_ERROR::WARN_LEVEL_WARN)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
static int
|
|
|
|
db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
|
|
|
|
ulong sql_mode, const char *params, const char *returns,
|
|
|
|
const char *body, st_sp_chistics &chistics,
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
const char *definer, longlong created, longlong modified,
|
|
|
|
Stored_program_creation_ctx *creation_ctx)
|
2005-11-23 00:11:19 +01:00
|
|
|
{
|
2006-01-05 23:47:49 +01:00
|
|
|
LEX *old_lex= thd->lex, newlex;
|
2005-11-23 00:11:19 +01:00
|
|
|
String defstr;
|
2007-08-31 18:42:14 +02:00
|
|
|
char saved_cur_db_name_buf[NAME_LEN+1];
|
|
|
|
LEX_STRING saved_cur_db_name=
|
|
|
|
{ saved_cur_db_name_buf, sizeof(saved_cur_db_name_buf) };
|
|
|
|
bool cur_db_changed;
|
2005-11-23 00:11:19 +01:00
|
|
|
ulong old_sql_mode= thd->variables.sql_mode;
|
2006-01-05 23:47:49 +01:00
|
|
|
ha_rows old_select_limit= thd->variables.select_limit;
|
|
|
|
sp_rcontext *old_spcont= thd->spcont;
|
2008-02-04 19:39:55 +01:00
|
|
|
Silence_deprecated_warning warning_handler;
|
|
|
|
|
2006-09-27 16:21:29 +02:00
|
|
|
char definer_user_name_holder[USERNAME_LENGTH + 1];
|
2006-09-13 09:03:52 +02:00
|
|
|
LEX_STRING definer_user_name= { definer_user_name_holder,
|
2006-09-28 15:00:44 +02:00
|
|
|
USERNAME_LENGTH };
|
2006-03-02 13:18:49 +01:00
|
|
|
|
|
|
|
char definer_host_name_holder[HOSTNAME_LENGTH + 1];
|
2006-05-18 16:57:50 +02:00
|
|
|
LEX_STRING definer_host_name= { definer_host_name_holder, HOSTNAME_LENGTH };
|
|
|
|
|
2006-01-05 23:47:49 +01:00
|
|
|
int ret;
|
2005-11-23 00:11:19 +01:00
|
|
|
|
|
|
|
thd->variables.sql_mode= sql_mode;
|
|
|
|
thd->variables.select_limit= HA_POS_ERROR;
|
|
|
|
|
|
|
|
thd->lex= &newlex;
|
|
|
|
newlex.current_select= NULL;
|
|
|
|
|
2006-03-02 13:18:49 +01:00
|
|
|
parse_user(definer, strlen(definer),
|
|
|
|
definer_user_name.str, &definer_user_name.length,
|
|
|
|
definer_host_name.str, &definer_host_name.length);
|
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
defstr.set_charset(creation_ctx->get_client_cs());
|
2006-03-02 13:18:49 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
We have to add DEFINER clause and provide proper routine characterstics in
|
|
|
|
routine definition statement that we build here to be able to use this
|
|
|
|
definition for SHOW CREATE PROCEDURE later.
|
|
|
|
*/
|
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
if (!create_string(thd, &defstr,
|
2008-05-16 01:13:24 +02:00
|
|
|
type,
|
|
|
|
NULL, 0,
|
|
|
|
name->m_name.str, name->m_name.length,
|
|
|
|
params, strlen(params),
|
|
|
|
returns, strlen(returns),
|
|
|
|
body, strlen(body),
|
|
|
|
&chistics, &definer_user_name, &definer_host_name))
|
2006-01-05 23:47:49 +01:00
|
|
|
{
|
|
|
|
ret= SP_INTERNAL_ERROR;
|
2005-11-23 00:11:19 +01:00
|
|
|
goto end;
|
2006-01-05 23:47:49 +01:00
|
|
|
}
|
2004-03-17 12:09:03 +01:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
/*
|
2007-08-31 18:42:14 +02:00
|
|
|
Change the current database (if needed).
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
|
2007-08-31 18:42:14 +02:00
|
|
|
TODO: why do we force switch here?
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
*/
|
|
|
|
|
2007-08-31 18:42:14 +02:00
|
|
|
if (mysql_opt_change_db(thd, &name->m_db, &saved_cur_db_name, TRUE,
|
|
|
|
&cur_db_changed))
|
|
|
|
{
|
2007-08-31 22:12:00 +02:00
|
|
|
ret= SP_INTERNAL_ERROR;
|
2005-11-23 00:11:19 +01:00
|
|
|
goto end;
|
2007-08-31 18:42:14 +02:00
|
|
|
}
|
2003-07-01 17:19:48 +02:00
|
|
|
|
2007-06-14 16:35:59 +02:00
|
|
|
thd->spcont= NULL;
|
|
|
|
|
2007-04-26 05:38:12 +02:00
|
|
|
{
|
2008-07-14 23:41:30 +02:00
|
|
|
Parser_state parser_state(thd, defstr.c_ptr(), defstr.length());
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
|
2007-04-26 05:38:12 +02:00
|
|
|
lex_start(thd);
|
2005-11-23 00:11:19 +01:00
|
|
|
|
2008-02-04 19:39:55 +01:00
|
|
|
thd->push_internal_handler(&warning_handler);
|
2008-07-15 03:43:12 +02:00
|
|
|
ret= parse_sql(thd, & parser_state, creation_ctx) || newlex.sphead == NULL;
|
2008-02-04 19:39:55 +01:00
|
|
|
thd->pop_internal_handler();
|
2007-06-14 16:35:59 +02:00
|
|
|
|
2007-08-31 18:42:14 +02:00
|
|
|
/*
|
|
|
|
Force switching back to the saved current database (if changed),
|
|
|
|
because it may be NULL. In this case, mysql_change_db() would
|
|
|
|
generate an error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (cur_db_changed && mysql_change_db(thd, &saved_cur_db_name, TRUE))
|
|
|
|
{
|
|
|
|
delete newlex.sphead;
|
2007-08-31 22:12:00 +02:00
|
|
|
ret= SP_INTERNAL_ERROR;
|
2007-08-31 18:42:14 +02:00
|
|
|
goto end;
|
2007-06-14 16:35:59 +02:00
|
|
|
}
|
2007-08-31 18:42:14 +02:00
|
|
|
|
|
|
|
if (ret)
|
2007-06-14 16:35:59 +02:00
|
|
|
{
|
2007-08-31 18:42:14 +02:00
|
|
|
delete newlex.sphead;
|
|
|
|
ret= SP_PARSE_ERROR;
|
|
|
|
goto end;
|
2007-06-14 16:35:59 +02:00
|
|
|
}
|
2007-08-31 18:42:14 +02:00
|
|
|
|
|
|
|
*sphp= newlex.sphead;
|
|
|
|
(*sphp)->set_definer(&definer_user_name, &definer_host_name);
|
|
|
|
(*sphp)->set_info(created, modified, &chistics, sql_mode);
|
|
|
|
(*sphp)->set_creation_ctx(creation_ctx);
|
|
|
|
(*sphp)->optimize();
|
|
|
|
/*
|
|
|
|
Not strictly necessary to invoke this method here, since we know
|
|
|
|
that we've parsed CREATE PROCEDURE/FUNCTION and not an
|
|
|
|
UPDATE/DELETE/INSERT/REPLACE/LOAD/CREATE TABLE, but we try to
|
|
|
|
maintain the invariant that this method is called for each
|
|
|
|
distinct statement, in case its logic is extended with other
|
|
|
|
types of analyses in future.
|
|
|
|
*/
|
|
|
|
newlex.set_trg_event_type_for_tables();
|
2005-11-23 00:11:19 +01:00
|
|
|
}
|
2007-06-14 16:35:59 +02:00
|
|
|
|
2005-11-23 01:49:44 +01:00
|
|
|
end:
|
2006-05-04 14:30:38 +02:00
|
|
|
lex_end(thd->lex);
|
2006-01-05 23:47:49 +01:00
|
|
|
thd->spcont= old_spcont;
|
2005-11-23 00:11:19 +01:00
|
|
|
thd->variables.sql_mode= old_sql_mode;
|
2006-01-05 23:47:49 +01:00
|
|
|
thd->variables.select_limit= old_select_limit;
|
|
|
|
thd->lex= old_lex;
|
2005-11-23 00:11:19 +01:00
|
|
|
return ret;
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2005-03-04 22:14:35 +01:00
|
|
|
static void
|
|
|
|
sp_returns_type(THD *thd, String &result, sp_head *sp)
|
|
|
|
{
|
2005-03-10 20:42:57 +01:00
|
|
|
TABLE table;
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE share;
|
2005-03-04 22:14:35 +01:00
|
|
|
Field *field;
|
2005-11-23 21:45:02 +01:00
|
|
|
bzero((char*) &table, sizeof(table));
|
|
|
|
bzero((char*) &share, sizeof(share));
|
2005-03-10 20:42:57 +01:00
|
|
|
table.in_use= thd;
|
2005-11-23 21:45:02 +01:00
|
|
|
table.s = &share;
|
2005-12-07 15:01:17 +01:00
|
|
|
field= sp->create_result_field(0, 0, &table);
|
2005-03-04 22:14:35 +01:00
|
|
|
field->sql_type(result);
|
2006-07-27 15:57:43 +02:00
|
|
|
|
|
|
|
if (field->has_charset())
|
|
|
|
{
|
|
|
|
result.append(STRING_WITH_LEN(" CHARSET "));
|
|
|
|
result.append(field->charset()->csname);
|
|
|
|
}
|
|
|
|
|
2005-03-04 22:14:35 +01:00
|
|
|
delete field;
|
|
|
|
}
|
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Write stored-routine object into mysql.proc.
|
|
|
|
|
|
|
|
This operation stores attributes of the stored procedure/function into
|
|
|
|
the mysql.proc.
|
|
|
|
|
|
|
|
@param thd Thread context.
|
|
|
|
@param type Stored routine type
|
|
|
|
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION).
|
|
|
|
@param sp Stored routine object to store.
|
|
|
|
|
2008-02-19 12:43:01 +01:00
|
|
|
@note Opens and closes the thread tables. Therefore assumes
|
|
|
|
that there are no locked tables in this thread at the time of
|
|
|
|
invocation.
|
|
|
|
Unlike some other DDL statements, *does* close the tables
|
|
|
|
in the end, since the call to this function is normally
|
|
|
|
followed by an implicit grant (sp_grant_privileges())
|
|
|
|
and this subsequent call opens and closes mysql.procs_priv.
|
|
|
|
|
|
|
|
@return Error code. SP_OK is returned on success. Other
|
|
|
|
SP_ constants are used to indicate about errors.
|
2007-05-29 19:22:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_create_routine(THD *thd, int type, sp_head *sp)
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
2003-02-21 17:37:05 +01:00
|
|
|
int ret;
|
2002-12-12 13:14:23 +01:00
|
|
|
TABLE *table;
|
2006-01-11 00:07:40 +01:00
|
|
|
char definer[USER_HOST_BUFF_SIZE];
|
2008-02-07 11:47:39 +01:00
|
|
|
ulong saved_mode= thd->variables.sql_mode;
|
2007-05-29 19:22:33 +02:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
CHARSET_INFO *db_cs= get_default_db_collation(thd, sp->m_db.str);
|
|
|
|
|
2007-10-17 10:13:56 +02:00
|
|
|
enum_check_fields saved_count_cuted_fields;
|
|
|
|
|
|
|
|
bool store_failed= FALSE;
|
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
DBUG_ENTER("sp_create_routine");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",type, (int) sp->m_name.length,
|
2005-10-07 02:37:24 +02:00
|
|
|
sp->m_name.str));
|
2008-05-15 01:23:54 +02:00
|
|
|
String retstr(64);
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
|
|
|
|
type == TYPE_ENUM_FUNCTION);
|
|
|
|
|
2008-02-07 11:47:39 +01:00
|
|
|
/* Reset sql_mode during data dictionary operations. */
|
|
|
|
thd->variables.sql_mode= 0;
|
|
|
|
|
BUG#25091 (A DELETE statement to mysql database is not logged in ROW format):
With this patch, statements that change metadata (in the mysql database)
is logged as statements, while normal changes (e.g., using INSERT, DELETE,
and/or UPDATE) is logged according to the format in effect.
The log tables (i.e., general_log and slow_log) are not replicated at all.
With this patch, the following statements are replicated as statements:
GRANT, REVOKE (ALL), CREATE USER, DROP USER, and RENAME USER.
2007-02-26 10:19:08 +01:00
|
|
|
/*
|
|
|
|
This statement will be replicated as a statement, even when using
|
|
|
|
row-based replication. The flag will be reset at the end of the
|
|
|
|
statement.
|
|
|
|
*/
|
|
|
|
thd->clear_current_stmt_binlog_row_based();
|
|
|
|
|
2007-10-17 10:13:56 +02:00
|
|
|
saved_count_cuted_fields= thd->count_cuted_fields;
|
|
|
|
thd->count_cuted_fields= CHECK_FIELD_WARN;
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
if (!(table= open_proc_table_for_update(thd)))
|
2003-02-21 17:37:05 +01:00
|
|
|
ret= SP_OPEN_TABLE_FAILED;
|
|
|
|
else
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
2005-01-06 12:00:13 +01:00
|
|
|
restore_record(table, s->default_values); // Get default values for fields
|
2006-03-02 13:18:49 +01:00
|
|
|
|
|
|
|
/* NOTE: all needed privilege checks have been already done. */
|
2006-03-09 18:41:21 +01:00
|
|
|
strxnmov(definer, sizeof(definer)-1, thd->lex->definer->user.str, "@",
|
2006-03-02 13:18:49 +01:00
|
|
|
thd->lex->definer->host.str, NullS);
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2007-07-25 16:38:52 +02:00
|
|
|
if (table->s->fields < MYSQL_PROC_FIELD_COUNT)
|
2003-10-30 10:25:45 +01:00
|
|
|
{
|
|
|
|
ret= SP_GET_FIELD_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2006-02-16 13:40:37 +01:00
|
|
|
|
2006-03-28 15:06:06 +02:00
|
|
|
if (system_charset_info->cset->numchars(system_charset_info,
|
|
|
|
sp->m_name.str,
|
|
|
|
sp->m_name.str+sp->m_name.length) >
|
|
|
|
table->field[MYSQL_PROC_FIELD_NAME]->char_length())
|
2005-05-31 18:36:32 +02:00
|
|
|
{
|
|
|
|
ret= SP_BAD_IDENTIFIER;
|
|
|
|
goto done;
|
|
|
|
}
|
2005-07-27 03:08:49 +02:00
|
|
|
if (sp->m_body.length > table->field[MYSQL_PROC_FIELD_BODY]->field_length)
|
|
|
|
{
|
|
|
|
ret= SP_BODY_TOO_LONG;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-10-17 10:13:56 +02:00
|
|
|
|
|
|
|
store_failed=
|
|
|
|
table->field[MYSQL_PROC_FIELD_DB]->
|
|
|
|
store(sp->m_db.str, sp->m_db.length, system_charset_info);
|
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_NAME]->
|
|
|
|
store(sp->m_name.str, sp->m_name.length, system_charset_info);
|
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_MYSQL_TYPE]->
|
|
|
|
store((longlong)type, TRUE);
|
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_SPECIFIC_NAME]->
|
|
|
|
store(sp->m_name.str, sp->m_name.length, system_charset_info);
|
|
|
|
|
2004-10-14 18:07:09 +02:00
|
|
|
if (sp->m_chistics->daccess != SP_DEFAULT_ACCESS)
|
2007-10-17 10:13:56 +02:00
|
|
|
{
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_ACCESS]->
|
|
|
|
store((longlong)sp->m_chistics->daccess, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_DETERMINISTIC]->
|
|
|
|
store((longlong)(sp->m_chistics->detistic ? 1 : 2), TRUE);
|
|
|
|
|
2004-10-14 18:07:09 +02:00
|
|
|
if (sp->m_chistics->suid != SP_IS_DEFAULT_SUID)
|
2007-10-17 10:13:56 +02:00
|
|
|
{
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
|
|
|
|
store((longlong)sp->m_chistics->suid, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_PARAM_LIST]->
|
|
|
|
store(sp->m_params.str, sp->m_params.length, system_charset_info);
|
|
|
|
|
2005-03-04 22:14:35 +01:00
|
|
|
if (sp->m_type == TYPE_ENUM_FUNCTION)
|
|
|
|
{
|
|
|
|
sp_returns_type(thd, retstr, sp);
|
2007-10-17 10:13:56 +02:00
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_RETURNS]->
|
|
|
|
store(retstr.ptr(), retstr.length(), system_charset_info);
|
2005-03-04 22:14:35 +01:00
|
|
|
}
|
2007-10-17 10:13:56 +02:00
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_BODY]->
|
|
|
|
store(sp->m_body.str, sp->m_body.length, system_charset_info);
|
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_DEFINER]->
|
|
|
|
store(definer, (uint)strlen(definer), system_charset_info);
|
|
|
|
|
2003-10-30 10:25:45 +01:00
|
|
|
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_CREATED])->set_time();
|
2004-09-08 11:42:18 +02:00
|
|
|
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time();
|
2007-10-17 10:13:56 +02:00
|
|
|
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_SQL_MODE]->
|
2008-02-07 11:47:39 +01:00
|
|
|
store((longlong)saved_mode, TRUE);
|
2007-10-17 10:13:56 +02:00
|
|
|
|
2003-12-12 14:05:29 +01:00
|
|
|
if (sp->m_chistics->comment.str)
|
2007-10-17 10:13:56 +02:00
|
|
|
{
|
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_COMMENT]->
|
|
|
|
store(sp->m_chistics->comment.str, sp->m_chistics->comment.length,
|
|
|
|
system_charset_info);
|
|
|
|
}
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2005-11-10 17:50:51 +01:00
|
|
|
if ((sp->m_type == TYPE_ENUM_FUNCTION) &&
|
|
|
|
!trust_function_creators && mysql_bin_log.is_open())
|
2005-05-05 14:20:53 +02:00
|
|
|
{
|
|
|
|
if (!sp->m_chistics->detistic)
|
|
|
|
{
|
|
|
|
/*
|
2005-11-10 17:50:51 +01:00
|
|
|
Note that this test is not perfect; one could use
|
2005-05-05 14:20:53 +02:00
|
|
|
a non-deterministic read-only function in an update statement.
|
|
|
|
*/
|
|
|
|
enum enum_sp_data_access access=
|
|
|
|
(sp->m_chistics->daccess == SP_DEFAULT_ACCESS) ?
|
|
|
|
SP_DEFAULT_ACCESS_MAPPING : sp->m_chistics->daccess;
|
|
|
|
if (access == SP_CONTAINS_SQL ||
|
|
|
|
access == SP_MODIFIES_SQL_DATA)
|
|
|
|
{
|
|
|
|
my_message(ER_BINLOG_UNSAFE_ROUTINE,
|
|
|
|
ER(ER_BINLOG_UNSAFE_ROUTINE), MYF(0));
|
|
|
|
ret= SP_INTERNAL_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2005-09-15 21:29:07 +02:00
|
|
|
if (!(thd->security_ctx->master_access & SUPER_ACL))
|
2005-05-05 14:20:53 +02:00
|
|
|
{
|
|
|
|
my_message(ER_BINLOG_CREATE_ROUTINE_NEED_SUPER,
|
|
|
|
ER(ER_BINLOG_CREATE_ROUTINE_NEED_SUPER), MYF(0));
|
|
|
|
ret= SP_INTERNAL_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
table->field[MYSQL_PROC_FIELD_CHARACTER_SET_CLIENT]->set_notnull();
|
2007-10-17 10:13:56 +02:00
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_CHARACTER_SET_CLIENT]->store(
|
|
|
|
thd->charset()->csname,
|
|
|
|
strlen(thd->charset()->csname),
|
|
|
|
system_charset_info);
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
|
|
|
|
table->field[MYSQL_PROC_FIELD_COLLATION_CONNECTION]->set_notnull();
|
2007-10-17 10:13:56 +02:00
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_COLLATION_CONNECTION]->store(
|
|
|
|
thd->variables.collation_connection->name,
|
|
|
|
strlen(thd->variables.collation_connection->name),
|
|
|
|
system_charset_info);
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
|
|
|
|
table->field[MYSQL_PROC_FIELD_DB_COLLATION]->set_notnull();
|
2007-10-17 10:13:56 +02:00
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_DB_COLLATION]->store(
|
|
|
|
db_cs->name, strlen(db_cs->name), system_charset_info);
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
|
|
|
|
table->field[MYSQL_PROC_FIELD_BODY_UTF8]->set_notnull();
|
2007-10-17 10:13:56 +02:00
|
|
|
store_failed= store_failed ||
|
|
|
|
table->field[MYSQL_PROC_FIELD_BODY_UTF8]->store(
|
|
|
|
sp->m_body_utf8.str, sp->m_body_utf8.length, system_charset_info);
|
|
|
|
|
|
|
|
if (store_failed)
|
|
|
|
{
|
|
|
|
ret= SP_FLD_STORE_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
ret= SP_OK;
|
2005-12-22 06:39:02 +01:00
|
|
|
if (table->file->ha_write_row(table->record[0]))
|
2003-02-21 17:37:05 +01:00
|
|
|
ret= SP_WRITE_ROW_FAILED;
|
2005-05-05 14:20:53 +02:00
|
|
|
else if (mysql_bin_log.is_open())
|
|
|
|
{
|
|
|
|
thd->clear_error();
|
2006-03-02 13:18:49 +01:00
|
|
|
|
|
|
|
String log_query;
|
|
|
|
log_query.set_charset(system_charset_info);
|
Bug#25411 (trigger code truncated), PART II
Bug 28127 (Some valid identifiers names are not parsed correctly)
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
This patch is the second part of a major cleanup, required to fix
Bug 25411 (trigger code truncated).
The root cause of the issue stems from the function skip_rear_comments,
which was a work around to remove "extra" "*/" characters from the query
text, when parsing a query and reusing the text fragments to represent a
view, trigger, function or stored procedure.
The reason for this work around is that "special comments",
like /*!50002 XXX */, were not parsed properly, so that a query like:
AAA /*!50002 BBB */ CCC
would be seen by the parser as "AAA BBB */ CCC" when the current version
is greater or equal to 5.0.2
The root cause of this stems from how special comments are parsed.
Special comments are really out-of-bound text that appear inside a query,
that affects how the parser behave.
In nature, /*!50002 XXX */ in MySQL is similar to the C concept
of preprocessing :
#if VERSION >= 50002
XXX
#endif
Depending on the current VERSION of the server, either the special comment
should be expanded or it should be ignored, but in all cases the "text" of
the query should be re-written to strip the "/*!50002" and "*/" markers,
which does not belong to the SQL language itself.
Prior to this fix, these markers would leak into :
- the storage format for VIEW,
- the storage format for FUNCTION,
- the storage format for FUNCTION parameters, in mysql.proc (param_list),
- the storage format for PROCEDURE,
- the storage format for PROCEDURE parameters, in mysql.proc (param_list),
- the storage format for TRIGGER,
- the binary log used for replication.
In all cases, not only this cause format corruption, but also provide a vector
for dormant security issues, by allowing to tunnel code that will be activated
after an upgrade.
The proper solution is to deal with special comments strictly during parsing,
when accepting a query from the outside world.
Once a query is parsed and an object is created with a persistant
representation, this object should not arbitrarily mutate after an upgrade.
In short, special comments are a useful but limited feature for MYSQLdump,
when used at an *interface* level to facilitate import/export,
but bloating the server *internal* storage format is *not* the proper way
to deal with configuration management of the user logic.
With this fix:
- the Lex_input_stream class now acts as a comment pre-processor,
and either expands or ignore special comments on the fly.
- MYSQLlex and sql_yacc.yy have been cleaned up to strictly use the
public interface of Lex_input_stream. In particular, how the input stream
accepts or rejects a character is private to Lex_input_stream, and the
internal buffer pointers of that class are strictly private, and should not
be tempered with during parsing.
This caused many changes mostly in sql_lex.cc.
During the code cleanup in case MY_LEX_NUMBER_IDENT,
Bug 28127 (Some valid identifiers names are not parsed correctly)
was found and fixed.
By parsing special comments properly, and removing the function
'skip_rear_comments' [sic],
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
has been fixed as well.
2007-06-12 23:23:58 +02:00
|
|
|
|
2008-05-15 01:23:54 +02:00
|
|
|
if (!create_string(thd, &log_query,
|
|
|
|
sp->m_type,
|
2008-05-16 01:13:24 +02:00
|
|
|
(sp->m_explicit_name ? sp->m_db.str : NULL),
|
|
|
|
(sp->m_explicit_name ? sp->m_db.length : 0),
|
2008-05-15 01:23:54 +02:00
|
|
|
sp->m_name.str, sp->m_name.length,
|
|
|
|
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),
|
|
|
|
&(thd->lex->definer->host)))
|
|
|
|
{
|
|
|
|
ret= SP_INTERNAL_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2009-02-28 02:35:18 +01:00
|
|
|
/* restore sql_mode when binloging */
|
|
|
|
thd->variables.sql_mode= saved_mode;
|
2005-05-05 14:20:53 +02:00
|
|
|
/* Such a statement can always go directly to binlog, no trans cache */
|
2005-12-22 06:39:02 +01:00
|
|
|
thd->binlog_query(THD::MYSQL_QUERY_TYPE,
|
2009-04-09 01:42:51 +02:00
|
|
|
log_query.c_ptr(), log_query.length(),
|
2009-05-30 15:32:28 +02:00
|
|
|
FALSE, FALSE, 0);
|
2009-02-28 02:35:18 +01:00
|
|
|
thd->variables.sql_mode= 0;
|
2005-05-05 14:20:53 +02:00
|
|
|
}
|
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
|
|
|
|
2003-10-30 10:25:45 +01:00
|
|
|
done:
|
2007-10-17 10:13:56 +02:00
|
|
|
thd->count_cuted_fields= saved_count_cuted_fields;
|
2008-02-07 11:47:39 +01:00
|
|
|
thd->variables.sql_mode= saved_mode;
|
2007-10-17 10:13:56 +02:00
|
|
|
|
2003-02-28 15:07:14 +01:00
|
|
|
close_thread_tables(thd);
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
/**
|
|
|
|
Delete the record for the stored routine object from mysql.proc.
|
|
|
|
|
|
|
|
The operation deletes the record for the stored routine specified by name
|
|
|
|
from the mysql.proc table and invalidates the stored-routine cache.
|
|
|
|
|
|
|
|
@param thd Thread context.
|
|
|
|
@param type Stored routine type
|
|
|
|
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION)
|
|
|
|
@param name Stored routine name.
|
|
|
|
|
|
|
|
@return Error code. SP_OK is returned on success. Other SP_ constants are
|
|
|
|
used to indicate about errors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_drop_routine(THD *thd, int type, sp_name *name)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
int ret;
|
2007-05-29 19:22:33 +02:00
|
|
|
DBUG_ENTER("sp_drop_routine");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",
|
|
|
|
type, (int) name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
|
|
|
|
type == TYPE_ENUM_FUNCTION);
|
|
|
|
|
BUG#25091 (A DELETE statement to mysql database is not logged in ROW format):
With this patch, statements that change metadata (in the mysql database)
is logged as statements, while normal changes (e.g., using INSERT, DELETE,
and/or UPDATE) is logged according to the format in effect.
The log tables (i.e., general_log and slow_log) are not replicated at all.
With this patch, the following statements are replicated as statements:
GRANT, REVOKE (ALL), CREATE USER, DROP USER, and RENAME USER.
2007-02-26 10:19:08 +01:00
|
|
|
/*
|
|
|
|
This statement will be replicated as a statement, even when using
|
|
|
|
row-based replication. The flag will be reset at the end of the
|
|
|
|
statement.
|
|
|
|
*/
|
|
|
|
thd->clear_current_stmt_binlog_row_based();
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
if (!(table= open_proc_table_for_update(thd)))
|
|
|
|
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
|
|
|
|
if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2005-12-22 06:39:02 +01:00
|
|
|
if (table->file->ha_delete_row(table->record[0]))
|
2003-02-21 17:37:05 +01:00
|
|
|
ret= SP_DELETE_ROW_FAILED;
|
|
|
|
}
|
2006-10-03 19:38:25 +02:00
|
|
|
|
|
|
|
if (ret == SP_OK)
|
|
|
|
{
|
2007-06-19 13:27:53 +02:00
|
|
|
write_bin_log(thd, TRUE, thd->query, thd->query_length);
|
2007-05-29 19:22:33 +02:00
|
|
|
sp_cache_invalidate();
|
2006-10-03 19:38:25 +02:00
|
|
|
}
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
close_thread_tables(thd);
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
/**
|
|
|
|
Find and updated the record for the stored routine object in mysql.proc.
|
|
|
|
|
|
|
|
The operation finds the record for the stored routine specified by name
|
|
|
|
in the mysql.proc table and updates it with new attributes. After
|
|
|
|
successful update, the cache is invalidated.
|
|
|
|
|
|
|
|
@param thd Thread context.
|
|
|
|
@param type Stored routine type
|
|
|
|
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION)
|
|
|
|
@param name Stored routine name.
|
|
|
|
@param chistics New values of stored routine attributes to write.
|
|
|
|
|
|
|
|
@return Error code. SP_OK is returned on success. Other SP_ constants are
|
|
|
|
used to indicate about errors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
int ret;
|
2007-05-29 19:22:33 +02:00
|
|
|
DBUG_ENTER("sp_update_routine");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",
|
|
|
|
type, (int) name->m_name.length, name->m_name.str));
|
2007-05-29 19:22:33 +02:00
|
|
|
|
|
|
|
DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
|
|
|
|
type == TYPE_ENUM_FUNCTION);
|
BUG#25091 (A DELETE statement to mysql database is not logged in ROW format):
With this patch, statements that change metadata (in the mysql database)
is logged as statements, while normal changes (e.g., using INSERT, DELETE,
and/or UPDATE) is logged according to the format in effect.
The log tables (i.e., general_log and slow_log) are not replicated at all.
With this patch, the following statements are replicated as statements:
GRANT, REVOKE (ALL), CREATE USER, DROP USER, and RENAME USER.
2007-02-26 10:19:08 +01:00
|
|
|
/*
|
|
|
|
This statement will be replicated as a statement, even when using
|
2007-06-01 10:12:06 +02:00
|
|
|
row-based replication. The flag will be reset at the end of the
|
BUG#25091 (A DELETE statement to mysql database is not logged in ROW format):
With this patch, statements that change metadata (in the mysql database)
is logged as statements, while normal changes (e.g., using INSERT, DELETE,
and/or UPDATE) is logged according to the format in effect.
The log tables (i.e., general_log and slow_log) are not replicated at all.
With this patch, the following statements are replicated as statements:
GRANT, REVOKE (ALL), CREATE USER, DROP USER, and RENAME USER.
2007-02-26 10:19:08 +01:00
|
|
|
statement.
|
|
|
|
*/
|
|
|
|
thd->clear_current_stmt_binlog_row_based();
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
if (!(table= open_proc_table_for_update(thd)))
|
|
|
|
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
|
|
|
|
if ((ret= db_find_routine_aux(thd, type, name, table)) == SP_OK)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
|
|
|
store_record(table,record[1]);
|
2004-11-03 11:39:38 +01:00
|
|
|
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
|
2003-11-17 18:21:36 +01:00
|
|
|
((Field_timestamp *)table->field[MYSQL_PROC_FIELD_MODIFIED])->set_time();
|
2004-10-14 18:07:09 +02:00
|
|
|
if (chistics->suid != SP_IS_DEFAULT_SUID)
|
|
|
|
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
|
2006-06-16 12:17:20 +02:00
|
|
|
store((longlong)chistics->suid, TRUE);
|
2004-10-14 18:07:09 +02:00
|
|
|
if (chistics->daccess != SP_DEFAULT_ACCESS)
|
|
|
|
table->field[MYSQL_PROC_FIELD_ACCESS]->
|
2006-06-16 12:17:20 +02:00
|
|
|
store((longlong)chistics->daccess, TRUE);
|
2003-12-10 19:05:37 +01:00
|
|
|
if (chistics->comment.str)
|
|
|
|
table->field[MYSQL_PROC_FIELD_COMMENT]->store(chistics->comment.str,
|
|
|
|
chistics->comment.length,
|
2003-11-17 18:21:36 +01:00
|
|
|
system_charset_info);
|
2007-06-28 15:07:55 +02:00
|
|
|
if ((ret= table->file->ha_update_row(table->record[1],table->record[0])) &&
|
|
|
|
ret != HA_ERR_RECORD_IS_THE_SAME)
|
2003-11-17 18:21:36 +01:00
|
|
|
ret= SP_WRITE_ROW_FAILED;
|
2007-06-28 15:07:55 +02:00
|
|
|
else
|
|
|
|
ret= 0;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
2006-10-03 19:38:25 +02:00
|
|
|
|
|
|
|
if (ret == SP_OK)
|
|
|
|
{
|
2007-06-19 13:27:53 +02:00
|
|
|
write_bin_log(thd, TRUE, thd->query, thd->query_length);
|
2007-05-29 19:22:33 +02:00
|
|
|
sp_cache_invalidate();
|
2006-10-03 19:38:25 +02:00
|
|
|
}
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
close_thread_tables(thd);
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2008-02-19 12:43:01 +01:00
|
|
|
/**
|
|
|
|
Drop all routines in database 'db'
|
|
|
|
|
|
|
|
@note Close the thread tables, the calling code might want to
|
|
|
|
delete from other system tables afterwards.
|
|
|
|
*/
|
|
|
|
|
2004-03-22 14:44:41 +01:00
|
|
|
int
|
|
|
|
sp_drop_db_routines(THD *thd, char *db)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
int ret;
|
2006-04-18 16:01:01 +02:00
|
|
|
uint key_len;
|
2004-03-22 14:44:41 +01:00
|
|
|
DBUG_ENTER("sp_drop_db_routines");
|
|
|
|
DBUG_PRINT("enter", ("db: %s", db));
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
ret= SP_OPEN_TABLE_FAILED;
|
|
|
|
if (!(table= open_proc_table_for_update(thd)))
|
|
|
|
goto err;
|
2004-03-22 14:44:41 +01:00
|
|
|
|
2006-04-18 16:01:01 +02:00
|
|
|
table->field[MYSQL_PROC_FIELD_DB]->store(db, strlen(db), system_charset_info);
|
|
|
|
key_len= table->key_info->key_part[0].store_length;
|
|
|
|
|
2004-03-22 14:44:41 +01:00
|
|
|
ret= SP_OK;
|
2005-07-18 13:31:02 +02:00
|
|
|
table->file->ha_index_init(0, 1);
|
2007-08-13 15:11:25 +02:00
|
|
|
if (! table->file->index_read_map(table->record[0],
|
|
|
|
(uchar *)table->field[MYSQL_PROC_FIELD_DB]->ptr,
|
|
|
|
(key_part_map)1, HA_READ_KEY_EXACT))
|
2004-03-22 14:44:41 +01:00
|
|
|
{
|
|
|
|
int nxtres;
|
|
|
|
bool deleted= FALSE;
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
do
|
|
|
|
{
|
2005-12-22 06:39:02 +01:00
|
|
|
if (! table->file->ha_delete_row(table->record[0]))
|
2004-03-22 14:44:41 +01:00
|
|
|
deleted= TRUE; /* We deleted something */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret= SP_DELETE_ROW_FAILED;
|
2004-03-23 12:04:40 +01:00
|
|
|
nxtres= 0;
|
2004-03-22 14:44:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (! (nxtres= table->file->index_next_same(table->record[0],
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
(uchar *)table->field[MYSQL_PROC_FIELD_DB]->ptr,
|
2006-04-18 16:01:01 +02:00
|
|
|
key_len)));
|
2004-03-22 14:44:41 +01:00
|
|
|
if (nxtres != HA_ERR_END_OF_FILE)
|
|
|
|
ret= SP_KEY_NOT_FOUND;
|
|
|
|
if (deleted)
|
|
|
|
sp_cache_invalidate();
|
|
|
|
}
|
2004-07-15 03:19:07 +02:00
|
|
|
table->file->ha_index_end();
|
2004-03-22 14:44:41 +01:00
|
|
|
|
|
|
|
close_thread_tables(thd);
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
err:
|
2004-03-22 14:44:41 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
/**
|
|
|
|
Implement SHOW CREATE statement for stored routines.
|
|
|
|
|
|
|
|
The operation finds the stored routine object specified by name and then
|
|
|
|
calls sp_head::show_create_routine() for the object.
|
|
|
|
|
|
|
|
@param thd Thread context.
|
|
|
|
@param type Stored routine type
|
|
|
|
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION)
|
|
|
|
@param name Stored routine name.
|
|
|
|
|
|
|
|
@return Error status.
|
|
|
|
@retval FALSE on success
|
|
|
|
@retval TRUE on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
sp_show_create_routine(THD *thd, int type, sp_name *name)
|
|
|
|
{
|
|
|
|
bool err_status= TRUE;
|
|
|
|
sp_head *sp;
|
2007-05-30 14:24:21 +02:00
|
|
|
sp_cache **cache = type == TYPE_ENUM_PROCEDURE ?
|
|
|
|
&thd->sp_proc_cache : &thd->sp_func_cache;
|
2007-05-29 19:22:33 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("sp_show_create_routine");
|
2007-06-01 12:17:23 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s",
|
|
|
|
(int) name->m_name.length,
|
|
|
|
name->m_name.str));
|
2007-05-29 19:22:33 +02:00
|
|
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
2007-05-30 14:24:21 +02:00
|
|
|
if ((sp= sp_find_routine(thd, type, name, cache, FALSE)))
|
2007-05-29 19:22:33 +02:00
|
|
|
err_status= sp->show_create_routine(thd, type);
|
|
|
|
|
|
|
|
if (type == TYPE_ENUM_PROCEDURE)
|
|
|
|
thd->variables.max_sp_recursion_depth--;
|
|
|
|
|
|
|
|
DBUG_RETURN(err_status);
|
|
|
|
}
|
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-11-23 00:11:19 +01:00
|
|
|
Obtain object representing stored procedure/function by its name from
|
2005-03-04 14:35:28 +01:00
|
|
|
stored procedures cache and looking into mysql.proc if needed.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread context
|
|
|
|
@param type type of object (TYPE_ENUM_FUNCTION or TYPE_ENUM_PROCEDURE)
|
|
|
|
@param name name of procedure
|
|
|
|
@param cp hash to look routine in
|
|
|
|
@param cache_only if true perform cache-only lookup
|
|
|
|
(Don't look in mysql.proc).
|
|
|
|
|
|
|
|
@retval
|
|
|
|
NonNULL pointer to sp_head object for the procedure
|
|
|
|
@retval
|
|
|
|
NULL in case of error.
|
2005-03-04 14:35:28 +01:00
|
|
|
*/
|
|
|
|
|
2003-02-21 17:37:05 +01:00
|
|
|
sp_head *
|
2005-11-23 00:11:19 +01:00
|
|
|
sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp,
|
|
|
|
bool cache_only)
|
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
sp_head *sp;
|
2005-11-23 00:11:19 +01:00
|
|
|
ulong depth= (type == TYPE_ENUM_PROCEDURE ?
|
|
|
|
thd->variables.max_sp_recursion_depth :
|
|
|
|
0);
|
|
|
|
DBUG_ENTER("sp_find_routine");
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s.%.*s type: %d cache only %d",
|
|
|
|
(int) name->m_db.length, name->m_db.str,
|
|
|
|
(int) name->m_name.length, name->m_name.str,
|
2005-11-23 00:11:19 +01:00
|
|
|
type, cache_only));
|
2003-02-21 17:37:05 +01:00
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
if ((sp= sp_cache_lookup(cp, name)))
|
2003-07-01 18:14:24 +02:00
|
|
|
{
|
2005-11-23 00:11:19 +01:00
|
|
|
ulong level;
|
2006-01-05 23:47:49 +01:00
|
|
|
sp_head *new_sp;
|
|
|
|
const char *returns= "";
|
2006-01-11 00:07:40 +01:00
|
|
|
char definer[USER_HOST_BUFF_SIZE];
|
2006-07-27 15:57:43 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
String buffer for RETURNS data type must have system charset;
|
|
|
|
64 -- size of "returns" column of mysql.proc.
|
|
|
|
*/
|
2006-01-05 23:47:49 +01:00
|
|
|
String retstr(64);
|
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp));
|
|
|
|
if (sp->m_first_free_instance)
|
|
|
|
{
|
2007-01-29 00:47:35 +01:00
|
|
|
DBUG_PRINT("info", ("first free: 0x%lx level: %lu flags %x",
|
2005-11-23 00:11:19 +01:00
|
|
|
(ulong)sp->m_first_free_instance,
|
|
|
|
sp->m_first_free_instance->m_recursion_level,
|
|
|
|
sp->m_first_free_instance->m_flags));
|
|
|
|
DBUG_ASSERT(!(sp->m_first_free_instance->m_flags & sp_head::IS_INVOKED));
|
|
|
|
if (sp->m_first_free_instance->m_recursion_level > depth)
|
|
|
|
{
|
2006-01-05 23:47:49 +01:00
|
|
|
sp->recursion_level_error(thd);
|
2005-11-23 00:11:19 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(sp->m_first_free_instance);
|
|
|
|
}
|
2006-08-24 19:36:26 +02:00
|
|
|
/*
|
|
|
|
Actually depth could be +1 than the actual value in case a SP calls
|
|
|
|
SHOW CREATE PROCEDURE. Hence, the linked list could hold up to one more
|
|
|
|
instance.
|
|
|
|
*/
|
2006-08-04 12:50:49 +02:00
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
level= sp->m_last_cached_sp->m_recursion_level + 1;
|
|
|
|
if (level > depth)
|
|
|
|
{
|
2006-01-05 23:47:49 +01:00
|
|
|
sp->recursion_level_error(thd);
|
2005-11-23 00:11:19 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2006-01-05 23:47:49 +01:00
|
|
|
|
|
|
|
strxmov(definer, sp->m_definer_user.str, "@",
|
|
|
|
sp->m_definer_host.str, NullS);
|
|
|
|
if (type == TYPE_ENUM_FUNCTION)
|
2005-11-23 00:11:19 +01:00
|
|
|
{
|
2006-01-05 23:47:49 +01:00
|
|
|
sp_returns_type(thd, retstr, sp);
|
|
|
|
returns= retstr.ptr();
|
|
|
|
}
|
|
|
|
if (db_load_routine(thd, type, name, &new_sp,
|
|
|
|
sp->m_sql_mode, sp->m_params.str, returns,
|
|
|
|
sp->m_body.str, *sp->m_chistics, definer,
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
2007-06-28 19:34:54 +02:00
|
|
|
sp->m_created, sp->m_modified,
|
|
|
|
sp->get_creation_ctx()) == SP_OK)
|
2006-01-05 23:47:49 +01:00
|
|
|
{
|
|
|
|
sp->m_last_cached_sp->m_next_cached_sp= new_sp;
|
|
|
|
new_sp->m_recursion_level= level;
|
|
|
|
new_sp->m_first_instance= sp;
|
|
|
|
sp->m_last_cached_sp= sp->m_first_free_instance= new_sp;
|
|
|
|
DBUG_PRINT("info", ("added level: 0x%lx, level: %lu, flags %x",
|
2005-11-23 00:11:19 +01:00
|
|
|
(ulong)new_sp, new_sp->m_recursion_level,
|
|
|
|
new_sp->m_flags));
|
2006-01-05 23:47:49 +01:00
|
|
|
DBUG_RETURN(new_sp);
|
2005-11-23 00:11:19 +01:00
|
|
|
}
|
2006-01-05 23:47:49 +01:00
|
|
|
DBUG_RETURN(0);
|
2005-11-23 00:11:19 +01:00
|
|
|
}
|
|
|
|
if (!cache_only)
|
2003-07-01 18:14:24 +02:00
|
|
|
{
|
2005-11-23 00:11:19 +01:00
|
|
|
if (db_find_routine(thd, type, name, &sp) == SP_OK)
|
|
|
|
{
|
|
|
|
sp_cache_insert(cp, sp);
|
|
|
|
DBUG_PRINT("info", ("added new: 0x%lx, level: %lu, flags %x",
|
|
|
|
(ulong)sp, sp->m_recursion_level,
|
|
|
|
sp->m_flags));
|
|
|
|
}
|
2003-07-01 18:14:24 +02:00
|
|
|
}
|
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(sp);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2006-01-26 13:29:46 +01:00
|
|
|
This is used by sql_acl.cc:mysql_routine_grant() and is used to find
|
|
|
|
the routines in 'routines'.
|
2009-05-29 15:37:54 +02:00
|
|
|
|
|
|
|
@param thd Thread handler
|
|
|
|
@param routines List of needles in the hay stack
|
|
|
|
@param any Any of the needles are good enough
|
|
|
|
|
|
|
|
@return
|
|
|
|
@retval FALSE Found.
|
|
|
|
@retval TRUE Not found
|
2006-01-26 13:29:46 +01:00
|
|
|
*/
|
2005-11-23 00:11:19 +01:00
|
|
|
|
2009-05-29 15:37:54 +02:00
|
|
|
bool
|
|
|
|
sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any)
|
2004-12-23 11:46:24 +01:00
|
|
|
{
|
2006-01-26 13:29:46 +01:00
|
|
|
TABLE_LIST *routine;
|
2006-02-22 11:44:04 +01:00
|
|
|
bool sp_object_found;
|
2004-12-23 11:46:24 +01:00
|
|
|
DBUG_ENTER("sp_exists_routine");
|
2006-01-26 13:29:46 +01:00
|
|
|
for (routine= routines; routine; routine= routine->next_global)
|
2004-12-23 11:46:24 +01:00
|
|
|
{
|
|
|
|
sp_name *name;
|
|
|
|
LEX_STRING lex_db;
|
|
|
|
LEX_STRING lex_name;
|
2006-01-26 13:29:46 +01:00
|
|
|
lex_db.length= strlen(routine->db);
|
|
|
|
lex_name.length= strlen(routine->table_name);
|
|
|
|
lex_db.str= thd->strmake(routine->db, lex_db.length);
|
|
|
|
lex_name.str= thd->strmake(routine->table_name, lex_name.length);
|
2007-03-27 18:31:44 +02:00
|
|
|
name= new sp_name(lex_db, lex_name, true);
|
2004-12-23 11:46:24 +01:00
|
|
|
name->init_qname(thd);
|
2006-02-22 11:44:04 +01:00
|
|
|
sp_object_found= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name,
|
|
|
|
&thd->sp_proc_cache, FALSE) != NULL ||
|
|
|
|
sp_find_routine(thd, TYPE_ENUM_FUNCTION, name,
|
|
|
|
&thd->sp_func_cache, FALSE) != NULL;
|
2009-09-10 11:18:29 +02:00
|
|
|
thd->warning_info->clear_warning_info(thd->query_id);
|
2006-02-22 11:44:04 +01:00
|
|
|
if (sp_object_found)
|
2004-12-23 11:46:24 +01:00
|
|
|
{
|
|
|
|
if (any)
|
2009-05-29 15:37:54 +02:00
|
|
|
break;
|
2004-12-23 11:46:24 +01:00
|
|
|
}
|
|
|
|
else if (!any)
|
|
|
|
{
|
2009-05-29 15:37:54 +02:00
|
|
|
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE",
|
|
|
|
routine->table_name);
|
|
|
|
DBUG_RETURN(TRUE);
|
2004-12-23 11:46:24 +01:00
|
|
|
}
|
|
|
|
}
|
2009-05-29 15:37:54 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
2004-12-23 11:46:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2006-01-26 13:29:46 +01:00
|
|
|
Check if a routine exists in the mysql.proc table, without actually
|
2007-10-11 20:37:45 +02:00
|
|
|
parsing the definition. (Used for dropping).
|
2006-01-26 13:29:46 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread context
|
|
|
|
@param name name of procedure
|
2006-01-26 13:29:46 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
0 Success
|
|
|
|
@retval
|
|
|
|
non-0 Error; SP_OPEN_TABLE_FAILED or SP_KEY_NOT_FOUND
|
2006-01-26 13:29:46 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_routine_exists_in_table(THD *thd, int type, sp_name *name)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
int ret;
|
|
|
|
Open_tables_state open_tables_state_backup;
|
|
|
|
|
|
|
|
if (!(table= open_proc_table_for_read(thd, &open_tables_state_backup)))
|
|
|
|
ret= SP_OPEN_TABLE_FAILED;
|
|
|
|
else
|
|
|
|
{
|
2006-02-02 15:37:29 +01:00
|
|
|
if ((ret= db_find_routine_aux(thd, type, name, table)) != SP_OK)
|
2006-01-26 13:29:46 +01:00
|
|
|
ret= SP_KEY_NOT_FOUND;
|
BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked
The problem was that some facilities (like CONVERT_TZ() function or
server HELP statement) may require implicit access to some tables in
'mysql' database. This access was done by ordinary means of adding
such tables to the list of tables the query is going to open.
However, if we issued LOCK TABLES before that, we would get "table
was not locked" error trying to open such implicit tables.
The solution is to treat certain tables as MySQL system tables, like
we already do for mysql.proc. Such tables may be opened for reading
at any moment regardless of any locks in effect. The cost of this is
that system table may be locked for writing only together with other
system tables, it is disallowed to lock system tables for writing and
have any other lock on any other table.
After this patch the following tables are treated as MySQL system
tables:
mysql.help_category
mysql.help_keyword
mysql.help_relation
mysql.help_topic
mysql.proc (it already was)
mysql.time_zone
mysql.time_zone_leap_second
mysql.time_zone_name
mysql.time_zone_transition
mysql.time_zone_transition_type
These tables are now opened with open_system_tables_for_read() and
closed with close_system_tables(), or one table may be opened with
open_system_table_for_update() and closed with close_thread_tables()
(the latter is used for mysql.proc table, which is updated as part of
normal MySQL server operation). These functions may be used when
some tables were opened and locked already.
NOTE: online update of time zone tables is not possible during
replication, because there's no time zone cache flush neither on LOCK
TABLES, nor on FLUSH TABLES, so the master may serve stale time zone
data from cache, while on slave updated data will be loaded from the
time zone tables.
2007-03-09 11:12:31 +01:00
|
|
|
close_system_tables(thd, &open_tables_state_backup);
|
2006-01-26 13:29:46 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Structure that represents element in the set of stored routines
|
|
|
|
used by statement or routine.
|
|
|
|
*/
|
|
|
|
struct Sroutine_hash_entry;
|
|
|
|
|
|
|
|
struct Sroutine_hash_entry
|
2003-07-07 14:55:10 +02:00
|
|
|
{
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Set key consisting of one-byte routine type and quoted routine name.
|
|
|
|
*/
|
2005-07-09 19:51:59 +02:00
|
|
|
LEX_STRING key;
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Next element in list linking all routines in set. See also comments
|
|
|
|
for LEX::sroutine/sroutine_list and sp_head::m_sroutines.
|
|
|
|
*/
|
|
|
|
Sroutine_hash_entry *next;
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-12-07 10:27:17 +01:00
|
|
|
Uppermost view which directly or indirectly uses this routine.
|
|
|
|
0 if routine is not used in view. Note that it also can be 0 if
|
|
|
|
statement uses routine both via view and directly.
|
|
|
|
*/
|
|
|
|
TABLE_LIST *belong_to_view;
|
2005-07-09 19:51:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
extern "C" uchar* sp_sroutine_key(const uchar *ptr, size_t *plen,
|
|
|
|
my_bool first)
|
2005-07-09 19:51:59 +02:00
|
|
|
{
|
|
|
|
Sroutine_hash_entry *rn= (Sroutine_hash_entry *)ptr;
|
|
|
|
*plen= rn->key.length;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
return (uchar *)rn->key.str;
|
2003-07-07 14:55:10 +02:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-08-03 05:37:32 +02:00
|
|
|
Check if
|
|
|
|
- current statement (the one in thd->lex) needs table prelocking
|
|
|
|
- first routine in thd->lex->sroutines_list needs to execute its body in
|
|
|
|
prelocked mode.
|
2005-07-30 10:19:57 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Current thread, thd->lex is the statement to be
|
|
|
|
checked.
|
|
|
|
@param[out] need_prelocking TRUE - prelocked mode should be activated
|
|
|
|
before executing the statement;
|
|
|
|
FALSE - Don't activate prelocking
|
|
|
|
@param[out] first_no_prelocking TRUE - Tables used by first routine in
|
|
|
|
thd->lex->sroutines_list should be
|
|
|
|
prelocked. FALSE - Otherwise.
|
|
|
|
|
|
|
|
@note
|
2005-07-30 10:19:57 +02:00
|
|
|
This function assumes that for any "CALL proc(...)" statement routines_list
|
|
|
|
will have 'proc' as first element (it may have several, consider e.g.
|
|
|
|
"proc(sp_func(...)))". This property is currently guaranted by the parser.
|
|
|
|
*/
|
|
|
|
|
2005-08-03 05:37:32 +02:00
|
|
|
void sp_get_prelocking_info(THD *thd, bool *need_prelocking,
|
|
|
|
bool *first_no_prelocking)
|
2005-07-30 10:19:57 +02:00
|
|
|
{
|
|
|
|
Sroutine_hash_entry *routine;
|
2005-08-03 05:37:32 +02:00
|
|
|
routine= (Sroutine_hash_entry*)thd->lex->sroutines_list.first;
|
2005-07-30 10:19:57 +02:00
|
|
|
|
2005-08-03 05:37:32 +02:00
|
|
|
DBUG_ASSERT(routine);
|
|
|
|
bool first_is_procedure= (routine->key.str[0] == TYPE_ENUM_PROCEDURE);
|
2005-07-30 10:19:57 +02:00
|
|
|
|
2005-08-03 05:37:32 +02:00
|
|
|
*first_no_prelocking= first_is_procedure;
|
|
|
|
*need_prelocking= !first_is_procedure || test(routine->next);
|
2005-07-30 10:19:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Auxilary function that adds new element to the set of stored routines
|
|
|
|
used by statement.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
In case when statement uses stored routines but does not need
|
|
|
|
prelocking (i.e. it does not use any tables) we will access the
|
|
|
|
elements of LEX::sroutines set on prepared statement re-execution.
|
|
|
|
Because of this we have to allocate memory for both hash element
|
|
|
|
and copy of its key in persistent arena.
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param lex LEX representing statement
|
|
|
|
@param arena Arena in which memory for new element will be
|
|
|
|
allocated
|
|
|
|
@param key Key for the hash representing set
|
|
|
|
@param belong_to_view Uppermost view which uses this routine
|
|
|
|
(0 if routine is not used by view)
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
|
|
|
Will also add element to end of 'LEX::sroutines_list' list.
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@todo
|
2005-07-09 19:51:59 +02:00
|
|
|
When we will got rid of these accesses on re-executions we will be
|
|
|
|
able to allocate memory for hash elements in non-persitent arena
|
|
|
|
and directly use key values from sp_head::m_sroutines sets instead
|
|
|
|
of making their copies.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
TRUE new element was added.
|
|
|
|
@retval
|
|
|
|
FALSE element was not added (because it is already present in
|
|
|
|
the set).
|
2005-07-09 19:51:59 +02:00
|
|
|
*/
|
|
|
|
|
2005-07-09 21:11:17 +02:00
|
|
|
static bool add_used_routine(LEX *lex, Query_arena *arena,
|
2005-12-07 10:27:17 +01:00
|
|
|
const LEX_STRING *key,
|
|
|
|
TABLE_LIST *belong_to_view)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2006-11-01 13:41:48 +01:00
|
|
|
hash_init_opt(&lex->sroutines, system_charset_info,
|
|
|
|
Query_tables_list::START_SROUTINES_HASH_SIZE,
|
|
|
|
0, 0, sp_sroutine_key, 0, 0);
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!hash_search(&lex->sroutines, (uchar *)key->str, key->length))
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2005-07-09 19:51:59 +02:00
|
|
|
Sroutine_hash_entry *rn=
|
|
|
|
(Sroutine_hash_entry *)arena->alloc(sizeof(Sroutine_hash_entry) +
|
2007-10-10 01:46:33 +02:00
|
|
|
key->length + 1);
|
2005-07-09 19:51:59 +02:00
|
|
|
if (!rn) // OOM. Error will be reported using fatal_error().
|
|
|
|
return FALSE;
|
|
|
|
rn->key.length= key->length;
|
|
|
|
rn->key.str= (char *)rn + sizeof(Sroutine_hash_entry);
|
2007-10-10 01:46:33 +02:00
|
|
|
memcpy(rn->key.str, key->str, key->length + 1);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
my_hash_insert(&lex->sroutines, (uchar *)rn);
|
|
|
|
lex->sroutines_list.link_in_list((uchar *)rn, (uchar **)&rn->next);
|
2005-12-07 10:27:17 +01:00
|
|
|
rn->belong_to_view= belong_to_view;
|
2005-07-09 19:51:59 +02:00
|
|
|
return TRUE;
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
2005-07-09 19:51:59 +02:00
|
|
|
return FALSE;
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-09-15 01:56:09 +02:00
|
|
|
Add routine which is explicitly used by statement to the set of stored
|
|
|
|
routines used by this statement.
|
2005-03-04 14:35:28 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
To be friendly towards prepared statements one should pass
|
|
|
|
persistent arena as second argument.
|
|
|
|
|
|
|
|
@param lex LEX representing statement
|
|
|
|
@param arena arena in which memory for new element of the set
|
|
|
|
will be allocated
|
|
|
|
@param rt routine name
|
|
|
|
@param rt_type routine type (one of TYPE_ENUM_PROCEDURE/...)
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
2005-09-15 01:56:09 +02:00
|
|
|
Will also add element to end of 'LEX::sroutines_list' list (and will
|
|
|
|
take into account that this is explicitly used routine).
|
2005-07-09 19:51:59 +02:00
|
|
|
*/
|
|
|
|
|
2005-07-09 21:11:17 +02:00
|
|
|
void sp_add_used_routine(LEX *lex, Query_arena *arena,
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_name *rt, char rt_type)
|
|
|
|
{
|
|
|
|
rt->set_routine_type(rt_type);
|
2005-12-07 10:27:17 +01:00
|
|
|
(void)add_used_routine(lex, arena, &rt->m_sroutines_key, 0);
|
2005-09-15 01:56:09 +02:00
|
|
|
lex->sroutines_list_own_last= lex->sroutines_list.next;
|
|
|
|
lex->sroutines_list_own_elements= lex->sroutines_list.elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-09-15 01:56:09 +02:00
|
|
|
Remove routines which are only indirectly used by statement from
|
|
|
|
the set of routines used by this statement.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param lex LEX representing statement
|
2005-09-15 01:56:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void sp_remove_not_own_routines(LEX *lex)
|
|
|
|
{
|
|
|
|
Sroutine_hash_entry *not_own_rt, *next_rt;
|
|
|
|
for (not_own_rt= *(Sroutine_hash_entry **)lex->sroutines_list_own_last;
|
|
|
|
not_own_rt; not_own_rt= next_rt)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
It is safe to obtain not_own_rt->next after calling hash_delete() now
|
|
|
|
but we want to be more future-proof.
|
|
|
|
*/
|
|
|
|
next_rt= not_own_rt->next;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
hash_delete(&lex->sroutines, (uchar *)not_own_rt);
|
2005-09-15 01:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*(Sroutine_hash_entry **)lex->sroutines_list_own_last= NULL;
|
|
|
|
lex->sroutines_list.next= lex->sroutines_list_own_last;
|
|
|
|
lex->sroutines_list.elements= lex->sroutines_list_own_elements;
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Merge contents of two hashes representing sets of routines used
|
|
|
|
by statements or by other routines.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param dst hash to which elements should be added
|
|
|
|
@param src hash from which elements merged
|
2005-03-04 14:35:28 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
2005-07-09 19:51:59 +02:00
|
|
|
This procedure won't create new Sroutine_hash_entry objects,
|
|
|
|
instead it will simply add elements from source to destination
|
|
|
|
hash. Thus time of life of elements in destination hash becomes
|
|
|
|
dependant on time of life of elements from source hash. It also
|
|
|
|
won't touch lists linking elements in source and destination
|
|
|
|
hashes.
|
2005-03-04 14:35:28 +01:00
|
|
|
*/
|
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
void sp_update_sp_used_routines(HASH *dst, HASH *src)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2005-02-08 20:52:50 +01:00
|
|
|
for (uint i=0 ; i < src->records ; i++)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2005-07-09 19:51:59 +02:00
|
|
|
Sroutine_hash_entry *rt= (Sroutine_hash_entry *)hash_element(src, i);
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!hash_search(dst, (uchar *)rt->key.str, rt->key.length))
|
|
|
|
my_hash_insert(dst, (uchar *)rt);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Add contents of hash representing set of routines to the set of
|
|
|
|
routines used by statement.
|
2005-03-04 14:35:28 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread context
|
|
|
|
@param lex LEX representing statement
|
|
|
|
@param src Hash representing set from which routines will
|
|
|
|
be added
|
|
|
|
@param belong_to_view Uppermost view which uses these routines, 0 if none
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
2005-07-09 19:51:59 +02:00
|
|
|
It will also add elements to end of 'LEX::sroutines_list' list.
|
|
|
|
*/
|
|
|
|
|
2005-12-07 10:27:17 +01:00
|
|
|
static void
|
|
|
|
sp_update_stmt_used_routines(THD *thd, LEX *lex, HASH *src,
|
|
|
|
TABLE_LIST *belong_to_view)
|
2005-07-09 19:51:59 +02:00
|
|
|
{
|
|
|
|
for (uint i=0 ; i < src->records ; i++)
|
|
|
|
{
|
|
|
|
Sroutine_hash_entry *rt= (Sroutine_hash_entry *)hash_element(src, i);
|
2005-12-07 10:27:17 +01:00
|
|
|
(void)add_used_routine(lex, thd->stmt_arena, &rt->key, belong_to_view);
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-09-15 01:56:09 +02:00
|
|
|
Add contents of list representing set of routines to the set of
|
|
|
|
routines used by statement.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread context
|
|
|
|
@param lex LEX representing statement
|
|
|
|
@param src List representing set from which routines will
|
|
|
|
be added
|
|
|
|
@param belong_to_view Uppermost view which uses these routines, 0 if none
|
2005-09-15 01:56:09 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
2005-09-15 01:56:09 +02:00
|
|
|
It will also add elements to end of 'LEX::sroutines_list' list.
|
|
|
|
*/
|
|
|
|
|
2005-12-07 10:27:17 +01:00
|
|
|
static void sp_update_stmt_used_routines(THD *thd, LEX *lex, SQL_LIST *src,
|
|
|
|
TABLE_LIST *belong_to_view)
|
2005-09-15 01:56:09 +02:00
|
|
|
{
|
|
|
|
for (Sroutine_hash_entry *rt= (Sroutine_hash_entry *)src->first;
|
|
|
|
rt; rt= rt->next)
|
2005-12-07 10:27:17 +01:00
|
|
|
(void)add_used_routine(lex, thd->stmt_arena, &rt->key, belong_to_view);
|
2005-09-15 01:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Cache sub-set of routines used by statement, add tables used by these
|
|
|
|
routines to statement table list. Do the same for all routines used
|
|
|
|
by these routines.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread context
|
|
|
|
@param lex LEX representing statement
|
|
|
|
@param start first routine from the list of routines to be cached
|
|
|
|
(this list defines mentioned sub-set).
|
|
|
|
@param first_no_prelock If true, don't add tables or cache routines used by
|
|
|
|
the body of the first routine (i.e. *start)
|
|
|
|
will be executed in non-prelocked mode.
|
|
|
|
@param tabs_changed Set to TRUE some tables were added, FALSE otherwise
|
|
|
|
|
|
|
|
@note
|
2005-03-04 14:35:28 +01:00
|
|
|
If some function is missing this won't be reported here.
|
|
|
|
Instead this fact will be discovered during query execution.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
0 success
|
|
|
|
@retval
|
|
|
|
non-0 failure
|
2005-03-04 14:35:28 +01:00
|
|
|
*/
|
|
|
|
|
2005-10-26 15:34:57 +02:00
|
|
|
static int
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_cache_routines_and_add_tables_aux(THD *thd, LEX *lex,
|
2005-07-30 10:19:57 +02:00
|
|
|
Sroutine_hash_entry *start,
|
2006-07-26 12:40:26 +02:00
|
|
|
bool first_no_prelock)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2005-10-26 15:34:57 +02:00
|
|
|
int ret= 0;
|
2005-07-30 10:19:57 +02:00
|
|
|
bool first= TRUE;
|
2005-07-09 19:51:59 +02:00
|
|
|
DBUG_ENTER("sp_cache_routines_and_add_tables_aux");
|
2003-03-02 19:17:41 +01:00
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
for (Sroutine_hash_entry *rt= start; rt; rt= rt->next)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2007-10-10 01:46:33 +02:00
|
|
|
sp_name name(thd, rt->key.str, rt->key.length);
|
2005-07-09 19:51:59 +02:00
|
|
|
int type= rt->key.str[0];
|
|
|
|
sp_head *sp;
|
2003-07-01 18:14:24 +02:00
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
if (!(sp= sp_cache_lookup((type == TYPE_ENUM_FUNCTION ?
|
|
|
|
&thd->sp_func_cache : &thd->sp_proc_cache),
|
|
|
|
&name)))
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2005-10-26 15:34:57 +02:00
|
|
|
switch ((ret= db_find_routine(thd, type, &name, &sp)))
|
2003-07-07 14:55:10 +02:00
|
|
|
{
|
2005-10-26 15:34:57 +02:00
|
|
|
case SP_OK:
|
|
|
|
{
|
|
|
|
if (type == TYPE_ENUM_FUNCTION)
|
|
|
|
sp_cache_insert(&thd->sp_func_cache, sp);
|
|
|
|
else
|
|
|
|
sp_cache_insert(&thd->sp_proc_cache, sp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SP_KEY_NOT_FOUND:
|
|
|
|
ret= SP_OK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
2005-11-25 17:09:26 +01:00
|
|
|
Any error when loading an existing routine is either some problem
|
|
|
|
with the mysql.proc table, or a parse error because the contents
|
|
|
|
has been tampered with (in which case we clear that error).
|
|
|
|
*/
|
|
|
|
if (ret == SP_PARSE_ERROR)
|
|
|
|
thd->clear_error();
|
2005-12-06 14:25:12 +01:00
|
|
|
/*
|
|
|
|
If we cleared the parse error, or when db_find_routine() flagged
|
|
|
|
an error with it's return value without calling my_error(), we
|
|
|
|
set the generic "mysql.proc table corrupt" error here.
|
|
|
|
*/
|
2007-10-30 18:08:16 +01:00
|
|
|
if (! thd->is_error())
|
2005-11-25 17:09:26 +01:00
|
|
|
{
|
2006-09-27 21:23:17 +02:00
|
|
|
/*
|
|
|
|
SP allows full NAME_LEN chars thus he have to allocate enough
|
|
|
|
size in bytes. Otherwise there is stack overrun could happen
|
|
|
|
if multibyte sequence is `name`. `db` is still safe because the
|
|
|
|
rest of the server checks agains NAME_LEN bytes and not chars.
|
|
|
|
Hence, the overrun happens only if the name is in length > 32 and
|
|
|
|
uses multibyte (cyrillic, greek, etc.)
|
|
|
|
*/
|
2007-04-03 13:13:27 +02:00
|
|
|
char n[NAME_LEN*2+2];
|
2005-11-25 17:09:26 +01:00
|
|
|
|
|
|
|
/* m_qname.str is not always \0 terminated */
|
|
|
|
memcpy(n, name.m_qname.str, name.m_qname.length);
|
|
|
|
n[name.m_qname.length]= '\0';
|
|
|
|
my_error(ER_SP_PROC_TABLE_CORRUPT, MYF(0), n, ret);
|
|
|
|
}
|
2005-10-26 15:34:57 +02:00
|
|
|
break;
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sp)
|
|
|
|
{
|
2005-07-30 10:19:57 +02:00
|
|
|
if (!(first && first_no_prelock))
|
|
|
|
{
|
2005-12-07 10:27:17 +01:00
|
|
|
sp_update_stmt_used_routines(thd, lex, &sp->m_sroutines,
|
|
|
|
rt->belong_to_view);
|
2006-07-26 12:40:26 +02:00
|
|
|
(void)sp->add_used_tables_to_table_list(thd, &lex->query_tables_last,
|
|
|
|
rt->belong_to_view);
|
2005-07-30 10:19:57 +02:00
|
|
|
}
|
* Mixed replication mode * :
1) Fix for BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog":
a stored function inserting into two such tables may fail to replicate
(inserting wrong data in the slave's copy of the second table) if the slave's
second table had an internal auto_increment counter different from master's.
Because the auto_increment value autogenerated by master for the 2nd table
does not go into binlog, only the first does, so the slave lacks information.
To fix this, if running in mixed binlogging mode, if the stored function or
trigger plans to update two different tables both having auto_increment
columns, we switch to row-based for the whole function.
We don't have a simple solution for statement-based binlogging mode, there
the bug remains and will be documented as a known problem.
Re-enabling rpl_switch_stm_row_mixed.
2) Fix for BUG#20630 "Mixed binlogging mode does not work with stored
functions, triggers, views", which was a documented limitation (in mixed
mode, we didn't detect that a stored function's execution needed row-based
binlogging (due to some UUID() call for example); same for
triggers, same for views (a view created from a SELECT UUID(), and doing
INSERT INTO sometable SELECT theview; would not replicate row-based).
This is implemented by, after parsing a routine's body, remembering in sp_head
that this routine needs row-based binlogging. Then when this routine is used,
the caller is marked to require row-based binlogging too.
Same for views: when we parse a view and detect that its SELECT needs
row-based binary logging, we mark the calling LEX as such.
3) Fix for BUG#20499 "mixed mode with temporary table breaks binlog":
a temporary table containing e.g. UUID has its changes not binlogged,
so any query updating a permanent table with data from the temporary table
will run wrongly on slave. Solution: in mixed mode we don't switch back
from row-based to statement-based when there exists temporary tables.
4) Attempt to test mysqlbinlog on a binlog generated by mysqlbinlog;
impossible due to BUG#11312 and BUG#20329, but test is in place for when
they are fixed.
2006-07-09 17:00:47 +02:00
|
|
|
sp->propagate_attributes(lex);
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
2005-07-30 10:19:57 +02:00
|
|
|
first= FALSE;
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
2005-10-26 15:34:57 +02:00
|
|
|
DBUG_RETURN(ret);
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Cache all routines from the set of used by statement, add tables used
|
|
|
|
by those routines to statement table list. Do the same for all routines
|
|
|
|
used by those routines.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread context
|
|
|
|
@param lex LEX representing statement
|
|
|
|
@param first_no_prelock If true, don't add tables or cache routines used by
|
|
|
|
the body of the first routine (i.e. *start)
|
2006-07-26 12:40:26 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
0 success
|
|
|
|
@retval
|
|
|
|
non-0 failure
|
2005-07-09 19:51:59 +02:00
|
|
|
*/
|
|
|
|
|
2005-10-26 15:34:57 +02:00
|
|
|
int
|
2006-07-26 12:40:26 +02:00
|
|
|
sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock)
|
2005-07-09 19:51:59 +02:00
|
|
|
{
|
|
|
|
return sp_cache_routines_and_add_tables_aux(thd, lex,
|
2005-07-30 10:19:57 +02:00
|
|
|
(Sroutine_hash_entry *)lex->sroutines_list.first,
|
2006-07-26 12:40:26 +02:00
|
|
|
first_no_prelock);
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Add all routines used by view to the set of routines used by
|
|
|
|
statement.
|
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
Add tables used by those routines to statement table list. Do the same
|
|
|
|
for all routines used by these routines.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread context
|
|
|
|
@param lex LEX representing statement
|
|
|
|
@param view Table list element representing view
|
2005-12-07 10:47:25 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
0 success
|
|
|
|
@retval
|
|
|
|
non-0 failure
|
2005-07-09 19:51:59 +02:00
|
|
|
*/
|
|
|
|
|
2005-10-26 15:34:57 +02:00
|
|
|
int
|
2005-12-07 10:27:17 +01:00
|
|
|
sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex, TABLE_LIST *view)
|
2005-07-09 19:51:59 +02:00
|
|
|
{
|
|
|
|
Sroutine_hash_entry **last_cached_routine_ptr=
|
|
|
|
(Sroutine_hash_entry **)lex->sroutines_list.next;
|
2005-12-07 10:27:17 +01:00
|
|
|
sp_update_stmt_used_routines(thd, lex, &view->view->sroutines_list,
|
|
|
|
view->top_table());
|
2006-07-26 12:40:26 +02:00
|
|
|
return sp_cache_routines_and_add_tables_aux(thd, lex,
|
|
|
|
*last_cached_routine_ptr, FALSE);
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-07-09 19:51:59 +02:00
|
|
|
Add triggers for table to the set of routines used by statement.
|
|
|
|
Add tables used by them to statement table list. Do the same for
|
|
|
|
all implicitly used routines.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread context
|
|
|
|
@param lex LEX respresenting statement
|
|
|
|
@param table Table list element for table with trigger
|
2005-10-26 15:34:57 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
0 success
|
|
|
|
@retval
|
|
|
|
non-0 failure
|
2005-07-09 19:51:59 +02:00
|
|
|
*/
|
|
|
|
|
2005-10-26 15:34:57 +02:00
|
|
|
int
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex,
|
2005-12-07 10:27:17 +01:00
|
|
|
TABLE_LIST *table)
|
2005-07-09 19:51:59 +02:00
|
|
|
{
|
2005-10-26 15:34:57 +02:00
|
|
|
int ret= 0;
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
2007-07-12 20:26:41 +02:00
|
|
|
|
|
|
|
Sroutine_hash_entry **last_cached_routine_ptr=
|
|
|
|
(Sroutine_hash_entry **)lex->sroutines_list.next;
|
|
|
|
|
|
|
|
if (static_cast<int>(table->lock_type) >=
|
|
|
|
static_cast<int>(TL_WRITE_ALLOW_WRITE))
|
2005-07-09 19:51:59 +02:00
|
|
|
{
|
2005-07-19 18:06:49 +02:00
|
|
|
for (int i= 0; i < (int)TRG_EVENT_MAX; i++)
|
2005-07-28 15:10:14 +02:00
|
|
|
{
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
2007-07-12 20:26:41 +02:00
|
|
|
if (table->trg_event_map &
|
|
|
|
static_cast<uint8>(1 << static_cast<int>(i)))
|
2005-07-28 15:10:14 +02:00
|
|
|
{
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
2007-07-12 20:26:41 +02:00
|
|
|
for (int j= 0; j < (int)TRG_ACTION_MAX; j++)
|
2005-03-04 14:35:28 +01:00
|
|
|
{
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
2007-07-12 20:26:41 +02:00
|
|
|
/* We can have only one trigger per action type currently */
|
|
|
|
sp_head *trigger= table->table->triggers->bodies[i][j];
|
|
|
|
if (trigger &&
|
|
|
|
add_used_routine(lex, thd->stmt_arena, &trigger->m_sroutines_key,
|
|
|
|
table->belong_to_view))
|
|
|
|
{
|
|
|
|
trigger->add_used_tables_to_table_list(thd, &lex->query_tables_last,
|
|
|
|
table->belong_to_view);
|
2007-07-16 21:31:36 +02:00
|
|
|
trigger->propagate_attributes(lex);
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
2007-07-12 20:26:41 +02:00
|
|
|
sp_update_stmt_used_routines(thd, lex,
|
|
|
|
&trigger->m_sroutines,
|
|
|
|
table->belong_to_view);
|
|
|
|
}
|
2005-03-04 14:35:28 +01:00
|
|
|
}
|
2005-07-28 15:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
2007-07-12 20:26:41 +02:00
|
|
|
ret= sp_cache_routines_and_add_tables_aux(thd, lex,
|
|
|
|
*last_cached_routine_ptr,
|
2007-07-16 22:59:21 +02:00
|
|
|
FALSE);
|
2005-10-26 15:34:57 +02:00
|
|
|
return ret;
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
2003-12-12 14:05:29 +01:00
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Generates the CREATE... string from the table information.
|
|
|
|
|
|
|
|
@return
|
|
|
|
Returns TRUE on success, FALSE on (alloc) failure.
|
|
|
|
*/
|
2004-06-09 14:19:43 +02:00
|
|
|
static bool
|
|
|
|
create_string(THD *thd, String *buf,
|
2008-05-16 01:13:24 +02:00
|
|
|
int type,
|
|
|
|
const char *db, ulong dblen,
|
|
|
|
const char *name, ulong namelen,
|
|
|
|
const char *params, ulong paramslen,
|
|
|
|
const char *returns, ulong returnslen,
|
|
|
|
const char *body, ulong bodylen,
|
|
|
|
st_sp_chistics *chistics,
|
2006-03-02 13:18:49 +01:00
|
|
|
const LEX_STRING *definer_user,
|
|
|
|
const LEX_STRING *definer_host)
|
2003-12-12 14:05:29 +01:00
|
|
|
{
|
2004-06-09 14:19:43 +02:00
|
|
|
/* Make some room to begin with */
|
2008-05-16 01:13:24 +02:00
|
|
|
if (buf->alloc(100 + dblen + 1 + namelen + paramslen + returnslen + bodylen +
|
2006-03-02 13:18:49 +01:00
|
|
|
chistics->comment.length + 10 /* length of " DEFINER= "*/ +
|
|
|
|
USER_HOST_BUFF_SIZE))
|
2004-06-09 14:19:43 +02:00
|
|
|
return FALSE;
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN("CREATE "));
|
2006-03-02 13:18:49 +01:00
|
|
|
append_definer(thd, buf, definer_user, definer_host);
|
2003-12-12 14:05:29 +01:00
|
|
|
if (type == TYPE_ENUM_FUNCTION)
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN("FUNCTION "));
|
2004-06-09 14:19:43 +02:00
|
|
|
else
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN("PROCEDURE "));
|
2008-05-16 01:13:24 +02:00
|
|
|
if (dblen > 0)
|
|
|
|
{
|
|
|
|
append_identifier(thd, buf, db, dblen);
|
|
|
|
buf->append('.');
|
|
|
|
}
|
2008-05-15 01:23:54 +02:00
|
|
|
append_identifier(thd, buf, name, namelen);
|
2004-06-09 14:19:43 +02:00
|
|
|
buf->append('(');
|
|
|
|
buf->append(params, paramslen);
|
|
|
|
buf->append(')');
|
|
|
|
if (type == TYPE_ENUM_FUNCTION)
|
|
|
|
{
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN(" RETURNS "));
|
2004-06-09 14:19:43 +02:00
|
|
|
buf->append(returns, returnslen);
|
|
|
|
}
|
|
|
|
buf->append('\n');
|
2004-10-14 18:07:09 +02:00
|
|
|
switch (chistics->daccess) {
|
|
|
|
case SP_NO_SQL:
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN(" NO SQL\n"));
|
2004-10-14 18:07:09 +02:00
|
|
|
break;
|
|
|
|
case SP_READS_SQL_DATA:
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN(" READS SQL DATA\n"));
|
2004-10-14 18:07:09 +02:00
|
|
|
break;
|
|
|
|
case SP_MODIFIES_SQL_DATA:
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN(" MODIFIES SQL DATA\n"));
|
2004-10-14 18:07:09 +02:00
|
|
|
break;
|
2004-11-03 11:39:38 +01:00
|
|
|
case SP_DEFAULT_ACCESS:
|
|
|
|
case SP_CONTAINS_SQL:
|
|
|
|
/* Do nothing */
|
|
|
|
break;
|
2004-10-14 18:07:09 +02:00
|
|
|
}
|
2003-12-12 14:05:29 +01:00
|
|
|
if (chistics->detistic)
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN(" DETERMINISTIC\n"));
|
2004-10-14 18:07:09 +02:00
|
|
|
if (chistics->suid == SP_IS_NOT_SUID)
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN(" SQL SECURITY INVOKER\n"));
|
2003-12-13 16:40:52 +01:00
|
|
|
if (chistics->comment.length)
|
2003-12-21 01:07:45 +01:00
|
|
|
{
|
2005-11-23 00:29:25 +01:00
|
|
|
buf->append(STRING_WITH_LEN(" COMMENT "));
|
2004-06-09 14:19:43 +02:00
|
|
|
append_unescaped(buf, chistics->comment.str, chistics->comment.length);
|
|
|
|
buf->append('\n');
|
2003-12-21 01:07:45 +01:00
|
|
|
}
|
2004-06-09 14:19:43 +02:00
|
|
|
buf->append(body, bodylen);
|
|
|
|
return TRUE;
|
2003-12-12 14:05:29 +01:00
|
|
|
}
|