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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
int sp_type,
|
2004-03-11 17:18:59 +01:00
|
|
|
sp_name *name,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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,
|
|
|
|
const char *definer, longlong created, longlong modified);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* DB storage of Stored PROCEDUREs and FUNCTIONs
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
enum
|
|
|
|
{
|
2003-12-16 19:14:10 +01:00
|
|
|
MYSQL_PROC_FIELD_DB = 0,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
MYSQL_PROC_FIELD_NAME,
|
|
|
|
MYSQL_PROC_FIELD_TYPE,
|
|
|
|
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,
|
|
|
|
MYSQL_PROC_FIELD_COUNT
|
|
|
|
};
|
2003-10-30 10:25:45 +01:00
|
|
|
|
2004-03-26 12:14:40 +01:00
|
|
|
bool mysql_proc_table_exists= 1;
|
|
|
|
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
2005-05-05 14:20:53 +02:00
|
|
|
/* Tells what SP_DEFAULT_ACCESS should be mapped to */
|
|
|
|
#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Close mysql.proc, opened with open_proc_table_for_read().
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
close_proc_table()
|
2005-08-08 15:46:06 +02:00
|
|
|
thd Thread context
|
|
|
|
backup Pointer to Open_tables_state instance which holds
|
|
|
|
information about tables which were open before we
|
|
|
|
decided to access mysql.proc.
|
2005-07-13 11:48:13 +02:00
|
|
|
*/
|
|
|
|
|
2005-08-08 15:46:06 +02:00
|
|
|
void close_proc_table(THD *thd, Open_tables_state *backup)
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
2005-07-13 11:48:13 +02:00
|
|
|
close_thread_tables(thd);
|
2005-08-08 15:46:06 +02:00
|
|
|
thd->restore_backup_open_tables_state(backup);
|
2005-07-13 11:48:13 +02:00
|
|
|
}
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Open the mysql.proc table for read.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
open_proc_table_for_read()
|
2005-08-08 15:46:06 +02:00
|
|
|
thd Thread context
|
|
|
|
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
|
|
|
|
|
|
|
NOTES
|
|
|
|
Thanks to restrictions which we put on opening and locking of
|
|
|
|
this table for writing, we can open and lock it for reading
|
|
|
|
even when we already have some other tables open and locked.
|
|
|
|
One must call close_proc_table() to close table opened with
|
|
|
|
this call.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Error
|
|
|
|
# Pointer to TABLE object of mysql.proc
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
|
|
|
TABLE_LIST tables;
|
|
|
|
TABLE *table;
|
2005-09-15 01:56:09 +02:00
|
|
|
bool not_used;
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_ENTER("open_proc_table");
|
2005-05-19 03:48:22 +02:00
|
|
|
|
2004-03-26 12:14:40 +01:00
|
|
|
/*
|
2005-04-06 23:40:29 +02:00
|
|
|
Speed up things if mysql.proc doesn't exists. mysql_proc_table_exists
|
|
|
|
is set when we create or read stored procedure or on flush privileges.
|
2004-03-26 12:14:40 +01:00
|
|
|
*/
|
2005-07-13 11:48:13 +02:00
|
|
|
if (!mysql_proc_table_exists)
|
|
|
|
DBUG_RETURN(0);
|
2004-03-26 12:14:40 +01:00
|
|
|
|
2005-08-08 15:46:06 +02:00
|
|
|
thd->reset_n_backup_open_tables_state(backup);
|
2005-07-13 11:48:13 +02:00
|
|
|
|
|
|
|
bzero((char*) &tables, sizeof(tables));
|
|
|
|
tables.db= (char*) "mysql";
|
|
|
|
tables.table_name= tables.alias= (char*)"proc";
|
2005-09-15 01:56:09 +02:00
|
|
|
if (!(table= open_table(thd, &tables, thd->mem_root, ¬_used,
|
2005-07-13 11:48:13 +02:00
|
|
|
MYSQL_LOCK_IGNORE_FLUSH)))
|
2004-09-01 18:00:41 +02:00
|
|
|
{
|
2005-08-08 15:46:06 +02:00
|
|
|
thd->restore_backup_open_tables_state(backup);
|
2005-07-13 11:48:13 +02:00
|
|
|
mysql_proc_table_exists= 0;
|
|
|
|
DBUG_RETURN(0);
|
2004-09-01 18:00:41 +02:00
|
|
|
}
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
BitKeeper/etc/ignore:
added mysys/test_bitmap
include/base64.h:
Removed my_global.h, as this must be included first in any program
include/heap.h:
Added heap_reset() (Required by new handler interface)
include/my_base.h:
Removed HA_EXTRA_RESET. MySQL will now call ::reset() instead of ::extra(HA_EXTRA_RESET).
HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIVE_PRIMARY key are deleted as the column bitmaps makes these unnecessary
include/my_bitmap.h:
Remove my_pthread.h (should be included at upper level)
Introduced my_bitmap_map typedef to make it the bitmap handling more like a black box
Added bitmap_is_overlapping(), bitmap_test_and_clear(), bitmap_copy() and bitmap_cmp()
Made bitmap_set_bit(), bitmap_flip_bit(), bitmap_clear_bit() return void
include/myisam.h:
Added mi_reset() (Required by new handler interface)
include/myisammrg.h:
Added myrg_reset() (Required by new handler interface)
include/mysql_com.h:
Added flag FIELD_IN_ADD_INDEX to be able to remove Field->add_index
mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/install_test_db.sh:
Simplify ldata usage
Added --tmpdir=. option to mysqld bootstrap (Removed some warnings when TMPDIR was wrongly set)
mysql-test/mysql-test-run.pl:
Added --tmpdir=. to bootstrap
mysql-test/mysql-test-run.sh:
Use copy instead of INSTALL_DB for master and slave databases.
(Speeds up startup time a lot!)
Remove snapshot directories at startup (removes some strange warnings)
mysql-test/r/binlog_row_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/r/binlog_stm_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
mysql-test/r/create.result:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/r/federated.result:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/r/func_gconcat.result:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/r/func_time.result:
Added drop of test function
mysql-test/r/innodb_mysql.result:
Added tests for CREATE ... SELECT
mysql-test/r/insert.result:
More tests
Added testing of duplicate columns in insert
mysql-test/r/loaddata.result:
Added testing LOAD DATA ... SET ...
mysql-test/r/multi_update.result:
Test multi updates and deletes using primary key and without
mysql-test/r/ndb_index_unique.result:
Better error message
mysql-test/r/ndb_replace.result:
New correct result after fixing REPLACE handling with NDB
mysql-test/r/rpl_ddl.result:
Now we don't get these (wrong) warnings anymore
mysql-test/r/view_grant.result:
Drop used views
mysql-test/t/create.test:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/t/federated.test:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/t/func_gconcat.test:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/t/func_time.test:
Added drop of test function
mysql-test/t/innodb_mysql.test:
Added tests for CREATE ... SELECT
mysql-test/t/insert.test:
More tests
Added testing of duplicate columns in insert
mysql-test/t/loaddata.test:
Added testing LOAD DATA ... SET ...
mysql-test/t/multi_update.test:
Test multi updates and deletes using primary key and without
mysql-test/t/view_grant.test:
Drop used views
mysql-test/valgrind.supp:
Added supression of not needed warnings when printing stack trace
mysys/base64.c:
Include my_global.h first
mysys/my_bitmap.c:
Added bitmap_is_overlapping(), bitmap_test_and_clear() and bitmap_copy()
Changed logic of bitmap handling to be a bit more efficent (Did this together with Mikael Ronström)
Now the 'extra, not used bits' in the bitmap are assumed to have a 'random value' and the bitmap functions are free to change them whenever needed.
Changed how mutex is allocated to make 'bitmap_free()' function simpler.
mysys/thr_lock.c:
Added 0x before thread pointers (for easier comparison of DBUG traces)
sql/event.cc:
Ensure 'use_all_columns()' is used for event tables
Don't print warning that event table is damaged if it doesn't exists.
sql/field.cc:
Added ASSERT_COLUMN_MARKED_FOR_WRITE in all store() methods and ASSERT_COLUMN_MARKED_FOR_READ in all val() methods to catch wrong setting if table->read_set and table->write_set
(Rest of changes are only indentation cleanups)
sql/field.h:
Removed Field->query_id (replaced by table->read_set and table->write_set)
Removed Field->fieldnr (use Field->field_index instead)
Removed Field->add_index (Use Field->flags instead)
Add Field->part_of_key_not_clustered (for usage in opt_range.cc)
sql/filesort.cc:
Added paramater sort_postion to filesort() to force sorting by position instead of storing all fields in the result set.
This allowed me to remove checking of sql_command.
Create a temporary column bitmap for fields that are used by the sorting process.
Use column bitmaps instead of query_id
sql/ha_berkeley.cc:
Update to 'newer' table handler interface
sql/ha_berkeley.h:
Update to 'newer' table handler interface
sql/ha_federated.cc:
Update to 'newer' table handler interface
Only read columns that are needed from remote server.
In case of eq ranges, don't generate two conditions in the WHERE clause
(this can still be optimized, but would require a bigger code change)
Use 'simpler to use' XXXX_LEN' macros
A bit simpler logic in ::write_row() when creating statements.
In update, only include test of fields actually read.
(This greatly simplifies the queries sent by the federated engine)
Similar changes done for delete_row()
sql/ha_federated.h:
Update to 'newer' table handler interface
Changed XXX_LEN macros to use sizeof(...)-1, to simplify usage in ha_federated.cc
Added HA_PRIMARY_KEY_REQUIRED_FOR_DELETE to tell MySQL to read all primary key columns in case of DELETE
sql/ha_heap.cc:
Update to 'newer' table handler interface
sql/ha_heap.h:
Update to 'newer' table handler interface
sql/ha_innodb.cc:
Update to 'newer' table handler interface
- Update innobase_create_handler() to new interface
- Removed HA_NOT_EXACT_COUNT (not needed)
- Renamed HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- Prefixed base status variables with 'stats'
- Use table column bitmaps instead of ha_get_bit_in_read_set()
- Added ::reset(), with code from ::extra(HA_EXTRA_RESET)
- Removed HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIEVE_PRIMARY_KEY as
the table->read_set and table->write_set bitmaps now are accurate
sql/ha_innodb.h:
Update to 'newer' table handler interface
- table_flags are now ulonglong
- Added reset() method
- Removed not needed ha_retrieve_all_cols() and ha_retrieve_all_pk() columns.
- Made build_template() a class function to be able to easier access class variables
sql/ha_myisam.cc:
Update to 'newer' table handler interface
sql/ha_myisam.h:
Update to 'newer' table handler interface
sql/ha_myisammrg.cc:
Update to 'newer' table handler interface
sql/ha_myisammrg.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster.cc:
Update to 'newer' table handler interface
Fixed use_blob_value() to be accurate
In ::complemented_read() we have to check both the read and write bitmap as the old code did mark all changed columns also in the read map
Correct dumping of field data with DBUG_DUMP
Prefix addresses in DBUG_PRINT with 0x
Fixed usage of not initialized memory
Update to use field->flags & FIELD_IN_ADD_INDEX instead of field->add_index.
sql/ha_ndbcluster.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster_binlog.cc:
Mark usage of all columns in ndbcluster binlog tables
false -> FALSE, true -> TRUE
Use table->s->all_set instead of creating a temporary bitmap.
sql/ha_partition.cc:
Update to 'newer' table handler interface
Added memroot to initialise_partitions() and related functions to get faster memory allocation.
partition_create_handler() is now responsible for initialisation of the partition object
Some trivial optimizations and indentation fixes
Ensure that table_flags() are up to date
Removed documentation for removed HA_EXTRA flags
Fixed 'strange' usage of m_file[i] in new_handlers_from_part_info()that worked in current code 'by chance'
sql/ha_partition.h:
Update to 'newer' table handler interface
sql/handler.cc:
create_xxx handler now takes MEMROOT as an argument to simplify memory allocation.
Much simpler get_new_handler()
(Initialization of the object is now handled by the create method for the engine)
Moved all allocation of bitmap handling to the TABLE object (in table.cc)
Added column_bitmaps_signal() to signal column usage changes.
Changed binlog_log_row() to use the exiusting all_set bitmap in the table object.
Added ha_reset() function to test that the file object is ok at end of statement and call handler::reset()
Added use_hidden_primary_key() to signal handler that we we are going to read and update + delete the row and the handler should thus remember the position for the row
sql/handler.h:
Added HA_NO_TRANSACTIONS, HA_PARTIAL_COLUMN_READ, HA_REQUIRES_KEY_COLUMNS_FOR_DELETE,HA_PRIMARY_KEY_REQUIRED_FOR_DELETE and HA_HAS_RECORDS
Removed HA_NOT_EXACT_COUNT, HA_READ_RND_SAME
HA_DUPP_POS -> HA_DUPLICATE_POS
HA_NOT_EXACT_COUNT replaced by HA_STATS_RECORDS_IS_EXACT, HA_HAS_RECORDS and records()
HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION
Added future row type 'ROW_TYPE_PAGES'
Added MEM_ROOT to handlerton 'create' function
Added ha_statistics, a structure for all status variable in the base handler class.
Moved all status variables in the handler class into a stats structs to improve readability.
ha_table_flags() is now a cached (not virtual) version of table_flags()
reset() doesn't anymore call extra(HA_EXTRA_RESET) but is a function of it's own.
Renamed dupp_ref to dup_ref
Renamed not used handler::sortkey
Moved read_set and write_set to TABLE structure
handler::init() function added for cacheing of virtual constants from engine.
sql/item.cc:
Added register_field_in_read_map() for marking used columns in expression.
This is used by filesort() for creating an optimal column bitmap while retrieving columns for sorting.
Initalize value.cs_info.character_set_client to fix core dump bug with --debug
set_query_id -> mark_used_columns
Mark used columns in read_set OR write_set.
sql/item.h:
Removed reset_query_id_processor() as it's not needed anymore.
Added register_field_in_read_map()
Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
sql/item_cmpfunc.cc:
Temporary mark used columns to be read/writable
Update Item::walk to new interface
sql/item_cmpfunc.h:
Added extra argument to Item::walk() to indicate if we should also traverse sub queries.
sql/item_func.cc:
Update Item::walk() to new interface
table_flags() -> ha_table_flags()
sql/item_func.h:
Update Item::walk() to new interface
sql/item_row.cc:
Update Item::walk() to new interface
sql/item_row.h:
Update Item::walk() to new interface
sql/item_strfunc.h:
Update Item::walk() to new interface
sql/item_subselect.cc:
Added Item_subselect::walk()
(It was a bug it was missing before. Not sure what kind of bugs this could have caused)
sql/item_subselect.h:
Update Item::walk() to new interface
sql/item_sum.cc:
Update Item::walk() to new interface
Updates for new handler interace
sql/item_sum.h:
Update Item::walk() to new interface
sql/key.cc:
Updates for new handler interace
sql/log.cc:
Mark all columns used for log tables
Split options flag
Ensured that second argument to trans_register_ha is a bool
sql/log_event.cc:
Fixed comments to be withing 79 characters
Use OPTION_KEEP_LOG instead of OPTION_STATUS_NO_TRANS_UPDATE to remove wrong warnings
Updates for new handler interface
Use 0x%lx instead of %p (portability problem)
sql/mysql_priv.h:
Added OPTION_KEEP_LOG to indicate that we should replicate the binlog even on rollback
Removed not used 'conds' argument to setup_tables
sql/mysqld.cc:
Indentation fixes and removed old comment
sql/opt_range.cc:
Update to new handler and bitmap interface.
Fixed calls to cp_buffer_from_ref() and walk() (new argument).
Create new temporary bitmaps for ror scans.
(Needed because of handler changes and to get more accurate column bitmaps than before)
Remove not needed file->ha_reset() call before file->close().
Some trivial optimization and indentation fixes.
Use Field->part_of_key_not_clustered() to check if field is part of a key, instead of looping over all key parts.
Added flag 'in_ror_merged_scan' to allow ::get_next() to know that we need a special column bitmap to only fetch pointer to record.
This is needed because ror scan uses the same TABLE object but different file objects, which creates problem for the column bitmap handling.
(This is a temporary solution. A better one would be to allocate an own TABLE object for ROR scans)
Optimized bitmap handling in ror scans:
- Start bitmap at position 0, not 1
- Use same bitmap size as in TABLE
- Use table->read_set and table->write_set to create column bitmaps instead of looping over all fields in table
sql/opt_range.h:
Added 'in_ror_merged_scan' to indicate if we are doing a ROR scan
Added temporary column bitmaps used in ROR scans
sql/opt_sum.cc:
Added get_ext_record_count() which is used in COUNT() optimization if handler has HA_HAS_RECORDS
Note that we don't call this if handler has HA_STATS_RECORDS_IS_EXACT set.
sql/protocol.cc:
We need to mark columns as readable in ::store() as we sometimes return default value for fields to the user
sql/records.cc:
Updates for new handler interface
sql/set_var.cc:
Handle splitting OPTION_STATUS_NO_TRANS_UPDATE to two flags
sql/share/errmsg.txt:
Fixed wrong
sql/sp.cc:
Mark that we are using all columns for the proc table
Update call to setup_tables() to use new prototype
sql/sp_head.cc:
Removed QQ comment
sql/spatial.cc:
Removed wrong QQ comment
sql/sql_acl.cc:
Mark that we need all columns for acl tables
Supply memroot to some 'new' calls.
Indentation fixes
sql/sql_base.cc:
set_query_id removed
Ensure we call ha_reset() at end of each statement
Mark read columns in read_set and changed columns in write_set (Before all columns was marked in read set)
Fixed marking of some columns that was not proplerly marked before
Maintain in TABLE->merge_keys set of all keys that are used in some way
Removed not used 'conds' argument from setup_tables()
Remove not used setting of 'dupp_field' in insert_fields()
Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after crash)
sql/sql_bitmap.h:
Added is_overlapping()
sql/sql_class.cc:
Slow_logs was not properly initialized, which could maybe cause extra/lost entries in slow log.
set_query_id -> mark_used_columns
Simpler variable usage in pack_row() (cleanup)
Moved some variable declartion at start of function for better code readability
sql/sql_class.h:
Added enum_mark_columns
Updated comments
Renamed dupp_field -> dup_field
Added virtual function 'can_rollback_data()' to select_insert() to be used in CREATE ... SELECT to optimize use of OPTION_STATUS_NO_TRANS_UPDATE.
(This fixes a bug in CREATE ... SELECT where we did give wrong warnings when using non transacational tables)
sql/sql_delete.cc:
Updates to new handler interface
Call table->mark_columns_needed_for_delete() to allow us to put additional columns in column usage maps if handler so requires.
Call table->prepare_for_position() to tell handler that we are going to call ha_position().
Removed call to free_io_cache(). (io_cache is now removed in ha_reset()).
Fixed calls to setup_tables()
sql/sql_do.cc:
Update call to setup_fields()
sql/sql_handler.cc:
Tell handler tables to always read all columns.
Use temporary column map when storing value in field for later index usage
sql/sql_help.cc:
Makr all used fields to be read
Update call to setup_fields()
sql/sql_insert.cc:
Tell handler we are going to update the auto_increment column
dupp_field -> dup_field
Set column usage bits for timestamp field.
Call table->mark_columns_needed_for_insert() and table->mark_auto_increment_column()
Removed not used argument from mysql_prepare_insert_check_table().
If we get an duplicate row on insert, change column map to read and write all columns while retrying the operatation.
This is required by the definition of REPLACE and also ensures that fields that are only part of UPDATE are properly handled.
This fixed a bug in NDB and REPLACE where REPLACE wrongly copied some column values from the replaced row.
Setup new bitmaps for delayed insert rows
Remove reseting of next_number_fields as it will be reset on next call to handler_insert()
Fixed usage of thd->options and OPTION_STATUS_NO_TRANS_UPDATE.
The issue was that one should not to reset this flag as it may be set by a previous statement.
The way it was now used caused us to loose some warnings and get other wrong warnings when using non transactional tables mixed with transactional.
I fixed it by introducing 'select_insert::can_rollback_data' to inform send_error() that the given statement can be rolled back (which in case of CREATE TABLE can always be done)
Don't close tables created with CREATE ... SELECT but keep them in the table cache.
Moved out MY_HOOKS from inside function (better readability)
sql/sql_load.cc:
Update to use new handler and column marking interface
Update using setup_tables()
sql/sql_olap.cc:
Update calls to setup_tables
Use enums instead of constants to setup_fields()
sql/sql_parse.cc:
Handle OPTION_KEEP_LOG:
- Set it on CREATE TEMPORARY TABLE / DROP TABLE
- Reset it when OPTION_STATUS_NO_TRANS_UPDATE is reset
- Don't set it for CREATE ... SELECT (this is handled in select_create class)
Remove reseting of OPTION_STATUS_NO_TRANS_UPDATE in begin_trans() as this should already be reset.
If in autocommit mode, reset OPTION_KEEP_LOG and OPTION_STATUS_NO_TRANS_UPDATE to not give warnings in future commands
sql/sql_partition.cc:
Update walk() usage
Trivial indentation fixes
sql/sql_plugin.cc:
Mark all columns as used for plugins
sql/sql_prepare.cc:
Added assert to find out hidden bugs in character_set_client (got an error in debug binary when this not set correctly)
Updates for new handler interface
Update calls to setup_fields()
sql/sql_repl.cc:
Indentation fixes
sql/sql_select.cc:
Update call to setup_tables() and setup_fields()
Remove some old disabled code
Update to new hadler interface
Indentation cleanups
Added column bitmaps for temporary tables.
Remove updating of the removed slots in the Field class
Added TABLE argument to cp_buffer_from_ref() (To be able to install temporary column maps)
For internal temporary tables, use handler::write_row(), handler::delete_row() and handler::update_row() instead of handler::ha_xxxx() for faster execution.
sql/sql_select.h:
Indentaition fixes.
Install temporary column usage maps when needed
Added TABLE element to cp_buffer_from_ref()
sql/sql_show.cc:
Update to new handler interface
Mark all columns used for internal tables.
Style fixes.
Added support for 'future' ROW_TYPE_PAGES.
Don't allocate TMP_TABLE_PARAM with calloc. The 'init()' function will initialize the structure properly.
sql/sql_table.cc:
Update to new handler interface
Simple my_snprintf -> strmake()
Changed some constants to defines
Don't test for NULL in primary key (as we a couple of line above force the PRIMARY KEY to be NOT NULL)
Change field->add_index to use field->flags & FIELD_IN_ADD_INDEX
Mark all columns as used for ALTER TABLE
Style fixes
Update call to filesort()
sql/sql_trigger.h:
Added friend functions to be able to test if triggers exists for table we are going to insert/update or delete in.
sql/sql_udf.cc:
Mark all columns as used for udf system table.
sql/sql_union.cc:
Update call to walk()
Update to new handler interface
sql/sql_update.cc:
Remove query_id argument from compare_record()
Use column bitmaps instead of query_id.
We can't use compare_records() to skip updates for handlers that returns a partial column set and the read_set doesn't cover all columns in the write set, because compare_record() can't in this case know if a not read column changed value.
Update call to setup_fields()
Using separate column read and write sets allows for easier checking of timestamp field was set by statement.
Removed call to free_io_cache() as this is now done in ha_reset()
Call table->mark_columns_needed_for_update() and table->prepare_for_position()
Style fixes
sql/sql_view.cc:
Style fixes
sql/table.cc:
Remove implicitely include 'errno.h'
Remove code for building normalized path, as this is now identical to 'path'
Remove field->fieldnr
Added update of field->part_of_key_not_clustered()
Create column bitmaps in TABLE and TABLE_SHARE
Don't setup a temporary MEM_ROOT object as a thread specific variable for the handler. Instead we send the to-be-used MEMROOT to get_new_handler()
Update to new handler interface
Update call to walk()
Added new functions:
- st_table::clear_column_bitmaps()
- st_table::prepare_for_position()
- st_table::mark_columns_used_by_index()
- st_table::restore_column_maps_after_mark_index()
- st_table::mark_columns_used_by_index_no_reset()
- st_table::mark_auto_increment_column()
- st_table::mark_columns_needed_for_delete()
- st_table::mark_columns_needed_for_update()
- st_table::mark_columns_needed_for_insert()
sql/table.h:
Moved column usage bitmaps from handler to TABLE
Added to TABLE_SHARE all_set and column_bitmap_size
Added to TABLE merge_keys, bitmap_init_values, def_read_set, def_write_set, tmp_set, read_set and write_set.
Declared all new table column bitmap functions
Added TABLE functions column_bitmaps_set(), column_bitmaps_set_no_signal(), use_all_columns() and default_column_bitmaps()
Added functions: tmp_use_all_columns() and tmp_restore_column_map() to temporarly switch column bitmaps
Added functions: dbug_tmp_use_all_columns() and dbug_tmp_restore_column_map() to temporarly switch column bitmaps to avoid asserts in Field::store() and Field::val().
sql/tztime.cc:
Mark all columns as used for timezone tables
storage/archive/ha_archive.cc:
Update to new handler interface
storage/archive/ha_archive.h:
Update to new handler interface
storage/blackhole/ha_blackhole.cc:
Update to new handler interface
storage/blackhole/ha_blackhole.h:
Update to new handler interface
removed not needed flag HA_DUPP_POS
storage/csv/ha_tina.cc:
Update to new handler interface
storage/csv/ha_tina.h:
Update to new handler interface
storage/example/ha_example.cc:
Update to new handler interface
storage/example/ha_example.h:
Update to new handler interface
storage/heap/hp_extra.c:
Added heap_reset() (Required by new handler interface)
storage/heap/hp_test2.c:
Use heap_reset()
storage/myisam/ft_boolean_search.c:
Fixed compiler warning
storage/myisam/mi_extra.c:
Added mi_reset() (Required by new handler interface)
storage/myisam/mi_search.c:
Fixed DBUG_PRINT messages to use 0x%lx instead of %lx
storage/myisam/mi_test2.c:
Use mi_reset()
storage/myisam/myisampack.c:
Use mi_reset()
storage/myisammrg/myrg_extra.c:
Added myrg_reset() (Required by new handler interface)
unittest/mysys/base64.t.c:
Include my_global.h
Don't include implictely include file 'stdlib.h'
2006-06-04 17:52:22 +02:00
|
|
|
table->use_all_columns();
|
2003-03-02 19:17:41 +01:00
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_ASSERT(table->s->system_table);
|
|
|
|
|
|
|
|
table->reginfo.lock_type= TL_READ;
|
|
|
|
/*
|
2005-08-08 15:46:06 +02:00
|
|
|
We have to ensure we are not blocked by a flush tables, as this
|
|
|
|
could lead to a deadlock if we have other tables opened.
|
2005-07-13 11:48:13 +02:00
|
|
|
*/
|
|
|
|
if (!(thd->lock= mysql_lock_tables(thd, &table, 1,
|
2005-09-15 01:56:09 +02:00
|
|
|
MYSQL_LOCK_IGNORE_FLUSH, ¬_used)))
|
2005-07-13 11:48:13 +02:00
|
|
|
{
|
2005-08-08 15:46:06 +02:00
|
|
|
close_proc_table(thd, backup);
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_RETURN(0);
|
2003-02-28 15:07:14 +01:00
|
|
|
}
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_RETURN(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Open the mysql.proc table for update.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
open_proc_table_for_update()
|
|
|
|
thd Thread context
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Table opened with this call should closed using close_thread_tables().
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Error
|
|
|
|
# Pointer to TABLE object of mysql.proc
|
|
|
|
*/
|
|
|
|
|
|
|
|
static TABLE *open_proc_table_for_update(THD *thd)
|
|
|
|
{
|
|
|
|
TABLE_LIST tables;
|
|
|
|
TABLE *table;
|
|
|
|
DBUG_ENTER("open_proc_table");
|
|
|
|
|
|
|
|
bzero((char*) &tables, sizeof(tables));
|
|
|
|
tables.db= (char*) "mysql";
|
|
|
|
tables.table_name= tables.alias= (char*)"proc";
|
|
|
|
tables.lock_type= TL_WRITE;
|
|
|
|
|
|
|
|
table= open_ltable(thd, &tables, TL_WRITE);
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
BitKeeper/etc/ignore:
added mysys/test_bitmap
include/base64.h:
Removed my_global.h, as this must be included first in any program
include/heap.h:
Added heap_reset() (Required by new handler interface)
include/my_base.h:
Removed HA_EXTRA_RESET. MySQL will now call ::reset() instead of ::extra(HA_EXTRA_RESET).
HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIVE_PRIMARY key are deleted as the column bitmaps makes these unnecessary
include/my_bitmap.h:
Remove my_pthread.h (should be included at upper level)
Introduced my_bitmap_map typedef to make it the bitmap handling more like a black box
Added bitmap_is_overlapping(), bitmap_test_and_clear(), bitmap_copy() and bitmap_cmp()
Made bitmap_set_bit(), bitmap_flip_bit(), bitmap_clear_bit() return void
include/myisam.h:
Added mi_reset() (Required by new handler interface)
include/myisammrg.h:
Added myrg_reset() (Required by new handler interface)
include/mysql_com.h:
Added flag FIELD_IN_ADD_INDEX to be able to remove Field->add_index
mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/install_test_db.sh:
Simplify ldata usage
Added --tmpdir=. option to mysqld bootstrap (Removed some warnings when TMPDIR was wrongly set)
mysql-test/mysql-test-run.pl:
Added --tmpdir=. to bootstrap
mysql-test/mysql-test-run.sh:
Use copy instead of INSTALL_DB for master and slave databases.
(Speeds up startup time a lot!)
Remove snapshot directories at startup (removes some strange warnings)
mysql-test/r/binlog_row_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/r/binlog_stm_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
mysql-test/r/create.result:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/r/federated.result:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/r/func_gconcat.result:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/r/func_time.result:
Added drop of test function
mysql-test/r/innodb_mysql.result:
Added tests for CREATE ... SELECT
mysql-test/r/insert.result:
More tests
Added testing of duplicate columns in insert
mysql-test/r/loaddata.result:
Added testing LOAD DATA ... SET ...
mysql-test/r/multi_update.result:
Test multi updates and deletes using primary key and without
mysql-test/r/ndb_index_unique.result:
Better error message
mysql-test/r/ndb_replace.result:
New correct result after fixing REPLACE handling with NDB
mysql-test/r/rpl_ddl.result:
Now we don't get these (wrong) warnings anymore
mysql-test/r/view_grant.result:
Drop used views
mysql-test/t/create.test:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/t/federated.test:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/t/func_gconcat.test:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/t/func_time.test:
Added drop of test function
mysql-test/t/innodb_mysql.test:
Added tests for CREATE ... SELECT
mysql-test/t/insert.test:
More tests
Added testing of duplicate columns in insert
mysql-test/t/loaddata.test:
Added testing LOAD DATA ... SET ...
mysql-test/t/multi_update.test:
Test multi updates and deletes using primary key and without
mysql-test/t/view_grant.test:
Drop used views
mysql-test/valgrind.supp:
Added supression of not needed warnings when printing stack trace
mysys/base64.c:
Include my_global.h first
mysys/my_bitmap.c:
Added bitmap_is_overlapping(), bitmap_test_and_clear() and bitmap_copy()
Changed logic of bitmap handling to be a bit more efficent (Did this together with Mikael Ronström)
Now the 'extra, not used bits' in the bitmap are assumed to have a 'random value' and the bitmap functions are free to change them whenever needed.
Changed how mutex is allocated to make 'bitmap_free()' function simpler.
mysys/thr_lock.c:
Added 0x before thread pointers (for easier comparison of DBUG traces)
sql/event.cc:
Ensure 'use_all_columns()' is used for event tables
Don't print warning that event table is damaged if it doesn't exists.
sql/field.cc:
Added ASSERT_COLUMN_MARKED_FOR_WRITE in all store() methods and ASSERT_COLUMN_MARKED_FOR_READ in all val() methods to catch wrong setting if table->read_set and table->write_set
(Rest of changes are only indentation cleanups)
sql/field.h:
Removed Field->query_id (replaced by table->read_set and table->write_set)
Removed Field->fieldnr (use Field->field_index instead)
Removed Field->add_index (Use Field->flags instead)
Add Field->part_of_key_not_clustered (for usage in opt_range.cc)
sql/filesort.cc:
Added paramater sort_postion to filesort() to force sorting by position instead of storing all fields in the result set.
This allowed me to remove checking of sql_command.
Create a temporary column bitmap for fields that are used by the sorting process.
Use column bitmaps instead of query_id
sql/ha_berkeley.cc:
Update to 'newer' table handler interface
sql/ha_berkeley.h:
Update to 'newer' table handler interface
sql/ha_federated.cc:
Update to 'newer' table handler interface
Only read columns that are needed from remote server.
In case of eq ranges, don't generate two conditions in the WHERE clause
(this can still be optimized, but would require a bigger code change)
Use 'simpler to use' XXXX_LEN' macros
A bit simpler logic in ::write_row() when creating statements.
In update, only include test of fields actually read.
(This greatly simplifies the queries sent by the federated engine)
Similar changes done for delete_row()
sql/ha_federated.h:
Update to 'newer' table handler interface
Changed XXX_LEN macros to use sizeof(...)-1, to simplify usage in ha_federated.cc
Added HA_PRIMARY_KEY_REQUIRED_FOR_DELETE to tell MySQL to read all primary key columns in case of DELETE
sql/ha_heap.cc:
Update to 'newer' table handler interface
sql/ha_heap.h:
Update to 'newer' table handler interface
sql/ha_innodb.cc:
Update to 'newer' table handler interface
- Update innobase_create_handler() to new interface
- Removed HA_NOT_EXACT_COUNT (not needed)
- Renamed HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- Prefixed base status variables with 'stats'
- Use table column bitmaps instead of ha_get_bit_in_read_set()
- Added ::reset(), with code from ::extra(HA_EXTRA_RESET)
- Removed HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIEVE_PRIMARY_KEY as
the table->read_set and table->write_set bitmaps now are accurate
sql/ha_innodb.h:
Update to 'newer' table handler interface
- table_flags are now ulonglong
- Added reset() method
- Removed not needed ha_retrieve_all_cols() and ha_retrieve_all_pk() columns.
- Made build_template() a class function to be able to easier access class variables
sql/ha_myisam.cc:
Update to 'newer' table handler interface
sql/ha_myisam.h:
Update to 'newer' table handler interface
sql/ha_myisammrg.cc:
Update to 'newer' table handler interface
sql/ha_myisammrg.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster.cc:
Update to 'newer' table handler interface
Fixed use_blob_value() to be accurate
In ::complemented_read() we have to check both the read and write bitmap as the old code did mark all changed columns also in the read map
Correct dumping of field data with DBUG_DUMP
Prefix addresses in DBUG_PRINT with 0x
Fixed usage of not initialized memory
Update to use field->flags & FIELD_IN_ADD_INDEX instead of field->add_index.
sql/ha_ndbcluster.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster_binlog.cc:
Mark usage of all columns in ndbcluster binlog tables
false -> FALSE, true -> TRUE
Use table->s->all_set instead of creating a temporary bitmap.
sql/ha_partition.cc:
Update to 'newer' table handler interface
Added memroot to initialise_partitions() and related functions to get faster memory allocation.
partition_create_handler() is now responsible for initialisation of the partition object
Some trivial optimizations and indentation fixes
Ensure that table_flags() are up to date
Removed documentation for removed HA_EXTRA flags
Fixed 'strange' usage of m_file[i] in new_handlers_from_part_info()that worked in current code 'by chance'
sql/ha_partition.h:
Update to 'newer' table handler interface
sql/handler.cc:
create_xxx handler now takes MEMROOT as an argument to simplify memory allocation.
Much simpler get_new_handler()
(Initialization of the object is now handled by the create method for the engine)
Moved all allocation of bitmap handling to the TABLE object (in table.cc)
Added column_bitmaps_signal() to signal column usage changes.
Changed binlog_log_row() to use the exiusting all_set bitmap in the table object.
Added ha_reset() function to test that the file object is ok at end of statement and call handler::reset()
Added use_hidden_primary_key() to signal handler that we we are going to read and update + delete the row and the handler should thus remember the position for the row
sql/handler.h:
Added HA_NO_TRANSACTIONS, HA_PARTIAL_COLUMN_READ, HA_REQUIRES_KEY_COLUMNS_FOR_DELETE,HA_PRIMARY_KEY_REQUIRED_FOR_DELETE and HA_HAS_RECORDS
Removed HA_NOT_EXACT_COUNT, HA_READ_RND_SAME
HA_DUPP_POS -> HA_DUPLICATE_POS
HA_NOT_EXACT_COUNT replaced by HA_STATS_RECORDS_IS_EXACT, HA_HAS_RECORDS and records()
HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION
Added future row type 'ROW_TYPE_PAGES'
Added MEM_ROOT to handlerton 'create' function
Added ha_statistics, a structure for all status variable in the base handler class.
Moved all status variables in the handler class into a stats structs to improve readability.
ha_table_flags() is now a cached (not virtual) version of table_flags()
reset() doesn't anymore call extra(HA_EXTRA_RESET) but is a function of it's own.
Renamed dupp_ref to dup_ref
Renamed not used handler::sortkey
Moved read_set and write_set to TABLE structure
handler::init() function added for cacheing of virtual constants from engine.
sql/item.cc:
Added register_field_in_read_map() for marking used columns in expression.
This is used by filesort() for creating an optimal column bitmap while retrieving columns for sorting.
Initalize value.cs_info.character_set_client to fix core dump bug with --debug
set_query_id -> mark_used_columns
Mark used columns in read_set OR write_set.
sql/item.h:
Removed reset_query_id_processor() as it's not needed anymore.
Added register_field_in_read_map()
Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
sql/item_cmpfunc.cc:
Temporary mark used columns to be read/writable
Update Item::walk to new interface
sql/item_cmpfunc.h:
Added extra argument to Item::walk() to indicate if we should also traverse sub queries.
sql/item_func.cc:
Update Item::walk() to new interface
table_flags() -> ha_table_flags()
sql/item_func.h:
Update Item::walk() to new interface
sql/item_row.cc:
Update Item::walk() to new interface
sql/item_row.h:
Update Item::walk() to new interface
sql/item_strfunc.h:
Update Item::walk() to new interface
sql/item_subselect.cc:
Added Item_subselect::walk()
(It was a bug it was missing before. Not sure what kind of bugs this could have caused)
sql/item_subselect.h:
Update Item::walk() to new interface
sql/item_sum.cc:
Update Item::walk() to new interface
Updates for new handler interace
sql/item_sum.h:
Update Item::walk() to new interface
sql/key.cc:
Updates for new handler interace
sql/log.cc:
Mark all columns used for log tables
Split options flag
Ensured that second argument to trans_register_ha is a bool
sql/log_event.cc:
Fixed comments to be withing 79 characters
Use OPTION_KEEP_LOG instead of OPTION_STATUS_NO_TRANS_UPDATE to remove wrong warnings
Updates for new handler interface
Use 0x%lx instead of %p (portability problem)
sql/mysql_priv.h:
Added OPTION_KEEP_LOG to indicate that we should replicate the binlog even on rollback
Removed not used 'conds' argument to setup_tables
sql/mysqld.cc:
Indentation fixes and removed old comment
sql/opt_range.cc:
Update to new handler and bitmap interface.
Fixed calls to cp_buffer_from_ref() and walk() (new argument).
Create new temporary bitmaps for ror scans.
(Needed because of handler changes and to get more accurate column bitmaps than before)
Remove not needed file->ha_reset() call before file->close().
Some trivial optimization and indentation fixes.
Use Field->part_of_key_not_clustered() to check if field is part of a key, instead of looping over all key parts.
Added flag 'in_ror_merged_scan' to allow ::get_next() to know that we need a special column bitmap to only fetch pointer to record.
This is needed because ror scan uses the same TABLE object but different file objects, which creates problem for the column bitmap handling.
(This is a temporary solution. A better one would be to allocate an own TABLE object for ROR scans)
Optimized bitmap handling in ror scans:
- Start bitmap at position 0, not 1
- Use same bitmap size as in TABLE
- Use table->read_set and table->write_set to create column bitmaps instead of looping over all fields in table
sql/opt_range.h:
Added 'in_ror_merged_scan' to indicate if we are doing a ROR scan
Added temporary column bitmaps used in ROR scans
sql/opt_sum.cc:
Added get_ext_record_count() which is used in COUNT() optimization if handler has HA_HAS_RECORDS
Note that we don't call this if handler has HA_STATS_RECORDS_IS_EXACT set.
sql/protocol.cc:
We need to mark columns as readable in ::store() as we sometimes return default value for fields to the user
sql/records.cc:
Updates for new handler interface
sql/set_var.cc:
Handle splitting OPTION_STATUS_NO_TRANS_UPDATE to two flags
sql/share/errmsg.txt:
Fixed wrong
sql/sp.cc:
Mark that we are using all columns for the proc table
Update call to setup_tables() to use new prototype
sql/sp_head.cc:
Removed QQ comment
sql/spatial.cc:
Removed wrong QQ comment
sql/sql_acl.cc:
Mark that we need all columns for acl tables
Supply memroot to some 'new' calls.
Indentation fixes
sql/sql_base.cc:
set_query_id removed
Ensure we call ha_reset() at end of each statement
Mark read columns in read_set and changed columns in write_set (Before all columns was marked in read set)
Fixed marking of some columns that was not proplerly marked before
Maintain in TABLE->merge_keys set of all keys that are used in some way
Removed not used 'conds' argument from setup_tables()
Remove not used setting of 'dupp_field' in insert_fields()
Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after crash)
sql/sql_bitmap.h:
Added is_overlapping()
sql/sql_class.cc:
Slow_logs was not properly initialized, which could maybe cause extra/lost entries in slow log.
set_query_id -> mark_used_columns
Simpler variable usage in pack_row() (cleanup)
Moved some variable declartion at start of function for better code readability
sql/sql_class.h:
Added enum_mark_columns
Updated comments
Renamed dupp_field -> dup_field
Added virtual function 'can_rollback_data()' to select_insert() to be used in CREATE ... SELECT to optimize use of OPTION_STATUS_NO_TRANS_UPDATE.
(This fixes a bug in CREATE ... SELECT where we did give wrong warnings when using non transacational tables)
sql/sql_delete.cc:
Updates to new handler interface
Call table->mark_columns_needed_for_delete() to allow us to put additional columns in column usage maps if handler so requires.
Call table->prepare_for_position() to tell handler that we are going to call ha_position().
Removed call to free_io_cache(). (io_cache is now removed in ha_reset()).
Fixed calls to setup_tables()
sql/sql_do.cc:
Update call to setup_fields()
sql/sql_handler.cc:
Tell handler tables to always read all columns.
Use temporary column map when storing value in field for later index usage
sql/sql_help.cc:
Makr all used fields to be read
Update call to setup_fields()
sql/sql_insert.cc:
Tell handler we are going to update the auto_increment column
dupp_field -> dup_field
Set column usage bits for timestamp field.
Call table->mark_columns_needed_for_insert() and table->mark_auto_increment_column()
Removed not used argument from mysql_prepare_insert_check_table().
If we get an duplicate row on insert, change column map to read and write all columns while retrying the operatation.
This is required by the definition of REPLACE and also ensures that fields that are only part of UPDATE are properly handled.
This fixed a bug in NDB and REPLACE where REPLACE wrongly copied some column values from the replaced row.
Setup new bitmaps for delayed insert rows
Remove reseting of next_number_fields as it will be reset on next call to handler_insert()
Fixed usage of thd->options and OPTION_STATUS_NO_TRANS_UPDATE.
The issue was that one should not to reset this flag as it may be set by a previous statement.
The way it was now used caused us to loose some warnings and get other wrong warnings when using non transactional tables mixed with transactional.
I fixed it by introducing 'select_insert::can_rollback_data' to inform send_error() that the given statement can be rolled back (which in case of CREATE TABLE can always be done)
Don't close tables created with CREATE ... SELECT but keep them in the table cache.
Moved out MY_HOOKS from inside function (better readability)
sql/sql_load.cc:
Update to use new handler and column marking interface
Update using setup_tables()
sql/sql_olap.cc:
Update calls to setup_tables
Use enums instead of constants to setup_fields()
sql/sql_parse.cc:
Handle OPTION_KEEP_LOG:
- Set it on CREATE TEMPORARY TABLE / DROP TABLE
- Reset it when OPTION_STATUS_NO_TRANS_UPDATE is reset
- Don't set it for CREATE ... SELECT (this is handled in select_create class)
Remove reseting of OPTION_STATUS_NO_TRANS_UPDATE in begin_trans() as this should already be reset.
If in autocommit mode, reset OPTION_KEEP_LOG and OPTION_STATUS_NO_TRANS_UPDATE to not give warnings in future commands
sql/sql_partition.cc:
Update walk() usage
Trivial indentation fixes
sql/sql_plugin.cc:
Mark all columns as used for plugins
sql/sql_prepare.cc:
Added assert to find out hidden bugs in character_set_client (got an error in debug binary when this not set correctly)
Updates for new handler interface
Update calls to setup_fields()
sql/sql_repl.cc:
Indentation fixes
sql/sql_select.cc:
Update call to setup_tables() and setup_fields()
Remove some old disabled code
Update to new hadler interface
Indentation cleanups
Added column bitmaps for temporary tables.
Remove updating of the removed slots in the Field class
Added TABLE argument to cp_buffer_from_ref() (To be able to install temporary column maps)
For internal temporary tables, use handler::write_row(), handler::delete_row() and handler::update_row() instead of handler::ha_xxxx() for faster execution.
sql/sql_select.h:
Indentaition fixes.
Install temporary column usage maps when needed
Added TABLE element to cp_buffer_from_ref()
sql/sql_show.cc:
Update to new handler interface
Mark all columns used for internal tables.
Style fixes.
Added support for 'future' ROW_TYPE_PAGES.
Don't allocate TMP_TABLE_PARAM with calloc. The 'init()' function will initialize the structure properly.
sql/sql_table.cc:
Update to new handler interface
Simple my_snprintf -> strmake()
Changed some constants to defines
Don't test for NULL in primary key (as we a couple of line above force the PRIMARY KEY to be NOT NULL)
Change field->add_index to use field->flags & FIELD_IN_ADD_INDEX
Mark all columns as used for ALTER TABLE
Style fixes
Update call to filesort()
sql/sql_trigger.h:
Added friend functions to be able to test if triggers exists for table we are going to insert/update or delete in.
sql/sql_udf.cc:
Mark all columns as used for udf system table.
sql/sql_union.cc:
Update call to walk()
Update to new handler interface
sql/sql_update.cc:
Remove query_id argument from compare_record()
Use column bitmaps instead of query_id.
We can't use compare_records() to skip updates for handlers that returns a partial column set and the read_set doesn't cover all columns in the write set, because compare_record() can't in this case know if a not read column changed value.
Update call to setup_fields()
Using separate column read and write sets allows for easier checking of timestamp field was set by statement.
Removed call to free_io_cache() as this is now done in ha_reset()
Call table->mark_columns_needed_for_update() and table->prepare_for_position()
Style fixes
sql/sql_view.cc:
Style fixes
sql/table.cc:
Remove implicitely include 'errno.h'
Remove code for building normalized path, as this is now identical to 'path'
Remove field->fieldnr
Added update of field->part_of_key_not_clustered()
Create column bitmaps in TABLE and TABLE_SHARE
Don't setup a temporary MEM_ROOT object as a thread specific variable for the handler. Instead we send the to-be-used MEMROOT to get_new_handler()
Update to new handler interface
Update call to walk()
Added new functions:
- st_table::clear_column_bitmaps()
- st_table::prepare_for_position()
- st_table::mark_columns_used_by_index()
- st_table::restore_column_maps_after_mark_index()
- st_table::mark_columns_used_by_index_no_reset()
- st_table::mark_auto_increment_column()
- st_table::mark_columns_needed_for_delete()
- st_table::mark_columns_needed_for_update()
- st_table::mark_columns_needed_for_insert()
sql/table.h:
Moved column usage bitmaps from handler to TABLE
Added to TABLE_SHARE all_set and column_bitmap_size
Added to TABLE merge_keys, bitmap_init_values, def_read_set, def_write_set, tmp_set, read_set and write_set.
Declared all new table column bitmap functions
Added TABLE functions column_bitmaps_set(), column_bitmaps_set_no_signal(), use_all_columns() and default_column_bitmaps()
Added functions: tmp_use_all_columns() and tmp_restore_column_map() to temporarly switch column bitmaps
Added functions: dbug_tmp_use_all_columns() and dbug_tmp_restore_column_map() to temporarly switch column bitmaps to avoid asserts in Field::store() and Field::val().
sql/tztime.cc:
Mark all columns as used for timezone tables
storage/archive/ha_archive.cc:
Update to new handler interface
storage/archive/ha_archive.h:
Update to new handler interface
storage/blackhole/ha_blackhole.cc:
Update to new handler interface
storage/blackhole/ha_blackhole.h:
Update to new handler interface
removed not needed flag HA_DUPP_POS
storage/csv/ha_tina.cc:
Update to new handler interface
storage/csv/ha_tina.h:
Update to new handler interface
storage/example/ha_example.cc:
Update to new handler interface
storage/example/ha_example.h:
Update to new handler interface
storage/heap/hp_extra.c:
Added heap_reset() (Required by new handler interface)
storage/heap/hp_test2.c:
Use heap_reset()
storage/myisam/ft_boolean_search.c:
Fixed compiler warning
storage/myisam/mi_extra.c:
Added mi_reset() (Required by new handler interface)
storage/myisam/mi_search.c:
Fixed DBUG_PRINT messages to use 0x%lx instead of %lx
storage/myisam/mi_test2.c:
Use mi_reset()
storage/myisam/myisampack.c:
Use mi_reset()
storage/myisammrg/myrg_extra.c:
Added myrg_reset() (Required by new handler interface)
unittest/mysys/base64.t.c:
Include my_global.h
Don't include implictely include file 'stdlib.h'
2006-06-04 17:52:22 +02:00
|
|
|
if (table)
|
|
|
|
table->use_all_columns();
|
2005-07-13 11:48:13 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Under explicit LOCK TABLES or in prelocked mode we should not
|
|
|
|
say that mysql.proc table does not exist if we are unable to
|
|
|
|
open and lock it for writing since this condition may be
|
|
|
|
transient.
|
|
|
|
*/
|
|
|
|
if (!(thd->locked_tables || thd->prelocked_mode) || table)
|
|
|
|
mysql_proc_table_exists= test(table);
|
|
|
|
|
|
|
|
DBUG_RETURN(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Find row in open mysql.proc table representing stored routine.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
db_find_routine_aux()
|
|
|
|
thd Thread context
|
|
|
|
type Type of routine to find (function or procedure)
|
|
|
|
name Name of routine
|
|
|
|
table TABLE object for open mysql.proc table.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
SP_OK - Routine found
|
|
|
|
SP_KEY_NOT_FOUND- No routine with given name
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
db_find_routine_aux(THD *thd, int type, sp_name *name, TABLE *table)
|
|
|
|
{
|
2005-07-13 13:08:13 +02:00
|
|
|
byte key[MAX_KEY_LENGTH]; // db, name, optional key length type
|
2005-07-13 11:48:13 +02:00
|
|
|
DBUG_ENTER("db_find_routine_aux");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",
|
2005-07-13 11:48:13 +02:00
|
|
|
type, 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);
|
Added option --valgrind-mysqltest to mysql-test-run
Added flag to Field::store(longlong) to specify if value is unsigned.
This fixes bug #12750: Incorrect storage of 9999999999999999999 in DECIMAL(19, 0)
Fixed warning from valgrind in CREATE ... SELECT
Fixed double free of mysql.options if reconnect failed
mysql-test/mysql-test-run.sh:
Added option --valgrind-mysqltest to allow one to run mysqltest with valgrind
mysql-test/r/bigint.result:
Update results after fix for Field::store(longlong)
mysql-test/r/range.result:
Update results after fix for Field::store(longlong)
mysql-test/r/strict.result:
Update results after fix for Field::store(longlong)
(This fixes some wrong results when storing things into bigint columns)
mysql-test/r/type_ranges.result:
Update results after fix for Field::store(longlong)
mysql-test/t/bigint.test:
Added testing for #12750: Incorrect storage of 9999999999999999999 in DECIMAL(19, 0)
mysql-test/t/innodb.test:
Removed comments affected by this bug fix
mysql-test/t/mysqldump.test:
Fixed result to not depend on existing config files
mysql-test/t/range.test:
0xff numbers are now unsigned
mysql-test/t/strict.test:
Added errors for things that previously (wrongly) succeeded
sql-common/client.c:
Fixed double free of mysql.options if reconnect failed
sql/field.cc:
Added flag to Field::store(longlong) to specify if value is unsigned
sql/field.h:
Added flag to Field::store(longlong) to specify if value is unsigned
sql/field_conv.cc:
Fixed calls to Field::store(longlong,flag)
sql/ha_ndbcluster.cc:
Fixed calls to Field::store(longlong,flag)
sql/handler.cc:
Fixed calls to Field::store(longlong,flag)
sql/item.cc:
Fixed calls to Field::store(longlong,flag)
sql/item_sum.cc:
Fixed calls to Field::store(longlong,flag)
sql/sp.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_acl.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_help.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_show.cc:
Fixed calls to Field::store(longlong,flag)
sql/sql_table.cc:
Fixed varning from valgrind
sql/sql_udf.cc:
Fixed calls to Field::store(longlong,flag)
sql/tztime.cc:
Fixed calls to Field::store(longlong,flag)
sql/unireg.cc:
Fixed calls to Field::store(longlong,flag)
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);
|
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
if (table->file->index_read_idx(table->record[0], 0,
|
2005-04-04 15:43:25 +02:00
|
|
|
key, table->key_info->key_length,
|
2002-12-12 13:14:23 +01:00
|
|
|
HA_READ_KEY_EXACT))
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
2002-12-12 13:14:23 +01:00
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(SP_OK);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
/*
|
|
|
|
Find routine definition in mysql.proc table and create corresponding
|
|
|
|
sp_head object for it.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
db_find_routine()
|
|
|
|
thd Thread context
|
|
|
|
type Type of routine (TYPE_ENUM_PROCEDURE/...)
|
|
|
|
name Name of routine
|
|
|
|
sphp Out parameter in which pointer to created sp_head
|
|
|
|
object is returned (0 in case of error).
|
|
|
|
|
|
|
|
NOTE
|
|
|
|
This function may damage current LEX during execution, so it is good
|
|
|
|
idea to create temporary LEX and make it active before calling it.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 - Success
|
|
|
|
non-0 - Error (may be one of special codes like SP_KEY_NOT_FOUND)
|
|
|
|
*/
|
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
const char *params, *returns, *body;
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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);
|
2003-12-11 12:23:50 +01:00
|
|
|
ulong sql_mode;
|
2005-08-08 15:46:06 +02:00
|
|
|
Open_tables_state open_tables_state_backup;
|
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#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
type, 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);
|
|
|
|
|
|
|
|
if ((ret= db_find_routine_aux(thd, type, name, table)) != SP_OK)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
goto done;
|
2003-10-30 10:25:45 +01:00
|
|
|
|
2005-01-06 12:00:13 +01: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:
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
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,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_DETERMINISTIC])) == NULL)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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
|
|
|
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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;
|
|
|
|
}
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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()))
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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
|
|
|
|
2005-08-08 15:46:06 +02:00
|
|
|
close_proc_table(thd, &open_tables_state_backup);
|
2005-07-13 11:48:13 +02:00
|
|
|
table= 0;
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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,
|
|
|
|
definer, created, modified);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (table)
|
|
|
|
close_proc_table(thd, &open_tables_state_backup);
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
|
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,
|
|
|
|
const char *definer, longlong created, longlong modified)
|
|
|
|
{
|
2006-01-05 23:47:49 +01:00
|
|
|
LEX *old_lex= thd->lex, newlex;
|
2005-11-23 00:11:19 +01:00
|
|
|
String defstr;
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
char old_db_buf[NAME_LEN+1];
|
|
|
|
LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
|
2005-11-23 00:11:19 +01:00
|
|
|
bool dbchanged;
|
|
|
|
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;
|
2006-05-18 16:57:50 +02:00
|
|
|
|
2006-03-02 13:18:49 +01:00
|
|
|
char definer_user_name_holder[USERNAME_LENGTH + 1];
|
2006-05-18 16:57:50 +02:00
|
|
|
LEX_STRING definer_user_name= { definer_user_name_holder, 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);
|
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
defstr.set_charset(system_charset_info);
|
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,
|
|
|
|
type,
|
|
|
|
name,
|
|
|
|
params, strlen(params),
|
|
|
|
returns, strlen(returns),
|
|
|
|
body, strlen(body),
|
2006-03-02 13:18:49 +01:00
|
|
|
&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
|
|
|
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
if ((ret= sp_use_new_db(thd, name->m_db, &old_db, 1, &dbchanged)))
|
2005-11-23 00:11:19 +01:00
|
|
|
goto end;
|
2003-07-01 17:19:48 +02:00
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
lex_start(thd, (uchar*)defstr.c_ptr(), defstr.length());
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2005-11-23 00:29:25 +01:00
|
|
|
thd->spcont= 0;
|
2006-03-10 01:44:08 +01:00
|
|
|
if (MYSQLparse(thd) || thd->is_fatal_error || newlex.sphead == NULL)
|
2005-11-23 00:11:19 +01:00
|
|
|
{
|
|
|
|
sp_head *sp= newlex.sphead;
|
|
|
|
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
if (dbchanged && (ret= mysql_change_db(thd, old_db.str, 1)))
|
2005-11-23 00:11:19 +01:00
|
|
|
goto end;
|
|
|
|
delete sp;
|
|
|
|
ret= SP_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
if (dbchanged && (ret= mysql_change_db(thd, old_db.str, 1)))
|
2005-11-23 01:49:44 +01:00
|
|
|
goto end;
|
2005-11-23 00:11:19 +01:00
|
|
|
*sphp= newlex.sphead;
|
2006-03-02 13:18:49 +01:00
|
|
|
(*sphp)->set_definer(&definer_user_name, &definer_host_name);
|
2005-11-23 01:49:44 +01:00
|
|
|
(*sphp)->set_info(created, modified, &chistics, sql_mode);
|
2005-11-23 00:11:19 +01:00
|
|
|
(*sphp)->optimize();
|
|
|
|
}
|
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;
|
Table definition cache, part 2
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
Other noteworthy changes:
- In TABLE_SHARE the most common strings are now LEX_STRING's
- Better error message when table is not found
- Variable table_cache is now renamed 'table_open_cache'
- New variable 'table_definition_cache' that is the number of table defintions that will be cached
- strxnmov() calls are now fixed to avoid overflows
- strxnmov() will now always add one end \0 to result
- engine objects are now created with a TABLE_SHARE object instead of a TABLE object.
- After creating a field object one must call field->init(table) before using it
- For a busy system this change will give you:
- Less memory usage for table object
- Faster opening of tables (if it's has been in use or is in table definition cache)
- Allow you to cache many table definitions objects
- Faster drop of table
mysql-test/mysql-test-run.sh:
Fixed some problems with --gdb option
Test both with socket and tcp/ip port that all old servers are killed
mysql-test/r/flush_table.result:
More tests with lock table with 2 threads + flush table
mysql-test/r/information_schema.result:
Removed old (now wrong) result
mysql-test/r/innodb.result:
Better error messages (thanks to TDC patch)
mysql-test/r/merge.result:
Extra flush table test
mysql-test/r/ndb_bitfield.result:
Better error messages (thanks to TDC patch)
mysql-test/r/ndb_partition_error.result:
Better error messages (thanks to TDC patch)
mysql-test/r/query_cache.result:
Remove tables left from old tests
mysql-test/r/temp_table.result:
Test truncate with temporary tables
mysql-test/r/variables.result:
Table_cache -> Table_open_cache
mysql-test/t/flush_table.test:
More tests with lock table with 2 threads + flush table
mysql-test/t/merge.test:
Extra flush table test
mysql-test/t/multi_update.test:
Added 'sleep' to make test predictable
mysql-test/t/query_cache.test:
Remove tables left from old tests
mysql-test/t/temp_table.test:
Test truncate with temporary tables
mysql-test/t/variables.test:
Table_cache -> Table_open_cache
mysql-test/valgrind.supp:
Remove warning that may happens becasue threads dies in different order
mysys/hash.c:
Fixed wrong DBUG_PRINT
mysys/mf_dirname.c:
More DBUG
mysys/mf_pack.c:
Better comment
mysys/mf_tempdir.c:
More DBUG
Ensure that we call cleanup_dirname() on all temporary directory paths.
If we don't do this, we will get a failure when comparing temporary table
names as in some cases the temporary table name is run through convert_dirname())
mysys/my_alloc.c:
Indentation fix
sql/examples/ha_example.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_example.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/field.cc:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Use s->db instead of s->table_cache_key
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/field.h:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/ha_archive.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_archive.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_berkeley.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Changed name of argument create() to not hide internal 'table' variable.
table->s -> table_share
sql/ha_berkeley.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_federated.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed comments
Remove index variable and replace with pointers (simple optimization)
move_field() -> move_field_offset()
Removed some strlen() calls
sql/ha_federated.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_heap.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Simplify delete_table() and create() as the given file names are now without extension
sql/ha_heap.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisam.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Remove not needed fn_format()
Fixed for new table->s structure
sql/ha_myisam.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisammrg.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Don't set 'is_view' for MERGE tables
Use new interface to find_temporary_table()
sql/ha_myisammrg.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Added flag HA_NO_COPY_ON_ALTER
sql/ha_ndbcluster.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed wrong calls to strxnmov()
Give error HA_ERR_TABLE_DEF_CHANGED if table definition has changed
drop_table -> intern_drop_table()
table->s -> table_share
Move part_info to TABLE
Fixed comments & DBUG print's
New arguments to print_error()
sql/ha_ndbcluster.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_partition.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
We can't set up or use part_info when creating handler as there is not yet any table object
New ha_intialise() to work with TDC (Done by Mikael)
sql/ha_partition.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Got set_part_info() from Mikael
sql/handler.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
ha_delete_table() now also takes database as an argument
handler::ha_open() now takes TABLE as argument
ha_open() now calls ha_allocate_read_write_set()
Simplify ha_allocate_read_write_set()
Remove ha_deallocate_read_write_set()
Use table_share (Cached by table definition cache)
sql/handler.h:
New table flag: HA_NO_COPY_ON_ALTER (used by merge tables)
Remove ha_deallocate_read_write_set()
get_new_handler() now takes TABLE_SHARE as argument
ha_delete_table() now gets database as argument
sql/item.cc:
table_name and db are now LEX_STRING objects
When creating fields, we have now have to call field->init(table)
move_field -> move_field_offset()
sql/item.h:
tmp_table_field_from_field_type() now takes an extra paramenter 'fixed_length' to allow one to force usage of CHAR
instead of BLOB
sql/item_cmpfunc.cc:
Fixed call to tmp_table_field_from_field_type()
sql/item_create.cc:
Assert if new not handled cast type
sql/item_func.cc:
When creating fields, we have now have to call field->init(table)
dummy_table used by 'sp' now needs a TABLE_SHARE object
sql/item_subselect.cc:
Trivial code cleanups
sql/item_sum.cc:
When creating fields, we have now have to call field->init(table)
sql/item_timefunc.cc:
Item_func_str_to_date::tmp_table_field() now replaced by call to
tmp_table_field_from_field_type() (see item_timefunc.h)
sql/item_timefunc.h:
Simply tmp_table_field()
sql/item_uniq.cc:
When creating fields, we have now have to call field->init(table)
sql/key.cc:
Added 'KEY' argument to 'find_ref_key' to simplify code
sql/lock.cc:
More debugging
Use create_table_def_key() to create key for table cache
Allocate TABLE_SHARE properly when creating name lock
Fix that locked_table_name doesn't test same table twice
sql/mysql_priv.h:
New functions for table definition cache
New interfaces to a lot of functions.
New faster interface to find_temporary_table() and close_temporary_table()
sql/mysqld.cc:
Added support for table definition cache of size 'table_def_size'
Fixed som calls to strnmov()
Changed name of 'table_cache' to 'table_open_cache'
sql/opt_range.cc:
Use new interfaces
Fixed warnings from valgrind
sql/parse_file.cc:
Safer calls to strxnmov()
Fixed typo
sql/set_var.cc:
Added variable 'table_definition_cache'
Variable table_cache renamed to 'table_open_cache'
sql/slave.cc:
Use new interface
sql/sp.cc:
Proper use of TABLE_SHARE
sql/sp_head.cc:
Remove compiler warnings
We have now to call field->init(table)
sql/sp_head.h:
Pointers to parsed strings are now const
sql/sql_acl.cc:
table_name is now a LEX_STRING
sql/sql_base.cc:
Main implementation of table definition cache
(The #ifdef's are there for the future when table definition cache will replace open table cache)
Now table definitions are cached indepndent of open tables, which will speed up things when a table is in use at once from several places
Views are not yet cached; For the moment we only cache if a table is a view or not.
Faster implementation of find_temorary_table()
Replace 'wait_for_refresh()' with the more general function 'wait_for_condition()'
Drop table is slightly faster as we can use the table definition cache to know the type of the table
sql/sql_cache.cc:
table_cache_key and table_name are now LEX_STRING
'sDBUG print fixes
sql/sql_class.cc:
table_cache_key is now a LEX_STRING
safer strxnmov()
sql/sql_class.h:
Added number of open table shares (table definitions)
sql/sql_db.cc:
safer strxnmov()
sql/sql_delete.cc:
Use new interface to find_temporary_table()
sql/sql_derived.cc:
table_name is now a LEX_STRING
sql/sql_handler.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_insert.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_lex.cc:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_lex.h:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_load.cc:
Safer strxnmov()
sql/sql_parse.cc:
Better error if wrong DB name
sql/sql_partition.cc:
part_info moved to TABLE from TABLE_SHARE
Indentation changes
sql/sql_select.cc:
Indentation fixes
Call field->init(TABLE) for new created fields
Update create_tmp_table() to use TABLE_SHARE properly
sql/sql_select.h:
Call field->init(TABLE) for new created fields
sql/sql_show.cc:
table_name is now a LEX_STRING
part_info moved to TABLE
sql/sql_table.cc:
Use table definition cache to speed up delete of tables
Fixed calls to functions with new interfaces
Don't use 'share_not_to_be_used'
Instead of doing openfrm() when doing repair, we now have to call
get_table_share() followed by open_table_from_share().
Replace some fn_format() with faster unpack_filename().
Safer strxnmov()
part_info is now in TABLE
Added Mikaels patch for partition and ALTER TABLE
Instead of using 'TABLE_SHARE->is_view' use 'table_flags() & HA_NO_COPY_ON_ALTER
sql/sql_test.cc:
table_name and table_cache_key are now LEX_STRING's
sql/sql_trigger.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
safer strxnmov()
Removed compiler warnings
sql/sql_update.cc:
Call field->init(TABLE) after field is created
sql/sql_view.cc:
safer strxnmov()
Create common TABLE_SHARE object for views to allow us to cache if table is a view
sql/structs.h:
Added SHOW_TABLE_DEFINITIONS
sql/table.cc:
Creation and destruct of TABLE_SHARE objects that are common for many TABLE objects
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
open_table_def() is written in such a way that it should be trival to add parsing of the .frm files in new formats
sql/table.h:
TABLE objects for the same database table now share a common TABLE_SHARE object
In TABLE_SHARE the most common strings are now LEX_STRING's
sql/unireg.cc:
Changed arguments to rea_create_table() to have same order as other functions
Call field->init(table) for new created fields
sql/unireg.h:
Added OPEN_VIEW
strings/strxnmov.c:
Change strxnmov() to always add end \0
This makes usage of strxnmov() safer as most of MySQL code assumes that strxnmov() will create a null terminated string
2005-11-23 21:45:02 +01:00
|
|
|
TABLE_SHARE share;
|
2005-03-04 22:14:35 +01:00
|
|
|
Field *field;
|
Table definition cache, part 2
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
Other noteworthy changes:
- In TABLE_SHARE the most common strings are now LEX_STRING's
- Better error message when table is not found
- Variable table_cache is now renamed 'table_open_cache'
- New variable 'table_definition_cache' that is the number of table defintions that will be cached
- strxnmov() calls are now fixed to avoid overflows
- strxnmov() will now always add one end \0 to result
- engine objects are now created with a TABLE_SHARE object instead of a TABLE object.
- After creating a field object one must call field->init(table) before using it
- For a busy system this change will give you:
- Less memory usage for table object
- Faster opening of tables (if it's has been in use or is in table definition cache)
- Allow you to cache many table definitions objects
- Faster drop of table
mysql-test/mysql-test-run.sh:
Fixed some problems with --gdb option
Test both with socket and tcp/ip port that all old servers are killed
mysql-test/r/flush_table.result:
More tests with lock table with 2 threads + flush table
mysql-test/r/information_schema.result:
Removed old (now wrong) result
mysql-test/r/innodb.result:
Better error messages (thanks to TDC patch)
mysql-test/r/merge.result:
Extra flush table test
mysql-test/r/ndb_bitfield.result:
Better error messages (thanks to TDC patch)
mysql-test/r/ndb_partition_error.result:
Better error messages (thanks to TDC patch)
mysql-test/r/query_cache.result:
Remove tables left from old tests
mysql-test/r/temp_table.result:
Test truncate with temporary tables
mysql-test/r/variables.result:
Table_cache -> Table_open_cache
mysql-test/t/flush_table.test:
More tests with lock table with 2 threads + flush table
mysql-test/t/merge.test:
Extra flush table test
mysql-test/t/multi_update.test:
Added 'sleep' to make test predictable
mysql-test/t/query_cache.test:
Remove tables left from old tests
mysql-test/t/temp_table.test:
Test truncate with temporary tables
mysql-test/t/variables.test:
Table_cache -> Table_open_cache
mysql-test/valgrind.supp:
Remove warning that may happens becasue threads dies in different order
mysys/hash.c:
Fixed wrong DBUG_PRINT
mysys/mf_dirname.c:
More DBUG
mysys/mf_pack.c:
Better comment
mysys/mf_tempdir.c:
More DBUG
Ensure that we call cleanup_dirname() on all temporary directory paths.
If we don't do this, we will get a failure when comparing temporary table
names as in some cases the temporary table name is run through convert_dirname())
mysys/my_alloc.c:
Indentation fix
sql/examples/ha_example.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_example.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/field.cc:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Use s->db instead of s->table_cache_key
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/field.h:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/ha_archive.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_archive.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_berkeley.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Changed name of argument create() to not hide internal 'table' variable.
table->s -> table_share
sql/ha_berkeley.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_federated.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed comments
Remove index variable and replace with pointers (simple optimization)
move_field() -> move_field_offset()
Removed some strlen() calls
sql/ha_federated.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_heap.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Simplify delete_table() and create() as the given file names are now without extension
sql/ha_heap.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisam.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Remove not needed fn_format()
Fixed for new table->s structure
sql/ha_myisam.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisammrg.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Don't set 'is_view' for MERGE tables
Use new interface to find_temporary_table()
sql/ha_myisammrg.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Added flag HA_NO_COPY_ON_ALTER
sql/ha_ndbcluster.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed wrong calls to strxnmov()
Give error HA_ERR_TABLE_DEF_CHANGED if table definition has changed
drop_table -> intern_drop_table()
table->s -> table_share
Move part_info to TABLE
Fixed comments & DBUG print's
New arguments to print_error()
sql/ha_ndbcluster.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_partition.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
We can't set up or use part_info when creating handler as there is not yet any table object
New ha_intialise() to work with TDC (Done by Mikael)
sql/ha_partition.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Got set_part_info() from Mikael
sql/handler.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
ha_delete_table() now also takes database as an argument
handler::ha_open() now takes TABLE as argument
ha_open() now calls ha_allocate_read_write_set()
Simplify ha_allocate_read_write_set()
Remove ha_deallocate_read_write_set()
Use table_share (Cached by table definition cache)
sql/handler.h:
New table flag: HA_NO_COPY_ON_ALTER (used by merge tables)
Remove ha_deallocate_read_write_set()
get_new_handler() now takes TABLE_SHARE as argument
ha_delete_table() now gets database as argument
sql/item.cc:
table_name and db are now LEX_STRING objects
When creating fields, we have now have to call field->init(table)
move_field -> move_field_offset()
sql/item.h:
tmp_table_field_from_field_type() now takes an extra paramenter 'fixed_length' to allow one to force usage of CHAR
instead of BLOB
sql/item_cmpfunc.cc:
Fixed call to tmp_table_field_from_field_type()
sql/item_create.cc:
Assert if new not handled cast type
sql/item_func.cc:
When creating fields, we have now have to call field->init(table)
dummy_table used by 'sp' now needs a TABLE_SHARE object
sql/item_subselect.cc:
Trivial code cleanups
sql/item_sum.cc:
When creating fields, we have now have to call field->init(table)
sql/item_timefunc.cc:
Item_func_str_to_date::tmp_table_field() now replaced by call to
tmp_table_field_from_field_type() (see item_timefunc.h)
sql/item_timefunc.h:
Simply tmp_table_field()
sql/item_uniq.cc:
When creating fields, we have now have to call field->init(table)
sql/key.cc:
Added 'KEY' argument to 'find_ref_key' to simplify code
sql/lock.cc:
More debugging
Use create_table_def_key() to create key for table cache
Allocate TABLE_SHARE properly when creating name lock
Fix that locked_table_name doesn't test same table twice
sql/mysql_priv.h:
New functions for table definition cache
New interfaces to a lot of functions.
New faster interface to find_temporary_table() and close_temporary_table()
sql/mysqld.cc:
Added support for table definition cache of size 'table_def_size'
Fixed som calls to strnmov()
Changed name of 'table_cache' to 'table_open_cache'
sql/opt_range.cc:
Use new interfaces
Fixed warnings from valgrind
sql/parse_file.cc:
Safer calls to strxnmov()
Fixed typo
sql/set_var.cc:
Added variable 'table_definition_cache'
Variable table_cache renamed to 'table_open_cache'
sql/slave.cc:
Use new interface
sql/sp.cc:
Proper use of TABLE_SHARE
sql/sp_head.cc:
Remove compiler warnings
We have now to call field->init(table)
sql/sp_head.h:
Pointers to parsed strings are now const
sql/sql_acl.cc:
table_name is now a LEX_STRING
sql/sql_base.cc:
Main implementation of table definition cache
(The #ifdef's are there for the future when table definition cache will replace open table cache)
Now table definitions are cached indepndent of open tables, which will speed up things when a table is in use at once from several places
Views are not yet cached; For the moment we only cache if a table is a view or not.
Faster implementation of find_temorary_table()
Replace 'wait_for_refresh()' with the more general function 'wait_for_condition()'
Drop table is slightly faster as we can use the table definition cache to know the type of the table
sql/sql_cache.cc:
table_cache_key and table_name are now LEX_STRING
'sDBUG print fixes
sql/sql_class.cc:
table_cache_key is now a LEX_STRING
safer strxnmov()
sql/sql_class.h:
Added number of open table shares (table definitions)
sql/sql_db.cc:
safer strxnmov()
sql/sql_delete.cc:
Use new interface to find_temporary_table()
sql/sql_derived.cc:
table_name is now a LEX_STRING
sql/sql_handler.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_insert.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_lex.cc:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_lex.h:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_load.cc:
Safer strxnmov()
sql/sql_parse.cc:
Better error if wrong DB name
sql/sql_partition.cc:
part_info moved to TABLE from TABLE_SHARE
Indentation changes
sql/sql_select.cc:
Indentation fixes
Call field->init(TABLE) for new created fields
Update create_tmp_table() to use TABLE_SHARE properly
sql/sql_select.h:
Call field->init(TABLE) for new created fields
sql/sql_show.cc:
table_name is now a LEX_STRING
part_info moved to TABLE
sql/sql_table.cc:
Use table definition cache to speed up delete of tables
Fixed calls to functions with new interfaces
Don't use 'share_not_to_be_used'
Instead of doing openfrm() when doing repair, we now have to call
get_table_share() followed by open_table_from_share().
Replace some fn_format() with faster unpack_filename().
Safer strxnmov()
part_info is now in TABLE
Added Mikaels patch for partition and ALTER TABLE
Instead of using 'TABLE_SHARE->is_view' use 'table_flags() & HA_NO_COPY_ON_ALTER
sql/sql_test.cc:
table_name and table_cache_key are now LEX_STRING's
sql/sql_trigger.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
safer strxnmov()
Removed compiler warnings
sql/sql_update.cc:
Call field->init(TABLE) after field is created
sql/sql_view.cc:
safer strxnmov()
Create common TABLE_SHARE object for views to allow us to cache if table is a view
sql/structs.h:
Added SHOW_TABLE_DEFINITIONS
sql/table.cc:
Creation and destruct of TABLE_SHARE objects that are common for many TABLE objects
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
open_table_def() is written in such a way that it should be trival to add parsing of the .frm files in new formats
sql/table.h:
TABLE objects for the same database table now share a common TABLE_SHARE object
In TABLE_SHARE the most common strings are now LEX_STRING's
sql/unireg.cc:
Changed arguments to rea_create_table() to have same order as other functions
Call field->init(table) for new created fields
sql/unireg.h:
Added OPEN_VIEW
strings/strxnmov.c:
Change strxnmov() to always add end \0
This makes usage of strxnmov() safer as most of MySQL code assumes that strxnmov() will create a null terminated string
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;
|
Table definition cache, part 2
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
Other noteworthy changes:
- In TABLE_SHARE the most common strings are now LEX_STRING's
- Better error message when table is not found
- Variable table_cache is now renamed 'table_open_cache'
- New variable 'table_definition_cache' that is the number of table defintions that will be cached
- strxnmov() calls are now fixed to avoid overflows
- strxnmov() will now always add one end \0 to result
- engine objects are now created with a TABLE_SHARE object instead of a TABLE object.
- After creating a field object one must call field->init(table) before using it
- For a busy system this change will give you:
- Less memory usage for table object
- Faster opening of tables (if it's has been in use or is in table definition cache)
- Allow you to cache many table definitions objects
- Faster drop of table
mysql-test/mysql-test-run.sh:
Fixed some problems with --gdb option
Test both with socket and tcp/ip port that all old servers are killed
mysql-test/r/flush_table.result:
More tests with lock table with 2 threads + flush table
mysql-test/r/information_schema.result:
Removed old (now wrong) result
mysql-test/r/innodb.result:
Better error messages (thanks to TDC patch)
mysql-test/r/merge.result:
Extra flush table test
mysql-test/r/ndb_bitfield.result:
Better error messages (thanks to TDC patch)
mysql-test/r/ndb_partition_error.result:
Better error messages (thanks to TDC patch)
mysql-test/r/query_cache.result:
Remove tables left from old tests
mysql-test/r/temp_table.result:
Test truncate with temporary tables
mysql-test/r/variables.result:
Table_cache -> Table_open_cache
mysql-test/t/flush_table.test:
More tests with lock table with 2 threads + flush table
mysql-test/t/merge.test:
Extra flush table test
mysql-test/t/multi_update.test:
Added 'sleep' to make test predictable
mysql-test/t/query_cache.test:
Remove tables left from old tests
mysql-test/t/temp_table.test:
Test truncate with temporary tables
mysql-test/t/variables.test:
Table_cache -> Table_open_cache
mysql-test/valgrind.supp:
Remove warning that may happens becasue threads dies in different order
mysys/hash.c:
Fixed wrong DBUG_PRINT
mysys/mf_dirname.c:
More DBUG
mysys/mf_pack.c:
Better comment
mysys/mf_tempdir.c:
More DBUG
Ensure that we call cleanup_dirname() on all temporary directory paths.
If we don't do this, we will get a failure when comparing temporary table
names as in some cases the temporary table name is run through convert_dirname())
mysys/my_alloc.c:
Indentation fix
sql/examples/ha_example.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_example.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/examples/ha_tina.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/field.cc:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Use s->db instead of s->table_cache_key
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/field.h:
Update for table definition cache:
- Field creation now takes TABLE_SHARE instead of TABLE as argument
(This is becasue field definitions are now cached in TABLE_SHARE)
When a field is created, one now must call field->init(TABLE) before using it
- Added Field::clone() to create a field in TABLE from a field in TABLE_SHARE
- make_field() takes TABLE_SHARE as argument instead of TABLE
- move_field() -> move_field_offset()
sql/ha_archive.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_archive.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_berkeley.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Changed name of argument create() to not hide internal 'table' variable.
table->s -> table_share
sql/ha_berkeley.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_blackhole.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_federated.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed comments
Remove index variable and replace with pointers (simple optimization)
move_field() -> move_field_offset()
Removed some strlen() calls
sql/ha_federated.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_heap.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Simplify delete_table() and create() as the given file names are now without extension
sql/ha_heap.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_innodb.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisam.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Remove not needed fn_format()
Fixed for new table->s structure
sql/ha_myisam.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_myisammrg.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Don't set 'is_view' for MERGE tables
Use new interface to find_temporary_table()
sql/ha_myisammrg.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Added flag HA_NO_COPY_ON_ALTER
sql/ha_ndbcluster.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Fixed wrong calls to strxnmov()
Give error HA_ERR_TABLE_DEF_CHANGED if table definition has changed
drop_table -> intern_drop_table()
table->s -> table_share
Move part_info to TABLE
Fixed comments & DBUG print's
New arguments to print_error()
sql/ha_ndbcluster.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
sql/ha_partition.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
We can't set up or use part_info when creating handler as there is not yet any table object
New ha_intialise() to work with TDC (Done by Mikael)
sql/ha_partition.h:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
Got set_part_info() from Mikael
sql/handler.cc:
We new use TABLE_SHARE instead of TABLE when creating engine handlers
ha_delete_table() now also takes database as an argument
handler::ha_open() now takes TABLE as argument
ha_open() now calls ha_allocate_read_write_set()
Simplify ha_allocate_read_write_set()
Remove ha_deallocate_read_write_set()
Use table_share (Cached by table definition cache)
sql/handler.h:
New table flag: HA_NO_COPY_ON_ALTER (used by merge tables)
Remove ha_deallocate_read_write_set()
get_new_handler() now takes TABLE_SHARE as argument
ha_delete_table() now gets database as argument
sql/item.cc:
table_name and db are now LEX_STRING objects
When creating fields, we have now have to call field->init(table)
move_field -> move_field_offset()
sql/item.h:
tmp_table_field_from_field_type() now takes an extra paramenter 'fixed_length' to allow one to force usage of CHAR
instead of BLOB
sql/item_cmpfunc.cc:
Fixed call to tmp_table_field_from_field_type()
sql/item_create.cc:
Assert if new not handled cast type
sql/item_func.cc:
When creating fields, we have now have to call field->init(table)
dummy_table used by 'sp' now needs a TABLE_SHARE object
sql/item_subselect.cc:
Trivial code cleanups
sql/item_sum.cc:
When creating fields, we have now have to call field->init(table)
sql/item_timefunc.cc:
Item_func_str_to_date::tmp_table_field() now replaced by call to
tmp_table_field_from_field_type() (see item_timefunc.h)
sql/item_timefunc.h:
Simply tmp_table_field()
sql/item_uniq.cc:
When creating fields, we have now have to call field->init(table)
sql/key.cc:
Added 'KEY' argument to 'find_ref_key' to simplify code
sql/lock.cc:
More debugging
Use create_table_def_key() to create key for table cache
Allocate TABLE_SHARE properly when creating name lock
Fix that locked_table_name doesn't test same table twice
sql/mysql_priv.h:
New functions for table definition cache
New interfaces to a lot of functions.
New faster interface to find_temporary_table() and close_temporary_table()
sql/mysqld.cc:
Added support for table definition cache of size 'table_def_size'
Fixed som calls to strnmov()
Changed name of 'table_cache' to 'table_open_cache'
sql/opt_range.cc:
Use new interfaces
Fixed warnings from valgrind
sql/parse_file.cc:
Safer calls to strxnmov()
Fixed typo
sql/set_var.cc:
Added variable 'table_definition_cache'
Variable table_cache renamed to 'table_open_cache'
sql/slave.cc:
Use new interface
sql/sp.cc:
Proper use of TABLE_SHARE
sql/sp_head.cc:
Remove compiler warnings
We have now to call field->init(table)
sql/sp_head.h:
Pointers to parsed strings are now const
sql/sql_acl.cc:
table_name is now a LEX_STRING
sql/sql_base.cc:
Main implementation of table definition cache
(The #ifdef's are there for the future when table definition cache will replace open table cache)
Now table definitions are cached indepndent of open tables, which will speed up things when a table is in use at once from several places
Views are not yet cached; For the moment we only cache if a table is a view or not.
Faster implementation of find_temorary_table()
Replace 'wait_for_refresh()' with the more general function 'wait_for_condition()'
Drop table is slightly faster as we can use the table definition cache to know the type of the table
sql/sql_cache.cc:
table_cache_key and table_name are now LEX_STRING
'sDBUG print fixes
sql/sql_class.cc:
table_cache_key is now a LEX_STRING
safer strxnmov()
sql/sql_class.h:
Added number of open table shares (table definitions)
sql/sql_db.cc:
safer strxnmov()
sql/sql_delete.cc:
Use new interface to find_temporary_table()
sql/sql_derived.cc:
table_name is now a LEX_STRING
sql/sql_handler.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_insert.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
sql/sql_lex.cc:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_lex.h:
Make parsed string a const (to quickly find out if anything is trying to change the query string)
sql/sql_load.cc:
Safer strxnmov()
sql/sql_parse.cc:
Better error if wrong DB name
sql/sql_partition.cc:
part_info moved to TABLE from TABLE_SHARE
Indentation changes
sql/sql_select.cc:
Indentation fixes
Call field->init(TABLE) for new created fields
Update create_tmp_table() to use TABLE_SHARE properly
sql/sql_select.h:
Call field->init(TABLE) for new created fields
sql/sql_show.cc:
table_name is now a LEX_STRING
part_info moved to TABLE
sql/sql_table.cc:
Use table definition cache to speed up delete of tables
Fixed calls to functions with new interfaces
Don't use 'share_not_to_be_used'
Instead of doing openfrm() when doing repair, we now have to call
get_table_share() followed by open_table_from_share().
Replace some fn_format() with faster unpack_filename().
Safer strxnmov()
part_info is now in TABLE
Added Mikaels patch for partition and ALTER TABLE
Instead of using 'TABLE_SHARE->is_view' use 'table_flags() & HA_NO_COPY_ON_ALTER
sql/sql_test.cc:
table_name and table_cache_key are now LEX_STRING's
sql/sql_trigger.cc:
TABLE_SHARE->db and TABLE_SHARE->table_name are now LEX_STRING's
safer strxnmov()
Removed compiler warnings
sql/sql_update.cc:
Call field->init(TABLE) after field is created
sql/sql_view.cc:
safer strxnmov()
Create common TABLE_SHARE object for views to allow us to cache if table is a view
sql/structs.h:
Added SHOW_TABLE_DEFINITIONS
sql/table.cc:
Creation and destruct of TABLE_SHARE objects that are common for many TABLE objects
The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
object and open a handler to the table object
open_table_def() is written in such a way that it should be trival to add parsing of the .frm files in new formats
sql/table.h:
TABLE objects for the same database table now share a common TABLE_SHARE object
In TABLE_SHARE the most common strings are now LEX_STRING's
sql/unireg.cc:
Changed arguments to rea_create_table() to have same order as other functions
Call field->init(table) for new created fields
sql/unireg.h:
Added OPEN_VIEW
strings/strxnmov.c:
Change strxnmov() to always add end \0
This makes usage of strxnmov() safer as most of MySQL code assumes that strxnmov() will create a null terminated string
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);
|
|
|
|
delete field;
|
|
|
|
}
|
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
db_create_routine(THD *thd, int type, sp_head *sp)
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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];
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
char old_db_buf[NAME_LEN+1];
|
|
|
|
LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
|
2004-06-15 15:42:28 +02:00
|
|
|
bool dbchanged;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_create_routine");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",type,sp->m_name.length,
|
|
|
|
sp->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
if ((ret= sp_use_new_db(thd, sp->m_db, &old_db, 0, &dbchanged)))
|
2004-06-15 15:42:28 +02:00
|
|
|
{
|
|
|
|
ret= SP_NO_DB_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2005-07-13 11:48:13 +02:00
|
|
|
if (!(table= open_proc_table_for_update(thd)))
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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);
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
|
2005-01-06 12:00:13 +01: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;
|
|
|
|
}
|
2004-03-11 17:18:59 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_DB]->
|
|
|
|
store(sp->m_db.str, sp->m_db.length, system_charset_info);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_NAME]->
|
|
|
|
store(sp->m_name.str, sp->m_name.length, system_charset_info);
|
|
|
|
table->field[MYSQL_PROC_FIELD_TYPE]->
|
2006-06-16 12:17:20 +02:00
|
|
|
store((longlong)type, TRUE);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
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)
|
|
|
|
table->field[MYSQL_PROC_FIELD_ACCESS]->
|
2006-06-16 12:17:20 +02:00
|
|
|
store((longlong)sp->m_chistics->daccess, TRUE);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_DETERMINISTIC]->
|
2006-06-16 12:17:20 +02:00
|
|
|
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)
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_SECURITY_TYPE]->
|
2006-06-16 12:17:20 +02:00
|
|
|
store((longlong)sp->m_chistics->suid, TRUE);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
String retstr(64);
|
|
|
|
sp_returns_type(thd, retstr, sp);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_RETURNS]->
|
2005-03-04 22:14:35 +01:00
|
|
|
store(retstr.ptr(), retstr.length(), system_charset_info);
|
|
|
|
}
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_BODY]->
|
|
|
|
store(sp->m_body.str, sp->m_body.length, system_charset_info);
|
|
|
|
table->field[MYSQL_PROC_FIELD_DEFINER]->
|
2003-12-13 16:40:52 +01:00
|
|
|
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();
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
table->field[MYSQL_PROC_FIELD_SQL_MODE]->
|
2006-06-16 12:17:20 +02:00
|
|
|
store((longlong)thd->variables.sql_mode, TRUE);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
if (sp->m_chistics->comment.str)
|
|
|
|
table->field[MYSQL_PROC_FIELD_COMMENT]->
|
|
|
|
store(sp->m_chistics->comment.str, sp->m_chistics->comment.length,
|
|
|
|
system_charset_info);
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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())
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
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
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
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))
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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]))
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
ret= SP_WRITE_ROW_FAILED;
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
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);
|
|
|
|
log_query.append(STRING_WITH_LEN("CREATE "));
|
|
|
|
append_definer(thd, &log_query, &thd->lex->definer->user,
|
|
|
|
&thd->lex->definer->host);
|
|
|
|
log_query.append(thd->lex->stmt_definition_begin);
|
|
|
|
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
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,
|
2006-03-09 18:41:21 +01:00
|
|
|
log_query.c_ptr(), log_query.length(), FALSE, FALSE);
|
Approximative fixes for BUG#2610,2611,9100 i.e. WL#2146 binlogging/replication of routines (stored procs and functions).
Approximative, because it's using our binlogging way (what we call "query"-level) and this is not as good as record-level binlog (5.1) would be. It imposes several
limitations to routines, and has caveats (which I'll document, and for which the server will try to issue errors but that is not always possible).
Reason I don't propagate caller info to the binlog as planned is that on master and slave
users may be different; even with that some caveats would remain.
mysql-test/mysql-test-run.sh:
In the testsuite we know what we do, we are not creating nasty routines, and breaking binlog is ok except in rpl_sp.
mysql-test/r/blackhole.result:
Updating results now that 4.1 has been merged
mysql-test/valgrind.supp:
Some suppressions for Valgrind (useful on my machine Suse 9.1);
this is just adding to the already existing suppressions of pthread and dl.
sql/item_func.cc:
Don't binlog the substatements when executing a function. If the function
is declared to modify data and does not complete, warning "broken binlog".
Note that SELECT myfunc() will not be binlogged even if myfunc() updates data (will be documented);
but INSERT INTO t VALUES(myfunc()) will be binlogged (what decides is if the caller
gets binlogged; the function changes nothing to binlogging).
sql/log_event.cc:
Just making functions which can be re-used when we binlog more strings
in status_vars in Query_log_event (e.g. one day "user", "host").
sql/log_event.h:
comment
sql/mysql_priv.h:
--log-bin-trust-routine-creators
sql/mysqld.cc:
--log-bin-trust-routine-creators
sql/set_var.cc:
--log-bin-trust-routine-creators
sql/share/errmsg.txt:
error messages to warn about problems with routines and binlog
sql/slave.cc:
If in a routine, replication table inclusion/exclusion rules always answer "replicate!" (see comment in code).
sql/sp.cc:
If binlog is on: errors if one wants to create a non-deterministic update routine
(repeatability problem - note that the test is not perfect for functions) or does not have SUPER (because routines can easily
be made to destroy slave's data with just CREATE ROUTINE and EXECUTE priv on master).
--log-bin-trust-routine-creators removes these errors.
Binlogging of CREATE PROCEDURE|FUNCTION.
sql/sql_acl.cc:
No thd==0 in tables_ok().
sql/sql_parse.cc:
Binlogging of CALL (and not of the substatements of the SP).
If SP returns error, we don't binlog it (see comment); we push warning in this case.
Binlogging of ALTER|DROP PROCEDURE|FUNCTION with safety messages.
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:
|
2003-02-28 15:07:14 +01:00
|
|
|
close_thread_tables(thd);
|
2004-06-15 15:42:28 +02:00
|
|
|
if (dbchanged)
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
(void) mysql_change_db(thd, old_db.str, 1);
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
static int
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
db_drop_routine(THD *thd, int type, sp_name *name)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
int ret;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_drop_routine");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
type, name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
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)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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]))
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
ret= SP_DELETE_ROW_FAILED;
|
|
|
|
}
|
2005-07-13 11:48:13 +02:00
|
|
|
close_thread_tables(thd);
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
static int
|
Fixed BUG#6027: Stored procedures can be renamed.
Removed the support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
mysql-test/r/sp-error.result:
Removed test for renaming procedures with alter.
mysql-test/r/sp.result:
Removed test for renaming procedures with alter.
mysql-test/t/sp-error.test:
Removed test for renaming procedures with alter.
mysql-test/t/sp.test:
Removed test for renaming procedures with alter.
sql/sp.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sp.h:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_parse.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_yacc.yy:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
2004-10-22 19:05:17 +02:00
|
|
|
db_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;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_update_routine");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("type: %d name: %.*s",
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
type, name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
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);
|
2005-12-22 06:39:02 +01:00
|
|
|
if ((table->file->ha_update_row(table->record[1],table->record[0])))
|
2003-11-17 18:21:36 +01:00
|
|
|
ret= SP_WRITE_ROW_FAILED;
|
|
|
|
}
|
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
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
struct st_used_field
|
|
|
|
{
|
|
|
|
const char *field_name;
|
|
|
|
uint field_length;
|
|
|
|
enum enum_field_types field_type;
|
|
|
|
Field *field;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct st_used_field init_fields[]=
|
|
|
|
{
|
2004-03-11 17:18:59 +01:00
|
|
|
{ "Db", NAME_LEN, MYSQL_TYPE_STRING, 0},
|
2003-11-17 18:21:36 +01:00
|
|
|
{ "Name", NAME_LEN, MYSQL_TYPE_STRING, 0},
|
|
|
|
{ "Type", 9, MYSQL_TYPE_STRING, 0},
|
2003-12-10 19:05:37 +01:00
|
|
|
{ "Definer", 77, MYSQL_TYPE_STRING, 0},
|
2003-11-17 18:21:36 +01:00
|
|
|
{ "Modified", 0, MYSQL_TYPE_TIMESTAMP, 0},
|
|
|
|
{ "Created", 0, MYSQL_TYPE_TIMESTAMP, 0},
|
2003-12-10 19:05:37 +01:00
|
|
|
{ "Security_type", 1, MYSQL_TYPE_STRING, 0},
|
2003-11-17 18:21:36 +01:00
|
|
|
{ "Comment", NAME_LEN, MYSQL_TYPE_STRING, 0},
|
|
|
|
{ 0, 0, MYSQL_TYPE_STRING, 0}
|
|
|
|
};
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-20 15:07:22 +01:00
|
|
|
static int
|
|
|
|
print_field_values(THD *thd, TABLE *table,
|
|
|
|
struct st_used_field *used_fields,
|
|
|
|
int type, const char *wild)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
|
|
|
|
if (table->field[MYSQL_PROC_FIELD_TYPE]->val_int() == type)
|
|
|
|
{
|
2004-03-11 17:18:59 +01:00
|
|
|
String db_string;
|
|
|
|
String name_string;
|
2003-11-17 18:21:36 +01:00
|
|
|
struct st_used_field *used_field= used_fields;
|
2003-11-20 15:07:22 +01:00
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
if (get_field(thd->mem_root, used_field->field, &db_string))
|
2004-03-11 17:18:59 +01:00
|
|
|
db_string.set_ascii("", 0);
|
|
|
|
used_field+= 1;
|
2004-11-09 02:58:44 +01:00
|
|
|
get_field(thd->mem_root, used_field->field, &name_string);
|
2004-03-11 17:18:59 +01:00
|
|
|
|
|
|
|
if (!wild || !wild[0] || !wild_compare(name_string.ptr(), wild, 0))
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
|
|
|
protocol->prepare_for_resend();
|
2004-03-11 17:18:59 +01:00
|
|
|
protocol->store(&db_string);
|
|
|
|
protocol->store(&name_string);
|
2003-11-17 18:21:36 +01:00
|
|
|
for (used_field++;
|
|
|
|
used_field->field_name;
|
|
|
|
used_field++)
|
|
|
|
{
|
|
|
|
switch (used_field->field_type) {
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
|
|
|
TIME tmp_time;
|
2003-12-10 19:05:37 +01:00
|
|
|
|
|
|
|
bzero((char *)&tmp_time, sizeof(tmp_time));
|
2003-11-20 15:07:22 +01:00
|
|
|
((Field_timestamp *) used_field->field)->get_time(&tmp_time);
|
|
|
|
protocol->store(&tmp_time);
|
|
|
|
}
|
|
|
|
break;
|
2003-11-17 18:21:36 +01:00
|
|
|
default:
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
2004-03-11 17:18:59 +01:00
|
|
|
String tmp_string;
|
2003-12-10 19:05:37 +01:00
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
get_field(thd->mem_root, used_field->field, &tmp_string);
|
2004-03-11 17:18:59 +01:00
|
|
|
protocol->store(&tmp_string);
|
2003-11-20 15:07:22 +01:00
|
|
|
}
|
|
|
|
break;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (protocol->write())
|
2003-11-20 15:07:22 +01:00
|
|
|
return SP_INTERNAL_ERROR;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
return SP_OK;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-20 15:07:22 +01:00
|
|
|
static int
|
2003-11-17 18:21:36 +01:00
|
|
|
db_show_routine_status(THD *thd, int type, const char *wild)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
|
|
|
TABLE_LIST tables;
|
2003-11-20 15:07:22 +01:00
|
|
|
int res;
|
2003-12-21 11:48:03 +01:00
|
|
|
DBUG_ENTER("db_show_routine_status");
|
2003-11-17 18:21:36 +01:00
|
|
|
|
|
|
|
memset(&tables, 0, sizeof(tables));
|
|
|
|
tables.db= (char*)"mysql";
|
2005-01-06 12:00:13 +01:00
|
|
|
tables.table_name= tables.alias= (char*)"proc";
|
2003-11-17 18:21:36 +01:00
|
|
|
|
|
|
|
if (! (table= open_ltable(thd, &tables, TL_READ)))
|
|
|
|
{
|
2003-11-20 15:07:22 +01:00
|
|
|
res= SP_OPEN_TABLE_FAILED;
|
|
|
|
goto done;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Item *item;
|
|
|
|
List<Item> field_list;
|
|
|
|
struct st_used_field *used_field;
|
2004-09-14 18:28:29 +02:00
|
|
|
TABLE_LIST *leaves= 0;
|
2003-11-17 18:21:36 +01:00
|
|
|
st_used_field used_fields[array_elements(init_fields)];
|
2003-11-20 15:07:22 +01:00
|
|
|
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
BitKeeper/etc/ignore:
added mysys/test_bitmap
include/base64.h:
Removed my_global.h, as this must be included first in any program
include/heap.h:
Added heap_reset() (Required by new handler interface)
include/my_base.h:
Removed HA_EXTRA_RESET. MySQL will now call ::reset() instead of ::extra(HA_EXTRA_RESET).
HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIVE_PRIMARY key are deleted as the column bitmaps makes these unnecessary
include/my_bitmap.h:
Remove my_pthread.h (should be included at upper level)
Introduced my_bitmap_map typedef to make it the bitmap handling more like a black box
Added bitmap_is_overlapping(), bitmap_test_and_clear(), bitmap_copy() and bitmap_cmp()
Made bitmap_set_bit(), bitmap_flip_bit(), bitmap_clear_bit() return void
include/myisam.h:
Added mi_reset() (Required by new handler interface)
include/myisammrg.h:
Added myrg_reset() (Required by new handler interface)
include/mysql_com.h:
Added flag FIELD_IN_ADD_INDEX to be able to remove Field->add_index
mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/install_test_db.sh:
Simplify ldata usage
Added --tmpdir=. option to mysqld bootstrap (Removed some warnings when TMPDIR was wrongly set)
mysql-test/mysql-test-run.pl:
Added --tmpdir=. to bootstrap
mysql-test/mysql-test-run.sh:
Use copy instead of INSTALL_DB for master and slave databases.
(Speeds up startup time a lot!)
Remove snapshot directories at startup (removes some strange warnings)
mysql-test/r/binlog_row_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/r/binlog_stm_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
mysql-test/r/create.result:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/r/federated.result:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/r/func_gconcat.result:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/r/func_time.result:
Added drop of test function
mysql-test/r/innodb_mysql.result:
Added tests for CREATE ... SELECT
mysql-test/r/insert.result:
More tests
Added testing of duplicate columns in insert
mysql-test/r/loaddata.result:
Added testing LOAD DATA ... SET ...
mysql-test/r/multi_update.result:
Test multi updates and deletes using primary key and without
mysql-test/r/ndb_index_unique.result:
Better error message
mysql-test/r/ndb_replace.result:
New correct result after fixing REPLACE handling with NDB
mysql-test/r/rpl_ddl.result:
Now we don't get these (wrong) warnings anymore
mysql-test/r/view_grant.result:
Drop used views
mysql-test/t/create.test:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/t/federated.test:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/t/func_gconcat.test:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/t/func_time.test:
Added drop of test function
mysql-test/t/innodb_mysql.test:
Added tests for CREATE ... SELECT
mysql-test/t/insert.test:
More tests
Added testing of duplicate columns in insert
mysql-test/t/loaddata.test:
Added testing LOAD DATA ... SET ...
mysql-test/t/multi_update.test:
Test multi updates and deletes using primary key and without
mysql-test/t/view_grant.test:
Drop used views
mysql-test/valgrind.supp:
Added supression of not needed warnings when printing stack trace
mysys/base64.c:
Include my_global.h first
mysys/my_bitmap.c:
Added bitmap_is_overlapping(), bitmap_test_and_clear() and bitmap_copy()
Changed logic of bitmap handling to be a bit more efficent (Did this together with Mikael Ronström)
Now the 'extra, not used bits' in the bitmap are assumed to have a 'random value' and the bitmap functions are free to change them whenever needed.
Changed how mutex is allocated to make 'bitmap_free()' function simpler.
mysys/thr_lock.c:
Added 0x before thread pointers (for easier comparison of DBUG traces)
sql/event.cc:
Ensure 'use_all_columns()' is used for event tables
Don't print warning that event table is damaged if it doesn't exists.
sql/field.cc:
Added ASSERT_COLUMN_MARKED_FOR_WRITE in all store() methods and ASSERT_COLUMN_MARKED_FOR_READ in all val() methods to catch wrong setting if table->read_set and table->write_set
(Rest of changes are only indentation cleanups)
sql/field.h:
Removed Field->query_id (replaced by table->read_set and table->write_set)
Removed Field->fieldnr (use Field->field_index instead)
Removed Field->add_index (Use Field->flags instead)
Add Field->part_of_key_not_clustered (for usage in opt_range.cc)
sql/filesort.cc:
Added paramater sort_postion to filesort() to force sorting by position instead of storing all fields in the result set.
This allowed me to remove checking of sql_command.
Create a temporary column bitmap for fields that are used by the sorting process.
Use column bitmaps instead of query_id
sql/ha_berkeley.cc:
Update to 'newer' table handler interface
sql/ha_berkeley.h:
Update to 'newer' table handler interface
sql/ha_federated.cc:
Update to 'newer' table handler interface
Only read columns that are needed from remote server.
In case of eq ranges, don't generate two conditions in the WHERE clause
(this can still be optimized, but would require a bigger code change)
Use 'simpler to use' XXXX_LEN' macros
A bit simpler logic in ::write_row() when creating statements.
In update, only include test of fields actually read.
(This greatly simplifies the queries sent by the federated engine)
Similar changes done for delete_row()
sql/ha_federated.h:
Update to 'newer' table handler interface
Changed XXX_LEN macros to use sizeof(...)-1, to simplify usage in ha_federated.cc
Added HA_PRIMARY_KEY_REQUIRED_FOR_DELETE to tell MySQL to read all primary key columns in case of DELETE
sql/ha_heap.cc:
Update to 'newer' table handler interface
sql/ha_heap.h:
Update to 'newer' table handler interface
sql/ha_innodb.cc:
Update to 'newer' table handler interface
- Update innobase_create_handler() to new interface
- Removed HA_NOT_EXACT_COUNT (not needed)
- Renamed HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- Prefixed base status variables with 'stats'
- Use table column bitmaps instead of ha_get_bit_in_read_set()
- Added ::reset(), with code from ::extra(HA_EXTRA_RESET)
- Removed HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIEVE_PRIMARY_KEY as
the table->read_set and table->write_set bitmaps now are accurate
sql/ha_innodb.h:
Update to 'newer' table handler interface
- table_flags are now ulonglong
- Added reset() method
- Removed not needed ha_retrieve_all_cols() and ha_retrieve_all_pk() columns.
- Made build_template() a class function to be able to easier access class variables
sql/ha_myisam.cc:
Update to 'newer' table handler interface
sql/ha_myisam.h:
Update to 'newer' table handler interface
sql/ha_myisammrg.cc:
Update to 'newer' table handler interface
sql/ha_myisammrg.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster.cc:
Update to 'newer' table handler interface
Fixed use_blob_value() to be accurate
In ::complemented_read() we have to check both the read and write bitmap as the old code did mark all changed columns also in the read map
Correct dumping of field data with DBUG_DUMP
Prefix addresses in DBUG_PRINT with 0x
Fixed usage of not initialized memory
Update to use field->flags & FIELD_IN_ADD_INDEX instead of field->add_index.
sql/ha_ndbcluster.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster_binlog.cc:
Mark usage of all columns in ndbcluster binlog tables
false -> FALSE, true -> TRUE
Use table->s->all_set instead of creating a temporary bitmap.
sql/ha_partition.cc:
Update to 'newer' table handler interface
Added memroot to initialise_partitions() and related functions to get faster memory allocation.
partition_create_handler() is now responsible for initialisation of the partition object
Some trivial optimizations and indentation fixes
Ensure that table_flags() are up to date
Removed documentation for removed HA_EXTRA flags
Fixed 'strange' usage of m_file[i] in new_handlers_from_part_info()that worked in current code 'by chance'
sql/ha_partition.h:
Update to 'newer' table handler interface
sql/handler.cc:
create_xxx handler now takes MEMROOT as an argument to simplify memory allocation.
Much simpler get_new_handler()
(Initialization of the object is now handled by the create method for the engine)
Moved all allocation of bitmap handling to the TABLE object (in table.cc)
Added column_bitmaps_signal() to signal column usage changes.
Changed binlog_log_row() to use the exiusting all_set bitmap in the table object.
Added ha_reset() function to test that the file object is ok at end of statement and call handler::reset()
Added use_hidden_primary_key() to signal handler that we we are going to read and update + delete the row and the handler should thus remember the position for the row
sql/handler.h:
Added HA_NO_TRANSACTIONS, HA_PARTIAL_COLUMN_READ, HA_REQUIRES_KEY_COLUMNS_FOR_DELETE,HA_PRIMARY_KEY_REQUIRED_FOR_DELETE and HA_HAS_RECORDS
Removed HA_NOT_EXACT_COUNT, HA_READ_RND_SAME
HA_DUPP_POS -> HA_DUPLICATE_POS
HA_NOT_EXACT_COUNT replaced by HA_STATS_RECORDS_IS_EXACT, HA_HAS_RECORDS and records()
HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION
Added future row type 'ROW_TYPE_PAGES'
Added MEM_ROOT to handlerton 'create' function
Added ha_statistics, a structure for all status variable in the base handler class.
Moved all status variables in the handler class into a stats structs to improve readability.
ha_table_flags() is now a cached (not virtual) version of table_flags()
reset() doesn't anymore call extra(HA_EXTRA_RESET) but is a function of it's own.
Renamed dupp_ref to dup_ref
Renamed not used handler::sortkey
Moved read_set and write_set to TABLE structure
handler::init() function added for cacheing of virtual constants from engine.
sql/item.cc:
Added register_field_in_read_map() for marking used columns in expression.
This is used by filesort() for creating an optimal column bitmap while retrieving columns for sorting.
Initalize value.cs_info.character_set_client to fix core dump bug with --debug
set_query_id -> mark_used_columns
Mark used columns in read_set OR write_set.
sql/item.h:
Removed reset_query_id_processor() as it's not needed anymore.
Added register_field_in_read_map()
Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
sql/item_cmpfunc.cc:
Temporary mark used columns to be read/writable
Update Item::walk to new interface
sql/item_cmpfunc.h:
Added extra argument to Item::walk() to indicate if we should also traverse sub queries.
sql/item_func.cc:
Update Item::walk() to new interface
table_flags() -> ha_table_flags()
sql/item_func.h:
Update Item::walk() to new interface
sql/item_row.cc:
Update Item::walk() to new interface
sql/item_row.h:
Update Item::walk() to new interface
sql/item_strfunc.h:
Update Item::walk() to new interface
sql/item_subselect.cc:
Added Item_subselect::walk()
(It was a bug it was missing before. Not sure what kind of bugs this could have caused)
sql/item_subselect.h:
Update Item::walk() to new interface
sql/item_sum.cc:
Update Item::walk() to new interface
Updates for new handler interace
sql/item_sum.h:
Update Item::walk() to new interface
sql/key.cc:
Updates for new handler interace
sql/log.cc:
Mark all columns used for log tables
Split options flag
Ensured that second argument to trans_register_ha is a bool
sql/log_event.cc:
Fixed comments to be withing 79 characters
Use OPTION_KEEP_LOG instead of OPTION_STATUS_NO_TRANS_UPDATE to remove wrong warnings
Updates for new handler interface
Use 0x%lx instead of %p (portability problem)
sql/mysql_priv.h:
Added OPTION_KEEP_LOG to indicate that we should replicate the binlog even on rollback
Removed not used 'conds' argument to setup_tables
sql/mysqld.cc:
Indentation fixes and removed old comment
sql/opt_range.cc:
Update to new handler and bitmap interface.
Fixed calls to cp_buffer_from_ref() and walk() (new argument).
Create new temporary bitmaps for ror scans.
(Needed because of handler changes and to get more accurate column bitmaps than before)
Remove not needed file->ha_reset() call before file->close().
Some trivial optimization and indentation fixes.
Use Field->part_of_key_not_clustered() to check if field is part of a key, instead of looping over all key parts.
Added flag 'in_ror_merged_scan' to allow ::get_next() to know that we need a special column bitmap to only fetch pointer to record.
This is needed because ror scan uses the same TABLE object but different file objects, which creates problem for the column bitmap handling.
(This is a temporary solution. A better one would be to allocate an own TABLE object for ROR scans)
Optimized bitmap handling in ror scans:
- Start bitmap at position 0, not 1
- Use same bitmap size as in TABLE
- Use table->read_set and table->write_set to create column bitmaps instead of looping over all fields in table
sql/opt_range.h:
Added 'in_ror_merged_scan' to indicate if we are doing a ROR scan
Added temporary column bitmaps used in ROR scans
sql/opt_sum.cc:
Added get_ext_record_count() which is used in COUNT() optimization if handler has HA_HAS_RECORDS
Note that we don't call this if handler has HA_STATS_RECORDS_IS_EXACT set.
sql/protocol.cc:
We need to mark columns as readable in ::store() as we sometimes return default value for fields to the user
sql/records.cc:
Updates for new handler interface
sql/set_var.cc:
Handle splitting OPTION_STATUS_NO_TRANS_UPDATE to two flags
sql/share/errmsg.txt:
Fixed wrong
sql/sp.cc:
Mark that we are using all columns for the proc table
Update call to setup_tables() to use new prototype
sql/sp_head.cc:
Removed QQ comment
sql/spatial.cc:
Removed wrong QQ comment
sql/sql_acl.cc:
Mark that we need all columns for acl tables
Supply memroot to some 'new' calls.
Indentation fixes
sql/sql_base.cc:
set_query_id removed
Ensure we call ha_reset() at end of each statement
Mark read columns in read_set and changed columns in write_set (Before all columns was marked in read set)
Fixed marking of some columns that was not proplerly marked before
Maintain in TABLE->merge_keys set of all keys that are used in some way
Removed not used 'conds' argument from setup_tables()
Remove not used setting of 'dupp_field' in insert_fields()
Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after crash)
sql/sql_bitmap.h:
Added is_overlapping()
sql/sql_class.cc:
Slow_logs was not properly initialized, which could maybe cause extra/lost entries in slow log.
set_query_id -> mark_used_columns
Simpler variable usage in pack_row() (cleanup)
Moved some variable declartion at start of function for better code readability
sql/sql_class.h:
Added enum_mark_columns
Updated comments
Renamed dupp_field -> dup_field
Added virtual function 'can_rollback_data()' to select_insert() to be used in CREATE ... SELECT to optimize use of OPTION_STATUS_NO_TRANS_UPDATE.
(This fixes a bug in CREATE ... SELECT where we did give wrong warnings when using non transacational tables)
sql/sql_delete.cc:
Updates to new handler interface
Call table->mark_columns_needed_for_delete() to allow us to put additional columns in column usage maps if handler so requires.
Call table->prepare_for_position() to tell handler that we are going to call ha_position().
Removed call to free_io_cache(). (io_cache is now removed in ha_reset()).
Fixed calls to setup_tables()
sql/sql_do.cc:
Update call to setup_fields()
sql/sql_handler.cc:
Tell handler tables to always read all columns.
Use temporary column map when storing value in field for later index usage
sql/sql_help.cc:
Makr all used fields to be read
Update call to setup_fields()
sql/sql_insert.cc:
Tell handler we are going to update the auto_increment column
dupp_field -> dup_field
Set column usage bits for timestamp field.
Call table->mark_columns_needed_for_insert() and table->mark_auto_increment_column()
Removed not used argument from mysql_prepare_insert_check_table().
If we get an duplicate row on insert, change column map to read and write all columns while retrying the operatation.
This is required by the definition of REPLACE and also ensures that fields that are only part of UPDATE are properly handled.
This fixed a bug in NDB and REPLACE where REPLACE wrongly copied some column values from the replaced row.
Setup new bitmaps for delayed insert rows
Remove reseting of next_number_fields as it will be reset on next call to handler_insert()
Fixed usage of thd->options and OPTION_STATUS_NO_TRANS_UPDATE.
The issue was that one should not to reset this flag as it may be set by a previous statement.
The way it was now used caused us to loose some warnings and get other wrong warnings when using non transactional tables mixed with transactional.
I fixed it by introducing 'select_insert::can_rollback_data' to inform send_error() that the given statement can be rolled back (which in case of CREATE TABLE can always be done)
Don't close tables created with CREATE ... SELECT but keep them in the table cache.
Moved out MY_HOOKS from inside function (better readability)
sql/sql_load.cc:
Update to use new handler and column marking interface
Update using setup_tables()
sql/sql_olap.cc:
Update calls to setup_tables
Use enums instead of constants to setup_fields()
sql/sql_parse.cc:
Handle OPTION_KEEP_LOG:
- Set it on CREATE TEMPORARY TABLE / DROP TABLE
- Reset it when OPTION_STATUS_NO_TRANS_UPDATE is reset
- Don't set it for CREATE ... SELECT (this is handled in select_create class)
Remove reseting of OPTION_STATUS_NO_TRANS_UPDATE in begin_trans() as this should already be reset.
If in autocommit mode, reset OPTION_KEEP_LOG and OPTION_STATUS_NO_TRANS_UPDATE to not give warnings in future commands
sql/sql_partition.cc:
Update walk() usage
Trivial indentation fixes
sql/sql_plugin.cc:
Mark all columns as used for plugins
sql/sql_prepare.cc:
Added assert to find out hidden bugs in character_set_client (got an error in debug binary when this not set correctly)
Updates for new handler interface
Update calls to setup_fields()
sql/sql_repl.cc:
Indentation fixes
sql/sql_select.cc:
Update call to setup_tables() and setup_fields()
Remove some old disabled code
Update to new hadler interface
Indentation cleanups
Added column bitmaps for temporary tables.
Remove updating of the removed slots in the Field class
Added TABLE argument to cp_buffer_from_ref() (To be able to install temporary column maps)
For internal temporary tables, use handler::write_row(), handler::delete_row() and handler::update_row() instead of handler::ha_xxxx() for faster execution.
sql/sql_select.h:
Indentaition fixes.
Install temporary column usage maps when needed
Added TABLE element to cp_buffer_from_ref()
sql/sql_show.cc:
Update to new handler interface
Mark all columns used for internal tables.
Style fixes.
Added support for 'future' ROW_TYPE_PAGES.
Don't allocate TMP_TABLE_PARAM with calloc. The 'init()' function will initialize the structure properly.
sql/sql_table.cc:
Update to new handler interface
Simple my_snprintf -> strmake()
Changed some constants to defines
Don't test for NULL in primary key (as we a couple of line above force the PRIMARY KEY to be NOT NULL)
Change field->add_index to use field->flags & FIELD_IN_ADD_INDEX
Mark all columns as used for ALTER TABLE
Style fixes
Update call to filesort()
sql/sql_trigger.h:
Added friend functions to be able to test if triggers exists for table we are going to insert/update or delete in.
sql/sql_udf.cc:
Mark all columns as used for udf system table.
sql/sql_union.cc:
Update call to walk()
Update to new handler interface
sql/sql_update.cc:
Remove query_id argument from compare_record()
Use column bitmaps instead of query_id.
We can't use compare_records() to skip updates for handlers that returns a partial column set and the read_set doesn't cover all columns in the write set, because compare_record() can't in this case know if a not read column changed value.
Update call to setup_fields()
Using separate column read and write sets allows for easier checking of timestamp field was set by statement.
Removed call to free_io_cache() as this is now done in ha_reset()
Call table->mark_columns_needed_for_update() and table->prepare_for_position()
Style fixes
sql/sql_view.cc:
Style fixes
sql/table.cc:
Remove implicitely include 'errno.h'
Remove code for building normalized path, as this is now identical to 'path'
Remove field->fieldnr
Added update of field->part_of_key_not_clustered()
Create column bitmaps in TABLE and TABLE_SHARE
Don't setup a temporary MEM_ROOT object as a thread specific variable for the handler. Instead we send the to-be-used MEMROOT to get_new_handler()
Update to new handler interface
Update call to walk()
Added new functions:
- st_table::clear_column_bitmaps()
- st_table::prepare_for_position()
- st_table::mark_columns_used_by_index()
- st_table::restore_column_maps_after_mark_index()
- st_table::mark_columns_used_by_index_no_reset()
- st_table::mark_auto_increment_column()
- st_table::mark_columns_needed_for_delete()
- st_table::mark_columns_needed_for_update()
- st_table::mark_columns_needed_for_insert()
sql/table.h:
Moved column usage bitmaps from handler to TABLE
Added to TABLE_SHARE all_set and column_bitmap_size
Added to TABLE merge_keys, bitmap_init_values, def_read_set, def_write_set, tmp_set, read_set and write_set.
Declared all new table column bitmap functions
Added TABLE functions column_bitmaps_set(), column_bitmaps_set_no_signal(), use_all_columns() and default_column_bitmaps()
Added functions: tmp_use_all_columns() and tmp_restore_column_map() to temporarly switch column bitmaps
Added functions: dbug_tmp_use_all_columns() and dbug_tmp_restore_column_map() to temporarly switch column bitmaps to avoid asserts in Field::store() and Field::val().
sql/tztime.cc:
Mark all columns as used for timezone tables
storage/archive/ha_archive.cc:
Update to new handler interface
storage/archive/ha_archive.h:
Update to new handler interface
storage/blackhole/ha_blackhole.cc:
Update to new handler interface
storage/blackhole/ha_blackhole.h:
Update to new handler interface
removed not needed flag HA_DUPP_POS
storage/csv/ha_tina.cc:
Update to new handler interface
storage/csv/ha_tina.h:
Update to new handler interface
storage/example/ha_example.cc:
Update to new handler interface
storage/example/ha_example.h:
Update to new handler interface
storage/heap/hp_extra.c:
Added heap_reset() (Required by new handler interface)
storage/heap/hp_test2.c:
Use heap_reset()
storage/myisam/ft_boolean_search.c:
Fixed compiler warning
storage/myisam/mi_extra.c:
Added mi_reset() (Required by new handler interface)
storage/myisam/mi_search.c:
Fixed DBUG_PRINT messages to use 0x%lx instead of %lx
storage/myisam/mi_test2.c:
Use mi_reset()
storage/myisam/myisampack.c:
Use mi_reset()
storage/myisammrg/myrg_extra.c:
Added myrg_reset() (Required by new handler interface)
unittest/mysys/base64.t.c:
Include my_global.h
Don't include implictely include file 'stdlib.h'
2006-06-04 17:52:22 +02:00
|
|
|
table->use_all_columns();
|
2003-11-17 18:21:36 +01:00
|
|
|
memcpy((char*) used_fields, (char*) init_fields, sizeof(used_fields));
|
|
|
|
/* Init header */
|
|
|
|
for (used_field= &used_fields[0];
|
|
|
|
used_field->field_name;
|
|
|
|
used_field++)
|
|
|
|
{
|
|
|
|
switch (used_field->field_type) {
|
|
|
|
case MYSQL_TYPE_TIMESTAMP:
|
|
|
|
field_list.push_back(item=new Item_datetime(used_field->field_name));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
field_list.push_back(item=new Item_empty_string(used_field->field_name,
|
|
|
|
used_field->
|
|
|
|
field_length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Print header */
|
Port of cursors to be pushed into 5.0 tree:
- client side part is simple and may be considered stable
- server side part now just joggles with THD state to save execution
state and has no additional locking wisdom.
Lot's of it are to be rewritten.
include/mysql.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new statement attribute STMT_ATTR_CURSOR_TYPE
- MYSQL_STMT::flags to store statement cursor type
- MYSQL_STMT::server_status to store server status (i. e. if the server
was able to open a cursor for this query).
include/mysql_com.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new COMmand, COM_FETCH, to fetch K rows from read-only cursor.
By design should support scrollable cursors as well.
- a few new server statuses:
SERVER_STATUS_CURSOR_EXISTS is sent by server in reply to COM_EXECUTE,
when cursor was successfully opened for this query
SERVER_STATUS_LAST_ROW_SENT is sent along with the last row to prevent one
more round trip just for finding out that all rows were fetched from
this cursor (this is server mem savier also).
- and finally, all possible values of STMT_ATTR_CURSOR_TYPE,
while now we support only CURSORT_TYPE_NO_CURSOR and
CURSOR_TYPE_READ_ONLY
libmysql/libmysql.c:
Cursor patch to push into the main tree, client library part (considered
stable):
- simple additions to mysql_stmt_fetch implementation to read data
from an opened cursor: we can read up to iteration count rows per
one request; read rows are buffered in the same way as rows of
mysql_stmt_store_result.
- now send stmt->flags to server to let him now if we wish to have
a cursor for this statement.
- support for setting/getting statement cursor type.
libmysqld/examples/Makefile.am:
Testing cursors was originally implemented in C++. Now when these tests
go into client_test, it's time to convert it to C++ as well.
libmysqld/lib_sql.cc:
- cleanup: send_fields flags are now named.
sql/ha_innodb.cc:
- cleanup: send_fields flags are now named.
sql/mysql_priv.h:
- cursors support: declaration for server-side handler of COM_FETCH
sql/protocol.cc:
- cleanup: send_fields flags are now named.
- we can't anymore assert that field_types[field_pos] is sensible:
if we have COM_EXCUTE(stmt1), COM_EXECUTE(stmt2), COM_FETCH(stmt1)
field_types[field_pos] will point to fields of stmt2.
sql/protocol.h:
- cleanup: send_fields flag_s_ are now named.
sql/protocol_cursor.cc:
- cleanup: send_fields flags are now named.
sql/repl_failsafe.cc:
- cleanup: send_fields flags are now named.
sql/slave.cc:
- cleanup: send_fields flags are now named.
sql/sp.cc:
- cleanup: send_fields flags are now named.
sql/sp_head.cc:
- cleanup: send_fields flags are now named.
sql/sql_acl.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.h:
- cleanup: send_fields flags are now named.
sql/sql_error.cc:
- cleanup: send_fields flags are now named.
sql/sql_handler.cc:
- cleanup: send_fields flags are now named.
sql/sql_help.cc:
- cleanup: send_fields flags are now named.
sql/sql_parse.cc:
Server side support for cursors:
- handle COM_FETCH
- enforce assumption that whenever we free thd->free_list,
we reset it to zero. This way it's much easier to handle free_list
in prepared statements implementation.
sql/sql_prepare.cc:
Server side support for cursors:
- implementation of mysql_stmt_fetch (fetch some rows from open cursor).
- management of cursors memory is quite tricky now.
- execute_stmt can't be reused anymore in mysql_stmt_execute and
mysql_sql_stmt_execute
sql/sql_repl.cc:
- cleanup: send_fields flags are now named.
sql/sql_select.cc:
Server side support for cursors:
- implementation of Cursor::open, Cursor::fetch (buggy when it comes to
non-equi joins), cursor cleanups.
- -4 -3 -0 constants indicating return value of sub_select and end_send are
to be renamed to something more readable:
it turned out to be not so simple, so it should come with the other patch.
sql/sql_select.h:
Server side support for cursors:
- declaration of Cursor class.
- JOIN::fetch_limit contains runtime value of rows fetched via cursor.
sql/sql_show.cc:
- cleanup: send_fields flags are now named.
sql/sql_table.cc:
- cleanup: send_fields flags are now named.
sql/sql_union.cc:
- if there was a cursor, don't cleanup unit: we'll need it to fetch
the rest of the rows.
tests/Makefile.am:
Now client_test is in C++.
tests/client_test.cc:
A few elementary tests for cursors.
BitKeeper/etc/ignore:
Added libmysqld/examples/client_test.cc to the ignore list
2004-08-03 12:32:21 +02:00
|
|
|
if (thd->protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
|
|
|
|
Protocol::SEND_EOF))
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
|
|
|
res= SP_INTERNAL_ERROR;
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case;
|
2003-11-20 15:07:22 +01:00
|
|
|
}
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2004-07-16 00:15:55 +02:00
|
|
|
/*
|
|
|
|
Init fields
|
|
|
|
|
|
|
|
tables is not VIEW for sure => we can pass 0 as condition
|
|
|
|
*/
|
2005-07-01 06:05:42 +02:00
|
|
|
thd->lex->select_lex.context.resolve_in_table_list_only(&tables);
|
|
|
|
setup_tables(thd, &thd->lex->select_lex.context,
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 16:57:19 +02:00
|
|
|
&thd->lex->select_lex.top_join_list,
|
This changeset is largely a handler cleanup changeset (WL#3281), but includes fixes and cleanups that was found necessary while testing the handler changes
Changes that requires code changes in other code of other storage engines.
(Note that all changes are very straightforward and one should find all issues
by compiling a --debug build and fixing all compiler errors and all
asserts in field.cc while running the test suite),
- New optional handler function introduced: reset()
This is called after every DML statement to make it easy for a handler to
statement specific cleanups.
(The only case it's not called is if force the file to be closed)
- handler::extra(HA_EXTRA_RESET) is removed. Code that was there before
should be moved to handler::reset()
- table->read_set contains a bitmap over all columns that are needed
in the query. read_row() and similar functions only needs to read these
columns
- table->write_set contains a bitmap over all columns that will be updated
in the query. write_row() and update_row() only needs to update these
columns.
The above bitmaps should now be up to date in all context
(including ALTER TABLE, filesort()).
The handler is informed of any changes to the bitmap after
fix_fields() by calling the virtual function
handler::column_bitmaps_signal(). If the handler does caching of
these bitmaps (instead of using table->read_set, table->write_set),
it should redo the caching in this code. as the signal() may be sent
several times, it's probably best to set a variable in the signal
and redo the caching on read_row() / write_row() if the variable was
set.
- Removed the read_set and write_set bitmap objects from the handler class
- Removed all column bit handling functions from the handler class.
(Now one instead uses the normal bitmap functions in my_bitmap.c instead
of handler dedicated bitmap functions)
- field->query_id is removed. One should instead instead check
table->read_set and table->write_set if a field is used in the query.
- handler::extra(HA_EXTRA_RETRIVE_ALL_COLS) and
handler::extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY) are removed. One should now
instead use table->read_set to check for which columns to retrieve.
- If a handler needs to call Field->val() or Field->store() on columns
that are not used in the query, one should install a temporary
all-columns-used map while doing so. For this, we provide the following
functions:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
field->val();
dbug_tmp_restore_column_map(table->read_set, old_map);
and similar for the write map:
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
field->val();
dbug_tmp_restore_column_map(table->write_set, old_map);
If this is not done, you will sooner or later hit a DBUG_ASSERT
in the field store() / val() functions.
(For not DBUG binaries, the dbug_tmp_restore_column_map() and
dbug_tmp_restore_column_map() are inline dummy functions and should
be optimized away be the compiler).
- If one needs to temporary set the column map for all binaries (and not
just to avoid the DBUG_ASSERT() in the Field::store() / Field::val()
methods) one should use the functions tmp_use_all_columns() and
tmp_restore_column_map() instead of the above dbug_ variants.
- All 'status' fields in the handler base class (like records,
data_file_length etc) are now stored in a 'stats' struct. This makes
it easier to know what status variables are provided by the base
handler. This requires some trivial variable names in the extra()
function.
- New virtual function handler::records(). This is called to optimize
COUNT(*) if (handler::table_flags() & HA_HAS_RECORDS()) is true.
(stats.records is not supposed to be an exact value. It's only has to
be 'reasonable enough' for the optimizer to be able to choose a good
optimization path).
- Non virtual handler::init() function added for caching of virtual
constants from engine.
- Removed has_transactions() virtual method. Now one should instead return
HA_NO_TRANSACTIONS in table_flags() if the table handler DOES NOT support
transactions.
- The 'xxxx_create_handler()' function now has a MEM_ROOT_root argument
that is to be used with 'new handler_name()' to allocate the handler
in the right area. The xxxx_create_handler() function is also
responsible for any initialization of the object before returning.
For example, one should change:
static handler *myisam_create_handler(TABLE_SHARE *table)
{
return new ha_myisam(table);
}
->
static handler *myisam_create_handler(TABLE_SHARE *table, MEM_ROOT *mem_root)
{
return new (mem_root) ha_myisam(table);
}
- New optional virtual function: use_hidden_primary_key().
This is called in case of an update/delete when
(table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
but we don't have a primary key. This allows the handler to take precisions
in remembering any hidden primary key to able to update/delete any
found row. The default handler marks all columns to be read.
- handler::table_flags() now returns a ulonglong (to allow for more flags).
- New/changed table_flags()
- HA_HAS_RECORDS Set if ::records() is supported
- HA_NO_TRANSACTIONS Set if engine doesn't support transactions
- HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Set if we should mark all primary key columns for
read when reading rows as part of a DELETE
statement. If there is no primary key,
all columns are marked for read.
- HA_PARTIAL_COLUMN_READ Set if engine will not read all columns in some
cases (based on table->read_set)
- HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS
Renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- HA_DUPP_POS Renamed to HA_DUPLICATE_POS
- HA_REQUIRES_KEY_COLUMNS_FOR_DELETE
Set this if we should mark ALL key columns for
read when when reading rows as part of a DELETE
statement. In case of an update we will mark
all keys for read for which key part changed
value.
- HA_STATS_RECORDS_IS_EXACT
Set this if stats.records is exact.
(This saves us some extra records() calls
when optimizing COUNT(*))
- Removed table_flags()
- HA_NOT_EXACT_COUNT Now one should instead use HA_HAS_RECORDS if
handler::records() gives an exact count() and
HA_STATS_RECORDS_IS_EXACT if stats.records is exact.
- HA_READ_RND_SAME Removed (no one supported this one)
- Removed not needed functions ha_retrieve_all_cols() and ha_retrieve_all_pk()
- Renamed handler::dupp_pos to handler::dup_pos
- Removed not used variable handler::sortkey
Upper level handler changes:
- ha_reset() now does some overall checks and calls ::reset()
- ha_table_flags() added. This is a cached version of table_flags(). The
cache is updated on engine creation time and updated on open.
MySQL level changes (not obvious from the above):
- DBUG_ASSERT() added to check that column usage matches what is set
in the column usage bit maps. (This found a LOT of bugs in current
column marking code).
- In 5.1 before, all used columns was marked in read_set and only updated
columns was marked in write_set. Now we only mark columns for which we
need a value in read_set.
- Column bitmaps are created in open_binary_frm() and open_table_from_share().
(Before this was in table.cc)
- handler::table_flags() calls are replaced with handler::ha_table_flags()
- For calling field->val() you must have the corresponding bit set in
table->read_set. For calling field->store() you must have the
corresponding bit set in table->write_set. (There are asserts in
all store()/val() functions to catch wrong usage)
- thd->set_query_id is renamed to thd->mark_used_columns and instead
of setting this to an integer value, this has now the values:
MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE
Changed also all variables named 'set_query_id' to mark_used_columns.
- In filesort() we now inform the handler of exactly which columns are needed
doing the sort and choosing the rows.
- The TABLE_SHARE object has a 'all_set' column bitmap one can use
when one needs a column bitmap with all columns set.
(This is used for table->use_all_columns() and other places)
- The TABLE object has 3 column bitmaps:
- def_read_set Default bitmap for columns to be read
- def_write_set Default bitmap for columns to be written
- tmp_set Can be used as a temporary bitmap when needed.
The table object has also two pointer to bitmaps read_set and write_set
that the handler should use to find out which columns are used in which way.
- count() optimization now calls handler::records() instead of using
handler->stats.records (if (table_flags() & HA_HAS_RECORDS) is true).
- Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
- Added TABLE parameter to cp_buffer_from_ref()
- Don't close tables created with CREATE ... SELECT but keep them in
the table cache. (Faster usage of newly created tables).
New interfaces:
- table->clear_column_bitmaps() to initialize the bitmaps for tables
at start of new statements.
- table->column_bitmaps_set() to set up new column bitmaps and signal
the handler about this.
- table->column_bitmaps_set_no_signal() for some few cases where we need
to setup new column bitmaps but don't signal the handler (as the handler
has already been signaled about these before). Used for the momement
only in opt_range.cc when doing ROR scans.
- table->use_all_columns() to install a bitmap where all columns are marked
as use in the read and the write set.
- table->default_column_bitmaps() to install the normal read and write
column bitmaps, but not signaling the handler about this.
This is mainly used when creating TABLE instances.
- table->mark_columns_needed_for_delete(),
table->mark_columns_needed_for_delete() and
table->mark_columns_needed_for_insert() to allow us to put additional
columns in column usage maps if handler so requires.
(The handler indicates what it neads in handler->table_flags())
- table->prepare_for_position() to allow us to tell handler that it
needs to read primary key parts to be able to store them in
future table->position() calls.
(This replaces the table->file->ha_retrieve_all_pk function)
- table->mark_auto_increment_column() to tell handler are going to update
columns part of any auto_increment key.
- table->mark_columns_used_by_index() to mark all columns that is part of
an index. It will also send extra(HA_EXTRA_KEYREAD) to handler to allow
it to quickly know that it only needs to read colums that are part
of the key. (The handler can also use the column map for detecting this,
but simpler/faster handler can just monitor the extra() call).
- table->mark_columns_used_by_index_no_reset() to in addition to other columns,
also mark all columns that is used by the given key.
- table->restore_column_maps_after_mark_index() to restore to default
column maps after a call to table->mark_columns_used_by_index().
- New item function register_field_in_read_map(), for marking used columns
in table->read_map. Used by filesort() to mark all used columns
- Maintain in TABLE->merge_keys set of all keys that are used in query.
(Simplices some optimization loops)
- Maintain Field->part_of_key_not_clustered which is like Field->part_of_key
but the field in the clustered key is not assumed to be part of all index.
(used in opt_range.cc for faster loops)
- dbug_tmp_use_all_columns(), dbug_tmp_restore_column_map()
tmp_use_all_columns() and tmp_restore_column_map() functions to temporally
mark all columns as usable. The 'dbug_' version is primarily intended
inside a handler when it wants to just call Field:store() & Field::val()
functions, but don't need the column maps set for any other usage.
(ie:: bitmap_is_set() is never called)
- We can't use compare_records() to skip updates for handlers that returns
a partial column set and the read_set doesn't cover all columns in the
write set. The reason for this is that if we have a column marked only for
write we can't in the MySQL level know if the value changed or not.
The reason this worked before was that MySQL marked all to be written
columns as also to be read. The new 'optimal' bitmaps exposed this 'hidden
bug'.
- open_table_from_share() does not anymore setup temporary MEM_ROOT
object as a thread specific variable for the handler. Instead we
send the to-be-used MEMROOT to get_new_handler().
(Simpler, faster code)
Bugs fixed:
- Column marking was not done correctly in a lot of cases.
(ALTER TABLE, when using triggers, auto_increment fields etc)
(Could potentially result in wrong values inserted in table handlers
relying on that the old column maps or field->set_query_id was correct)
Especially when it comes to triggers, there may be cases where the
old code would cause lost/wrong values for NDB and/or InnoDB tables.
- Split thd->options flag OPTION_STATUS_NO_TRANS_UPDATE to two flags:
OPTION_STATUS_NO_TRANS_UPDATE and OPTION_KEEP_LOG.
This allowed me to remove some wrong warnings about:
"Some non-transactional changed tables couldn't be rolled back"
- Fixed handling of INSERT .. SELECT and CREATE ... SELECT that wrongly reset
(thd->options & OPTION_STATUS_NO_TRANS_UPDATE) which caused us to loose
some warnings about
"Some non-transactional changed tables couldn't be rolled back")
- Fixed use of uninitialized memory in ha_ndbcluster.cc::delete_table()
which could cause delete_table to report random failures.
- Fixed core dumps for some tests when running with --debug
- Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after
crash)
- slow_logs was not properly initialized, which could maybe cause
extra/lost entries in slow log.
- If we get an duplicate row on insert, change column map to read and
write all columns while retrying the operation. This is required by
the definition of REPLACE and also ensures that fields that are only
part of UPDATE are properly handled. This fixed a bug in NDB and
REPLACE where REPLACE wrongly copied some column values from the replaced
row.
- For table handler that doesn't support NULL in keys, we would give an error
when creating a primary key with NULL fields, even after the fields has been
automaticly converted to NOT NULL.
- Creating a primary key on a SPATIAL key, would fail if field was not
declared as NOT NULL.
Cleanups:
- Removed not used condition argument to setup_tables
- Removed not needed item function reset_query_id_processor().
- Field->add_index is removed. Now this is instead maintained in
(field->flags & FIELD_IN_ADD_INDEX)
- Field->fieldnr is removed (use field->field_index instead)
- New argument to filesort() to indicate that it should return a set of
row pointers (not used columns). This allowed me to remove some references
to sql_command in filesort and should also enable us to return column
results in some cases where we couldn't before.
- Changed column bitmap handling in opt_range.cc to be aligned with TABLE
bitmap, which allowed me to use bitmap functions instead of looping over
all fields to create some needed bitmaps. (Faster and smaller code)
- Broke up found too long lines
- Moved some variable declaration at start of function for better code
readability.
- Removed some not used arguments from functions.
(setup_fields(), mysql_prepare_insert_check_table())
- setup_fields() now takes an enum instead of an int for marking columns
usage.
- For internal temporary tables, use handler::write_row(),
handler::delete_row() and handler::update_row() instead of
handler::ha_xxxx() for faster execution.
- Changed some constants to enum's and define's.
- Using separate column read and write sets allows for easier checking
of timestamp field was set by statement.
- Remove calls to free_io_cache() as this is now done automaticly in ha_reset()
- Don't build table->normalized_path as this is now identical to table->path
(after bar's fixes to convert filenames)
- Fixed some missed DBUG_PRINT(.."%lx") to use "0x%lx" to make it easier to
do comparision with the 'convert-dbug-for-diff' tool.
Things left to do in 5.1:
- We wrongly log failed CREATE TABLE ... SELECT in some cases when using
row based logging (as shown by testcase binlog_row_mix_innodb_myisam.result)
Mats has promised to look into this.
- Test that my fix for CREATE TABLE ... SELECT is indeed correct.
(I added several test cases for this, but in this case it's better that
someone else also tests this throughly).
Lars has promosed to do this.
BitKeeper/etc/ignore:
added mysys/test_bitmap
include/base64.h:
Removed my_global.h, as this must be included first in any program
include/heap.h:
Added heap_reset() (Required by new handler interface)
include/my_base.h:
Removed HA_EXTRA_RESET. MySQL will now call ::reset() instead of ::extra(HA_EXTRA_RESET).
HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIVE_PRIMARY key are deleted as the column bitmaps makes these unnecessary
include/my_bitmap.h:
Remove my_pthread.h (should be included at upper level)
Introduced my_bitmap_map typedef to make it the bitmap handling more like a black box
Added bitmap_is_overlapping(), bitmap_test_and_clear(), bitmap_copy() and bitmap_cmp()
Made bitmap_set_bit(), bitmap_flip_bit(), bitmap_clear_bit() return void
include/myisam.h:
Added mi_reset() (Required by new handler interface)
include/myisammrg.h:
Added myrg_reset() (Required by new handler interface)
include/mysql_com.h:
Added flag FIELD_IN_ADD_INDEX to be able to remove Field->add_index
mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/install_test_db.sh:
Simplify ldata usage
Added --tmpdir=. option to mysqld bootstrap (Removed some warnings when TMPDIR was wrongly set)
mysql-test/mysql-test-run.pl:
Added --tmpdir=. to bootstrap
mysql-test/mysql-test-run.sh:
Use copy instead of INSTALL_DB for master and slave databases.
(Speeds up startup time a lot!)
Remove snapshot directories at startup (removes some strange warnings)
mysql-test/r/binlog_row_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
(This found some bugs that Mats is going to fix shortly)
mysql-test/r/binlog_stm_mix_innodb_myisam.result:
Added testing of CREATE ... SELECT in a mixed environment
mysql-test/r/create.result:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/r/federated.result:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/r/func_gconcat.result:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/r/func_time.result:
Added drop of test function
mysql-test/r/innodb_mysql.result:
Added tests for CREATE ... SELECT
mysql-test/r/insert.result:
More tests
Added testing of duplicate columns in insert
mysql-test/r/loaddata.result:
Added testing LOAD DATA ... SET ...
mysql-test/r/multi_update.result:
Test multi updates and deletes using primary key and without
mysql-test/r/ndb_index_unique.result:
Better error message
mysql-test/r/ndb_replace.result:
New correct result after fixing REPLACE handling with NDB
mysql-test/r/rpl_ddl.result:
Now we don't get these (wrong) warnings anymore
mysql-test/r/view_grant.result:
Drop used views
mysql-test/t/create.test:
Some extra tests of warnings and number of tables opened by CREATE ... SELECT
mysql-test/t/federated.test:
Drop some left over tables
Added testing of multiple table update and multiple table delete (with and without keys)
mysql-test/t/func_gconcat.test:
Enable some disabled tests (converted them slightly to be predictable)
mysql-test/t/func_time.test:
Added drop of test function
mysql-test/t/innodb_mysql.test:
Added tests for CREATE ... SELECT
mysql-test/t/insert.test:
More tests
Added testing of duplicate columns in insert
mysql-test/t/loaddata.test:
Added testing LOAD DATA ... SET ...
mysql-test/t/multi_update.test:
Test multi updates and deletes using primary key and without
mysql-test/t/view_grant.test:
Drop used views
mysql-test/valgrind.supp:
Added supression of not needed warnings when printing stack trace
mysys/base64.c:
Include my_global.h first
mysys/my_bitmap.c:
Added bitmap_is_overlapping(), bitmap_test_and_clear() and bitmap_copy()
Changed logic of bitmap handling to be a bit more efficent (Did this together with Mikael Ronström)
Now the 'extra, not used bits' in the bitmap are assumed to have a 'random value' and the bitmap functions are free to change them whenever needed.
Changed how mutex is allocated to make 'bitmap_free()' function simpler.
mysys/thr_lock.c:
Added 0x before thread pointers (for easier comparison of DBUG traces)
sql/event.cc:
Ensure 'use_all_columns()' is used for event tables
Don't print warning that event table is damaged if it doesn't exists.
sql/field.cc:
Added ASSERT_COLUMN_MARKED_FOR_WRITE in all store() methods and ASSERT_COLUMN_MARKED_FOR_READ in all val() methods to catch wrong setting if table->read_set and table->write_set
(Rest of changes are only indentation cleanups)
sql/field.h:
Removed Field->query_id (replaced by table->read_set and table->write_set)
Removed Field->fieldnr (use Field->field_index instead)
Removed Field->add_index (Use Field->flags instead)
Add Field->part_of_key_not_clustered (for usage in opt_range.cc)
sql/filesort.cc:
Added paramater sort_postion to filesort() to force sorting by position instead of storing all fields in the result set.
This allowed me to remove checking of sql_command.
Create a temporary column bitmap for fields that are used by the sorting process.
Use column bitmaps instead of query_id
sql/ha_berkeley.cc:
Update to 'newer' table handler interface
sql/ha_berkeley.h:
Update to 'newer' table handler interface
sql/ha_federated.cc:
Update to 'newer' table handler interface
Only read columns that are needed from remote server.
In case of eq ranges, don't generate two conditions in the WHERE clause
(this can still be optimized, but would require a bigger code change)
Use 'simpler to use' XXXX_LEN' macros
A bit simpler logic in ::write_row() when creating statements.
In update, only include test of fields actually read.
(This greatly simplifies the queries sent by the federated engine)
Similar changes done for delete_row()
sql/ha_federated.h:
Update to 'newer' table handler interface
Changed XXX_LEN macros to use sizeof(...)-1, to simplify usage in ha_federated.cc
Added HA_PRIMARY_KEY_REQUIRED_FOR_DELETE to tell MySQL to read all primary key columns in case of DELETE
sql/ha_heap.cc:
Update to 'newer' table handler interface
sql/ha_heap.h:
Update to 'newer' table handler interface
sql/ha_innodb.cc:
Update to 'newer' table handler interface
- Update innobase_create_handler() to new interface
- Removed HA_NOT_EXACT_COUNT (not needed)
- Renamed HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
- Prefixed base status variables with 'stats'
- Use table column bitmaps instead of ha_get_bit_in_read_set()
- Added ::reset(), with code from ::extra(HA_EXTRA_RESET)
- Removed HA_EXTRA_RETRIVE_ALL_COLS and HA_EXTRA_RETRIEVE_PRIMARY_KEY as
the table->read_set and table->write_set bitmaps now are accurate
sql/ha_innodb.h:
Update to 'newer' table handler interface
- table_flags are now ulonglong
- Added reset() method
- Removed not needed ha_retrieve_all_cols() and ha_retrieve_all_pk() columns.
- Made build_template() a class function to be able to easier access class variables
sql/ha_myisam.cc:
Update to 'newer' table handler interface
sql/ha_myisam.h:
Update to 'newer' table handler interface
sql/ha_myisammrg.cc:
Update to 'newer' table handler interface
sql/ha_myisammrg.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster.cc:
Update to 'newer' table handler interface
Fixed use_blob_value() to be accurate
In ::complemented_read() we have to check both the read and write bitmap as the old code did mark all changed columns also in the read map
Correct dumping of field data with DBUG_DUMP
Prefix addresses in DBUG_PRINT with 0x
Fixed usage of not initialized memory
Update to use field->flags & FIELD_IN_ADD_INDEX instead of field->add_index.
sql/ha_ndbcluster.h:
Update to 'newer' table handler interface
sql/ha_ndbcluster_binlog.cc:
Mark usage of all columns in ndbcluster binlog tables
false -> FALSE, true -> TRUE
Use table->s->all_set instead of creating a temporary bitmap.
sql/ha_partition.cc:
Update to 'newer' table handler interface
Added memroot to initialise_partitions() and related functions to get faster memory allocation.
partition_create_handler() is now responsible for initialisation of the partition object
Some trivial optimizations and indentation fixes
Ensure that table_flags() are up to date
Removed documentation for removed HA_EXTRA flags
Fixed 'strange' usage of m_file[i] in new_handlers_from_part_info()that worked in current code 'by chance'
sql/ha_partition.h:
Update to 'newer' table handler interface
sql/handler.cc:
create_xxx handler now takes MEMROOT as an argument to simplify memory allocation.
Much simpler get_new_handler()
(Initialization of the object is now handled by the create method for the engine)
Moved all allocation of bitmap handling to the TABLE object (in table.cc)
Added column_bitmaps_signal() to signal column usage changes.
Changed binlog_log_row() to use the exiusting all_set bitmap in the table object.
Added ha_reset() function to test that the file object is ok at end of statement and call handler::reset()
Added use_hidden_primary_key() to signal handler that we we are going to read and update + delete the row and the handler should thus remember the position for the row
sql/handler.h:
Added HA_NO_TRANSACTIONS, HA_PARTIAL_COLUMN_READ, HA_REQUIRES_KEY_COLUMNS_FOR_DELETE,HA_PRIMARY_KEY_REQUIRED_FOR_DELETE and HA_HAS_RECORDS
Removed HA_NOT_EXACT_COUNT, HA_READ_RND_SAME
HA_DUPP_POS -> HA_DUPLICATE_POS
HA_NOT_EXACT_COUNT replaced by HA_STATS_RECORDS_IS_EXACT, HA_HAS_RECORDS and records()
HA_PRIMARY_KEY_ALLOW_RANDOM_ACCESS renamed to HA_PRIMARY_KEY_REQUIRED_FOR_POSITION
Added future row type 'ROW_TYPE_PAGES'
Added MEM_ROOT to handlerton 'create' function
Added ha_statistics, a structure for all status variable in the base handler class.
Moved all status variables in the handler class into a stats structs to improve readability.
ha_table_flags() is now a cached (not virtual) version of table_flags()
reset() doesn't anymore call extra(HA_EXTRA_RESET) but is a function of it's own.
Renamed dupp_ref to dup_ref
Renamed not used handler::sortkey
Moved read_set and write_set to TABLE structure
handler::init() function added for cacheing of virtual constants from engine.
sql/item.cc:
Added register_field_in_read_map() for marking used columns in expression.
This is used by filesort() for creating an optimal column bitmap while retrieving columns for sorting.
Initalize value.cs_info.character_set_client to fix core dump bug with --debug
set_query_id -> mark_used_columns
Mark used columns in read_set OR write_set.
sql/item.h:
Removed reset_query_id_processor() as it's not needed anymore.
Added register_field_in_read_map()
Added extra argument to Item::walk() to indicate if we should also
traverse sub queries.
sql/item_cmpfunc.cc:
Temporary mark used columns to be read/writable
Update Item::walk to new interface
sql/item_cmpfunc.h:
Added extra argument to Item::walk() to indicate if we should also traverse sub queries.
sql/item_func.cc:
Update Item::walk() to new interface
table_flags() -> ha_table_flags()
sql/item_func.h:
Update Item::walk() to new interface
sql/item_row.cc:
Update Item::walk() to new interface
sql/item_row.h:
Update Item::walk() to new interface
sql/item_strfunc.h:
Update Item::walk() to new interface
sql/item_subselect.cc:
Added Item_subselect::walk()
(It was a bug it was missing before. Not sure what kind of bugs this could have caused)
sql/item_subselect.h:
Update Item::walk() to new interface
sql/item_sum.cc:
Update Item::walk() to new interface
Updates for new handler interace
sql/item_sum.h:
Update Item::walk() to new interface
sql/key.cc:
Updates for new handler interace
sql/log.cc:
Mark all columns used for log tables
Split options flag
Ensured that second argument to trans_register_ha is a bool
sql/log_event.cc:
Fixed comments to be withing 79 characters
Use OPTION_KEEP_LOG instead of OPTION_STATUS_NO_TRANS_UPDATE to remove wrong warnings
Updates for new handler interface
Use 0x%lx instead of %p (portability problem)
sql/mysql_priv.h:
Added OPTION_KEEP_LOG to indicate that we should replicate the binlog even on rollback
Removed not used 'conds' argument to setup_tables
sql/mysqld.cc:
Indentation fixes and removed old comment
sql/opt_range.cc:
Update to new handler and bitmap interface.
Fixed calls to cp_buffer_from_ref() and walk() (new argument).
Create new temporary bitmaps for ror scans.
(Needed because of handler changes and to get more accurate column bitmaps than before)
Remove not needed file->ha_reset() call before file->close().
Some trivial optimization and indentation fixes.
Use Field->part_of_key_not_clustered() to check if field is part of a key, instead of looping over all key parts.
Added flag 'in_ror_merged_scan' to allow ::get_next() to know that we need a special column bitmap to only fetch pointer to record.
This is needed because ror scan uses the same TABLE object but different file objects, which creates problem for the column bitmap handling.
(This is a temporary solution. A better one would be to allocate an own TABLE object for ROR scans)
Optimized bitmap handling in ror scans:
- Start bitmap at position 0, not 1
- Use same bitmap size as in TABLE
- Use table->read_set and table->write_set to create column bitmaps instead of looping over all fields in table
sql/opt_range.h:
Added 'in_ror_merged_scan' to indicate if we are doing a ROR scan
Added temporary column bitmaps used in ROR scans
sql/opt_sum.cc:
Added get_ext_record_count() which is used in COUNT() optimization if handler has HA_HAS_RECORDS
Note that we don't call this if handler has HA_STATS_RECORDS_IS_EXACT set.
sql/protocol.cc:
We need to mark columns as readable in ::store() as we sometimes return default value for fields to the user
sql/records.cc:
Updates for new handler interface
sql/set_var.cc:
Handle splitting OPTION_STATUS_NO_TRANS_UPDATE to two flags
sql/share/errmsg.txt:
Fixed wrong
sql/sp.cc:
Mark that we are using all columns for the proc table
Update call to setup_tables() to use new prototype
sql/sp_head.cc:
Removed QQ comment
sql/spatial.cc:
Removed wrong QQ comment
sql/sql_acl.cc:
Mark that we need all columns for acl tables
Supply memroot to some 'new' calls.
Indentation fixes
sql/sql_base.cc:
set_query_id removed
Ensure we call ha_reset() at end of each statement
Mark read columns in read_set and changed columns in write_set (Before all columns was marked in read set)
Fixed marking of some columns that was not proplerly marked before
Maintain in TABLE->merge_keys set of all keys that are used in some way
Removed not used 'conds' argument from setup_tables()
Remove not used setting of 'dupp_field' in insert_fields()
Added missing FN_LIBCHAR in mysql_rm_tmp_tables()
(This has probably caused us to not properly remove temporary files after crash)
sql/sql_bitmap.h:
Added is_overlapping()
sql/sql_class.cc:
Slow_logs was not properly initialized, which could maybe cause extra/lost entries in slow log.
set_query_id -> mark_used_columns
Simpler variable usage in pack_row() (cleanup)
Moved some variable declartion at start of function for better code readability
sql/sql_class.h:
Added enum_mark_columns
Updated comments
Renamed dupp_field -> dup_field
Added virtual function 'can_rollback_data()' to select_insert() to be used in CREATE ... SELECT to optimize use of OPTION_STATUS_NO_TRANS_UPDATE.
(This fixes a bug in CREATE ... SELECT where we did give wrong warnings when using non transacational tables)
sql/sql_delete.cc:
Updates to new handler interface
Call table->mark_columns_needed_for_delete() to allow us to put additional columns in column usage maps if handler so requires.
Call table->prepare_for_position() to tell handler that we are going to call ha_position().
Removed call to free_io_cache(). (io_cache is now removed in ha_reset()).
Fixed calls to setup_tables()
sql/sql_do.cc:
Update call to setup_fields()
sql/sql_handler.cc:
Tell handler tables to always read all columns.
Use temporary column map when storing value in field for later index usage
sql/sql_help.cc:
Makr all used fields to be read
Update call to setup_fields()
sql/sql_insert.cc:
Tell handler we are going to update the auto_increment column
dupp_field -> dup_field
Set column usage bits for timestamp field.
Call table->mark_columns_needed_for_insert() and table->mark_auto_increment_column()
Removed not used argument from mysql_prepare_insert_check_table().
If we get an duplicate row on insert, change column map to read and write all columns while retrying the operatation.
This is required by the definition of REPLACE and also ensures that fields that are only part of UPDATE are properly handled.
This fixed a bug in NDB and REPLACE where REPLACE wrongly copied some column values from the replaced row.
Setup new bitmaps for delayed insert rows
Remove reseting of next_number_fields as it will be reset on next call to handler_insert()
Fixed usage of thd->options and OPTION_STATUS_NO_TRANS_UPDATE.
The issue was that one should not to reset this flag as it may be set by a previous statement.
The way it was now used caused us to loose some warnings and get other wrong warnings when using non transactional tables mixed with transactional.
I fixed it by introducing 'select_insert::can_rollback_data' to inform send_error() that the given statement can be rolled back (which in case of CREATE TABLE can always be done)
Don't close tables created with CREATE ... SELECT but keep them in the table cache.
Moved out MY_HOOKS from inside function (better readability)
sql/sql_load.cc:
Update to use new handler and column marking interface
Update using setup_tables()
sql/sql_olap.cc:
Update calls to setup_tables
Use enums instead of constants to setup_fields()
sql/sql_parse.cc:
Handle OPTION_KEEP_LOG:
- Set it on CREATE TEMPORARY TABLE / DROP TABLE
- Reset it when OPTION_STATUS_NO_TRANS_UPDATE is reset
- Don't set it for CREATE ... SELECT (this is handled in select_create class)
Remove reseting of OPTION_STATUS_NO_TRANS_UPDATE in begin_trans() as this should already be reset.
If in autocommit mode, reset OPTION_KEEP_LOG and OPTION_STATUS_NO_TRANS_UPDATE to not give warnings in future commands
sql/sql_partition.cc:
Update walk() usage
Trivial indentation fixes
sql/sql_plugin.cc:
Mark all columns as used for plugins
sql/sql_prepare.cc:
Added assert to find out hidden bugs in character_set_client (got an error in debug binary when this not set correctly)
Updates for new handler interface
Update calls to setup_fields()
sql/sql_repl.cc:
Indentation fixes
sql/sql_select.cc:
Update call to setup_tables() and setup_fields()
Remove some old disabled code
Update to new hadler interface
Indentation cleanups
Added column bitmaps for temporary tables.
Remove updating of the removed slots in the Field class
Added TABLE argument to cp_buffer_from_ref() (To be able to install temporary column maps)
For internal temporary tables, use handler::write_row(), handler::delete_row() and handler::update_row() instead of handler::ha_xxxx() for faster execution.
sql/sql_select.h:
Indentaition fixes.
Install temporary column usage maps when needed
Added TABLE element to cp_buffer_from_ref()
sql/sql_show.cc:
Update to new handler interface
Mark all columns used for internal tables.
Style fixes.
Added support for 'future' ROW_TYPE_PAGES.
Don't allocate TMP_TABLE_PARAM with calloc. The 'init()' function will initialize the structure properly.
sql/sql_table.cc:
Update to new handler interface
Simple my_snprintf -> strmake()
Changed some constants to defines
Don't test for NULL in primary key (as we a couple of line above force the PRIMARY KEY to be NOT NULL)
Change field->add_index to use field->flags & FIELD_IN_ADD_INDEX
Mark all columns as used for ALTER TABLE
Style fixes
Update call to filesort()
sql/sql_trigger.h:
Added friend functions to be able to test if triggers exists for table we are going to insert/update or delete in.
sql/sql_udf.cc:
Mark all columns as used for udf system table.
sql/sql_union.cc:
Update call to walk()
Update to new handler interface
sql/sql_update.cc:
Remove query_id argument from compare_record()
Use column bitmaps instead of query_id.
We can't use compare_records() to skip updates for handlers that returns a partial column set and the read_set doesn't cover all columns in the write set, because compare_record() can't in this case know if a not read column changed value.
Update call to setup_fields()
Using separate column read and write sets allows for easier checking of timestamp field was set by statement.
Removed call to free_io_cache() as this is now done in ha_reset()
Call table->mark_columns_needed_for_update() and table->prepare_for_position()
Style fixes
sql/sql_view.cc:
Style fixes
sql/table.cc:
Remove implicitely include 'errno.h'
Remove code for building normalized path, as this is now identical to 'path'
Remove field->fieldnr
Added update of field->part_of_key_not_clustered()
Create column bitmaps in TABLE and TABLE_SHARE
Don't setup a temporary MEM_ROOT object as a thread specific variable for the handler. Instead we send the to-be-used MEMROOT to get_new_handler()
Update to new handler interface
Update call to walk()
Added new functions:
- st_table::clear_column_bitmaps()
- st_table::prepare_for_position()
- st_table::mark_columns_used_by_index()
- st_table::restore_column_maps_after_mark_index()
- st_table::mark_columns_used_by_index_no_reset()
- st_table::mark_auto_increment_column()
- st_table::mark_columns_needed_for_delete()
- st_table::mark_columns_needed_for_update()
- st_table::mark_columns_needed_for_insert()
sql/table.h:
Moved column usage bitmaps from handler to TABLE
Added to TABLE_SHARE all_set and column_bitmap_size
Added to TABLE merge_keys, bitmap_init_values, def_read_set, def_write_set, tmp_set, read_set and write_set.
Declared all new table column bitmap functions
Added TABLE functions column_bitmaps_set(), column_bitmaps_set_no_signal(), use_all_columns() and default_column_bitmaps()
Added functions: tmp_use_all_columns() and tmp_restore_column_map() to temporarly switch column bitmaps
Added functions: dbug_tmp_use_all_columns() and dbug_tmp_restore_column_map() to temporarly switch column bitmaps to avoid asserts in Field::store() and Field::val().
sql/tztime.cc:
Mark all columns as used for timezone tables
storage/archive/ha_archive.cc:
Update to new handler interface
storage/archive/ha_archive.h:
Update to new handler interface
storage/blackhole/ha_blackhole.cc:
Update to new handler interface
storage/blackhole/ha_blackhole.h:
Update to new handler interface
removed not needed flag HA_DUPP_POS
storage/csv/ha_tina.cc:
Update to new handler interface
storage/csv/ha_tina.h:
Update to new handler interface
storage/example/ha_example.cc:
Update to new handler interface
storage/example/ha_example.h:
Update to new handler interface
storage/heap/hp_extra.c:
Added heap_reset() (Required by new handler interface)
storage/heap/hp_test2.c:
Use heap_reset()
storage/myisam/ft_boolean_search.c:
Fixed compiler warning
storage/myisam/mi_extra.c:
Added mi_reset() (Required by new handler interface)
storage/myisam/mi_search.c:
Fixed DBUG_PRINT messages to use 0x%lx instead of %lx
storage/myisam/mi_test2.c:
Use mi_reset()
storage/myisam/myisampack.c:
Use mi_reset()
storage/myisammrg/myrg_extra.c:
Added myrg_reset() (Required by new handler interface)
unittest/mysys/base64.t.c:
Include my_global.h
Don't include implictely include file 'stdlib.h'
2006-06-04 17:52:22 +02:00
|
|
|
&tables, &leaves, FALSE);
|
2003-11-17 18:21:36 +01:00
|
|
|
for (used_field= &used_fields[0];
|
|
|
|
used_field->field_name;
|
|
|
|
used_field++)
|
|
|
|
{
|
2005-07-01 06:05:42 +02:00
|
|
|
Item_field *field= new Item_field(&thd->lex->select_lex.context,
|
|
|
|
"mysql", "proc",
|
2003-11-17 18:21:36 +01:00
|
|
|
used_field->field_name);
|
2005-07-01 06:05:42 +02:00
|
|
|
if (!field ||
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 16:57:19 +02:00
|
|
|
!(used_field->field= find_field_in_tables(thd, field, &tables, NULL,
|
2005-07-02 23:51:02 +02:00
|
|
|
0, REPORT_ALL_ERRORS, 1,
|
|
|
|
TRUE)))
|
2003-11-20 15:07:22 +01:00
|
|
|
{
|
|
|
|
res= SP_INTERNAL_ERROR;
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case1;
|
2003-11-20 15:07:22 +01:00
|
|
|
}
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2005-07-18 13:31:02 +02:00
|
|
|
table->file->ha_index_init(0, 1);
|
2003-11-20 15:07:22 +01:00
|
|
|
if ((res= table->file->index_first(table->record[0])))
|
|
|
|
{
|
2003-12-21 11:48:03 +01:00
|
|
|
res= (res == HA_ERR_END_OF_FILE) ? 0 : SP_INTERNAL_ERROR;
|
2003-11-20 15:07:22 +01:00
|
|
|
goto err_case1;
|
|
|
|
}
|
|
|
|
if ((res= print_field_values(thd, table, used_fields, type, wild)))
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case1;
|
|
|
|
while (!table->file->index_next(table->record[0]))
|
|
|
|
{
|
2003-11-20 15:07:22 +01:00
|
|
|
if ((res= print_field_values(thd, table, used_fields, type, wild)))
|
2003-11-17 18:21:36 +01:00
|
|
|
goto err_case1;
|
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
res= SP_OK;
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
err_case1:
|
2003-11-17 18:21:36 +01:00
|
|
|
send_eof(thd);
|
2003-12-21 11:48:03 +01:00
|
|
|
err_case:
|
2004-07-15 03:19:07 +02:00
|
|
|
table->file->ha_index_end();
|
2003-11-17 18:21:36 +01:00
|
|
|
close_thread_tables(thd);
|
2003-12-21 11:48:03 +01:00
|
|
|
done:
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_RETURN(res);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
|
2004-03-22 14:44:41 +01:00
|
|
|
/* Drop all routines in database 'db' */
|
|
|
|
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);
|
2004-03-22 14:44:41 +01:00
|
|
|
if (! table->file->index_read(table->record[0],
|
2006-04-21 14:30:44 +02:00
|
|
|
(byte *)table->field[MYSQL_PROC_FIELD_DB]->ptr,
|
2006-04-18 16:01:01 +02:00
|
|
|
key_len, 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],
|
2006-04-21 14:30:44 +02:00
|
|
|
(byte *)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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
PROCEDURE
|
|
|
|
******************************************************************************/
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
/*
|
2005-11-23 00:11:19 +01:00
|
|
|
Obtain object representing stored procedure/function by its name from
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
stored procedures cache and looking into mysql.proc if needed.
|
|
|
|
|
|
|
|
SYNOPSIS
|
2005-11-23 00:11:19 +01:00
|
|
|
sp_find_routine()
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
thd - thread context
|
2005-11-23 00:11:19 +01:00
|
|
|
type - type of object (TYPE_ENUM_FUNCTION or TYPE_ENUM_PROCEDURE)
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
name - name of procedure
|
2005-11-23 00:11:19 +01:00
|
|
|
cp - hash to look routine in
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
cache_only - if true perform cache-only lookup
|
|
|
|
(Don't look in mysql.proc).
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
Non-0 pointer to sp_head object for the procedure, or
|
|
|
|
0 - in case of error.
|
|
|
|
*/
|
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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");
|
|
|
|
DBUG_PRINT("enter", ("name: %.*s.%.*s, type: %d, cache only %d",
|
|
|
|
name->m_db.length, name->m_db.str,
|
|
|
|
name->m_name.length, name->m_name.str,
|
|
|
|
type, cache_only));
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
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-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)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("first free: 0x%lx, level: %lu, flags %x",
|
|
|
|
(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);
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
sp->m_created, sp->m_modified) == SP_OK)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_RETURN(sp);
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01: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'.
|
|
|
|
*/
|
2005-11-23 00:11:19 +01:00
|
|
|
|
2004-12-23 11:46:24 +01:00
|
|
|
int
|
2006-01-26 13:29:46 +01:00
|
|
|
sp_exist_routines(THD *thd, TABLE_LIST *routines, bool any, bool no_error)
|
2004-12-23 11:46:24 +01:00
|
|
|
{
|
2006-01-26 13:29:46 +01:00
|
|
|
TABLE_LIST *routine;
|
2004-12-23 11:46:24 +01:00
|
|
|
bool result= 0;
|
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);
|
2004-12-23 11:46:24 +01:00
|
|
|
name= new sp_name(lex_db, lex_name);
|
|
|
|
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;
|
|
|
|
mysql_reset_errors(thd, TRUE);
|
|
|
|
if (sp_object_found)
|
2004-12-23 11:46:24 +01:00
|
|
|
{
|
|
|
|
if (any)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
result= 1;
|
|
|
|
}
|
|
|
|
else if (!any)
|
|
|
|
{
|
|
|
|
if (!no_error)
|
|
|
|
{
|
|
|
|
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE",
|
2006-01-26 13:29:46 +01:00
|
|
|
routine->table_name);
|
2004-12-23 11:46:24 +01:00
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-26 13:29:46 +01:00
|
|
|
/*
|
|
|
|
Check if a routine exists in the mysql.proc table, without actually
|
|
|
|
parsing the definition. (Used for dropping)
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_routine_exists_in_table()
|
|
|
|
thd - thread context
|
|
|
|
name - name of procedure
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 - Success
|
|
|
|
non-0 - Error; SP_OPEN_TABLE_FAILED or SP_KEY_NOT_FOUND
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
close_proc_table(thd, &open_tables_state_backup);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
int
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
sp_create_procedure(THD *thd, sp_head *sp)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_ENTER("sp_create_procedure");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", sp->m_name.length, sp->m_name.str));
|
2004-01-14 18:18:29 +01:00
|
|
|
|
|
|
|
ret= db_create_routine(thd, TYPE_ENUM_PROCEDURE, sp);
|
|
|
|
DBUG_RETURN(ret);
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2002-12-12 13:14:23 +01:00
|
|
|
int
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
sp_drop_procedure(THD *thd, sp_name *name)
|
2002-12-12 13:14:23 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_drop_procedure");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
|
2002-12-12 13:14:23 +01:00
|
|
|
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
ret= db_drop_routine(thd, TYPE_ENUM_PROCEDURE, name);
|
2005-08-09 01:23:34 +02:00
|
|
|
if (!ret)
|
2004-08-06 18:11:14 +02:00
|
|
|
sp_cache_invalidate();
|
2004-01-14 18:18:29 +01:00
|
|
|
DBUG_RETURN(ret);
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
Fixed BUG#6027: Stored procedures can be renamed.
Removed the support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
mysql-test/r/sp-error.result:
Removed test for renaming procedures with alter.
mysql-test/r/sp.result:
Removed test for renaming procedures with alter.
mysql-test/t/sp-error.test:
Removed test for renaming procedures with alter.
mysql-test/t/sp.test:
Removed test for renaming procedures with alter.
sql/sp.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sp.h:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_parse.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_yacc.yy:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
2004-10-22 19:05:17 +02:00
|
|
|
sp_update_procedure(THD *thd, sp_name *name, st_sp_chistics *chistics)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_update_procedure");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
Fixed BUG#6027: Stored procedures can be renamed.
Removed the support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
mysql-test/r/sp-error.result:
Removed test for renaming procedures with alter.
mysql-test/r/sp.result:
Removed test for renaming procedures with alter.
mysql-test/t/sp-error.test:
Removed test for renaming procedures with alter.
mysql-test/t/sp.test:
Removed test for renaming procedures with alter.
sql/sp.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sp.h:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_parse.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_yacc.yy:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
2004-10-22 19:05:17 +02:00
|
|
|
ret= db_update_routine(thd, TYPE_ENUM_PROCEDURE, name, chistics);
|
2005-08-09 01:23:34 +02:00
|
|
|
if (!ret)
|
2004-08-06 18:11:14 +02:00
|
|
|
sp_cache_invalidate();
|
2004-01-14 18:18:29 +01:00
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
sp_show_create_procedure(THD *thd, sp_name *name)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2003-12-21 11:48:03 +01:00
|
|
|
sp_head *sp;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_show_create_procedure");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
if ((sp= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name,
|
|
|
|
&thd->sp_proc_cache, FALSE)))
|
2004-01-14 18:18:29 +01:00
|
|
|
{
|
|
|
|
int ret= sp->show_create_procedure(thd);
|
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2003-11-20 15:07:22 +01:00
|
|
|
sp_show_status_procedure(THD *thd, const char *wild)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_ENTER("sp_show_status_procedure");
|
2004-01-14 18:18:29 +01:00
|
|
|
|
|
|
|
ret= db_show_routine_status(thd, TYPE_ENUM_PROCEDURE, wild);
|
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
2002-12-12 13:14:23 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
FUNCTION
|
|
|
|
******************************************************************************/
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
|
|
|
|
int
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
sp_create_function(THD *thd, sp_head *sp)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_ENTER("sp_create_function");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", sp->m_name.length, sp->m_name.str));
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
|
2004-01-14 18:18:29 +01:00
|
|
|
ret= db_create_routine(thd, TYPE_ENUM_FUNCTION, sp);
|
|
|
|
DBUG_RETURN(ret);
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
int
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
sp_drop_function(THD *thd, sp_name *name)
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
DBUG_ENTER("sp_drop_function");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
|
Most of the groundwork for sprint task 729 (implement FUNCTIONs).
Expanded the mysql.proc table, reworked the find/create/drop functions
completely, added new functions for FUNCTIONs (lotta functions here :),
got rid of some unnecessary use of Item_strings while at it. Extended
the parser correspondingly, and fiddled around a bit to make SP FUNCTIONs
coexist with UDFs.
Can now CREATE and DROP FUNCTIONs. Invoking yet to come...
Docs/sp-implemented.txt:
Updated with info about CASCADE/RESTICT and METHOD, and some answers to questions.
include/mysqld_error.h:
New error message for misuse of RETURN.
mysql-test/install_test_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
mysql-test/r/sp.result:
New test for creating and dropping FUNCTIONS.
mysql-test/t/sp.test:
New test for creating and dropping FUNCTIONS.
scripts/mysql_install_db.sh:
Added enum field to mysql.proc to distinguish between FUNCTION and PROCEDURE.
sql/lex.h:
De-UDFed some symbol names, as they are now used for SPs as well.
Added RETURN_SYM.
sql/share/czech/errmsg.txt:
New error message for misuse of RETURN.
sql/share/danish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/dutch/errmsg.txt:
New error message for misuse of RETURN.
sql/share/english/errmsg.txt:
New error message for misuse of RETURN.
sql/share/estonian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/french/errmsg.txt:
New error message for misuse of RETURN.
sql/share/german/errmsg.txt:
New error message for misuse of RETURN.
sql/share/greek/errmsg.txt:
New error message for misuse of RETURN.
sql/share/hungarian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/italian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/japanese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/korean/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian-ny/errmsg.txt:
New error message for misuse of RETURN.
sql/share/norwegian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/polish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/portuguese/errmsg.txt:
New error message for misuse of RETURN.
sql/share/romanian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/russian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/serbian/errmsg.txt:
New error message for misuse of RETURN.
sql/share/slovak/errmsg.txt:
New error message for misuse of RETURN.
sql/share/spanish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/swedish/errmsg.txt:
New error message for misuse of RETURN.
sql/share/ukrainian/errmsg.txt:
New error message for misuse of RETURN.
sql/sp.cc:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp.h:
Major rehack to accomodate FUNCTIONs, and to make it easier to add
future in-memory cache of prepared SPs.
sql/sp_head.cc:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sp_head.h:
Now creates FUNCTIONs too. (And got rid of some unnecessary Item_string use.)
sql/sql_lex.h:
New stored FUNCTION commands.
sql/sql_parse.cc:
Added FUNCTION support ("drop" merged with the old UDF code), and made some
additional changes for better error handling (following the sp.cc rehacking).
sql/sql_yacc.yy:
Some former UDF specific symbols renamed.
Added CREATE FUNCTION parsing.
DROP FUNCTION had to be partly merged with the old UDF code, because of the similar
syntax.
RETURN statement added, but still a no-op.
2003-02-21 17:37:05 +01:00
|
|
|
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
ret= db_drop_routine(thd, TYPE_ENUM_FUNCTION, name);
|
2005-08-09 01:23:34 +02:00
|
|
|
if (!ret)
|
2004-08-06 18:11:14 +02:00
|
|
|
sp_cache_invalidate();
|
2004-01-14 18:18:29 +01:00
|
|
|
DBUG_RETURN(ret);
|
2002-12-12 13:14:23 +01:00
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
Fixed BUG#6027: Stored procedures can be renamed.
Removed the support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
mysql-test/r/sp-error.result:
Removed test for renaming procedures with alter.
mysql-test/r/sp.result:
Removed test for renaming procedures with alter.
mysql-test/t/sp-error.test:
Removed test for renaming procedures with alter.
mysql-test/t/sp.test:
Removed test for renaming procedures with alter.
sql/sp.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sp.h:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_parse.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_yacc.yy:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
2004-10-22 19:05:17 +02:00
|
|
|
sp_update_function(THD *thd, sp_name *name, st_sp_chistics *chistics)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_update_procedure");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
Fixed BUG#6027: Stored procedures can be renamed.
Removed the support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
mysql-test/r/sp-error.result:
Removed test for renaming procedures with alter.
mysql-test/r/sp.result:
Removed test for renaming procedures with alter.
mysql-test/t/sp-error.test:
Removed test for renaming procedures with alter.
mysql-test/t/sp.test:
Removed test for renaming procedures with alter.
sql/sp.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sp.h:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_parse.cc:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
sql/sql_yacc.yy:
Removed support for renaming SPs. It's non-standard, conflicted with a standard
syntax, and was a bit broken anyway.
2004-10-22 19:05:17 +02:00
|
|
|
ret= db_update_routine(thd, TYPE_ENUM_FUNCTION, name, chistics);
|
2005-08-09 01:23:34 +02:00
|
|
|
if (!ret)
|
2004-08-06 18:11:14 +02:00
|
|
|
sp_cache_invalidate();
|
2004-01-14 18:18:29 +01:00
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
WL#1366: Use the schema (db) associated with an SP.
Phase 1: Introduced sp_name class, for qualified name support.
sql/item_func.cc:
Introduced sp_name class; moved some methods from item_func.h.
sql/item_func.h:
Introduced sp_name class; moved some methods to item_func.cc.
sql/sp.cc:
Introduced sp_name class, for qualified name support.
sql/sp.h:
Introduced sp_name class, for qualified name support.
sql/sp_cache.cc:
Introduced sp_name class, for qualified name support.
sql/sp_cache.h:
Introduced sp_name class, for qualified name support.
sql/sp_head.cc:
Introduced sp_name class, for qualified name support.
sql/sp_head.h:
Introduced sp_name class, for qualified name support.
sql/sql_lex.h:
Introduced sp_name class, for qualified name support.
sql/sql_parse.cc:
Introduced sp_name class, for qualified name support.
sql/sql_yacc.yy:
Introduced sp_name class, for qualified name support.
2004-02-17 17:36:53 +01:00
|
|
|
sp_show_create_function(THD *thd, sp_name *name)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2003-12-21 11:48:03 +01:00
|
|
|
sp_head *sp;
|
2003-11-17 18:21:36 +01:00
|
|
|
DBUG_ENTER("sp_show_create_function");
|
2005-10-07 02:37:24 +02:00
|
|
|
DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str));
|
2003-11-17 18:21:36 +01:00
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
if ((sp= sp_find_routine(thd, TYPE_ENUM_FUNCTION, name,
|
|
|
|
&thd->sp_func_cache, FALSE)))
|
2004-01-14 18:18:29 +01:00
|
|
|
{
|
|
|
|
int ret= sp->show_create_function(thd);
|
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_RETURN(SP_KEY_NOT_FOUND);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
int
|
2003-11-20 15:07:22 +01:00
|
|
|
sp_show_status_function(THD *thd, const char *wild)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2004-01-14 18:18:29 +01:00
|
|
|
int ret;
|
2003-11-20 15:07:22 +01:00
|
|
|
DBUG_ENTER("sp_show_status_function");
|
2004-01-14 18:18:29 +01:00
|
|
|
ret= db_show_routine_status(thd, TYPE_ENUM_FUNCTION, wild);
|
|
|
|
DBUG_RETURN(ret);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01: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
|
|
|
{
|
2005-07-09 19:51:59 +02:00
|
|
|
/* Set key consisting of one-byte routine type and quoted routine name. */
|
|
|
|
LEX_STRING key;
|
|
|
|
/*
|
|
|
|
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;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" byte* sp_sroutine_key(const byte *ptr, uint *plen, my_bool first)
|
|
|
|
{
|
|
|
|
Sroutine_hash_entry *rn= (Sroutine_hash_entry *)ptr;
|
|
|
|
*plen= rn->key.length;
|
|
|
|
return (byte *)rn->key.str;
|
2003-07-07 14:55:10 +02:00
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
2005-07-30 10:19:57 +02:00
|
|
|
/*
|
Prelocking-free SPs, post-review fixes:
* Don't activate prelocking mode for evaluating procedure arguments when it is not necessary.
* Code structure simplification and cleanup.
* Cleanup in .test files
mysql-test/r/sp-prelocking.result:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/r/sp-security.result:
Don't drop the table we're not using.
mysql-test/r/sp.result:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
mysql-test/t/sp-prelocking.test:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/t/sp-security.test:
Don't drop the table we're not using.
mysql-test/t/sp.test:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
sql/sp.cc:
New, better defined, sp_get_prelocking_info() function to get info about
statement prelocking options
sql/sp.h:
Prelocking-free SPs, post-review fixes: New, better defined, sp_get_prelocking_info()
function to get info about statement prelocking options
sql/sp_cache.h:
Prelocking-free SPs, post-review fixes: Amended the comments
sql/sp_head.cc:
Prelocking-free SPs, post-review fixes: Amend the comments, simplify the code that
attaches removes statement's prelocking tables.
sql/sql_base.cc:
Prelocking-free SPs, post-review fixes:
* Use a better defined sp_get_prelocking_info() function to get info about
statement prelocking options
* Don't activate prelocked mode for evaluation of SP arguments that use tables
but don't need prelocking.
sql/sql_class.cc:
Prelocking-free SPs, post-review fixes: Initialize THD members in the order they are declared.
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
|
|
|
|
|
|
|
SYNOPSIS
|
Prelocking-free SPs, post-review fixes:
* Don't activate prelocking mode for evaluating procedure arguments when it is not necessary.
* Code structure simplification and cleanup.
* Cleanup in .test files
mysql-test/r/sp-prelocking.result:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/r/sp-security.result:
Don't drop the table we're not using.
mysql-test/r/sp.result:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
mysql-test/t/sp-prelocking.test:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/t/sp-security.test:
Don't drop the table we're not using.
mysql-test/t/sp.test:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
sql/sp.cc:
New, better defined, sp_get_prelocking_info() function to get info about
statement prelocking options
sql/sp.h:
Prelocking-free SPs, post-review fixes: New, better defined, sp_get_prelocking_info()
function to get info about statement prelocking options
sql/sp_cache.h:
Prelocking-free SPs, post-review fixes: Amended the comments
sql/sp_head.cc:
Prelocking-free SPs, post-review fixes: Amend the comments, simplify the code that
attaches removes statement's prelocking tables.
sql/sql_base.cc:
Prelocking-free SPs, post-review fixes:
* Use a better defined sp_get_prelocking_info() function to get info about
statement prelocking options
* Don't activate prelocked mode for evaluation of SP arguments that use tables
but don't need prelocking.
sql/sql_class.cc:
Prelocking-free SPs, post-review fixes: Initialize THD members in the order they are declared.
2005-08-03 05:37:32 +02:00
|
|
|
sp_get_prelocking_info()
|
|
|
|
thd Current thread, thd->lex is the statement to be
|
|
|
|
checked.
|
|
|
|
need_prelocking OUT TRUE - prelocked mode should be activated
|
|
|
|
before executing the statement
|
|
|
|
FALSE - Don't activate prelocking
|
|
|
|
first_no_prelocking OUT TRUE - Tables used by first routine in
|
|
|
|
thd->lex->sroutines_list should be
|
|
|
|
prelocked.
|
|
|
|
FALSE - Otherwise.
|
2005-07-30 10:19:57 +02:00
|
|
|
NOTES
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
Prelocking-free SPs, post-review fixes:
* Don't activate prelocking mode for evaluating procedure arguments when it is not necessary.
* Code structure simplification and cleanup.
* Cleanup in .test files
mysql-test/r/sp-prelocking.result:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/r/sp-security.result:
Don't drop the table we're not using.
mysql-test/r/sp.result:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
mysql-test/t/sp-prelocking.test:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/t/sp-security.test:
Don't drop the table we're not using.
mysql-test/t/sp.test:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
sql/sp.cc:
New, better defined, sp_get_prelocking_info() function to get info about
statement prelocking options
sql/sp.h:
Prelocking-free SPs, post-review fixes: New, better defined, sp_get_prelocking_info()
function to get info about statement prelocking options
sql/sp_cache.h:
Prelocking-free SPs, post-review fixes: Amended the comments
sql/sp_head.cc:
Prelocking-free SPs, post-review fixes: Amend the comments, simplify the code that
attaches removes statement's prelocking tables.
sql/sql_base.cc:
Prelocking-free SPs, post-review fixes:
* Use a better defined sp_get_prelocking_info() function to get info about
statement prelocking options
* Don't activate prelocked mode for evaluation of SP arguments that use tables
but don't need prelocking.
sql/sql_class.cc:
Prelocking-free SPs, post-review fixes: Initialize THD members in the order they are declared.
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;
|
Prelocking-free SPs, post-review fixes:
* Don't activate prelocking mode for evaluating procedure arguments when it is not necessary.
* Code structure simplification and cleanup.
* Cleanup in .test files
mysql-test/r/sp-prelocking.result:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/r/sp-security.result:
Don't drop the table we're not using.
mysql-test/r/sp.result:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
mysql-test/t/sp-prelocking.test:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/t/sp-security.test:
Don't drop the table we're not using.
mysql-test/t/sp.test:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
sql/sp.cc:
New, better defined, sp_get_prelocking_info() function to get info about
statement prelocking options
sql/sp.h:
Prelocking-free SPs, post-review fixes: New, better defined, sp_get_prelocking_info()
function to get info about statement prelocking options
sql/sp_cache.h:
Prelocking-free SPs, post-review fixes: Amended the comments
sql/sp_head.cc:
Prelocking-free SPs, post-review fixes: Amend the comments, simplify the code that
attaches removes statement's prelocking tables.
sql/sql_base.cc:
Prelocking-free SPs, post-review fixes:
* Use a better defined sp_get_prelocking_info() function to get info about
statement prelocking options
* Don't activate prelocked mode for evaluation of SP arguments that use tables
but don't need prelocking.
sql/sql_class.cc:
Prelocking-free SPs, post-review fixes: Initialize THD members in the order they are declared.
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
|
|
|
|
Prelocking-free SPs, post-review fixes:
* Don't activate prelocking mode for evaluating procedure arguments when it is not necessary.
* Code structure simplification and cleanup.
* Cleanup in .test files
mysql-test/r/sp-prelocking.result:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/r/sp-security.result:
Don't drop the table we're not using.
mysql-test/r/sp.result:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
mysql-test/t/sp-prelocking.test:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/t/sp-security.test:
Don't drop the table we're not using.
mysql-test/t/sp.test:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
sql/sp.cc:
New, better defined, sp_get_prelocking_info() function to get info about
statement prelocking options
sql/sp.h:
Prelocking-free SPs, post-review fixes: New, better defined, sp_get_prelocking_info()
function to get info about statement prelocking options
sql/sp_cache.h:
Prelocking-free SPs, post-review fixes: Amended the comments
sql/sp_head.cc:
Prelocking-free SPs, post-review fixes: Amend the comments, simplify the code that
attaches removes statement's prelocking tables.
sql/sql_base.cc:
Prelocking-free SPs, post-review fixes:
* Use a better defined sp_get_prelocking_info() function to get info about
statement prelocking options
* Don't activate prelocked mode for evaluation of SP arguments that use tables
but don't need prelocking.
sql/sql_class.cc:
Prelocking-free SPs, post-review fixes: Initialize THD members in the order they are declared.
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
|
|
|
|
Prelocking-free SPs, post-review fixes:
* Don't activate prelocking mode for evaluating procedure arguments when it is not necessary.
* Code structure simplification and cleanup.
* Cleanup in .test files
mysql-test/r/sp-prelocking.result:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/r/sp-security.result:
Don't drop the table we're not using.
mysql-test/r/sp.result:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
mysql-test/t/sp-prelocking.test:
Prelocking-free SPs, post-review fixes:
Added comment, s/testdb/mysqltest/, fixed a wrong test (error wasnt reported because of known bug in mysqltestrun)
mysql-test/t/sp-security.test:
Don't drop the table we're not using.
mysql-test/t/sp.test:
Prelocking-free SPs, post-review fixes:
remove redundant "drop table if exists t3" statements
sql/sp.cc:
New, better defined, sp_get_prelocking_info() function to get info about
statement prelocking options
sql/sp.h:
Prelocking-free SPs, post-review fixes: New, better defined, sp_get_prelocking_info()
function to get info about statement prelocking options
sql/sp_cache.h:
Prelocking-free SPs, post-review fixes: Amended the comments
sql/sp_head.cc:
Prelocking-free SPs, post-review fixes: Amend the comments, simplify the code that
attaches removes statement's prelocking tables.
sql/sql_base.cc:
Prelocking-free SPs, post-review fixes:
* Use a better defined sp_get_prelocking_info() function to get info about
statement prelocking options
* Don't activate prelocked mode for evaluation of SP arguments that use tables
but don't need prelocking.
sql/sql_class.cc:
Prelocking-free SPs, post-review fixes: Initialize THD members in the order they are declared.
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
/*
|
|
|
|
Auxilary function that adds new element to the set of stored routines
|
|
|
|
used by statement.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
add_used_routine()
|
2005-12-07 10:27:17 +01:00
|
|
|
lex LEX representing statement
|
|
|
|
arena Arena in which memory for new element will be allocated
|
|
|
|
key Key for the hash representing set
|
|
|
|
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
|
|
|
|
|
|
|
NOTES
|
|
|
|
Will also add element to end of 'LEX::sroutines_list' list.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
TODO
|
|
|
|
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.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
TRUE - new element was added.
|
|
|
|
FALSE - element was not added (because it is already present in the set).
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
2005-07-09 19:51:59 +02:00
|
|
|
if (!hash_search(&lex->sroutines, (byte *)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) +
|
|
|
|
key->length);
|
|
|
|
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);
|
|
|
|
memcpy(rn->key.str, key->str, key->length);
|
|
|
|
my_hash_insert(&lex->sroutines, (byte *)rn);
|
|
|
|
lex->sroutines_list.link_in_list((byte *)rn, (byte **)&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
|
|
|
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01: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.
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_add_used_routine()
|
|
|
|
lex - LEX representing statement
|
|
|
|
arena - arena in which memory for new element of the set
|
|
|
|
will be allocated
|
|
|
|
rt - routine name
|
|
|
|
rt_type - routine type (one of TYPE_ENUM_PROCEDURE/...)
|
|
|
|
|
|
|
|
NOTES
|
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
|
|
|
|
|
|
|
To be friendly towards prepared statements one should pass
|
|
|
|
persistent arena as second argument.
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Remove routines which are only indirectly used by statement from
|
|
|
|
the set of routines used by this statement.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_remove_not_own_routines()
|
|
|
|
lex LEX representing statement
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
hash_delete(&lex->sroutines, (byte *)not_own_rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
*(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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Merge contents of two hashes representing sets of routines used
|
|
|
|
by statements or by other routines.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_update_sp_used_routines()
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
dst - hash to which elements should be added
|
|
|
|
src - hash from which elements merged
|
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
NOTE
|
|
|
|
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.
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
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
|
|
|
{
|
WL#2130: Table locking for stored FUNCTIONs
Collect all tables and SPs refered by a statement, and open all tables
with an implicit LOCK TABLES. Do find things refered by triggers and views,
we open them first (and then repeat this until nothing new is found), before
doing the actual lock tables.
mysql-test/r/information_schema.result:
Updated result for WL#2130.
mysql-test/r/lock.result:
Updated result for WL#2130.
mysql-test/r/sp-error.result:
Updated result for WL#2130.
mysql-test/r/sp.result:
Updated result for WL#2130.
mysql-test/r/view.result:
Updated result for WL#2130.
mysql-test/t/information_schema.test:
Disabled one test case due to a bug involving LOCK TABLES,
which shows up with WL#2130.
mysql-test/t/lock.test:
New error message with WL#2130. This change is under debate and might change
in the future, but will do for now.
mysql-test/t/sp-error.test:
Updated for WL#2130. Some tests are voided when table access does work from
functions.
mysql-test/t/sp.test:
Updated for WL#2130.
mysql-test/t/view.test:
Updated for WL#2130.
sql/item_func.cc:
We now have to set net.no_send_ok for functions too, with WL#2130.
sql/share/errmsg.txt:
Reused an error code since the old use was voided by WL#2130, but a new
one was needed instead (similar, but more specific restriction).
sql/sp.cc:
Fixed error handling and collection of used tables for WL#2130.
sql/sp.h:
Fixed error handling and collection of used tables for WL#2130.
sql/sp_head.cc:
Added support functions for collecting and merging hash tables and lists
of used tables from SPs and substatements, for WL#2130.
sql/sp_head.h:
Added support functions for collecting and merging hash tables and lists
of used tables from SPs and substatements, for WL#2130.
sql/sql_base.cc:
Changed the way table->query_id is tested and set during with locked tables
in effect. This makes some SP test cases work with WL#2130, but has a side
effect on some error cases with explicit LOCK TABLES. It's still debated if
this is the correct way, so it might change.
sql/sql_class.h:
Added flags for circumventing some interference between WL#2130 and mysql_make_view().
sql/sql_derived.cc:
Added some missing initializations. (Potential bugs.)
sql/sql_lex.cc:
Clear the new hash tables for WL#2130.
sql/sql_lex.h:
Added hash tables for procedures and tables too (as for functions), for WL#2130.
sql/sql_parse.cc:
WL#2130: Make table accesses from stored functions work by adding an implicit
LOCK TABLES around (most) executed statements. To do this, we have to go through
a loop where we collect all SPs and tables in mysql_execute_statement.
sql/sql_prepare.cc:
Cache both functions and procedures for WL#2130.
sql/sql_show.cc:
Added some missing initializations. (Potential bugs.)
sql/sql_view.cc:
Shortcut mysql_make_view() if thd->shortcut_make_view is true during
the pre-open phase for collecting tables in WL#2130. Otherwise, the
similar mechanism here causes interference.
sql/sql_yacc.yy:
For WL#2130, added caching of procedures and disallowed LOCK/UNLOCK TABLES in SPs.
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);
|
|
|
|
if (!hash_search(dst, (byte *)rt->key.str, rt->key.length))
|
|
|
|
my_hash_insert(dst, (byte *)rt);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-21 11:48:03 +01:00
|
|
|
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01: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.
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_update_stmt_used_routines()
|
2005-12-07 10:27:17 +01:00
|
|
|
thd Thread context
|
|
|
|
lex LEX representing statement
|
|
|
|
src Hash representing set from which routines will be added
|
|
|
|
belong_to_view Uppermost view which uses these routines, 0 if none
|
2005-07-09 19:51:59 +02:00
|
|
|
|
|
|
|
NOTE
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-15 01:56:09 +02:00
|
|
|
/*
|
|
|
|
Add contents of list representing set of routines to the set of
|
|
|
|
routines used by statement.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_update_stmt_used_routines()
|
2005-12-07 10:27:17 +01:00
|
|
|
thd Thread context
|
|
|
|
lex LEX representing statement
|
|
|
|
src List representing set from which routines will be added
|
|
|
|
belong_to_view Uppermost view which uses these routines, 0 if none
|
2005-09-15 01:56:09 +02:00
|
|
|
|
|
|
|
NOTE
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_cache_routines_and_add_tables_aux()
|
2005-07-30 10:19:57 +02:00
|
|
|
thd - thread context
|
|
|
|
lex - LEX representing statement
|
|
|
|
start - first routine from the list of routines to be cached
|
|
|
|
(this list defines mentioned sub-set).
|
|
|
|
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.
|
2005-10-26 15:34:57 +02:00
|
|
|
tabs_changed - Set to TRUE some tables were added, FALSE otherwise
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
NOTE
|
|
|
|
If some function is missing this won't be reported here.
|
|
|
|
Instead this fact will be discovered during query execution.
|
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
RETURN VALUE
|
2005-11-25 17:09:26 +01:00
|
|
|
0 - success
|
|
|
|
non-0 - failure
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
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,
|
2005-10-26 15:34:57 +02:00
|
|
|
bool first_no_prelock, bool *tabs_changed)
|
2003-03-02 19:17:41 +01:00
|
|
|
{
|
2005-10-26 15:34:57 +02:00
|
|
|
int ret= 0;
|
2005-12-06 14:25:12 +01:00
|
|
|
bool tabschnd= 0; /* Set if tables changed */
|
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
|
|
|
{
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_name name(rt->key.str, rt->key.length);
|
|
|
|
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-07-09 19:51:59 +02:00
|
|
|
name.m_name.str= strchr(name.m_qname.str, '.');
|
|
|
|
name.m_db.length= name.m_name.str - name.m_qname.str;
|
|
|
|
name.m_db.str= strmake_root(thd->mem_root, name.m_qname.str,
|
|
|
|
name.m_db.length);
|
|
|
|
name.m_name.str+= 1;
|
|
|
|
name.m_name.length= name.m_qname.length - name.m_db.length - 1;
|
|
|
|
|
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;
|
|
|
|
case SP_OPEN_TABLE_FAILED:
|
|
|
|
/*
|
|
|
|
Force it to attempt opening it again on subsequent calls;
|
|
|
|
otherwise we will get one error message the first time, and
|
|
|
|
then ER_SP_PROC_TABLE_CORRUPT (below) on subsequent tries.
|
|
|
|
*/
|
|
|
|
mysql_proc_table_exists= 1;
|
|
|
|
/* Fall through */
|
|
|
|
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.
|
|
|
|
*/
|
2005-11-25 17:09:26 +01:00
|
|
|
if (!thd->net.report_error)
|
|
|
|
{
|
|
|
|
char n[NAME_LEN*2+2];
|
|
|
|
|
|
|
|
/* 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);
|
2005-11-25 17:09:26 +01:00
|
|
|
tabschnd|=
|
2005-12-07 10:47:25 +01:00
|
|
|
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.
mysql-test/r/rpl_switch_stm_row_mixed.result:
testing BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog",
testing BUG#20930 "Mixed binlogging mode does not work with stored functions,
triggers, views.
testing BUG#20499 "mixed mode with temporary table breaks binlog".
I have carefully checked this big result file, it is correct.
mysql-test/t/disabled.def:
re-enabling test
mysql-test/t/rpl_switch_stm_row_mixed.test:
Test for BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog":
we test that it goes row-based, but only when needed;
without the bugfix, master and slave's data differed.
Test for BUG#20499 "mixed mode with temporary table breaks binlog":
without the bugfix, slave had 2 rows, not 3.
Test for BUG#20930 "Mixed binlogging mode does not work with stored
functions, triggers, views".
Making strings used more different, for easier tracking of "by which routine
was this binlog line generated".
Towards the end, an attempt to test mysqlbinlog on a binlog generated by
the mixed mode; attempt failed because of BUG#11312 and BUG#20929.
sql/item_create.cc:
fix for build without row-based replication
sql/set_var.cc:
cosmetic: in_sub_stmt is exactly meant to say if we are in stored
function/trigger, so better use it.
sql/sp.cc:
When a routine adds its tables to the top statement's tables, if this routine
needs row-based binlogging, mark the entire top statement as well.
Same for triggers.
Needed for making the mixed replication mode work with stored functions
and triggers.
sql/sp_head.cc:
new enum value for sp_head::m_flags, remembers if, when parsing the
routine, we found at least one element (UUID(), UDF) requiring row-based
binlogging.
sql/sp_head.h:
new enum value for sp_head::m_flags (see sp_head.cc).
An utility method, intended for attributes of a routine which need
to propagate upwards to the caller; so far only used for binlogging
information, but open to any other attribute.
sql/sql_base.cc:
For BUG#19630 "stored function inserting into two auto_increment
breaks statement-based binlog":
When we come to locking tables, we have collected all tables used by
functions, views and triggers, we detect if we're going to update two tables
having auto_increment columns. If yes, statement-based binlogging won't work
(Intvar_log_event records only one insert_id) so, if in mixed binlogging
mode, switch to row-based.
For making mixed mode work with stored functions using UUID/UDF:
when we come to locking tables, we have parsed the whole body so know if
some elements need row-based. Generation of row-based binlog events
depends on locked tables, so this is the good place to decide of the binlog
format.
sql/sql_class.h:
Fix for BUG#20499 "mixed mode with temporary table breaks binlog".
Making mixed mode work with stored functions/triggers: don't reset
back to statement-based if in executing a stored function/trigger.
sql/sql_lex.cc:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list, because
that boolean should not be affected when a SELECT reads the INFORMATION_SCHEMA
and thus implicitely parses a view or routine's body: this body may
contain needing-row-based components like UUID() but the SELECT on
INFORMATION_SCHEMA should not be affected by that and should not use
row-based; as Query_tables_list is backed-up/reset/restored when parsing
the view/routine's body, so does binlog_row_based_if_mixed and the
top SELECT is not affected.
sql/sql_lex.h:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list
(see sql_lex.cc)
sql/sql_parse.cc:
For the mixed mode to work with stored functions using UUID and UDF, we need
to move the switch-back-from-row-to-statement out of
mysql_execute_command() (which is executed for each statement, causing
the binlogging mode to change in the middle of the function, which would
not work)
The switch to row-based is now done in lock_tables(), no need to keep it
in mysql_execute_command(); in lock_tables() we also switch back from
row-based to statement-based (so in a stored procedure, all statements
have their binlogging mode). We must however keep a resetting in
mysql_reset_thd_for_next_command() as e.g. CREATE PROCEDURE does not call
lock_tables().
sql/sql_view.cc:
When a view's body needs row-based binlogging (e.g. the view is created
from SELECT UUID()), propagate this fact to the top st_lex.
sql/sql_yacc.yy:
use TRUE instead of 1, for binlog_row_based_if_mixed.
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-11-25 17:09:26 +01:00
|
|
|
if (tabs_changed) /* it can be NULL */
|
|
|
|
*tabs_changed= tabschnd;
|
2005-10-26 15:34:57 +02:00
|
|
|
DBUG_RETURN(ret);
|
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.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_cache_routines_and_add_tables()
|
2005-07-30 10:19:57 +02:00
|
|
|
thd - thread context
|
|
|
|
lex - LEX representing statement
|
|
|
|
first_no_prelock - If true, don't add tables or cache routines used by
|
|
|
|
the body of the first routine (i.e. *start)
|
2005-10-26 15:34:57 +02:00
|
|
|
tabs_changed - Set to TRUE some tables were added, FALSE otherwise
|
2005-07-30 10:19:57 +02:00
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
RETURN VALUE
|
2005-11-25 17:09:26 +01:00
|
|
|
0 - success
|
|
|
|
non-0 - failure
|
2005-07-09 19:51:59 +02:00
|
|
|
*/
|
|
|
|
|
2005-10-26 15:34:57 +02:00
|
|
|
int
|
|
|
|
sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock,
|
|
|
|
bool *tabs_changed)
|
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,
|
2005-10-26 15:34:57 +02:00
|
|
|
first_no_prelock, tabs_changed);
|
2005-07-09 19:51:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Add all routines used by view to the set of routines used by statement.
|
|
|
|
Add tables used by those routines to statement table list. Do the same
|
|
|
|
for all routines used by these routines.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_cache_routines_and_add_tables_for_view()
|
2005-12-07 10:27:17 +01:00
|
|
|
thd Thread context
|
|
|
|
lex LEX representing statement
|
|
|
|
view Table list element representing view
|
2005-12-07 10:47:25 +01:00
|
|
|
|
2005-10-26 15:34:57 +02:00
|
|
|
RETURN VALUE
|
2005-11-25 17:09:26 +01:00
|
|
|
0 - success
|
|
|
|
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());
|
2005-10-26 15:34:57 +02:00
|
|
|
return sp_cache_routines_and_add_tables_aux(thd, lex,
|
|
|
|
*last_cached_routine_ptr, FALSE,
|
|
|
|
NULL);
|
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.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_cache_routines_and_add_tables_for_triggers()
|
2005-12-07 10:27:17 +01:00
|
|
|
thd thread context
|
|
|
|
lex LEX respresenting statement
|
|
|
|
table Table list element for table with trigger
|
2005-10-26 15:34:57 +02:00
|
|
|
|
|
|
|
RETURN VALUE
|
2005-11-25 17:09:26 +01:00
|
|
|
0 - success
|
|
|
|
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;
|
2005-12-07 10:27:17 +01:00
|
|
|
Table_triggers_list *triggers= table->table->triggers;
|
|
|
|
if (add_used_routine(lex, thd->stmt_arena, &triggers->sroutines_key,
|
|
|
|
table->belong_to_view))
|
2005-07-09 19:51:59 +02:00
|
|
|
{
|
|
|
|
Sroutine_hash_entry **last_cached_routine_ptr=
|
|
|
|
(Sroutine_hash_entry **)lex->sroutines_list.next;
|
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
|
|
|
{
|
2005-07-19 18:06:49 +02:00
|
|
|
for (int j= 0; j < (int)TRG_ACTION_MAX; j++)
|
2005-07-28 15:10:14 +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.
mysql-test/r/rpl_switch_stm_row_mixed.result:
testing BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog",
testing BUG#20930 "Mixed binlogging mode does not work with stored functions,
triggers, views.
testing BUG#20499 "mixed mode with temporary table breaks binlog".
I have carefully checked this big result file, it is correct.
mysql-test/t/disabled.def:
re-enabling test
mysql-test/t/rpl_switch_stm_row_mixed.test:
Test for BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog":
we test that it goes row-based, but only when needed;
without the bugfix, master and slave's data differed.
Test for BUG#20499 "mixed mode with temporary table breaks binlog":
without the bugfix, slave had 2 rows, not 3.
Test for BUG#20930 "Mixed binlogging mode does not work with stored
functions, triggers, views".
Making strings used more different, for easier tracking of "by which routine
was this binlog line generated".
Towards the end, an attempt to test mysqlbinlog on a binlog generated by
the mixed mode; attempt failed because of BUG#11312 and BUG#20929.
sql/item_create.cc:
fix for build without row-based replication
sql/set_var.cc:
cosmetic: in_sub_stmt is exactly meant to say if we are in stored
function/trigger, so better use it.
sql/sp.cc:
When a routine adds its tables to the top statement's tables, if this routine
needs row-based binlogging, mark the entire top statement as well.
Same for triggers.
Needed for making the mixed replication mode work with stored functions
and triggers.
sql/sp_head.cc:
new enum value for sp_head::m_flags, remembers if, when parsing the
routine, we found at least one element (UUID(), UDF) requiring row-based
binlogging.
sql/sp_head.h:
new enum value for sp_head::m_flags (see sp_head.cc).
An utility method, intended for attributes of a routine which need
to propagate upwards to the caller; so far only used for binlogging
information, but open to any other attribute.
sql/sql_base.cc:
For BUG#19630 "stored function inserting into two auto_increment
breaks statement-based binlog":
When we come to locking tables, we have collected all tables used by
functions, views and triggers, we detect if we're going to update two tables
having auto_increment columns. If yes, statement-based binlogging won't work
(Intvar_log_event records only one insert_id) so, if in mixed binlogging
mode, switch to row-based.
For making mixed mode work with stored functions using UUID/UDF:
when we come to locking tables, we have parsed the whole body so know if
some elements need row-based. Generation of row-based binlog events
depends on locked tables, so this is the good place to decide of the binlog
format.
sql/sql_class.h:
Fix for BUG#20499 "mixed mode with temporary table breaks binlog".
Making mixed mode work with stored functions/triggers: don't reset
back to statement-based if in executing a stored function/trigger.
sql/sql_lex.cc:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list, because
that boolean should not be affected when a SELECT reads the INFORMATION_SCHEMA
and thus implicitely parses a view or routine's body: this body may
contain needing-row-based components like UUID() but the SELECT on
INFORMATION_SCHEMA should not be affected by that and should not use
row-based; as Query_tables_list is backed-up/reset/restored when parsing
the view/routine's body, so does binlog_row_based_if_mixed and the
top SELECT is not affected.
sql/sql_lex.h:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list
(see sql_lex.cc)
sql/sql_parse.cc:
For the mixed mode to work with stored functions using UUID and UDF, we need
to move the switch-back-from-row-to-statement out of
mysql_execute_command() (which is executed for each statement, causing
the binlogging mode to change in the middle of the function, which would
not work)
The switch to row-based is now done in lock_tables(), no need to keep it
in mysql_execute_command(); in lock_tables() we also switch back from
row-based to statement-based (so in a stored procedure, all statements
have their binlogging mode). We must however keep a resetting in
mysql_reset_thd_for_next_command() as e.g. CREATE PROCEDURE does not call
lock_tables().
sql/sql_view.cc:
When a view's body needs row-based binlogging (e.g. the view is created
from SELECT UUID()), propagate this fact to the top st_lex.
sql/sql_yacc.yy:
use TRUE instead of 1, for binlog_row_based_if_mixed.
2006-07-09 17:00:47 +02:00
|
|
|
sp_head *trigger_body= triggers->bodies[i][j];
|
|
|
|
if (trigger_body)
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01: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.
mysql-test/r/rpl_switch_stm_row_mixed.result:
testing BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog",
testing BUG#20930 "Mixed binlogging mode does not work with stored functions,
triggers, views.
testing BUG#20499 "mixed mode with temporary table breaks binlog".
I have carefully checked this big result file, it is correct.
mysql-test/t/disabled.def:
re-enabling test
mysql-test/t/rpl_switch_stm_row_mixed.test:
Test for BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog":
we test that it goes row-based, but only when needed;
without the bugfix, master and slave's data differed.
Test for BUG#20499 "mixed mode with temporary table breaks binlog":
without the bugfix, slave had 2 rows, not 3.
Test for BUG#20930 "Mixed binlogging mode does not work with stored
functions, triggers, views".
Making strings used more different, for easier tracking of "by which routine
was this binlog line generated".
Towards the end, an attempt to test mysqlbinlog on a binlog generated by
the mixed mode; attempt failed because of BUG#11312 and BUG#20929.
sql/item_create.cc:
fix for build without row-based replication
sql/set_var.cc:
cosmetic: in_sub_stmt is exactly meant to say if we are in stored
function/trigger, so better use it.
sql/sp.cc:
When a routine adds its tables to the top statement's tables, if this routine
needs row-based binlogging, mark the entire top statement as well.
Same for triggers.
Needed for making the mixed replication mode work with stored functions
and triggers.
sql/sp_head.cc:
new enum value for sp_head::m_flags, remembers if, when parsing the
routine, we found at least one element (UUID(), UDF) requiring row-based
binlogging.
sql/sp_head.h:
new enum value for sp_head::m_flags (see sp_head.cc).
An utility method, intended for attributes of a routine which need
to propagate upwards to the caller; so far only used for binlogging
information, but open to any other attribute.
sql/sql_base.cc:
For BUG#19630 "stored function inserting into two auto_increment
breaks statement-based binlog":
When we come to locking tables, we have collected all tables used by
functions, views and triggers, we detect if we're going to update two tables
having auto_increment columns. If yes, statement-based binlogging won't work
(Intvar_log_event records only one insert_id) so, if in mixed binlogging
mode, switch to row-based.
For making mixed mode work with stored functions using UUID/UDF:
when we come to locking tables, we have parsed the whole body so know if
some elements need row-based. Generation of row-based binlog events
depends on locked tables, so this is the good place to decide of the binlog
format.
sql/sql_class.h:
Fix for BUG#20499 "mixed mode with temporary table breaks binlog".
Making mixed mode work with stored functions/triggers: don't reset
back to statement-based if in executing a stored function/trigger.
sql/sql_lex.cc:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list, because
that boolean should not be affected when a SELECT reads the INFORMATION_SCHEMA
and thus implicitely parses a view or routine's body: this body may
contain needing-row-based components like UUID() but the SELECT on
INFORMATION_SCHEMA should not be affected by that and should not use
row-based; as Query_tables_list is backed-up/reset/restored when parsing
the view/routine's body, so does binlog_row_based_if_mixed and the
top SELECT is not affected.
sql/sql_lex.h:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list
(see sql_lex.cc)
sql/sql_parse.cc:
For the mixed mode to work with stored functions using UUID and UDF, we need
to move the switch-back-from-row-to-statement out of
mysql_execute_command() (which is executed for each statement, causing
the binlogging mode to change in the middle of the function, which would
not work)
The switch to row-based is now done in lock_tables(), no need to keep it
in mysql_execute_command(); in lock_tables() we also switch back from
row-based to statement-based (so in a stored procedure, all statements
have their binlogging mode). We must however keep a resetting in
mysql_reset_thd_for_next_command() as e.g. CREATE PROCEDURE does not call
lock_tables().
sql/sql_view.cc:
When a view's body needs row-based binlogging (e.g. the view is created
from SELECT UUID()), propagate this fact to the top st_lex.
sql/sql_yacc.yy:
use TRUE instead of 1, for binlog_row_based_if_mixed.
2006-07-09 17:00:47 +02:00
|
|
|
(void)trigger_body->
|
|
|
|
add_used_tables_to_table_list(thd, &lex->query_tables_last,
|
|
|
|
table->belong_to_view);
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_update_stmt_used_routines(thd, lex,
|
* 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.
mysql-test/r/rpl_switch_stm_row_mixed.result:
testing BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog",
testing BUG#20930 "Mixed binlogging mode does not work with stored functions,
triggers, views.
testing BUG#20499 "mixed mode with temporary table breaks binlog".
I have carefully checked this big result file, it is correct.
mysql-test/t/disabled.def:
re-enabling test
mysql-test/t/rpl_switch_stm_row_mixed.test:
Test for BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog":
we test that it goes row-based, but only when needed;
without the bugfix, master and slave's data differed.
Test for BUG#20499 "mixed mode with temporary table breaks binlog":
without the bugfix, slave had 2 rows, not 3.
Test for BUG#20930 "Mixed binlogging mode does not work with stored
functions, triggers, views".
Making strings used more different, for easier tracking of "by which routine
was this binlog line generated".
Towards the end, an attempt to test mysqlbinlog on a binlog generated by
the mixed mode; attempt failed because of BUG#11312 and BUG#20929.
sql/item_create.cc:
fix for build without row-based replication
sql/set_var.cc:
cosmetic: in_sub_stmt is exactly meant to say if we are in stored
function/trigger, so better use it.
sql/sp.cc:
When a routine adds its tables to the top statement's tables, if this routine
needs row-based binlogging, mark the entire top statement as well.
Same for triggers.
Needed for making the mixed replication mode work with stored functions
and triggers.
sql/sp_head.cc:
new enum value for sp_head::m_flags, remembers if, when parsing the
routine, we found at least one element (UUID(), UDF) requiring row-based
binlogging.
sql/sp_head.h:
new enum value for sp_head::m_flags (see sp_head.cc).
An utility method, intended for attributes of a routine which need
to propagate upwards to the caller; so far only used for binlogging
information, but open to any other attribute.
sql/sql_base.cc:
For BUG#19630 "stored function inserting into two auto_increment
breaks statement-based binlog":
When we come to locking tables, we have collected all tables used by
functions, views and triggers, we detect if we're going to update two tables
having auto_increment columns. If yes, statement-based binlogging won't work
(Intvar_log_event records only one insert_id) so, if in mixed binlogging
mode, switch to row-based.
For making mixed mode work with stored functions using UUID/UDF:
when we come to locking tables, we have parsed the whole body so know if
some elements need row-based. Generation of row-based binlog events
depends on locked tables, so this is the good place to decide of the binlog
format.
sql/sql_class.h:
Fix for BUG#20499 "mixed mode with temporary table breaks binlog".
Making mixed mode work with stored functions/triggers: don't reset
back to statement-based if in executing a stored function/trigger.
sql/sql_lex.cc:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list, because
that boolean should not be affected when a SELECT reads the INFORMATION_SCHEMA
and thus implicitely parses a view or routine's body: this body may
contain needing-row-based components like UUID() but the SELECT on
INFORMATION_SCHEMA should not be affected by that and should not use
row-based; as Query_tables_list is backed-up/reset/restored when parsing
the view/routine's body, so does binlog_row_based_if_mixed and the
top SELECT is not affected.
sql/sql_lex.h:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list
(see sql_lex.cc)
sql/sql_parse.cc:
For the mixed mode to work with stored functions using UUID and UDF, we need
to move the switch-back-from-row-to-statement out of
mysql_execute_command() (which is executed for each statement, causing
the binlogging mode to change in the middle of the function, which would
not work)
The switch to row-based is now done in lock_tables(), no need to keep it
in mysql_execute_command(); in lock_tables() we also switch back from
row-based to statement-based (so in a stored procedure, all statements
have their binlogging mode). We must however keep a resetting in
mysql_reset_thd_for_next_command() as e.g. CREATE PROCEDURE does not call
lock_tables().
sql/sql_view.cc:
When a view's body needs row-based binlogging (e.g. the view is created
from SELECT UUID()), propagate this fact to the top st_lex.
sql/sql_yacc.yy:
use TRUE instead of 1, for binlog_row_based_if_mixed.
2006-07-09 17:00:47 +02:00
|
|
|
&trigger_body->m_sroutines,
|
2005-12-07 10:27:17 +01:00
|
|
|
table->belong_to_view);
|
* 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.
mysql-test/r/rpl_switch_stm_row_mixed.result:
testing BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog",
testing BUG#20930 "Mixed binlogging mode does not work with stored functions,
triggers, views.
testing BUG#20499 "mixed mode with temporary table breaks binlog".
I have carefully checked this big result file, it is correct.
mysql-test/t/disabled.def:
re-enabling test
mysql-test/t/rpl_switch_stm_row_mixed.test:
Test for BUG#19630 "stored function inserting into two auto_increment breaks
statement-based binlog":
we test that it goes row-based, but only when needed;
without the bugfix, master and slave's data differed.
Test for BUG#20499 "mixed mode with temporary table breaks binlog":
without the bugfix, slave had 2 rows, not 3.
Test for BUG#20930 "Mixed binlogging mode does not work with stored
functions, triggers, views".
Making strings used more different, for easier tracking of "by which routine
was this binlog line generated".
Towards the end, an attempt to test mysqlbinlog on a binlog generated by
the mixed mode; attempt failed because of BUG#11312 and BUG#20929.
sql/item_create.cc:
fix for build without row-based replication
sql/set_var.cc:
cosmetic: in_sub_stmt is exactly meant to say if we are in stored
function/trigger, so better use it.
sql/sp.cc:
When a routine adds its tables to the top statement's tables, if this routine
needs row-based binlogging, mark the entire top statement as well.
Same for triggers.
Needed for making the mixed replication mode work with stored functions
and triggers.
sql/sp_head.cc:
new enum value for sp_head::m_flags, remembers if, when parsing the
routine, we found at least one element (UUID(), UDF) requiring row-based
binlogging.
sql/sp_head.h:
new enum value for sp_head::m_flags (see sp_head.cc).
An utility method, intended for attributes of a routine which need
to propagate upwards to the caller; so far only used for binlogging
information, but open to any other attribute.
sql/sql_base.cc:
For BUG#19630 "stored function inserting into two auto_increment
breaks statement-based binlog":
When we come to locking tables, we have collected all tables used by
functions, views and triggers, we detect if we're going to update two tables
having auto_increment columns. If yes, statement-based binlogging won't work
(Intvar_log_event records only one insert_id) so, if in mixed binlogging
mode, switch to row-based.
For making mixed mode work with stored functions using UUID/UDF:
when we come to locking tables, we have parsed the whole body so know if
some elements need row-based. Generation of row-based binlog events
depends on locked tables, so this is the good place to decide of the binlog
format.
sql/sql_class.h:
Fix for BUG#20499 "mixed mode with temporary table breaks binlog".
Making mixed mode work with stored functions/triggers: don't reset
back to statement-based if in executing a stored function/trigger.
sql/sql_lex.cc:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list, because
that boolean should not be affected when a SELECT reads the INFORMATION_SCHEMA
and thus implicitely parses a view or routine's body: this body may
contain needing-row-based components like UUID() but the SELECT on
INFORMATION_SCHEMA should not be affected by that and should not use
row-based; as Query_tables_list is backed-up/reset/restored when parsing
the view/routine's body, so does binlog_row_based_if_mixed and the
top SELECT is not affected.
sql/sql_lex.h:
fix for build without row-based replication.
binlog_row_based_if_mixed moves from st_lex to Query_tables_list
(see sql_lex.cc)
sql/sql_parse.cc:
For the mixed mode to work with stored functions using UUID and UDF, we need
to move the switch-back-from-row-to-statement out of
mysql_execute_command() (which is executed for each statement, causing
the binlogging mode to change in the middle of the function, which would
not work)
The switch to row-based is now done in lock_tables(), no need to keep it
in mysql_execute_command(); in lock_tables() we also switch back from
row-based to statement-based (so in a stored procedure, all statements
have their binlogging mode). We must however keep a resetting in
mysql_reset_thd_for_next_command() as e.g. CREATE PROCEDURE does not call
lock_tables().
sql/sql_view.cc:
When a view's body needs row-based binlogging (e.g. the view is created
from SELECT UUID()), propagate this fact to the top st_lex.
sql/sql_yacc.yy:
use TRUE instead of 1, for binlog_row_based_if_mixed.
2006-07-09 17:00:47 +02:00
|
|
|
trigger_body->propagate_attributes(lex);
|
Better approach for prelocking of tables for stored routines execution
and some SP-related cleanups.
- We don't have separate stage for calculation of list of tables
to be prelocked and doing implicit LOCK/UNLOCK any more.
Instead we calculate this list at open_tables() and do implicit
LOCK in lock_tables() (and UNLOCK in close_thread_tables()).
Also now we support cases when same table (with same alias) is
used several times in the same query in SP.
- Cleaned up execution of SP. Moved all common code which handles
LEX and does preparations before statement execution or complex
expression evaluation to auxilary sp_lex_keeper class. Now
all statements in SP (and corresponding instructions) that
evaluate expression which can contain subquery have their
own LEX.
mysql-test/r/lock.result:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/r/mysqldump.result:
Added dropping of view which is used in test to its beginning.
mysql-test/r/sp.result:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Replaced wrong results of test for bug #5240 with correct results after
fixing bug in handling of cursors.
mysql-test/t/lock.test:
Replaced wrong error code with the correct one after fixing bug in
SP-locking.
mysql-test/t/mysqldump.test:
Added dropping of view which is used in test to its beginning.
mysql-test/t/sp.test:
Added tests for improved SP-locking.
Temporarily disabled tests for SHOW PROCEDURE STATUS and alike
(Until Monty will allow to open mysql.proc under LOCK TABLES without
mentioning it in lock list).
Removed test for bug #1654 since we already test exactly this function
in one of SP-locking tests.
Removed comment about cursor's wrong behavior in test for bug #5240
after fixing bug which was its cause.
sql/item_func.cc:
Removed comment which is no longer true.
sql/mysql_priv.h:
Changed open_tables() signature.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sp.cc:
sp_find_procedure():
Added one more parameter which enforces cache only lookup.
sp_merge_hash():
Now uses its return value to indicate that first of two hashes changed
as result of merge.
sp_cache_routines():
This function caches all stored routines used in query now.
sql/sp.h:
- sp_find_procedure() now has one more parameter which enforces cache only
lookup.
- sp_merge_hash() now uses its return value to indicate that first of two
hashes changed as result of merge.
- sp_cache_routines() caches all stored routines now. So it does not need
third argument any more.
sql/sp_head.cc:
sp_head::sp_head():
Added initialization of new m_spfuns and m_spprocs members.
sp_head::execute():
Let us save/restore part of thread context which can be damaged by
execution of instructions.
sp_head::execute_function()/execute_procedure():
Now it is responsibility of caller to close tables used in
subqueries which are passed as routine parameters.
sp_head::restore_lex():
Let us accumulate information about routines used by this one
in new m_spfuns, m_spprocs hashes.
sp_lex_keeper::reset_lex_and_exec_core()
Main method of new auxilary sp_lex_keeper class to which instructions
delegate responsibility for handling LEX and preparations before
executing statement or calculating complex expression.
Since all instructions which calculate complex expression or execute
command now use sp_lex_keeper they have to implement
sp_instr::exec_core() method. Most of instruction specific logic
has moved from sp_instr::execute() to this new method.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sp_merge_table_list() became sp_head::merge_table_list() method. It
also treats sp_head::m_sptabs as multi-set of tables now.
sp_hash_to_table_list() became sp_head::add_used_tables_to_table_list().
It takes into account that sp_head::m_sptabs is multi-set and allocates
object into persistent arena of PS.
Removed sp_merge_table_hash(), sp_open_and_lock_tables(),
sp_unlock_tables(), sp_merge_routine_tables() methods since they are not
used by new prelocking mechanism.
Added sp_add_sp_tables_to_table_list() which serves for adding tables needed
by routines used in query to the query table list for prelocking.
sql/sp_head.h:
class sp_head:
- Added m_spfuns, m_spprocs members for storing names of routines used
by this routine.
- Added add_used_tables_to_table_list() method which allows to add
tables needed by this routine to query's table list.
- Converted sp_merge_table_list() to sp_head::merge_table_list() method.
- Changed semantics of THD::m_sptabs. Now it is multi-set which contains
only tables which are used by this routine and not routines that are
called from this one.
Removed sp_merge_routine_tables(), sp_merge_table_hash(),
sp_open_and_lock_tables(), sp_unlock_tables() calls since they are not
used for our prelocking list calculation.
Added auxilary sp_lex_keeper class to which instructions delegate
responsibility for handling LEX and preparations before executing
statement or calculating complex expression. This class uses
new sp_instr::exec_core() method which is responsible for executing
instruction's core function after all preparations were made.
All instructions which hold and calculate complex expression now have
their own LEX (by aggregating sp_lex_keeper instance). sp_instr_stmt
now uses sp_lex_keeper too.
Removed sp_instr_set_user_var class which is no longer used, because
nowdays we allow execution of statements in stored functions and
triggers.
sql/sp_rcontext.cc:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sp_rcontext.h:
Now sp_cursor holds pointer to sp_lex_keeper instead of LEX.
sql/sql_acl.cc:
acl_init(), grant_init():
Now we use simple_open_n_lock_tables() instead of explicit
calls to open_tables() and mysql_lock_tables().
sql/sql_base.cc:
Implemented support for execution of statements in "prelocked" mode.
When we have statement which uses stored routines explicitly or
implicitly (via views or triggers) we have to open and lock all tables
for these routines at the same time as tables for the main statement.
In fact we have to do implicit LOCK TABLES at the begining of such
statement and implict UNLOCK TABLES at its end. We call such mode
"prelocked".
When open_tables() is called for the statement tables which are needed
for execution of routines used by it are added to its tables list
(this process also caches all routines used). Implicit use of routines
is discovered when we open view or table with trigger and apropriate
tables are added to the table list at this moment. Statement which has
such extra tables in its list (well actually any that uses functions)
is marked as requiring prelocked mode for its execution.
When lock_tables() sees such statement it will issue implicit LOCK TABLES
for this extended table list instead of doing usual locking, it will also
set THD::prelocked_mode to indicate that we are in prelocked mode.
When open_tables()/lock_tables() are called for statement of stored
routine (substatement), they notice that we are running in prelocked mode
and use one of prelocked tables from those that are not used by upper
levels of execution.
close_thread_tables() for substatement won't really close tables used
but will mark them as free for reuse instead.
Finally when close_thread_tables() is called for the main statement it
really unlocks and closes all tables used.
Everything will work even if one uses such statement under real LOCK
TABLES (we are simply not doing implicit LOCK/UNLOCK in this case).
sql/sql_class.cc:
Added initialization of THD::prelocked_mode member.
sql/sql_class.h:
- Added prelocked_mode_type enum and THD::prelocked_mode member
which are used for indication whenever "prelocked mode" is on
(i.e. that statement uses stored routines and is executed under
implicit LOCK TABLES).
- Removed THD::shortcut_make_view which is no longer needed.
We use TABLE_LIST::prelocking_placeholder for the same purprose
now.
sql/sql_handler.cc:
Changed open_tables() invocation.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_lex.cc:
lex_start():
Added initialization of LEX::query_tables_own_last.
Unused LEX::sptabs member was removed.
st_lex::unlink_first_table()/link_first_table_back():
We should update LEX::query_tables_last properly if table list
contains(ed) only one element.
sql/sql_lex.h:
LEX:
- Removed sptabs member since it is no longer used.
- Added query_tables_own_last member, which if non-0 indicates that
statement requires prelocking (implicit LOCK TABLES) for its execution
and points to last own element in query table list. If it is zero
then this query does not need prelocking.
- Added requires_prelocking(), mark_as_requiring_prelocking(),
first_not_own_table() inline methods to incapsulate and simplify
usage of this new member.
sql/sql_parse.cc:
dispatch_command():
To properly leave prelocked mode when needed we should call
close_thread_tables() even if there are no open tables.
mysql_execute_command():
- Removed part of function which were responsible for doing implicit
LOCK TABLES before statement execution if statement used stored
routines (and doing UNLOCK TABLES at the end).
Now we do all this in open_tables()/lock_tables()/close_thread_tables()
instead.
- It is also sensible to reset errors before execution of statement
which uses routines.
- SQLCOM_DO, SQLCOM_SET_OPTION, SQLCOM_CALL
We should always try to open tables because even if statement has empty
table list, it can call routines using tables, which should be preopened
before statement execution.
- SQLCOM_CALL
We should not look up routine called in mysql.proc, since it should be
already cached by this moment by open_tables() call.
- SQLCOM_LOCK_TABLES
it is better to use simple_open_n_lock_tables() since we want to avoid
materialization of derived tables for this command.
sql/sql_prepare.cc:
mysql_test_update():
Changed open_tables() invocations. Now its 2nd parameter is in/out
since it can add elements to table list.
check_prepared_statement():
Since now we cache all routines used by statement in open_tables() we
don't need to do it explicitly.
mysql_stmt_prepare():
Now we should call close_thread_tables() when THD::lex points to the
LEX of statement which opened tables.
reset_stmt_for_execute():
Commented why we are resetting all tables in table list.
sql/sql_trigger.h:
Table_triggers_list::process_triggers():
We should surpress sending of ok packet when we are calling trigger's
routine, since now we allow statements in them.
sql/sql_update.cc:
Changed open_tables() invocations.
Now its 2nd parameter is in/out since it can add elements to table list.
sql/sql_view.cc:
mysql_make_view():
- Removed handling of routines used in view. Instead we add tables which
are needed for their execution to statement's table list in
open_tables().
- Now we use TABLE_LIST::prelocking_placeholder instead of
THD::shortcut_make_view for indicating that view is opened
only to discover which tables and routines it uses (this happens
when we build extended table list for prelocking). Also now we try
to avoid to modify main LEX in this case (except of its table list).
- Corrected small error we added tables to the table list of the main
LEX without updating its query_tables_last member properly.
sql/sql_yacc.yy:
Now each expression which is used in SP statements and can contain
subquery has its own LEX. This LEX is stored in corresponding sp_instr
object and used along with Item tree for expression calculation.
We don't need sp_instr_set_user_var() anymore since now we allow
execution of statements in stored functions and triggers.
sql/table.h:
Added TABLE_LIST::prelocking_placeholder member for distinguishing
elements of table list which does not belong to the statement itself
and added there only for prelocking (as they are to be used by routines
called by this statement).
sql/tztime.cc:
my_tz_init():
Now we use more simplier simple_open_n_lock_tables() call instead of
open_tables()/lock_tables() pair.
2005-03-04 14:35:28 +01:00
|
|
|
}
|
2005-07-28 15:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2005-10-26 15:34:57 +02:00
|
|
|
ret= sp_cache_routines_and_add_tables_aux(thd, lex,
|
|
|
|
*last_cached_routine_ptr,
|
|
|
|
FALSE, NULL);
|
2003-03-02 19:17:41 +01:00
|
|
|
}
|
2005-10-26 15:34:57 +02:00
|
|
|
return ret;
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
|
2005-07-09 19:51:59 +02:00
|
|
|
|
2004-06-09 14:19:43 +02:00
|
|
|
/*
|
|
|
|
* Generates the CREATE... string from the table information.
|
|
|
|
* Returns TRUE on success, FALSE on (alloc) failure.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
create_string(THD *thd, String *buf,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
int type,
|
2004-03-11 17:18:59 +01:00
|
|
|
sp_name *name,
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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)
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
{
|
2004-06-09 14:19:43 +02:00
|
|
|
/* Make some room to begin with */
|
|
|
|
if (buf->alloc(100 + name->m_qname.length + 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);
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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 "));
|
2004-06-09 14:19:43 +02:00
|
|
|
append_identifier(thd, buf, name->m_name.str, name->m_name.length);
|
|
|
|
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
|
|
|
}
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
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;
|
In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to
make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
Docs/sp-imp-spec.txt:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
mysql-test/r/sp.result:
New characteristics tests.
mysql-test/t/sp.test:
New characteristics tests.
scripts/mysql_create_system_tables.sh:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
scripts/mysql_fix_privilege_tables.sql:
Separated the definitions string of the procedure into different columns
in the mysql.proc schema.
sql/sp.cc:
Separated the definitions string of the procedure into different columns.
Rewrote much of the code related this (have a assemble the definition
string from its different parts now) and the way characteristics are now
handled, in order to make ALTER actually work.
sql/sp.h:
Changed prototypes.
sql/sp_head.cc:
Rewrote much of the code related to the new mysql.proc schema with separate
definition fields (have to assemble the definition string from its different
parts now) and the way characteristics are now handled, in order to make ALTER
actually work.
sql/sp_head.h:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
sql/sql_yacc.yy:
Separated the different parts of the definition strings: name, parameters,
return type (for functions) and body.
This is ugly and messy; hopefully there's a more elegant way to do this
when the new parser is installed.
2003-12-12 14:05:29 +01:00
|
|
|
}
|
2004-03-11 17:18:59 +01:00
|
|
|
|
|
|
|
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Change the current database if needed.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_use_new_db()
|
|
|
|
thd thread handle
|
|
|
|
|
|
|
|
new_db new database name (a string and its length)
|
|
|
|
|
|
|
|
old_db [IN] str points to a buffer where to store the old
|
|
|
|
database, length contains the size of the buffer
|
|
|
|
[OUT] if old db was not NULL, its name is copied
|
|
|
|
to the buffer pointed at by str and length is updated
|
|
|
|
accordingly. Otherwise str[0] is set to '\0' and length
|
|
|
|
is set to 0. The out parameter should be used only if
|
|
|
|
the database name has been changed (see dbchangedp).
|
|
|
|
|
|
|
|
dbchangedp [OUT] is set to TRUE if the current database is changed,
|
|
|
|
FALSE otherwise. A database is not changed if the old
|
|
|
|
name is the same as the new one, both names are empty,
|
|
|
|
or an error has occurred.
|
|
|
|
|
|
|
|
RETURN VALUE
|
|
|
|
0 success
|
|
|
|
1 access denied or out of memory (the error message is
|
|
|
|
set in THD)
|
|
|
|
*/
|
2004-03-11 17:18:59 +01:00
|
|
|
|
|
|
|
int
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
sp_use_new_db(THD *thd, LEX_STRING new_db, LEX_STRING *old_db,
|
2004-06-08 18:41:18 +02:00
|
|
|
bool no_access_check, bool *dbchangedp)
|
2004-03-11 17:18:59 +01:00
|
|
|
{
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
int ret;
|
|
|
|
static char empty_c_string[1]= {0}; /* used for not defined db */
|
2004-03-11 17:18:59 +01:00
|
|
|
DBUG_ENTER("sp_use_new_db");
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
DBUG_PRINT("enter", ("newdb: %s", new_db.str));
|
2004-03-11 17:18:59 +01:00
|
|
|
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
/*
|
|
|
|
Set new_db to an empty string if it's NULL, because mysql_change_db
|
|
|
|
requires a non-NULL argument.
|
|
|
|
new_db.str can be NULL only if we're restoring the old database after
|
|
|
|
execution of a stored procedure and there were no current database
|
|
|
|
selected. The stored procedure itself must always have its database
|
|
|
|
initialized.
|
|
|
|
*/
|
|
|
|
if (new_db.str == NULL)
|
|
|
|
new_db.str= empty_c_string;
|
|
|
|
|
|
|
|
if (thd->db)
|
2004-03-11 17:18:59 +01:00
|
|
|
{
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
old_db->length= (strmake(old_db->str, thd->db, old_db->length) -
|
|
|
|
old_db->str);
|
2004-03-11 17:18:59 +01:00
|
|
|
}
|
|
|
|
else
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
{
|
|
|
|
old_db->str[0]= '\0';
|
|
|
|
old_db->length= 0;
|
2004-03-11 17:18:59 +01:00
|
|
|
}
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
|
|
|
|
/* Don't change the database if the new name is the same as the old one. */
|
|
|
|
if (my_strcasecmp(system_charset_info, old_db->str, new_db.str) == 0)
|
2004-03-11 17:18:59 +01:00
|
|
|
{
|
2004-06-08 18:41:18 +02:00
|
|
|
*dbchangedp= FALSE;
|
2004-03-11 17:18:59 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
ret= mysql_change_db(thd, new_db.str, no_access_check);
|
|
|
|
|
|
|
|
*dbchangedp= ret == 0;
|
|
|
|
DBUG_RETURN(ret);
|
2004-03-11 17:18:59 +01:00
|
|
|
}
|
A fix and a test case for
Bug#19022 "Memory bug when switching db during trigger execution"
Bug#17199 "Problem when view calls function from another database."
Bug#18444 "Fully qualified stored function names don't work correctly in
SELECT statements"
Documentation note: this patch introduces a change in behaviour of prepared
statements.
This patch adds a few new invariants with regard to how THD::db should
be used. These invariants should be preserved in future:
- one should never refer to THD::db by pointer and always make a deep copy
(strmake, strdup)
- one should never compare two databases by pointer, but use strncmp or
my_strncasecmp
- TABLE_LIST object table->db should be always initialized in the parser or
by creator of the object.
For prepared statements it means that if the current database is changed
after a statement is prepared, the database that was current at prepare
remains active. This also means that you can not prepare a statement that
implicitly refers to the current database if the latter is not set.
This is not documented, and therefore needs documentation. This is NOT a
change in behavior for almost all SQL statements except:
- ALTER TABLE t1 RENAME t2
- OPTIMIZE TABLE t1
- ANALYZE TABLE t1
- TRUNCATE TABLE t1 --
until this patch t1 or t2 could be evaluated at the first execution of
prepared statement.
CURRENT_DATABASE() still works OK and is evaluated at every execution
of prepared statement.
Note, that in stored routines this is not an issue as the default
database is the database of the stored procedure and "use" statement
is prohibited in stored routines.
This patch makes obsolete the use of check_db_used (it was never used in the
old code too) and all other places that check for table->db and assign it
from THD::db if it's NULL, except the parser.
How this patch was created: THD::{db,db_length} were replaced with a
LEX_STRING, THD::db. All the places that refer to THD::{db,db_length} were
manually checked and:
- if the place uses thd->db by pointer, it was fixed to make a deep copy
- if a place compared two db pointers, it was fixed to compare them by value
(via strcmp/my_strcasecmp, whatever was approproate)
Then this intermediate patch was used to write a smaller patch that does the
same thing but without a rename.
TODO in 5.1:
- remove check_db_used
- deploy THD::set_db in mysql_change_db
See also comments to individual files.
mysql-test/r/create.result:
Modify the result file: a database can never be NULL.
mysql-test/r/ps.result:
Update test results (Bug#17199 et al)
mysql-test/r/sp.result:
Update test results (Bug#17199 et al)
mysql-test/t/create.test:
Update the id of the returned error.
mysql-test/t/ps.test:
Add test coverage for prepared statements and current database. In scope of
work on Bug#17199 "Problem when view calls function from another database."
mysql-test/t/sp.test:
Add a test case for Bug#17199 "Problem when view calls function from another
database." and Bug#18444 "Fully qualified stored function names don't work
correctly in SELECT statements". Test a complementary problem.
sql/item_strfunc.cc:
Touch the code that reads thd->db (cleanup).
sql/log_event.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/slave.h:
Remove a declaration for a method that is used only in one module.
sql/sp.cc:
Rewrite sp_use_new_db: this is a cleanup that I needed in order to understand
this function and ensure that it has no bugs.
sql/sp.h:
Add a new declaration for sp_use_new_db (uses LEX_STRINGs) and a comment.
sql/sp_head.cc:
- drop sp_name_current_db_new - a creator of sp_name class that was used
when sp_name was created for an identifier without an explicitly initialized
database. Now we pass thd->db to constructor of sp_name right in the
parser.
- rewrite sp_head::init_strings: name->m_db is always set now
- use the new variant of sp_use_new_db
- we don't need to update thd->db with SP MEM_ROOT pointer anymore when
parsing a stored procedure, as noone will refer to it (yes!)
sql/sp_head.h:
- remove unneded methods and members
sql/sql_class.h:
- introduce 3 THD methods to work with THD::db:
.set_db to assign the current database
.reset_db to reset the current database (temporarily) or set it to NULL
.opt_copy_db_to - to deep-copy thd->db to a pointer if it's not NULL
sql/sql_db.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_insert.cc:
- replace checks with asserts: table_list->db must be always set in the parser.
sql/sql_lex.h:
- add a comment
sql/sql_parse.cc:
- implement the invariant described in the changeset comment.
- remove juggling with lex->sphead in SQLCOM_CREATE_PROCEDURE:
now db_load_routine uses its own LEX object and doesn't damage the main
LEX.
- add DBUG_ASSERT(0) to unused "check_db_used"
sql/sql_table.cc:
- replace a check with an assert (table_ident->db)
sql/sql_trigger.cc:
While we are at it, replace direct access to thd->db with a method.
Should simplify future conversion of THD::db to LEX_STRING.
sql/sql_udf.cc:
- use thd->set_db instead of direct modification of to thd->db
sql/sql_view.cc:
- replace a check with an assert (view->db)
sql/sql_yacc.yy:
- make sure that we always copy table->db or name->db or ident->db or
select_lex->db from thd->db if the former is not set. If thd->db
is not set but is accessed, return an error.
sql/tztime.cc:
- be nice, never copy thd->db by pointer.
2006-06-26 22:47:52 +02:00
|
|
|
|