Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
/* Copyright (C) 2002 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
2005-06-05 16:20:22 +02:00
|
|
|
#include "mysql_priv.h"
|
2005-05-27 12:03:37 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
#include "sp_head.h"
|
2002-12-12 13:14:23 +01:00
|
|
|
#include "sp.h"
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
#include "sp_pcontext.h"
|
|
|
|
#include "sp_rcontext.h"
|
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
|
|
|
#include "sp_cache.h"
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2006-01-05 23:47:49 +01:00
|
|
|
/*
|
|
|
|
Sufficient max length of printed destinations and frame offsets (all uints).
|
|
|
|
*/
|
|
|
|
#define SP_INSTR_UINT_MAXLEN 8
|
|
|
|
#define SP_STMT_PRINT_MAXLEN 40
|
|
|
|
|
|
|
|
|
2006-01-11 00:07:40 +01:00
|
|
|
#include <my_user.h>
|
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
extern "C" uchar *sp_table_key(const uchar *ptr, size_t *plen, my_bool first);
|
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
Item_result
|
|
|
|
sp_map_result_type(enum enum_field_types type)
|
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
switch (type) {
|
Bug#12976 (stored procedures local variables of type bit)
Before this change, a local variables in stored procedures / stored functions
or triggers, when declared with a type of bit(N), would not evaluate their
value properly.
The problem was that the data was incorrectly typed as a string,
causing for example bit b'1', implemented as a byte 0x01, to be interpreted
as a string starting with the character 0x01. This later would cause
implicit conversions to integers or booleans to fail.
The root cause of this problem was an incorrect translation between field
types, like bit(N), and internal types used when representing values in Item
objects.
Also, before this change, the function HEX() would sometime print extra "0"
characters when invoked with bit(N) values.
With this fix, the type translation (sp_map_result_type, sp_map_item_type)
has been changed so that bit(N) fields are represented with integer values.
A consequence is that, for the function HEX(), when called with a stored
procedure local variable of type bit(N) as argument, HEX() is provided with an
integer instead of a string, and therefore does not print "0" padding.
A test case for Bug 12976 was present in the test suite, and has been updated.
mysql-test/r/sp-vars.result:
Local stored procedure variables of type bit(N) are integer values.
mysql-test/t/sp-vars.test:
Local stored procedure variables of type bit(N) are integer values.
sql/sp_head.cc:
Local stored procedure variables of type bit(N) are integer values.
2007-02-07 00:01:22 +01:00
|
|
|
case MYSQL_TYPE_BIT:
|
2003-02-26 19:22:29 +01:00
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
return INT_RESULT;
|
|
|
|
case MYSQL_TYPE_DECIMAL:
|
2005-02-08 23:50:45 +01:00
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
|
|
|
return DECIMAL_RESULT;
|
2003-02-26 19:22:29 +01:00
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
return REAL_RESULT;
|
|
|
|
default:
|
|
|
|
return STRING_RESULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
Item::Type
|
|
|
|
sp_map_item_type(enum enum_field_types type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
Bug#12976 (stored procedures local variables of type bit)
Before this change, a local variables in stored procedures / stored functions
or triggers, when declared with a type of bit(N), would not evaluate their
value properly.
The problem was that the data was incorrectly typed as a string,
causing for example bit b'1', implemented as a byte 0x01, to be interpreted
as a string starting with the character 0x01. This later would cause
implicit conversions to integers or booleans to fail.
The root cause of this problem was an incorrect translation between field
types, like bit(N), and internal types used when representing values in Item
objects.
Also, before this change, the function HEX() would sometime print extra "0"
characters when invoked with bit(N) values.
With this fix, the type translation (sp_map_result_type, sp_map_item_type)
has been changed so that bit(N) fields are represented with integer values.
A consequence is that, for the function HEX(), when called with a stored
procedure local variable of type bit(N) as argument, HEX() is provided with an
integer instead of a string, and therefore does not print "0" padding.
A test case for Bug 12976 was present in the test suite, and has been updated.
mysql-test/r/sp-vars.result:
Local stored procedure variables of type bit(N) are integer values.
mysql-test/t/sp-vars.test:
Local stored procedure variables of type bit(N) are integer values.
sql/sp_head.cc:
Local stored procedure variables of type bit(N) are integer values.
2007-02-07 00:01:22 +01:00
|
|
|
case MYSQL_TYPE_BIT:
|
2005-12-07 15:01:17 +01:00
|
|
|
case MYSQL_TYPE_TINY:
|
|
|
|
case MYSQL_TYPE_SHORT:
|
|
|
|
case MYSQL_TYPE_LONG:
|
|
|
|
case MYSQL_TYPE_LONGLONG:
|
|
|
|
case MYSQL_TYPE_INT24:
|
|
|
|
return Item::INT_ITEM;
|
|
|
|
case MYSQL_TYPE_DECIMAL:
|
|
|
|
case MYSQL_TYPE_NEWDECIMAL:
|
|
|
|
return Item::DECIMAL_ITEM;
|
|
|
|
case MYSQL_TYPE_FLOAT:
|
|
|
|
case MYSQL_TYPE_DOUBLE:
|
|
|
|
return Item::REAL_ITEM;
|
|
|
|
default:
|
|
|
|
return Item::STRING_ITEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-12-07 15:01:17 +01:00
|
|
|
Return a string representation of the Item value.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread handle
|
|
|
|
@param str string buffer for representation of the value
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
|
|
|
If the item has a string result type, the string is escaped
|
|
|
|
according to its character set.
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
NULL on error
|
|
|
|
@retval
|
|
|
|
non-NULL a pointer to valid a valid string on success
|
2005-12-07 15:01:17 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
static String *
|
2006-11-09 11:27:34 +01:00
|
|
|
sp_get_item_value(THD *thd, Item *item, String *str)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
switch (item->result_type()) {
|
|
|
|
case REAL_RESULT:
|
|
|
|
case INT_RESULT:
|
|
|
|
case DECIMAL_RESULT:
|
2007-10-21 17:37:37 +02:00
|
|
|
if (item->field_type() != MYSQL_TYPE_BIT)
|
|
|
|
return item->val_str(str);
|
|
|
|
else {/* Bit type is handled as binary string */}
|
2005-12-07 15:01:17 +01:00
|
|
|
case STRING_RESULT:
|
|
|
|
{
|
|
|
|
String *result= item->val_str(str);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
return NULL;
|
|
|
|
|
2006-01-20 13:59:22 +01:00
|
|
|
{
|
|
|
|
char buf_holder[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
String buf(buf_holder, sizeof(buf_holder), result->charset());
|
2006-11-09 11:27:34 +01:00
|
|
|
CHARSET_INFO *cs= thd->variables.character_set_client;
|
2006-01-20 13:59:22 +01:00
|
|
|
|
|
|
|
/* We must reset length of the buffer, because of String specificity. */
|
|
|
|
buf.length(0);
|
|
|
|
|
|
|
|
buf.append('_');
|
|
|
|
buf.append(result->charset()->csname);
|
2006-11-09 11:27:34 +01:00
|
|
|
if (cs->escape_with_backslash_is_dangerous)
|
2006-03-21 14:35:49 +01:00
|
|
|
buf.append(' ');
|
2006-11-09 11:27:34 +01:00
|
|
|
append_query_string(cs, result, &buf);
|
2006-01-20 13:59:22 +01:00
|
|
|
str->copy(buf);
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case ROW_RESULT:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Returns a combination of:
|
|
|
|
- sp_head::MULTI_RESULTS: added if the 'cmd' is a command that might
|
|
|
|
result in multiple result sets being sent back.
|
|
|
|
- sp_head::CONTAINS_DYNAMIC_SQL: added if 'cmd' is one of PREPARE,
|
|
|
|
EXECUTE, DEALLOCATE.
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint
|
|
|
|
sp_get_flags_for_command(LEX *lex)
|
2004-08-06 13:47:01 +02:00
|
|
|
{
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
uint flags;
|
|
|
|
|
|
|
|
switch (lex->sql_command) {
|
|
|
|
case SQLCOM_SELECT:
|
|
|
|
if (lex->result)
|
|
|
|
{
|
|
|
|
flags= 0; /* This is a SELECT with INTO clause */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthrough */
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_ANALYZE:
|
2006-08-23 15:50:06 +02:00
|
|
|
case SQLCOM_BACKUP_TABLE:
|
2005-12-03 15:02:09 +01:00
|
|
|
case SQLCOM_OPTIMIZE:
|
|
|
|
case SQLCOM_PRELOAD_KEYS:
|
|
|
|
case SQLCOM_ASSIGN_TO_KEYCACHE:
|
2004-08-30 14:52:21 +02:00
|
|
|
case SQLCOM_CHECKSUM:
|
2005-12-03 15:02:09 +01:00
|
|
|
case SQLCOM_CHECK:
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_HA_READ:
|
2006-08-23 15:50:06 +02:00
|
|
|
case SQLCOM_SHOW_AUTHORS:
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_SHOW_BINLOGS:
|
|
|
|
case SQLCOM_SHOW_BINLOG_EVENTS:
|
|
|
|
case SQLCOM_SHOW_CHARSETS:
|
|
|
|
case SQLCOM_SHOW_COLLATIONS:
|
|
|
|
case SQLCOM_SHOW_COLUMN_TYPES:
|
2006-08-23 15:50:06 +02:00
|
|
|
case SQLCOM_SHOW_CONTRIBUTORS:
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_SHOW_CREATE:
|
|
|
|
case SQLCOM_SHOW_CREATE_DB:
|
|
|
|
case SQLCOM_SHOW_CREATE_FUNC:
|
|
|
|
case SQLCOM_SHOW_CREATE_PROC:
|
2006-03-15 18:21:59 +01:00
|
|
|
case SQLCOM_SHOW_CREATE_EVENT:
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
case SQLCOM_SHOW_CREATE_TRIGGER:
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_SHOW_DATABASES:
|
|
|
|
case SQLCOM_SHOW_ERRORS:
|
|
|
|
case SQLCOM_SHOW_FIELDS:
|
2006-08-23 15:50:06 +02:00
|
|
|
case SQLCOM_SHOW_FUNC_CODE:
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_SHOW_GRANTS:
|
2005-11-07 16:25:06 +01:00
|
|
|
case SQLCOM_SHOW_ENGINE_STATUS:
|
|
|
|
case SQLCOM_SHOW_ENGINE_LOGS:
|
|
|
|
case SQLCOM_SHOW_ENGINE_MUTEX:
|
2006-08-23 15:50:06 +02:00
|
|
|
case SQLCOM_SHOW_EVENTS:
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_SHOW_KEYS:
|
|
|
|
case SQLCOM_SHOW_MASTER_STAT:
|
|
|
|
case SQLCOM_SHOW_NEW_MASTER:
|
|
|
|
case SQLCOM_SHOW_OPEN_TABLES:
|
|
|
|
case SQLCOM_SHOW_PRIVILEGES:
|
|
|
|
case SQLCOM_SHOW_PROCESSLIST:
|
2006-08-23 15:50:06 +02:00
|
|
|
case SQLCOM_SHOW_PROC_CODE:
|
2004-08-06 13:47:01 +02:00
|
|
|
case SQLCOM_SHOW_SLAVE_HOSTS:
|
|
|
|
case SQLCOM_SHOW_SLAVE_STAT:
|
|
|
|
case SQLCOM_SHOW_STATUS:
|
|
|
|
case SQLCOM_SHOW_STATUS_FUNC:
|
|
|
|
case SQLCOM_SHOW_STATUS_PROC:
|
|
|
|
case SQLCOM_SHOW_STORAGE_ENGINES:
|
|
|
|
case SQLCOM_SHOW_TABLES:
|
|
|
|
case SQLCOM_SHOW_VARIABLES:
|
|
|
|
case SQLCOM_SHOW_WARNS:
|
2005-12-02 22:59:45 +01:00
|
|
|
case SQLCOM_REPAIR:
|
|
|
|
case SQLCOM_RESTORE_TABLE:
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
flags= sp_head::MULTI_RESULTS;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
EXECUTE statement may return a result set, but doesn't have to.
|
|
|
|
We can't, however, know it in advance, and therefore must add
|
|
|
|
this statement here. This is ok, as is equivalent to a result-set
|
|
|
|
statement within an IF condition.
|
|
|
|
*/
|
|
|
|
case SQLCOM_EXECUTE:
|
|
|
|
flags= sp_head::MULTI_RESULTS | sp_head::CONTAINS_DYNAMIC_SQL;
|
|
|
|
break;
|
|
|
|
case SQLCOM_PREPARE:
|
|
|
|
case SQLCOM_DEALLOCATE_PREPARE:
|
|
|
|
flags= sp_head::CONTAINS_DYNAMIC_SQL;
|
|
|
|
break;
|
2005-11-16 13:09:06 +01:00
|
|
|
case SQLCOM_CREATE_TABLE:
|
|
|
|
if (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)
|
|
|
|
flags= 0;
|
|
|
|
else
|
|
|
|
flags= sp_head::HAS_COMMIT_OR_ROLLBACK;
|
|
|
|
break;
|
|
|
|
case SQLCOM_DROP_TABLE:
|
|
|
|
if (lex->drop_temporary)
|
|
|
|
flags= 0;
|
|
|
|
else
|
|
|
|
flags= sp_head::HAS_COMMIT_OR_ROLLBACK;
|
|
|
|
break;
|
2006-08-25 15:51:29 +02:00
|
|
|
case SQLCOM_FLUSH:
|
|
|
|
flags= sp_head::HAS_SQLCOM_FLUSH;
|
|
|
|
break;
|
|
|
|
case SQLCOM_RESET:
|
|
|
|
flags= sp_head::HAS_SQLCOM_RESET;
|
|
|
|
break;
|
2005-11-16 13:09:06 +01:00
|
|
|
case SQLCOM_CREATE_INDEX:
|
|
|
|
case SQLCOM_CREATE_DB:
|
|
|
|
case SQLCOM_CREATE_VIEW:
|
|
|
|
case SQLCOM_CREATE_TRIGGER:
|
|
|
|
case SQLCOM_CREATE_USER:
|
|
|
|
case SQLCOM_ALTER_TABLE:
|
Bug#21975 Grant and revoke statements are non-transactional
Bug#21422 GRANT/REVOKE possible inside stored function, probably in a trigger
Bug#17244 GRANT gives strange error message when used in a stored function
GRANT/REVOKE statements are non-transactional (no explicit transaction
boundaries) in nature and hence are forbidden inside stored functions and
triggers, but they weren't being effectively forbidden. Furthermore, the
absence of implict commits makes changes made by GRANT/REVOKE statements to
not be rolled back.
The implemented fix is to issue a implicit commit with every GRANT/REVOKE
statement, effectively prohibiting these statements in stored functions
and triggers. The implicit commit also fixes the replication bug, and looks
like being in concert with the behavior of DDL and administrative statements.
Since this is a incompatible change, the following sentence should be
added to the Manual in the very end of the 3rd paragraph, subclause
13.4.3 "Statements That Cause an Implicit Commit": "Beginning with
MySQL 5.0.??, the GRANT and REVOKE statements cause an implicit commit."
Patch contributed by Vladimir Shebordaev
mysql-test/r/sp-error.result:
Test case result for Bug#17244
mysql-test/t/sp-error.test:
Test case for Bug#17244
sql/sp_head.cc:
Set that a procedure with GRANT/REVOKE command has a (implicit or explicit)
commit.
sql/sql_parse.cc:
End active transaction in SQLCOM_GRANT and SQLCOM_REVOKE, and thus effectively
prohibit these statements in stored functions and triggers. An implicit commit
also fixes a bug in replication, when GRANT or REVOKE would disappear from the
binary log in case of a subsequent ROLLBACK, since they were considered
transactional statements.
mysql-test/suite/rpl/r/rpl_binlog_grant.result:
Add test case result for Bug#21975
mysql-test/suite/rpl/t/rpl_binlog_grant.test:
Add test case for Bug#21975
2007-08-29 21:59:38 +02:00
|
|
|
case SQLCOM_GRANT:
|
|
|
|
case SQLCOM_REVOKE:
|
2005-11-16 13:09:06 +01:00
|
|
|
case SQLCOM_BEGIN:
|
|
|
|
case SQLCOM_RENAME_TABLE:
|
|
|
|
case SQLCOM_RENAME_USER:
|
|
|
|
case SQLCOM_DROP_INDEX:
|
|
|
|
case SQLCOM_DROP_DB:
|
Bug#21975 Grant and revoke statements are non-transactional
Bug#21422 GRANT/REVOKE possible inside stored function, probably in a trigger
Bug#17244 GRANT gives strange error message when used in a stored function
GRANT/REVOKE statements are non-transactional (no explicit transaction
boundaries) in nature and hence are forbidden inside stored functions and
triggers, but they weren't being effectively forbidden. Furthermore, the
absence of implict commits makes changes made by GRANT/REVOKE statements to
not be rolled back.
The implemented fix is to issue a implicit commit with every GRANT/REVOKE
statement, effectively prohibiting these statements in stored functions
and triggers. The implicit commit also fixes the replication bug, and looks
like being in concert with the behavior of DDL and administrative statements.
Since this is a incompatible change, the following sentence should be
added to the Manual in the very end of the 3rd paragraph, subclause
13.4.3 "Statements That Cause an Implicit Commit": "Beginning with
MySQL 5.0.??, the GRANT and REVOKE statements cause an implicit commit."
Patch contributed by Vladimir Shebordaev
mysql-test/r/sp-error.result:
Test case result for Bug#17244
mysql-test/t/sp-error.test:
Test case for Bug#17244
sql/sp_head.cc:
Set that a procedure with GRANT/REVOKE command has a (implicit or explicit)
commit.
sql/sql_parse.cc:
End active transaction in SQLCOM_GRANT and SQLCOM_REVOKE, and thus effectively
prohibit these statements in stored functions and triggers. An implicit commit
also fixes a bug in replication, when GRANT or REVOKE would disappear from the
binary log in case of a subsequent ROLLBACK, since they were considered
transactional statements.
mysql-test/suite/rpl/r/rpl_binlog_grant.result:
Add test case result for Bug#21975
mysql-test/suite/rpl/t/rpl_binlog_grant.test:
Add test case for Bug#21975
2007-08-29 21:59:38 +02:00
|
|
|
case SQLCOM_REVOKE_ALL:
|
2005-11-16 13:09:06 +01:00
|
|
|
case SQLCOM_DROP_USER:
|
|
|
|
case SQLCOM_DROP_VIEW:
|
|
|
|
case SQLCOM_DROP_TRIGGER:
|
|
|
|
case SQLCOM_TRUNCATE:
|
|
|
|
case SQLCOM_COMMIT:
|
|
|
|
case SQLCOM_ROLLBACK:
|
2006-05-23 16:29:58 +02:00
|
|
|
case SQLCOM_LOAD:
|
2005-11-16 13:09:06 +01:00
|
|
|
case SQLCOM_LOAD_MASTER_DATA:
|
|
|
|
case SQLCOM_LOCK_TABLES:
|
|
|
|
case SQLCOM_CREATE_PROCEDURE:
|
|
|
|
case SQLCOM_CREATE_SPFUNCTION:
|
|
|
|
case SQLCOM_ALTER_PROCEDURE:
|
|
|
|
case SQLCOM_ALTER_FUNCTION:
|
|
|
|
case SQLCOM_DROP_PROCEDURE:
|
|
|
|
case SQLCOM_DROP_FUNCTION:
|
2006-02-15 17:12:27 +01:00
|
|
|
case SQLCOM_CREATE_EVENT:
|
|
|
|
case SQLCOM_ALTER_EVENT:
|
|
|
|
case SQLCOM_DROP_EVENT:
|
2006-08-23 15:50:06 +02:00
|
|
|
case SQLCOM_INSTALL_PLUGIN:
|
|
|
|
case SQLCOM_UNINSTALL_PLUGIN:
|
2005-11-16 13:09:06 +01:00
|
|
|
flags= sp_head::HAS_COMMIT_OR_ROLLBACK;
|
|
|
|
break;
|
2004-08-06 13:47:01 +02:00
|
|
|
default:
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
flags= 0;
|
|
|
|
break;
|
2004-08-06 13:47:01 +02:00
|
|
|
}
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
return flags;
|
2004-08-06 13:47:01 +02:00
|
|
|
}
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-12-07 15:01:17 +01:00
|
|
|
Prepare an Item for evaluation (call of fix_fields).
|
2005-05-09 00:59:10 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread handler
|
|
|
|
@param it_addr pointer on item refernce
|
2005-05-09 00:59:10 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
NULL error
|
|
|
|
@retval
|
|
|
|
non-NULL prepared item
|
2005-05-09 00:59:10 +02:00
|
|
|
*/
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
Item *
|
2005-05-09 00:59:10 +02:00
|
|
|
sp_prepare_func_item(THD* thd, Item **it_addr)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_prepare_func_item");
|
2005-12-07 15:01:17 +01:00
|
|
|
it_addr= (*it_addr)->this_item_addr(thd, it_addr);
|
2005-05-09 00:59:10 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!(*it_addr)->fixed &&
|
|
|
|
((*it_addr)->fix_fields(thd, it_addr) ||
|
|
|
|
(*it_addr)->check_cols(1)))
|
2005-05-09 00:59:10 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("fix_fields() failed"));
|
|
|
|
DBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
DBUG_RETURN(*it_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-12-07 15:01:17 +01:00
|
|
|
Evaluate an expression and store the result in the field.
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd current thread object
|
|
|
|
@param result_field the field to store the result
|
|
|
|
@param expr_item_ptr the root item of the expression
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
FALSE on success
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
TRUE on error
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
*/
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
bool
|
2006-05-15 12:01:55 +02:00
|
|
|
sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2006-05-15 12:01:55 +02:00
|
|
|
Item *expr_item;
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_ENTER("sp_eval_expr");
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2006-05-15 18:41:05 +02:00
|
|
|
if (!*expr_item_ptr)
|
2005-12-09 13:14:19 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
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
|
|
|
|
2006-05-15 12:01:55 +02:00
|
|
|
if (!(expr_item= sp_prepare_func_item(thd, expr_item_ptr)))
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
bool err_status= FALSE;
|
2002-12-13 18:25:36 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
Set THD flags to emit warnings/errors in case of overflow/type errors
|
|
|
|
during saving the item into the field.
|
2005-08-22 00:13:37 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
Save original values and restore them after save.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
|
|
|
|
bool save_abort_on_warning= thd->abort_on_warning;
|
(pushing for Andrei)
Bug #27417 thd->no_trans_update.stmt lost value inside of SF-exec-stack
Once had been set the flag might later got reset inside of a stored routine
execution stack.
The reason was in that there was no check if a new statement started at time
of resetting.
The artifact affects most of binlogable DML queries. Notice, that multi-update
is wrapped up within
bug@27716 fix, multi-delete bug@29136.
Fixed with saving parent's statement flag of whether the statement modified
non-transactional table, and unioning (merging) the value with that was gained
in mysql_execute_command.
Resettling thd->no_trans_update members into thd->transaction.`member`;
Asserting code;
Effectively the following properties are held.
1. At the end of a substatement thd->transaction.stmt.modified_non_trans_table
reflects the fact if such a table got modified by the substatement.
That also respects THD::really_abort_on_warnin() requirements.
2. Eventually thd->transaction.stmt.modified_non_trans_table will be computed as
the union of the values of all invoked sub-statements.
That fixes this bug#27417;
Computing of thd->transaction.all.modified_non_trans_table is refined to base to
the stmt's value for all the case including insert .. select statement which
before the patch had an extra issue bug@28960.
Minor issues are covered with mysql_load, mysql_delete, and binloggin of insert in
to temp_table select.
The supplied test verifies limitely, mostly asserts. The ultimate testing is defered
for bug@13270, bug@23333.
mysql-test/r/mix_innodb_myisam_binlog.result:
results changed
mysql-test/t/mix_innodb_myisam_binlog.test:
regression test incl the related bug#28960.
sql/ha_ndbcluster.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.h:
new member added
sql/log.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/set_var.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sp_head.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
and saving and merging stmt's flag at the end of a substatement.
sql/sql_class.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_class.h:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_delete.cc:
correcting basic delete incl truncate branch and multi-delete queries to set
stmt.modified_non_trans_table;
optimization to set the flag at the end of per-row loop;
multi-delete still has an extra issue similar to bug#27716 of multi-update
- to be address with bug_29136 fix.
sql/sql_insert.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_load.cc:
eliminating a separate issue where the stmt flag was saved and re-stored after
write_record that actually could change it and the change would be lost but
should remain permanent;
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_parse.cc:
initialization to transaction.stmt.modified_non_trans_table at the common part
of all types of statements processing - mysql_execute_command().
sql/sql_table.cc:
moving the reset up to the mysql_execute_command() caller
sql/sql_update.cc:
correcting update query case (multi-update part of the issues covered by other
bug#27716 fix)
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
2007-07-30 17:27:36 +02:00
|
|
|
bool save_stmt_modified_non_trans_table= thd->transaction.stmt.modified_non_trans_table;
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
thd->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
|
|
|
|
thd->abort_on_warning=
|
|
|
|
thd->variables.sql_mode &
|
|
|
|
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES);
|
(pushing for Andrei)
Bug #27417 thd->no_trans_update.stmt lost value inside of SF-exec-stack
Once had been set the flag might later got reset inside of a stored routine
execution stack.
The reason was in that there was no check if a new statement started at time
of resetting.
The artifact affects most of binlogable DML queries. Notice, that multi-update
is wrapped up within
bug@27716 fix, multi-delete bug@29136.
Fixed with saving parent's statement flag of whether the statement modified
non-transactional table, and unioning (merging) the value with that was gained
in mysql_execute_command.
Resettling thd->no_trans_update members into thd->transaction.`member`;
Asserting code;
Effectively the following properties are held.
1. At the end of a substatement thd->transaction.stmt.modified_non_trans_table
reflects the fact if such a table got modified by the substatement.
That also respects THD::really_abort_on_warnin() requirements.
2. Eventually thd->transaction.stmt.modified_non_trans_table will be computed as
the union of the values of all invoked sub-statements.
That fixes this bug#27417;
Computing of thd->transaction.all.modified_non_trans_table is refined to base to
the stmt's value for all the case including insert .. select statement which
before the patch had an extra issue bug@28960.
Minor issues are covered with mysql_load, mysql_delete, and binloggin of insert in
to temp_table select.
The supplied test verifies limitely, mostly asserts. The ultimate testing is defered
for bug@13270, bug@23333.
mysql-test/r/mix_innodb_myisam_binlog.result:
results changed
mysql-test/t/mix_innodb_myisam_binlog.test:
regression test incl the related bug#28960.
sql/ha_ndbcluster.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.h:
new member added
sql/log.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/set_var.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sp_head.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
and saving and merging stmt's flag at the end of a substatement.
sql/sql_class.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_class.h:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_delete.cc:
correcting basic delete incl truncate branch and multi-delete queries to set
stmt.modified_non_trans_table;
optimization to set the flag at the end of per-row loop;
multi-delete still has an extra issue similar to bug#27716 of multi-update
- to be address with bug_29136 fix.
sql/sql_insert.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_load.cc:
eliminating a separate issue where the stmt flag was saved and re-stored after
write_record that actually could change it and the change would be lost but
should remain permanent;
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_parse.cc:
initialization to transaction.stmt.modified_non_trans_table at the common part
of all types of statements processing - mysql_execute_command().
sql/sql_table.cc:
moving the reset up to the mysql_execute_command() caller
sql/sql_update.cc:
correcting update query case (multi-update part of the issues covered by other
bug#27716 fix)
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
2007-07-30 17:27:36 +02:00
|
|
|
thd->transaction.stmt.modified_non_trans_table= FALSE;
|
2005-09-08 18:25:42 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/* Save the value in the field. Convert the value if needed. */
|
2005-10-19 14:54:54 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
expr_item->save_in_field(result_field, 0);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
thd->count_cuted_fields= save_count_cuted_fields;
|
|
|
|
thd->abort_on_warning= save_abort_on_warning;
|
(pushing for Andrei)
Bug #27417 thd->no_trans_update.stmt lost value inside of SF-exec-stack
Once had been set the flag might later got reset inside of a stored routine
execution stack.
The reason was in that there was no check if a new statement started at time
of resetting.
The artifact affects most of binlogable DML queries. Notice, that multi-update
is wrapped up within
bug@27716 fix, multi-delete bug@29136.
Fixed with saving parent's statement flag of whether the statement modified
non-transactional table, and unioning (merging) the value with that was gained
in mysql_execute_command.
Resettling thd->no_trans_update members into thd->transaction.`member`;
Asserting code;
Effectively the following properties are held.
1. At the end of a substatement thd->transaction.stmt.modified_non_trans_table
reflects the fact if such a table got modified by the substatement.
That also respects THD::really_abort_on_warnin() requirements.
2. Eventually thd->transaction.stmt.modified_non_trans_table will be computed as
the union of the values of all invoked sub-statements.
That fixes this bug#27417;
Computing of thd->transaction.all.modified_non_trans_table is refined to base to
the stmt's value for all the case including insert .. select statement which
before the patch had an extra issue bug@28960.
Minor issues are covered with mysql_load, mysql_delete, and binloggin of insert in
to temp_table select.
The supplied test verifies limitely, mostly asserts. The ultimate testing is defered
for bug@13270, bug@23333.
mysql-test/r/mix_innodb_myisam_binlog.result:
results changed
mysql-test/t/mix_innodb_myisam_binlog.test:
regression test incl the related bug#28960.
sql/ha_ndbcluster.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.h:
new member added
sql/log.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/set_var.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sp_head.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
and saving and merging stmt's flag at the end of a substatement.
sql/sql_class.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_class.h:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_delete.cc:
correcting basic delete incl truncate branch and multi-delete queries to set
stmt.modified_non_trans_table;
optimization to set the flag at the end of per-row loop;
multi-delete still has an extra issue similar to bug#27716 of multi-update
- to be address with bug_29136 fix.
sql/sql_insert.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_load.cc:
eliminating a separate issue where the stmt flag was saved and re-stored after
write_record that actually could change it and the change would be lost but
should remain permanent;
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_parse.cc:
initialization to transaction.stmt.modified_non_trans_table at the common part
of all types of statements processing - mysql_execute_command().
sql/sql_table.cc:
moving the reset up to the mysql_execute_command() caller
sql/sql_update.cc:
correcting update query case (multi-update part of the issues covered by other
bug#27716 fix)
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
2007-07-30 17:27:36 +02:00
|
|
|
thd->transaction.stmt.modified_non_trans_table= save_stmt_modified_non_trans_table;
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2007-10-30 18:08:16 +01:00
|
|
|
if (thd->is_error())
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
/* Return error status if something went wrong. */
|
|
|
|
err_status= TRUE;
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
}
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(err_status);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +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
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* sp_name
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-10-17 04:47:08 +02:00
|
|
|
sp_name::sp_name(THD *thd, char *key, uint key_len)
|
|
|
|
{
|
|
|
|
m_sroutines_key.str= key;
|
|
|
|
m_sroutines_key.length= key_len;
|
|
|
|
m_qname.str= ++key;
|
|
|
|
m_qname.length= key_len - 1;
|
|
|
|
if ((m_name.str= strchr(m_qname.str, '.')))
|
|
|
|
{
|
|
|
|
m_db.length= m_name.str - key;
|
|
|
|
m_db.str= strmake_root(thd->mem_root, key, m_db.length);
|
|
|
|
m_name.str++;
|
|
|
|
m_name.length= m_qname.length - m_db.length - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_name.str= m_qname.str;
|
|
|
|
m_name.length= m_qname.length;
|
|
|
|
m_db.str= 0;
|
|
|
|
m_db.length= 0;
|
|
|
|
}
|
|
|
|
m_explicit_name= false;
|
|
|
|
}
|
|
|
|
|
2007-12-14 16:52:10 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Init the qualified name from the db and name.
|
|
|
|
*/
|
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
|
|
|
void
|
|
|
|
sp_name::init_qname(THD *thd)
|
|
|
|
{
|
2007-10-17 04:47:08 +02:00
|
|
|
const uint dot= !!m_db.length;
|
|
|
|
/* m_sroutines format: m_type + [database + dot] + name + nul */
|
|
|
|
m_sroutines_key.length= 1 + m_db.length + dot + m_name.length;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
if (!(m_sroutines_key.str= (char*) thd->alloc(m_sroutines_key.length + 1)))
|
2005-07-09 19:51:59 +02:00
|
|
|
return;
|
|
|
|
m_qname.length= m_sroutines_key.length - 1;
|
|
|
|
m_qname.str= m_sroutines_key.str + 1;
|
2007-10-17 04:47:08 +02:00
|
|
|
sprintf(m_qname.str, "%.*s%.*s%.*s",
|
|
|
|
(int) m_db.length, (m_db.length ? m_db.str : ""),
|
|
|
|
dot, ".",
|
|
|
|
(int) m_name.length, m_name.str);
|
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
|
|
|
}
|
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Check that the name 'ident' is ok. It's assumed to be an 'ident'
|
2006-01-19 16:13:04 +01:00
|
|
|
from the parser, so we only have to check length and trailing spaces.
|
|
|
|
The former is a standard requirement (and 'show status' assumes a
|
|
|
|
non-empty name), the latter is a mysql:ism as trailing spaces are
|
|
|
|
removed by get_field().
|
2007-10-11 20:37:45 +02:00
|
|
|
|
|
|
|
@retval
|
|
|
|
TRUE bad name
|
|
|
|
@retval
|
|
|
|
FALSE name is ok
|
2006-01-19 16:13:04 +01:00
|
|
|
*/
|
2006-01-11 15:11:05 +01:00
|
|
|
|
|
|
|
bool
|
2007-04-03 13:13:27 +02:00
|
|
|
check_routine_name(LEX_STRING *ident)
|
2006-01-11 15:11:05 +01:00
|
|
|
{
|
2007-04-03 13:13:27 +02:00
|
|
|
if (!ident || !ident->str || !ident->str[0] ||
|
|
|
|
ident->str[ident->length-1] == ' ')
|
2007-10-11 20:37:45 +02:00
|
|
|
{
|
2007-04-03 13:13:27 +02:00
|
|
|
my_error(ER_SP_WRONG_NAME, MYF(0), ident->str);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (check_string_char_length(ident, "", NAME_CHAR_LEN,
|
|
|
|
system_charset_info, 1))
|
|
|
|
{
|
|
|
|
my_error(ER_TOO_LONG_IDENT, MYF(0), ident->str);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2006-01-11 15:11:05 +01:00
|
|
|
}
|
2004-03-11 17:18:59 +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
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* sp_head
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-06-29 18:15:17 +02:00
|
|
|
void *
|
2007-11-19 17:59:44 +01:00
|
|
|
sp_head::operator new(size_t size) throw()
|
2003-06-29 18:15:17 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_head::operator new");
|
|
|
|
MEM_ROOT own_root;
|
|
|
|
sp_head *sp;
|
|
|
|
|
2007-11-19 17:59:44 +01:00
|
|
|
init_sql_alloc(&own_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC);
|
2004-11-09 02:58:44 +01:00
|
|
|
sp= (sp_head *) alloc_root(&own_root, size);
|
2007-11-19 17:59:44 +01:00
|
|
|
if (sp == NULL)
|
|
|
|
return NULL;
|
2004-11-09 02:58:44 +01:00
|
|
|
sp->main_mem_root= own_root;
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_PRINT("info", ("mem_root 0x%lx", (ulong) &sp->mem_root));
|
2003-06-29 18:15:17 +02:00
|
|
|
DBUG_RETURN(sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-14 21:38:58 +01:00
|
|
|
sp_head::operator delete(void *ptr, size_t size) throw()
|
2003-06-29 18:15:17 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_head::operator delete");
|
|
|
|
MEM_ROOT own_root;
|
2007-11-19 17:59:44 +01:00
|
|
|
|
|
|
|
if (ptr == NULL)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
sp_head *sp= (sp_head *) ptr;
|
2003-06-29 18:15:17 +02:00
|
|
|
|
2004-11-09 02:58:44 +01:00
|
|
|
/* Make a copy of main_mem_root as free_root will free the sp */
|
|
|
|
own_root= sp->main_mem_root;
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_PRINT("info", ("mem_root 0x%lx moved to 0x%lx",
|
|
|
|
(ulong) &sp->mem_root, (ulong) &own_root));
|
2003-06-29 18:15:17 +02:00
|
|
|
free_root(&own_root, MYF(0));
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-05-20 01:02:49 +02:00
|
|
|
|
2003-07-01 17:19:48 +02:00
|
|
|
sp_head::sp_head()
|
2005-06-22 09:59:13 +02:00
|
|
|
:Query_arena(&main_mem_root, INITIALIZED_FOR_SP),
|
2005-12-07 15:01:17 +01:00
|
|
|
m_flags(0), m_recursion_level(0), m_next_cached_sp(0),
|
2006-01-16 15:37:25 +01:00
|
|
|
m_cont_level(0)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2006-08-12 19:06:51 +02:00
|
|
|
const LEX_STRING str_reset= { NULL, 0 };
|
2006-11-30 02:40:42 +01:00
|
|
|
|
|
|
|
m_first_instance= this;
|
|
|
|
m_first_free_instance= this;
|
|
|
|
m_last_cached_sp= this;
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
m_return_field_def.charset = NULL;
|
2006-08-12 19:06:51 +02:00
|
|
|
/*
|
|
|
|
FIXME: the only use case when name is NULL is events, and it should
|
|
|
|
be rewritten soon. Remove the else part and replace 'if' with
|
|
|
|
an assert when this is done.
|
|
|
|
*/
|
|
|
|
m_db= m_name= m_qname= str_reset;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2003-04-03 20:00:52 +02:00
|
|
|
DBUG_ENTER("sp_head::sp_head");
|
2003-07-01 17:19:48 +02:00
|
|
|
|
|
|
|
m_backpatch.empty();
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
m_cont_backpatch.empty();
|
2003-07-01 17:19:48 +02:00
|
|
|
m_lex.empty();
|
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
|
|
|
hash_init(&m_sptabs, system_charset_info, 0, 0, 0, sp_table_key, 0, 0);
|
2005-07-09 19:51:59 +02:00
|
|
|
hash_init(&m_sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, 0, 0);
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
|
|
|
|
m_body_utf8.str= NULL;
|
|
|
|
m_body_utf8.length= 0;
|
|
|
|
|
2003-07-01 17:19:48 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-05-20 01:02:49 +02:00
|
|
|
|
2003-07-01 17:19:48 +02:00
|
|
|
void
|
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_head::init(LEX *lex)
|
2003-07-01 17:19:48 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_head::init");
|
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
|
|
|
|
Bug#26503 (Illegal SQL exception handler code causes the server to crash)
Before this fix, the parser would accept illegal code in SQL exceptions
handlers, that later causes the runtime to crash when executing the code,
due to memory violations in the exception handler stack.
The root cause of the problem is instructions within an exception handler
that jumps to code located outside of the handler. This is illegal according
to the SQL 2003 standard, since labels located outside the handler are not
supposed to be visible (they are "out of scope"), so any instruction that
jumps to these labels, like ITERATE or LEAVE, should not parse.
The section of the standard that is relevant for this is :
SQL:2003 SQL/PSM (ISO/IEC 9075-4:2003)
section 13.1 <compound statement>,
syntax rule 4
<quote>
The scope of the <beginning label> is CS excluding every <SQL schema
statement> contained in CS and excluding every
<local handler declaration list> contained in CS. <beginning label> shall
not be equivalent to any other <beginning label>s within that scope.
</quote>
With this fix, the C++ class sp_pcontext, which represent the "parsing
context" tree (a.k.a symbol table) of a stored procedure, has been changed
as follows:
- constructors have been cleaned up, so that only building a root node for
the tree is public; building nodes inside a tree is not public.
- a new member, m_label_scope, indicates if a given syntactic context
belongs to a DECLARE HANDLER block,
- label resolution, in the method find_label(), has been changed to
implement the restriction of scope regarding labels used in a compound
statement.
The actions in the parser, when parsing the body of a SQL exception handler,
have been changed as follows:
- the implementation of an exception handler (DECLARE HANDLER) now creates
explicitly a new sp_pcontext, to isolate the code inside the handler from
the containing compound statement context.
- registering exception handlers as a result occurs in the parent context,
see the rule sp_hcond_element
- the code in sp_hcond_list has been cleaned up, to avoid code duplication
In addition, the flags IN_SIMPLE_CASE and IN_HANDLER, declared in sp_head.h
have been removed, since they are unused and broken by design (as seen with
Bug 19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation), representing a stack in a single flag is not possible.
Tests in sp-error have been added to show that illegal constructs are now
rejected.
Tests in sp have been added for code coverage, to show that ITERATE or LEAVE
statements are legal when jumping to a label in scope, inside the body of
an exception handler.
mysql-test/r/sp-error.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/r/sp.result:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp-error.test:
SQL Exception handlers define a parsing context for label resolution.
mysql-test/t/sp.test:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_head.cc:
Minor cleanup
sql/sp_head.h:
Minor cleanup
sql/sp_pcontext.cc:
SQL Exception handlers define a parsing context for label resolution.
sql/sp_pcontext.h:
SQL Exception handlers define a parsing context for label resolution.
sql/sql_yacc.yy:
SQL Exception handlers define a parsing context for label resolution.
2007-03-14 19:02:32 +01:00
|
|
|
lex->spcont= m_pcont= new sp_pcontext();
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2007-11-19 17:59:44 +01:00
|
|
|
if (!lex->spcont)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
2004-11-24 10:24:02 +01:00
|
|
|
/*
|
|
|
|
Altough trg_table_fields list is used only in triggers we init for all
|
|
|
|
types of stored procedures to simplify reset_lex()/restore_lex() code.
|
|
|
|
*/
|
|
|
|
lex->trg_table_fields.empty();
|
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
|
|
|
my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
|
|
|
|
m_param_begin= NULL;
|
|
|
|
m_param_end= NULL;
|
|
|
|
|
|
|
|
m_body_begin= NULL ;
|
|
|
|
|
|
|
|
m_qname.str= NULL;
|
|
|
|
m_qname.length= 0;
|
|
|
|
|
|
|
|
m_db.str= NULL;
|
|
|
|
m_db.length= 0;
|
|
|
|
|
|
|
|
m_name.str= NULL;
|
|
|
|
m_name.length= 0;
|
|
|
|
|
|
|
|
m_params.str= NULL;
|
|
|
|
m_params.length= 0;
|
|
|
|
|
|
|
|
m_body.str= NULL;
|
|
|
|
m_body.length= 0;
|
|
|
|
|
|
|
|
m_defstr.str= NULL;
|
|
|
|
m_defstr.length= 0;
|
|
|
|
|
|
|
|
m_sroutines_key.str= NULL;
|
|
|
|
m_sroutines_key.length= 0;
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
m_return_field_def.charset= NULL;
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +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
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2006-07-27 15:57:43 +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
|
|
|
void
|
2006-07-27 15:57:43 +02:00
|
|
|
sp_head::init_sp_name(THD *thd, sp_name *spname)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_head::init_sp_name");
|
|
|
|
|
|
|
|
/* Must be initialized in the parser. */
|
|
|
|
|
|
|
|
DBUG_ASSERT(spname && spname->m_db.str && spname->m_db.length);
|
|
|
|
|
|
|
|
/* We have to copy strings to get them into the right memroot. */
|
|
|
|
|
|
|
|
m_db.length= spname->m_db.length;
|
|
|
|
m_db.str= strmake_root(thd->mem_root, spname->m_db.str, spname->m_db.length);
|
|
|
|
|
|
|
|
m_name.length= spname->m_name.length;
|
|
|
|
m_name.str= strmake_root(thd->mem_root, spname->m_name.str,
|
|
|
|
spname->m_name.length);
|
|
|
|
|
|
|
|
if (spname->m_qname.length == 0)
|
|
|
|
spname->init_qname(thd);
|
|
|
|
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
m_sroutines_key.length= spname->m_sroutines_key.length;
|
2007-07-16 22:59:21 +02:00
|
|
|
m_sroutines_key.str= (char*) memdup_root(thd->mem_root,
|
|
|
|
spname->m_sroutines_key.str,
|
|
|
|
spname->m_sroutines_key.length + 1);
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
m_sroutines_key.str[0]= static_cast<char>(m_type);
|
|
|
|
|
|
|
|
m_qname.length= m_sroutines_key.length - 1;
|
|
|
|
m_qname.str= m_sroutines_key.str + 1;
|
Manual merge 5.0->5.1. Post-merge fixes.
client/mysqldump.c:
A post-merge fix - 'sock' was renamed to 'mysql'
mysql-test/r/events_bugs.result:
A post merge fix: now we strip rear comments from the query before
it gets into the log.
mysql-test/r/func_group.result:
A post merge fix: default clause is now printed uppercase.
mysql-test/r/im_life_cycle.result:
Fix my mistake in manual resolve.
mysql-test/r/mysqlcheck.result:
use test; - after we drop client_test_db there is no current database.
This cleanup is present in 5.1 only, but the test that was added in
5.0 assumes there is a current database, test.
mysql-test/r/mysqldump.result:
Ignore results of execution of mysqldump: we can't rely on
MASTER_LOG_POS in test results, it's different for statement
and row level logging.
mysql-test/r/mysqlshow.result:
A post-merge fix: information schema contains a few more tables
in 5.1
mysql-test/r/mysqltest.result:
A post merge fix: add 5.1 test end separator.
mysql-test/r/ndb_basic.result:
A post-merge fix: add test end separators.
mysql-test/r/rpl_switch_stm_row_mixed.result:
A post merge fix: length of varbinary column is now 3 times less.
Assuming a side effect of some other change. Length of any
field is not relevant in this test.
mysql-test/r/rpl_view.result:
Add an end of test marker.
mysql-test/r/show_check.result:
Remove duplicate results. Add results from a merged test case.
mysql-test/r/sp-error.result:
Add test end separators.
mysql-test/r/sp-security.result:
Post-merge fix: use test after the current database is dropped.
mysql-test/r/sp.result:
Remove a duplicate result (bad merge that left a copy of
the test case for Bug#19862 in the test suite).
mysql-test/r/strict.result:
An after-merge fix for a new test case: in 5.1 we issue a more accurate
error message: "Incorrect value" instead of "Truncated value". I reason
it so that in case of an error nothing is truncated, really.
Also found similar changes in other test cases.
mysql-test/r/type_datetime.result:
Fix the text of an error.
mysql-test/r/union.result:
A post-merge fix: CHARACTER SET is now uppercase.
mysql-test/t/mysqlcheck.test:
A post-merge fix: use test, after current database is dropped, there
is no current database.
mysql-test/t/mysqldump.test:
Disable result log: it's dependent on binlog position.
mysql-test/t/sp-security.test:
use test
sql/item_sum.cc:
Adjust the call to the constructor after the merge.
sql/sp_head.cc:
Add a missing DBUG_VOID_RETURN, move security checks out of
execute_trigger to Table_triggers_list: in 5.1 we check for
TRIGGER privilege, not SUPER privilege to execute triggers, so these
checks lack table context inside execute_trigger and have to be
performed when we have table object on hand.
sql/sql_db.cc:
A post-merge fix: adjust load_db_opt_by_name and check_db_dir_existence
(new functions added in 5.0) to be tablename-to-filename encoding
friendly.
sql/sql_lex.cc:
A post-merge fix: make skip_rear_comments operate on const uchar *s.
sql/sql_lex.h:
A post-merge fix.
sql/sql_show.cc:
A post-merge fix: fix a bad merge, rename orig_sql_command -> sql_command.
sql/sql_trigger.cc:
A post-merge fix: move security checks to process_triggers
from execute_trigger.
sql/sql_view.cc:
Adjust to the new signature of skip_rear_comments.
sql/sql_yacc.yy:
Adjust to the new signature of init_strings.
2006-08-14 11:27:11 +02:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
2006-07-27 15:57:43 +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
|
|
|
void
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
sp_head::set_body_start(THD *thd, const char *begin_ptr)
|
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
|
|
|
{
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
m_body_begin= begin_ptr;
|
|
|
|
thd->m_lip->body_utf8_start(thd, begin_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_head::set_stmt_end(THD *thd)
|
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
|
|
|
{
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
Lex_input_stream *lip= thd->m_lip; /* shortcut */
|
|
|
|
const char *end_ptr= lip->get_cpp_ptr(); /* shortcut */
|
|
|
|
|
|
|
|
/* Make the string of parameters. */
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2004-09-07 14:29:46 +02:00
|
|
|
if (m_param_begin && m_param_end)
|
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
|
|
|
{
|
2004-09-07 14:29:46 +02:00
|
|
|
m_params.length= m_param_end - m_param_begin;
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
m_params.str= thd->strmake(m_param_begin, m_params.length);
|
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
|
|
|
}
|
2004-09-09 17:52:10 +02:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
/* Remember end pointer for further dumping of whole statement. */
|
2005-11-11 11:10:52 +01:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
thd->lex->stmt_definition_end= end_ptr;
|
|
|
|
|
|
|
|
/* Make the string of body (in the original character set). */
|
|
|
|
|
|
|
|
m_body.length= end_ptr - m_body_begin;
|
|
|
|
m_body.str= thd->strmake(m_body_begin, m_body.length);
|
Bug#25411 (trigger code truncated), PART II
Bug 28127 (Some valid identifiers names are not parsed correctly)
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
This patch is the second part of a major cleanup, required to fix
Bug 25411 (trigger code truncated).
The root cause of the issue stems from the function skip_rear_comments,
which was a work around to remove "extra" "*/" characters from the query
text, when parsing a query and reusing the text fragments to represent a
view, trigger, function or stored procedure.
The reason for this work around is that "special comments",
like /*!50002 XXX */, were not parsed properly, so that a query like:
AAA /*!50002 BBB */ CCC
would be seen by the parser as "AAA BBB */ CCC" when the current version
is greater or equal to 5.0.2
The root cause of this stems from how special comments are parsed.
Special comments are really out-of-bound text that appear inside a query,
that affects how the parser behave.
In nature, /*!50002 XXX */ in MySQL is similar to the C concept
of preprocessing :
#if VERSION >= 50002
XXX
#endif
Depending on the current VERSION of the server, either the special comment
should be expanded or it should be ignored, but in all cases the "text" of
the query should be re-written to strip the "/*!50002" and "*/" markers,
which does not belong to the SQL language itself.
Prior to this fix, these markers would leak into :
- the storage format for VIEW,
- the storage format for FUNCTION,
- the storage format for FUNCTION parameters, in mysql.proc (param_list),
- the storage format for PROCEDURE,
- the storage format for PROCEDURE parameters, in mysql.proc (param_list),
- the storage format for TRIGGER,
- the binary log used for replication.
In all cases, not only this cause format corruption, but also provide a vector
for dormant security issues, by allowing to tunnel code that will be activated
after an upgrade.
The proper solution is to deal with special comments strictly during parsing,
when accepting a query from the outside world.
Once a query is parsed and an object is created with a persistant
representation, this object should not arbitrarily mutate after an upgrade.
In short, special comments are a useful but limited feature for MYSQLdump,
when used at an *interface* level to facilitate import/export,
but bloating the server *internal* storage format is *not* the proper way
to deal with configuration management of the user logic.
With this fix:
- the Lex_input_stream class now acts as a comment pre-processor,
and either expands or ignore special comments on the fly.
- MYSQLlex and sql_yacc.yy have been cleaned up to strictly use the
public interface of Lex_input_stream. In particular, how the input stream
accepts or rejects a character is private to Lex_input_stream, and the
internal buffer pointers of that class are strictly private, and should not
be tempered with during parsing.
This caused many changes mostly in sql_lex.cc.
During the code cleanup in case MY_LEX_NUMBER_IDENT,
Bug 28127 (Some valid identifiers names are not parsed correctly)
was found and fixed.
By parsing special comments properly, and removing the function
'skip_rear_comments' [sic],
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
has been fixed as well.
sql/event_data_objects.cc:
Cleanup of the code that extracts the query text
sql/sp.cc:
Cleanup of the code that extracts the query text
sql/sp_head.cc:
Cleanup of the code that extracts the query text
sql/sql_trigger.cc:
Cleanup of the code that extracts the query text
sql/sql_view.cc:
Cleanup of the code that extracts the query text
mysql-test/r/comments.result:
Bug#25411 (trigger code truncated)
mysql-test/r/sp.result:
Bug#25411 (trigger code truncated)
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
mysql-test/r/trigger.result:
Bug#25411 (trigger code truncated)
mysql-test/r/varbinary.result:
Bug 28127 (Some valid identifiers names are not parsed correctly)
mysql-test/t/comments.test:
Bug#25411 (trigger code truncated)
mysql-test/t/sp.test:
Bug#25411 (trigger code truncated)
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
mysql-test/t/trigger.test:
Bug#25411 (trigger code truncated)
mysql-test/t/varbinary.test:
Bug 28127 (Some valid identifiers names are not parsed correctly)
sql/sql_lex.cc:
Implemented comment pre-processing in Lex_input_stream,
major cleanup of the lex/yacc code to not use Lex_input_stream private members.
sql/sql_lex.h:
Implemented comment pre-processing in Lex_input_stream,
major cleanup of the lex/yacc code to not use Lex_input_stream private members.
sql/sql_yacc.yy:
post merge fix : view_check_options must be parsed before signaling the end of the query
2007-06-12 23:23:58 +02:00
|
|
|
trim_whitespace(thd->charset(), & m_body);
|
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
/* Make the string of UTF-body. */
|
Bug#25411 (trigger code truncated), PART II
Bug 28127 (Some valid identifiers names are not parsed correctly)
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
This patch is the second part of a major cleanup, required to fix
Bug 25411 (trigger code truncated).
The root cause of the issue stems from the function skip_rear_comments,
which was a work around to remove "extra" "*/" characters from the query
text, when parsing a query and reusing the text fragments to represent a
view, trigger, function or stored procedure.
The reason for this work around is that "special comments",
like /*!50002 XXX */, were not parsed properly, so that a query like:
AAA /*!50002 BBB */ CCC
would be seen by the parser as "AAA BBB */ CCC" when the current version
is greater or equal to 5.0.2
The root cause of this stems from how special comments are parsed.
Special comments are really out-of-bound text that appear inside a query,
that affects how the parser behave.
In nature, /*!50002 XXX */ in MySQL is similar to the C concept
of preprocessing :
#if VERSION >= 50002
XXX
#endif
Depending on the current VERSION of the server, either the special comment
should be expanded or it should be ignored, but in all cases the "text" of
the query should be re-written to strip the "/*!50002" and "*/" markers,
which does not belong to the SQL language itself.
Prior to this fix, these markers would leak into :
- the storage format for VIEW,
- the storage format for FUNCTION,
- the storage format for FUNCTION parameters, in mysql.proc (param_list),
- the storage format for PROCEDURE,
- the storage format for PROCEDURE parameters, in mysql.proc (param_list),
- the storage format for TRIGGER,
- the binary log used for replication.
In all cases, not only this cause format corruption, but also provide a vector
for dormant security issues, by allowing to tunnel code that will be activated
after an upgrade.
The proper solution is to deal with special comments strictly during parsing,
when accepting a query from the outside world.
Once a query is parsed and an object is created with a persistant
representation, this object should not arbitrarily mutate after an upgrade.
In short, special comments are a useful but limited feature for MYSQLdump,
when used at an *interface* level to facilitate import/export,
but bloating the server *internal* storage format is *not* the proper way
to deal with configuration management of the user logic.
With this fix:
- the Lex_input_stream class now acts as a comment pre-processor,
and either expands or ignore special comments on the fly.
- MYSQLlex and sql_yacc.yy have been cleaned up to strictly use the
public interface of Lex_input_stream. In particular, how the input stream
accepts or rejects a character is private to Lex_input_stream, and the
internal buffer pointers of that class are strictly private, and should not
be tempered with during parsing.
This caused many changes mostly in sql_lex.cc.
During the code cleanup in case MY_LEX_NUMBER_IDENT,
Bug 28127 (Some valid identifiers names are not parsed correctly)
was found and fixed.
By parsing special comments properly, and removing the function
'skip_rear_comments' [sic],
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
has been fixed as well.
sql/event_data_objects.cc:
Cleanup of the code that extracts the query text
sql/sp.cc:
Cleanup of the code that extracts the query text
sql/sp_head.cc:
Cleanup of the code that extracts the query text
sql/sql_trigger.cc:
Cleanup of the code that extracts the query text
sql/sql_view.cc:
Cleanup of the code that extracts the query text
mysql-test/r/comments.result:
Bug#25411 (trigger code truncated)
mysql-test/r/sp.result:
Bug#25411 (trigger code truncated)
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
mysql-test/r/trigger.result:
Bug#25411 (trigger code truncated)
mysql-test/r/varbinary.result:
Bug 28127 (Some valid identifiers names are not parsed correctly)
mysql-test/t/comments.test:
Bug#25411 (trigger code truncated)
mysql-test/t/sp.test:
Bug#25411 (trigger code truncated)
Bug 26302 (MySQL server cuts off trailing "*/" from comments in SP/func)
mysql-test/t/trigger.test:
Bug#25411 (trigger code truncated)
mysql-test/t/varbinary.test:
Bug 28127 (Some valid identifiers names are not parsed correctly)
sql/sql_lex.cc:
Implemented comment pre-processing in Lex_input_stream,
major cleanup of the lex/yacc code to not use Lex_input_stream private members.
sql/sql_lex.h:
Implemented comment pre-processing in Lex_input_stream,
major cleanup of the lex/yacc code to not use Lex_input_stream private members.
sql/sql_yacc.yy:
post merge fix : view_check_options must be parsed before signaling the end of the query
2007-06-12 23:23:58 +02:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
lip->body_utf8_append(end_ptr);
|
|
|
|
|
|
|
|
m_body_utf8.length= lip->get_body_utf8_length();
|
|
|
|
m_body_utf8.str= thd->strmake(lip->get_body_utf8_str(), m_body_utf8.length);
|
|
|
|
trim_whitespace(thd->charset(), & m_body_utf8);
|
|
|
|
|
2005-11-11 11:10:52 +01:00
|
|
|
/*
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
Make the string of whole stored-program-definition query (in the
|
|
|
|
original character set).
|
2005-11-11 11:10:52 +01:00
|
|
|
*/
|
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
m_defstr.length= end_ptr - lip->get_cpp_buf();
|
|
|
|
m_defstr.str= thd->strmake(lip->get_cpp_buf(), m_defstr.length);
|
|
|
|
trim_whitespace(thd->charset(), & m_defstr);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
static TYPELIB *
|
2007-06-10 12:43:57 +02:00
|
|
|
create_typelib(MEM_ROOT *mem_root, Create_field *field_def, List<String> *src)
|
2005-03-04 22:14:35 +01:00
|
|
|
{
|
|
|
|
TYPELIB *result= NULL;
|
2005-12-07 15:01:17 +01:00
|
|
|
CHARSET_INFO *cs= field_def->charset;
|
|
|
|
DBUG_ENTER("create_typelib");
|
2006-03-29 16:04:00 +02:00
|
|
|
|
2005-03-04 22:14:35 +01:00
|
|
|
if (src->elements)
|
|
|
|
{
|
|
|
|
result= (TYPELIB*) alloc_root(mem_root, sizeof(TYPELIB));
|
|
|
|
result->count= src->elements;
|
|
|
|
result->name= "";
|
|
|
|
if (!(result->type_names=(const char **)
|
2005-04-20 19:08:42 +02:00
|
|
|
alloc_root(mem_root,(sizeof(char *)+sizeof(int))*(result->count+1))))
|
2006-03-29 16:04:00 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
result->type_lengths= (uint*)(result->type_names + result->count+1);
|
2005-03-04 22:14:35 +01:00
|
|
|
List_iterator<String> it(*src);
|
2005-05-06 10:39:30 +02:00
|
|
|
String conv;
|
|
|
|
for (uint i=0; i < result->count; i++)
|
2005-04-19 10:09:25 +02:00
|
|
|
{
|
2005-05-06 10:39:30 +02:00
|
|
|
uint32 dummy;
|
|
|
|
uint length;
|
|
|
|
String *tmp= it++;
|
|
|
|
|
2005-04-19 10:09:25 +02:00
|
|
|
if (String::needs_conversion(tmp->length(), tmp->charset(),
|
|
|
|
cs, &dummy))
|
|
|
|
{
|
|
|
|
uint cnv_errs;
|
|
|
|
conv.copy(tmp->ptr(), tmp->length(), tmp->charset(), cs, &cnv_errs);
|
2005-05-06 10:39:30 +02:00
|
|
|
|
|
|
|
length= conv.length();
|
|
|
|
result->type_names[i]= (char*) strmake_root(mem_root, conv.ptr(),
|
|
|
|
length);
|
2005-04-19 10:09:25 +02:00
|
|
|
}
|
2005-05-06 10:39:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
length= tmp->length();
|
|
|
|
result->type_names[i]= strmake_root(mem_root, tmp->ptr(), length);
|
2005-04-20 19:08:42 +02:00
|
|
|
}
|
2005-04-19 10:09:25 +02:00
|
|
|
|
|
|
|
// Strip trailing spaces.
|
2005-05-06 10:39:30 +02:00
|
|
|
length= cs->cset->lengthsp(cs, result->type_names[i], length);
|
|
|
|
result->type_lengths[i]= length;
|
|
|
|
((uchar *)result->type_names[i])[length]= '\0';
|
2005-04-19 10:09:25 +02:00
|
|
|
}
|
2005-03-04 22:14:35 +01:00
|
|
|
result->type_names[result->count]= 0;
|
2005-04-20 19:08:42 +02:00
|
|
|
result->type_lengths[result->count]= 0;
|
2005-03-04 22:14:35 +01:00
|
|
|
}
|
2006-03-29 16:04:00 +02:00
|
|
|
DBUG_RETURN(result);
|
2005-03-04 22:14:35 +01:00
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
int
|
|
|
|
sp_head::create(THD *thd)
|
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_head::create");
|
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
|
|
|
DBUG_PRINT("info", ("type: %d name: %s params: %s body: %s",
|
|
|
|
m_type, m_name.str, m_params.str, m_body.str));
|
2004-08-02 18:05:31 +02:00
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
DBUG_RETURN(sp_create_routine(thd, m_type, this));
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2003-06-29 18:15:17 +02:00
|
|
|
sp_head::~sp_head()
|
|
|
|
{
|
2006-07-13 10:59:58 +02:00
|
|
|
DBUG_ENTER("sp_head::~sp_head");
|
2003-06-29 18:15:17 +02:00
|
|
|
destroy();
|
2005-11-23 00:11:19 +01:00
|
|
|
delete m_next_cached_sp;
|
2003-06-29 18:15:17 +02:00
|
|
|
if (m_thd)
|
|
|
|
restore_thd_mem_root(m_thd);
|
2006-07-13 10:59:58 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2003-06-29 18:15:17 +02:00
|
|
|
}
|
|
|
|
|
2003-04-02 20:42:28 +02:00
|
|
|
void
|
|
|
|
sp_head::destroy()
|
|
|
|
{
|
2003-06-29 18:15:17 +02:00
|
|
|
sp_instr *i;
|
|
|
|
LEX *lex;
|
2005-02-05 15:05:46 +01:00
|
|
|
DBUG_ENTER("sp_head::destroy");
|
|
|
|
DBUG_PRINT("info", ("name: %s", m_name.str));
|
2003-06-29 18:15:17 +02:00
|
|
|
|
|
|
|
for (uint ip = 0 ; (i = get_instr(ip)) ; ip++)
|
|
|
|
delete i;
|
2003-04-02 20:42:28 +02:00
|
|
|
delete_dynamic(&m_instr);
|
|
|
|
m_pcont->destroy();
|
2005-06-23 18:22:08 +02:00
|
|
|
free_items();
|
2005-03-05 14:31:58 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
If we have non-empty LEX stack then we just came out of parser with
|
|
|
|
error. Now we should delete all auxilary LEXes and restore original
|
|
|
|
THD::lex (In this case sp_head::restore_thd_mem_root() was not called
|
|
|
|
too, so m_thd points to the current thread context).
|
|
|
|
It is safe to not update LEX::ptr because further query string parsing
|
|
|
|
and execution will be stopped anyway.
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT(m_lex.is_empty() || m_thd);
|
2003-06-29 18:15:17 +02:00
|
|
|
while ((lex= (LEX *)m_lex.pop()))
|
|
|
|
{
|
2006-05-04 14:30:38 +02:00
|
|
|
lex_end(m_thd->lex);
|
2005-03-05 14:31:58 +01:00
|
|
|
delete m_thd->lex;
|
|
|
|
m_thd->lex= lex;
|
2003-06-29 18:15:17 +02:00
|
|
|
}
|
2005-03-05 14:31:58 +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
|
|
|
hash_free(&m_sptabs);
|
2005-07-09 19:51:59 +02:00
|
|
|
hash_free(&m_sroutines);
|
2003-04-03 20:00:52 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2003-04-02 20:42:28 +02:00
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2005-03-04 22:14:35 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-08-22 00:13:37 +02:00
|
|
|
This is only used for result fields from functions (both during
|
|
|
|
fix_length_and_dec() and evaluation).
|
|
|
|
*/
|
|
|
|
|
2005-03-04 22:14:35 +01:00
|
|
|
Field *
|
2005-12-07 15:01:17 +01:00
|
|
|
sp_head::create_result_field(uint field_max_length, const char *field_name,
|
|
|
|
TABLE *table)
|
2005-03-04 22:14:35 +01:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
uint field_length;
|
2005-03-04 22:14:35 +01:00
|
|
|
Field *field;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
DBUG_ENTER("sp_head::create_result_field");
|
|
|
|
|
|
|
|
field_length= !m_return_field_def.length ?
|
|
|
|
field_max_length : m_return_field_def.length;
|
|
|
|
|
2005-12-09 13:14:19 +01:00
|
|
|
field= ::make_field(table->s, /* TABLE_SHARE ptr */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
(uchar*) 0, /* field ptr */
|
2005-12-07 15:01:17 +01:00
|
|
|
field_length, /* field [max] length */
|
|
|
|
(uchar*) "", /* null ptr */
|
|
|
|
0, /* null bit */
|
|
|
|
m_return_field_def.pack_flag,
|
|
|
|
m_return_field_def.sql_type,
|
|
|
|
m_return_field_def.charset,
|
|
|
|
m_return_field_def.geom_type,
|
|
|
|
Field::NONE, /* unreg check */
|
|
|
|
m_return_field_def.interval,
|
2005-12-09 13:14:19 +01:00
|
|
|
field_name ? field_name : (const char *) m_name.str);
|
2005-12-12 11:29:48 +01:00
|
|
|
|
|
|
|
if (field)
|
|
|
|
field->init(table);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2005-03-04 22:14:35 +01:00
|
|
|
DBUG_RETURN(field);
|
|
|
|
}
|
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
|
|
|
|
int cmp_splocal_locations(Item_splocal * const *a, Item_splocal * const *b)
|
|
|
|
{
|
|
|
|
return (int)((*a)->pos_in_query - (*b)->pos_in_query);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
StoredRoutinesBinlogging
|
2005-12-22 06:39:02 +01:00
|
|
|
This paragraph applies only to statement-based binlogging. Row-based
|
|
|
|
binlogging does not need anything special like this.
|
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
Top-down overview:
|
|
|
|
|
|
|
|
1. Statements
|
|
|
|
|
|
|
|
Statements that have is_update_query(stmt) == TRUE are written into the
|
|
|
|
binary log verbatim.
|
|
|
|
Examples:
|
|
|
|
UPDATE tbl SET tbl.x = spfunc_w_side_effects()
|
|
|
|
UPDATE tbl SET tbl.x=1 WHERE spfunc_w_side_effect_that_returns_false(tbl.y)
|
|
|
|
|
|
|
|
Statements that have is_update_query(stmt) == FALSE (e.g. SELECTs) are not
|
|
|
|
written into binary log. Instead we catch function calls the statement
|
|
|
|
makes and write it into binary log separately (see #3).
|
|
|
|
|
|
|
|
2. PROCEDURE calls
|
|
|
|
|
|
|
|
CALL statements are not written into binary log. Instead
|
|
|
|
* Any FUNCTION invocation (in SET, IF, WHILE, OPEN CURSOR and other SP
|
|
|
|
instructions) is written into binlog separately.
|
|
|
|
|
|
|
|
* Each statement executed in SP is binlogged separately, according to rules
|
|
|
|
in #1, with the exception that we modify query string: we replace uses
|
|
|
|
of SP local variables with NAME_CONST('spvar_name', <spvar-value>) calls.
|
|
|
|
This substitution is done in subst_spvars().
|
|
|
|
|
|
|
|
3. FUNCTION calls
|
|
|
|
|
|
|
|
In sp_head::execute_function(), we check
|
|
|
|
* If this function invocation is done from a statement that is written
|
|
|
|
into the binary log.
|
|
|
|
* If there were any attempts to write events to the binary log during
|
2005-09-07 17:39:47 +02:00
|
|
|
function execution (grep for start_union_events and stop_union_events)
|
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
If the answers are No and Yes, we write the function call into the binary
|
2006-02-18 23:37:56 +01:00
|
|
|
log as "SELECT spfunc(<param1value>, <param2value>, ...)"
|
2005-09-07 17:39:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
4. Miscellaneous issues.
|
|
|
|
|
|
|
|
4.1 User variables.
|
|
|
|
|
|
|
|
When we call mysql_bin_log.write() for an SP statement, thd->user_var_events
|
|
|
|
must hold set<{var_name, value}> pairs for all user variables used during
|
|
|
|
the statement execution.
|
|
|
|
This set is produced by tracking user variable reads during statement
|
|
|
|
execution.
|
|
|
|
|
Fixing problems I identified in my auto_increment work pushed in July
(as part of the auto_increment cleanup of WL#3146; let's not be
sad, that monster push still removed serious bugs):
one problem with INSERT DELAYED (unexpected interval releases),
one with stored functions (wrong auto_inc binlogging).
These bugs were not released.
mysql-test/extra/binlog_tests/binlog_insert_delayed.test:
more tests of binlogging of INSERT DELAYED: with multi-row INSERTs.
I identified why sleeps are needed to get a repeatable row-based
binlogged: because without sleeps rows sometimes get groupped
and so generate different row based events.
mysql-test/extra/rpl_tests/rpl_foreign_key.test:
don't forget to drop tables on slave too, otherwise it leaves
an orphan innodb table leading to rpl_insert_id failing sometimes
(like in pushbuild "sapsrv2 -max").
mysql-test/extra/rpl_tests/rpl_insert_id.test:
testing that if some statement does not update any row, it does
not pollute the auto_inc binlog variables of the next statement;
the test has to use stored procedures because with plain statements,
mysql_reset_thd_for_next_command() does the resetting (and thus
there is no problem); mysql_reset_thd_for_next_command() is not
called inside routines.
mysql-test/r/binlog_row_binlog.result:
result additions
mysql-test/r/binlog_statement_insert_delayed.result:
result additions
mysql-test/r/binlog_stm_binlog.result:
result additions
mysql-test/r/rpl_insert_id.result:
result additions
mysql-test/r/rpl_loaddata.result:
With the change to log.cc reverted, the result changes and is better:
the change to log.cc had caused some INSERT_ID events to disappear
though they were necessary (but testsuite could not catch that because
it's single-threaded).
mysql-test/r/rpl_ndb_insert_ignore.result:
NDB is now like other engines regarding INSERT IGNORE: autoincrement
values which caused a duplicate key are re-used for next row, not lost.
rpl_ndb_insert_ignore.result is now identical to rpl_insert_ignore.result.
sql/log.cc:
LOAD DATA INFILE is binlogged as several events, and the last of them must
have the auto_inc id. So it's wrong to reset the auto_inc id after every
binlog write (because then it's lost after the first event of LOAD
DATA INFILE and so missing for the last one)/
Another problem: MYSQL_LOG::write() is not always called (for example
if no row was updated), so we were missing reset in some cases.
sql/sp_head.cc:
SELECT func1(),func2() generates two binlog events, so needs to
clear auto_increment binlog variables after each binlog event
(it would be more natural to clear them in the log write code,
but LOAD DATA INFILE would suffer from this see the cset comment
for log.cc). Without the clearing, the problem is:
> exec func1()
>> call cleanup_after_query() (which does not clear our vars here)
>> binlog SELECT func1()
<
> exec func2()
and so SELECT func2() is binlogged with the auto_inc of SELECT func1().
sql/sql_class.cc:
after every statement we should clear auto_inc variables used for
binlogging, except if this was a function/trigger (in which case
it may be "INSERT SELECT func()", where the cleanup_after_query()
executed in func() should not reset the auto_inc binlog variables
as they'll be necessary when binlogging the INSERT SELECT later).
sql/sql_insert.cc:
- as INSERT DELAYED uses the same TABLE object as the delayed_insert
system thread, we should not call ha_release_auto_increment()
from INSERT DELAYED (and btw it's logical as we reserve nothing
as we don't perform the insert). Calling the function caused us to
release values being used by the delayed_insert thread.
So I do the call only if this is a non-DELAYED INSERT.
- Assuming two INSERT DELAYED which get grouped by the delayed_insert
thread, the second may use values reserved by the first, which is ok
per se, but is a problem in statement-based binlogging:
the 2nd INSERT gets binlogged with the "interval start" value
of the first INSERT (=> duplicate error in slave).
- no reason to ha_release_auto_increment() after every inserted row
in INSERT SELECT; more efficient to do it only when the statement ends
sql/sql_parse.cc:
a comment
2006-09-12 15:42:13 +02:00
|
|
|
For SPs, this has the following implications:
|
2005-09-07 17:39:47 +02:00
|
|
|
1) thd->user_var_events may contain events from several SP statements and
|
|
|
|
needs to be valid after exection of these statements was finished. In
|
|
|
|
order to achieve that, we
|
|
|
|
* Allocate user_var_events array elements on appropriate mem_root (grep
|
|
|
|
for user_var_events_alloc).
|
|
|
|
* Use is_query_in_union() to determine if user_var_event is created.
|
|
|
|
|
|
|
|
2) We need to empty thd->user_var_events after we have wrote a function
|
|
|
|
call. This is currently done by making
|
|
|
|
reset_dynamic(&thd->user_var_events);
|
|
|
|
calls in several different places. (TODO cosider moving this into
|
|
|
|
mysql_bin_log.write() function)
|
Fixing problems I identified in my auto_increment work pushed in July
(as part of the auto_increment cleanup of WL#3146; let's not be
sad, that monster push still removed serious bugs):
one problem with INSERT DELAYED (unexpected interval releases),
one with stored functions (wrong auto_inc binlogging).
These bugs were not released.
mysql-test/extra/binlog_tests/binlog_insert_delayed.test:
more tests of binlogging of INSERT DELAYED: with multi-row INSERTs.
I identified why sleeps are needed to get a repeatable row-based
binlogged: because without sleeps rows sometimes get groupped
and so generate different row based events.
mysql-test/extra/rpl_tests/rpl_foreign_key.test:
don't forget to drop tables on slave too, otherwise it leaves
an orphan innodb table leading to rpl_insert_id failing sometimes
(like in pushbuild "sapsrv2 -max").
mysql-test/extra/rpl_tests/rpl_insert_id.test:
testing that if some statement does not update any row, it does
not pollute the auto_inc binlog variables of the next statement;
the test has to use stored procedures because with plain statements,
mysql_reset_thd_for_next_command() does the resetting (and thus
there is no problem); mysql_reset_thd_for_next_command() is not
called inside routines.
mysql-test/r/binlog_row_binlog.result:
result additions
mysql-test/r/binlog_statement_insert_delayed.result:
result additions
mysql-test/r/binlog_stm_binlog.result:
result additions
mysql-test/r/rpl_insert_id.result:
result additions
mysql-test/r/rpl_loaddata.result:
With the change to log.cc reverted, the result changes and is better:
the change to log.cc had caused some INSERT_ID events to disappear
though they were necessary (but testsuite could not catch that because
it's single-threaded).
mysql-test/r/rpl_ndb_insert_ignore.result:
NDB is now like other engines regarding INSERT IGNORE: autoincrement
values which caused a duplicate key are re-used for next row, not lost.
rpl_ndb_insert_ignore.result is now identical to rpl_insert_ignore.result.
sql/log.cc:
LOAD DATA INFILE is binlogged as several events, and the last of them must
have the auto_inc id. So it's wrong to reset the auto_inc id after every
binlog write (because then it's lost after the first event of LOAD
DATA INFILE and so missing for the last one)/
Another problem: MYSQL_LOG::write() is not always called (for example
if no row was updated), so we were missing reset in some cases.
sql/sp_head.cc:
SELECT func1(),func2() generates two binlog events, so needs to
clear auto_increment binlog variables after each binlog event
(it would be more natural to clear them in the log write code,
but LOAD DATA INFILE would suffer from this see the cset comment
for log.cc). Without the clearing, the problem is:
> exec func1()
>> call cleanup_after_query() (which does not clear our vars here)
>> binlog SELECT func1()
<
> exec func2()
and so SELECT func2() is binlogged with the auto_inc of SELECT func1().
sql/sql_class.cc:
after every statement we should clear auto_inc variables used for
binlogging, except if this was a function/trigger (in which case
it may be "INSERT SELECT func()", where the cleanup_after_query()
executed in func() should not reset the auto_inc binlog variables
as they'll be necessary when binlogging the INSERT SELECT later).
sql/sql_insert.cc:
- as INSERT DELAYED uses the same TABLE object as the delayed_insert
system thread, we should not call ha_release_auto_increment()
from INSERT DELAYED (and btw it's logical as we reserve nothing
as we don't perform the insert). Calling the function caused us to
release values being used by the delayed_insert thread.
So I do the call only if this is a non-DELAYED INSERT.
- Assuming two INSERT DELAYED which get grouped by the delayed_insert
thread, the second may use values reserved by the first, which is ok
per se, but is a problem in statement-based binlogging:
the 2nd INSERT gets binlogged with the "interval start" value
of the first INSERT (=> duplicate error in slave).
- no reason to ha_release_auto_increment() after every inserted row
in INSERT SELECT; more efficient to do it only when the statement ends
sql/sql_parse.cc:
a comment
2006-09-12 15:42:13 +02:00
|
|
|
|
|
|
|
4.2 Auto_increment storage in binlog
|
|
|
|
|
|
|
|
As we may write two statements to binlog from one single logical statement
|
|
|
|
(case of "SELECT func1(),func2()": it is binlogged as "SELECT func1()" and
|
|
|
|
then "SELECT func2()"), we need to reset auto_increment binlog variables
|
|
|
|
after each binlogged SELECT. Otherwise, the auto_increment value of the
|
|
|
|
first SELECT would be used for the second too.
|
2005-08-25 15:34:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Replace thd->query{_length} with a string that one can write to
|
|
|
|
the binlog.
|
2005-08-25 15:34:34 +02:00
|
|
|
|
|
|
|
The binlog-suitable string is produced by replacing references to SP local
|
2007-10-11 20:37:45 +02:00
|
|
|
variables with NAME_CONST('sp_var_name', value) calls.
|
|
|
|
|
|
|
|
@param thd Current thread.
|
|
|
|
@param instr Instruction (we look for Item_splocal instances in
|
|
|
|
instr->free_list)
|
|
|
|
@param query_str Original query string
|
|
|
|
|
|
|
|
@return
|
|
|
|
- FALSE on success.
|
|
|
|
thd->query{_length} either has been appropriately replaced or there
|
|
|
|
is no need for replacements.
|
|
|
|
- TRUE out of memory error.
|
2005-08-25 15:34:34 +02:00
|
|
|
*/
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
static bool
|
|
|
|
subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str)
|
2005-08-25 15:34:34 +02:00
|
|
|
{
|
|
|
|
DBUG_ENTER("subst_spvars");
|
|
|
|
|
2007-07-28 13:01:29 +02:00
|
|
|
Dynamic_array<Item_splocal*> sp_vars_uses;
|
|
|
|
char *pbuf, *cur, buffer[512];
|
|
|
|
String qbuf(buffer, sizeof(buffer), &my_charset_bin);
|
|
|
|
int prev_pos, res, buf_len;
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2007-07-28 13:01:29 +02:00
|
|
|
/* Find all instances of Item_splocal used in this statement */
|
|
|
|
for (Item *item= instr->free_list; item; item= item->next)
|
|
|
|
{
|
|
|
|
if (item->is_splocal())
|
2005-08-25 15:34:34 +02:00
|
|
|
{
|
2007-07-28 13:01:29 +02:00
|
|
|
Item_splocal *item_spl= (Item_splocal*)item;
|
|
|
|
if (item_spl->pos_in_query)
|
|
|
|
sp_vars_uses.append(item_spl);
|
2005-08-25 15:34:34 +02:00
|
|
|
}
|
2007-07-28 13:01:29 +02:00
|
|
|
}
|
|
|
|
if (!sp_vars_uses.elements())
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
|
|
|
|
/* Sort SP var refs by their occurences in the query */
|
|
|
|
sp_vars_uses.sort(cmp_splocal_locations);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2007-07-28 13:01:29 +02:00
|
|
|
/*
|
|
|
|
Construct a statement string where SP local var refs are replaced
|
|
|
|
with "NAME_CONST(name, value)"
|
|
|
|
*/
|
|
|
|
qbuf.length(0);
|
|
|
|
cur= query_str->str;
|
|
|
|
prev_pos= res= 0;
|
|
|
|
for (Item_splocal **splocal= sp_vars_uses.front();
|
|
|
|
splocal < sp_vars_uses.back(); splocal++)
|
|
|
|
{
|
|
|
|
Item *val;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2007-07-28 13:01:29 +02:00
|
|
|
char str_buffer[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
String str_value_holder(str_buffer, sizeof(str_buffer),
|
|
|
|
&my_charset_latin1);
|
|
|
|
String *str_value;
|
|
|
|
|
|
|
|
/* append the text between sp ref occurences */
|
|
|
|
res|= qbuf.append(cur + prev_pos, (*splocal)->pos_in_query - prev_pos);
|
2007-07-30 01:35:16 +02:00
|
|
|
prev_pos= (*splocal)->pos_in_query + (*splocal)->len_in_query;
|
2007-07-28 13:01:29 +02:00
|
|
|
|
|
|
|
/* append the spvar substitute */
|
|
|
|
res|= qbuf.append(STRING_WITH_LEN(" NAME_CONST('"));
|
|
|
|
res|= qbuf.append((*splocal)->m_name.str, (*splocal)->m_name.length);
|
|
|
|
res|= qbuf.append(STRING_WITH_LEN("',"));
|
|
|
|
res|= (*splocal)->fix_fields(thd, (Item **) splocal);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
if (res)
|
2007-07-28 13:01:29 +02:00
|
|
|
break;
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2007-07-28 13:01:29 +02:00
|
|
|
val= (*splocal)->this_item();
|
2007-07-29 11:41:39 +02:00
|
|
|
DBUG_PRINT("info", ("print 0x%lx", (long) val));
|
2007-07-28 13:01:29 +02:00
|
|
|
str_value= sp_get_item_value(thd, val, &str_value_holder);
|
|
|
|
if (str_value)
|
|
|
|
res|= qbuf.append(*str_value);
|
|
|
|
else
|
|
|
|
res|= qbuf.append(STRING_WITH_LEN("NULL"));
|
|
|
|
res|= qbuf.append(')');
|
|
|
|
if (res)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res|= qbuf.append(cur + prev_pos, query_str->length - prev_pos);
|
|
|
|
if (res)
|
|
|
|
DBUG_RETURN(TRUE);
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2007-07-28 13:01:29 +02:00
|
|
|
/*
|
|
|
|
Allocate additional space at the end of the new query string for the
|
|
|
|
query_cache_send_result_to_client function.
|
|
|
|
*/
|
|
|
|
buf_len= qbuf.length() + thd->db_length + 1 + QUERY_CACHE_FLAGS_SIZE + 1;
|
2007-07-29 18:12:54 +02:00
|
|
|
if ((pbuf= (char *) alloc_root(thd->mem_root, buf_len)))
|
2007-07-28 13:01:29 +02:00
|
|
|
{
|
|
|
|
memcpy(pbuf, qbuf.ptr(), qbuf.length());
|
|
|
|
pbuf[qbuf.length()]= 0;
|
2005-08-25 15:34:34 +02:00
|
|
|
}
|
2007-07-28 13:01:29 +02:00
|
|
|
else
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
|
|
|
thd->query= pbuf;
|
|
|
|
thd->query_length= qbuf.length();
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
2005-08-25 15:34:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
/*
|
|
|
|
Return appropriate error about recursion limit reaching
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
sp_head::recursion_level_error()
|
2006-01-05 23:47:49 +01:00
|
|
|
thd Thread handle
|
2005-11-23 00:11:19 +01:00
|
|
|
|
|
|
|
NOTE
|
|
|
|
For functions and triggers we return error about prohibited recursion.
|
|
|
|
For stored procedures we return about reaching recursion limit.
|
|
|
|
*/
|
|
|
|
|
2006-01-05 23:47:49 +01:00
|
|
|
void sp_head::recursion_level_error(THD *thd)
|
2005-11-23 00:11:19 +01:00
|
|
|
{
|
|
|
|
if (m_type == TYPE_ENUM_PROCEDURE)
|
|
|
|
{
|
|
|
|
my_error(ER_SP_RECURSION_LIMIT, MYF(0),
|
|
|
|
thd->variables.max_sp_recursion_depth,
|
2005-12-12 12:57:35 +01:00
|
|
|
m_name.str);
|
2005-11-23 00:11:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
my_error(ER_SP_NO_RECURSION, MYF(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Execute the routine. The main instruction jump loop is there.
|
2005-08-25 15:34:34 +02:00
|
|
|
Assume the parameters already set.
|
2007-10-11 20:37:45 +02:00
|
|
|
@todo
|
|
|
|
- Will write this SP statement into binlog separately
|
|
|
|
(TODO: consider changing the condition to "not inside event union")
|
|
|
|
|
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
FALSE on success
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
TRUE on error
|
2005-08-25 15:34:34 +02:00
|
|
|
*/
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
bool
|
|
|
|
sp_head::execute(THD *thd)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_head::execute");
|
2007-08-31 18:42:14 +02:00
|
|
|
char saved_cur_db_name_buf[NAME_LEN+1];
|
|
|
|
LEX_STRING saved_cur_db_name=
|
|
|
|
{ saved_cur_db_name_buf, sizeof(saved_cur_db_name_buf) };
|
|
|
|
bool cur_db_changed= FALSE;
|
2004-07-22 16:46:59 +02:00
|
|
|
sp_rcontext *ctx;
|
2005-12-07 15:01:17 +01:00
|
|
|
bool err_status= FALSE;
|
2003-02-26 19:22:29 +01:00
|
|
|
uint ip= 0;
|
2005-07-28 21:39:11 +02:00
|
|
|
ulong save_sql_mode;
|
2006-04-19 12:27:59 +02:00
|
|
|
bool save_abort_on_warning;
|
2005-06-15 19:58:35 +02:00
|
|
|
Query_arena *old_arena;
|
2005-08-18 11:23:54 +02:00
|
|
|
/* per-instruction arena */
|
|
|
|
MEM_ROOT execute_mem_root;
|
|
|
|
Query_arena execute_arena(&execute_mem_root, INITIALIZED_FOR_SP),
|
2005-09-02 15:21:19 +02:00
|
|
|
backup_arena;
|
2005-03-04 15:46:45 +01:00
|
|
|
query_id_t old_query_id;
|
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
|
|
|
TABLE *old_derived_tables;
|
|
|
|
LEX *old_lex;
|
|
|
|
Item_change_list old_change_list;
|
|
|
|
String old_packet;
|
WL#4165 "Prepared statements: validation".
Add metadata validation to ~20 more SQL commands. Make sure that
these commands actually work in ps-protocol, since until now they
were enabled, but not carefully tested.
Fixes the ml003 bug found by Matthias during internal testing of the
patch.
mysql-test/r/ps_ddl.result:
Update test results (WL#4165)
mysql-test/t/ps_ddl.test:
Cover with tests metadata validation of 26 SQL statements.
sql/mysql_priv.h:
Fix the name in the comment.
sql/sp_head.cc:
Changed the way the observer is removed in case of stored procedures
to support validation prepare stmt from "call p1(<expr>)": whereas
tables used in the expression must be validated, substatements
of p1 must not.
The previous scheme used to silence the observer only in stored
functions and triggers.
sql/sql_class.cc:
Now the observer is silenced in sp_head::execute(). Remove it from
Sub_statement_state.
sql/sql_class.h:
Now the observer is silenced in sp_head::execute(). Remove it from
Sub_statement_state.
sql/sql_parse.cc:
Add CF_REEXECUTION_FRAGILE to 20 more SQLCOMs that need it.
sql/sql_prepare.cc:
Add metadata validation to ~20 new SQLCOMs that need it.
Fix memory leaks with expressions used in SHOW DATABASES and CALL
(and prepared statements).
We need to fix all expressions at prepare, since if these expressions
use subqueries, there are one-time transformations of the parse
tree that must be done at prepare.
List of fixed commands includes: SHOW TABLES, SHOW DATABASES,
SHOW TRIGGERS, SHOW EVENTS, SHOW OPEN TABLES,SHOW KEYS, SHOW FIELDS,
SHOW COLLATIONS, SHOW CHARSETS, SHOW VARIABLES, SHOW TATUS, SHOW TABLE
STATUS, SHOW PROCEDURE STATUS, SHOW FUNCTION STATUS, CALL.
Add comment to set_parameters().
sql/table.h:
Update comments.
2008-04-16 23:04:49 +02:00
|
|
|
Metadata_version_observer *save_metadata_observer= thd->m_metadata_observer;
|
2004-07-22 16:46:59 +02:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
Object_creation_ctx *saved_creation_ctx;
|
|
|
|
|
Fixed BUG#9937: Crash on call to stored procedure.
This only showed up on two known platforms, both ia64 (one HP-UX and one Linux wich icc).
For some reason, they only get half the stack size they are supposed to have, which
makes deep SP recursion overrun the stack before check_stack_overrun() is triggered.
Also made som minor fixes in the check_stack_overrun() definition, supporting variable
margins.
No test case added, but the reason for the bug report was a failed existing test case
on these machines, which now works.
sql/item_cmpfunc.cc:
Adopted call to new check_stack_overrun() definition.
sql/item_func.cc:
Adopted calls to new check_stack_overrun() definition.
sql/item_subselect.cc:
Adopted call to new check_stack_overrun() definition.
sql/mysql_priv.h:
Changed definition of check_stack_overrun(), thread_stack_min variable no longer needed.
sql/mysqld.cc:
thread_stack_min variable no longer needed (with variable margin arg. to check_thread_overrun()).
On (at least some) ia64 machines, it seems we only get half the requested stack in reality,
so deep SP recursion crashes before the thread overrun check is triggered.
We work around this by requesting twice the stack requested to get expected size.
sql/sp_head.cc:
Adopted call to new check_stack_overrun() definition, and use a wider margin
execution.
sql/sql_parse.cc:
Modified check_stack_overrun() definition. Removed unused arg that didn't sever any
purpose, and added a 'margin' argument to support different margins for different
callrers.
sql/table.cc:
Adopted call to new check_stack_overrun() definition.
2005-05-26 20:36:14 +02:00
|
|
|
/* Use some extra margin for possible SP recursion and functions */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
if (check_stack_overrun(thd, 8 * STACK_MIN_SIZE, (uchar*)&old_packet))
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2004-03-11 17:18:59 +01:00
|
|
|
|
2005-11-23 00:11:19 +01:00
|
|
|
/* init per-instruction memroot */
|
2007-11-19 17:59:44 +01:00
|
|
|
init_sql_alloc(&execute_mem_root, MEM_ROOT_BLOCK_SIZE, 0);
|
2005-11-23 00:11:19 +01:00
|
|
|
|
|
|
|
DBUG_ASSERT(!(m_flags & IS_INVOKED));
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
m_flags|= IS_INVOKED;
|
2005-11-23 00:11:19 +01:00
|
|
|
m_first_instance->m_first_free_instance= m_next_cached_sp;
|
2006-01-05 23:47:49 +01:00
|
|
|
if (m_next_cached_sp)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info",
|
|
|
|
("first free for 0x%lx ++: 0x%lx->0x%lx level: %lu flags %x",
|
|
|
|
(ulong)m_first_instance, (ulong) this,
|
|
|
|
(ulong) m_next_cached_sp,
|
|
|
|
m_next_cached_sp->m_recursion_level,
|
|
|
|
m_next_cached_sp->m_flags));
|
|
|
|
}
|
2005-11-23 00:11:19 +01:00
|
|
|
/*
|
|
|
|
Check that if there are not any instances after this one then
|
|
|
|
pointer to the last instance points on this instance or if there are
|
|
|
|
some instances after this one then recursion level of next instance
|
|
|
|
greater then recursion level of current instance on 1
|
|
|
|
*/
|
|
|
|
DBUG_ASSERT((m_next_cached_sp == 0 &&
|
|
|
|
m_first_instance->m_last_cached_sp == this) ||
|
|
|
|
(m_recursion_level + 1 == m_next_cached_sp->m_recursion_level));
|
2005-07-01 11:01:46 +02:00
|
|
|
|
2007-04-06 18:21:30 +02:00
|
|
|
/*
|
|
|
|
NOTE: The SQL Standard does not specify the context that should be
|
|
|
|
preserved for stored routines. However, at SAP/Walldorf meeting it was
|
|
|
|
decided that current database should be preserved.
|
|
|
|
*/
|
|
|
|
|
2004-09-08 14:23:14 +02:00
|
|
|
if (m_db.length &&
|
2007-08-31 18:42:14 +02:00
|
|
|
(err_status= mysql_opt_change_db(thd, &m_db, &saved_cur_db_name, FALSE,
|
|
|
|
&cur_db_changed)))
|
|
|
|
{
|
2004-03-11 17:18:59 +01:00
|
|
|
goto done;
|
2007-08-31 18:42:14 +02:00
|
|
|
}
|
2003-03-26 15:02:48 +01:00
|
|
|
|
2004-07-22 16:46:59 +02:00
|
|
|
if ((ctx= thd->spcont))
|
2003-09-16 14:26:08 +02:00
|
|
|
ctx->clear_handler();
|
2007-10-19 23:20:38 +02:00
|
|
|
thd->is_slave_error= 0;
|
2005-09-02 15:21:19 +02:00
|
|
|
old_arena= thd->stmt_arena;
|
2004-07-22 16:46:59 +02:00
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
/*
|
|
|
|
Switch query context. This has to be done early as this is sometimes
|
|
|
|
allocated trough sql_alloc
|
|
|
|
*/
|
|
|
|
saved_creation_ctx= m_creation_ctx->set_n_backup(thd);
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
We have to save/restore this info when we are changing call level to
|
|
|
|
be able properly do close_thread_tables() in instructions.
|
|
|
|
*/
|
|
|
|
old_query_id= thd->query_id;
|
|
|
|
old_derived_tables= thd->derived_tables;
|
|
|
|
thd->derived_tables= 0;
|
2005-07-28 21:39:11 +02:00
|
|
|
save_sql_mode= thd->variables.sql_mode;
|
|
|
|
thd->variables.sql_mode= m_sql_mode;
|
2006-04-19 12:27:59 +02:00
|
|
|
save_abort_on_warning= thd->abort_on_warning;
|
2006-10-19 20:39:51 +02:00
|
|
|
thd->abort_on_warning= 0;
|
WL#4165 "Prepared statements: validation".
Add metadata validation to ~20 more SQL commands. Make sure that
these commands actually work in ps-protocol, since until now they
were enabled, but not carefully tested.
Fixes the ml003 bug found by Matthias during internal testing of the
patch.
mysql-test/r/ps_ddl.result:
Update test results (WL#4165)
mysql-test/t/ps_ddl.test:
Cover with tests metadata validation of 26 SQL statements.
sql/mysql_priv.h:
Fix the name in the comment.
sql/sp_head.cc:
Changed the way the observer is removed in case of stored procedures
to support validation prepare stmt from "call p1(<expr>)": whereas
tables used in the expression must be validated, substatements
of p1 must not.
The previous scheme used to silence the observer only in stored
functions and triggers.
sql/sql_class.cc:
Now the observer is silenced in sp_head::execute(). Remove it from
Sub_statement_state.
sql/sql_class.h:
Now the observer is silenced in sp_head::execute(). Remove it from
Sub_statement_state.
sql/sql_parse.cc:
Add CF_REEXECUTION_FRAGILE to 20 more SQLCOMs that need it.
sql/sql_prepare.cc:
Add metadata validation to ~20 new SQLCOMs that need it.
Fix memory leaks with expressions used in SHOW DATABASES and CALL
(and prepared statements).
We need to fix all expressions at prepare, since if these expressions
use subqueries, there are one-time transformations of the parse
tree that must be done at prepare.
List of fixed commands includes: SHOW TABLES, SHOW DATABASES,
SHOW TRIGGERS, SHOW EVENTS, SHOW OPEN TABLES,SHOW KEYS, SHOW FIELDS,
SHOW COLLATIONS, SHOW CHARSETS, SHOW VARIABLES, SHOW TATUS, SHOW TABLE
STATUS, SHOW PROCEDURE STATUS, SHOW FUNCTION STATUS, CALL.
Add comment to set_parameters().
sql/table.h:
Update comments.
2008-04-16 23:04:49 +02:00
|
|
|
/**
|
|
|
|
When inside a substatement (a stored function or trigger
|
|
|
|
statement), clear the metadata observer in THD, if any.
|
|
|
|
Remember the value of the observer here, to be able
|
|
|
|
to restore it when leaving the substatement.
|
|
|
|
|
|
|
|
We reset the observer to suppress errors when a substatement
|
|
|
|
uses temporary tables. If a temporary table does not exist
|
|
|
|
at start of the main statement, it's not prelocked
|
|
|
|
and thus is not validated with other prelocked tables.
|
|
|
|
|
|
|
|
Later on, when the temporary table is opened, metadata
|
|
|
|
versions mismatch, expectedly.
|
|
|
|
|
|
|
|
The proper solution for the problem is to re-validate tables
|
|
|
|
of substatements (Bug#12257, Bug#27011, Bug#32868, Bug#33000),
|
|
|
|
but it's not implemented yet.
|
|
|
|
*/
|
|
|
|
thd->m_metadata_observer= 0;
|
2006-04-19 12:27:59 +02: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
|
|
|
/*
|
|
|
|
It is also more efficient to save/restore current thd->lex once when
|
|
|
|
do it in each instruction
|
|
|
|
*/
|
|
|
|
old_lex= thd->lex;
|
|
|
|
/*
|
|
|
|
We should also save Item tree change list to avoid rollback something
|
|
|
|
too early in the calling query.
|
|
|
|
*/
|
|
|
|
old_change_list= thd->change_list;
|
|
|
|
thd->change_list.empty();
|
|
|
|
/*
|
|
|
|
Cursors will use thd->packet, so they may corrupt data which was prepared
|
|
|
|
for sending by upper level. OTOH cursors in the same routine can share this
|
|
|
|
buffer safely so let use use routine-local packet instead of having own
|
|
|
|
packet buffer for each cursor.
|
|
|
|
|
|
|
|
It is probably safe to use same thd->convert_buff everywhere.
|
|
|
|
*/
|
|
|
|
old_packet.swap(thd->packet);
|
|
|
|
|
2005-08-18 11:23:54 +02:00
|
|
|
/*
|
|
|
|
Switch to per-instruction arena here. We can do it since we cleanup
|
|
|
|
arena after every instruction.
|
|
|
|
*/
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->set_n_backup_active_arena(&execute_arena, &backup_arena);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Save callers arena in order to store instruction results and out
|
|
|
|
parameters in it later during sp_eval_func_item()
|
|
|
|
*/
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->spcont->callers_arena= &backup_arena;
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2007-11-13 15:46:17 +01:00
|
|
|
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
|
|
|
|
/* Discard the initial part of executing routines. */
|
|
|
|
thd->profiling.discard_current_query();
|
|
|
|
#endif
|
2003-02-26 19:22:29 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
sp_instr *i;
|
2003-09-16 14:26:08 +02:00
|
|
|
uint hip; // Handler ip
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2007-11-13 15:46:17 +01:00
|
|
|
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
|
|
|
|
/*
|
|
|
|
Treat each "instr" of a routine as discrete unit that could be profiled.
|
|
|
|
Profiling only records information for segments of code that set the
|
|
|
|
source of the query, and almost all kinds of instructions in s-p do not.
|
|
|
|
*/
|
|
|
|
thd->profiling.finish_current_query();
|
|
|
|
thd->profiling.start_new_query("continuing inside routine");
|
|
|
|
#endif
|
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
i = get_instr(ip); // Returns NULL when we're done.
|
|
|
|
if (i == NULL)
|
2007-11-13 15:46:17 +01:00
|
|
|
{
|
|
|
|
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
|
|
|
|
thd->profiling.discard_current_query();
|
|
|
|
#endif
|
2003-02-26 19:22:29 +01:00
|
|
|
break;
|
2007-11-13 15:46:17 +01:00
|
|
|
}
|
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
DBUG_PRINT("execute", ("Instruction %u", ip));
|
2007-11-13 15:46:17 +01:00
|
|
|
|
2005-08-15 17:15:12 +02:00
|
|
|
/* Don't change NOW() in FUNCTION or TRIGGER */
|
|
|
|
if (!thd->in_sub_stmt)
|
|
|
|
thd->set_time(); // Make current_time() et al work
|
2005-09-07 17:39:47 +02:00
|
|
|
|
2005-06-23 18:22:08 +02:00
|
|
|
/*
|
2005-09-02 15:21:19 +02:00
|
|
|
We have to set thd->stmt_arena before executing the instruction
|
2005-06-23 18:22:08 +02:00
|
|
|
to store in the instruction free_list all new items, created
|
|
|
|
during the first execution (for example expanding of '*' or the
|
|
|
|
items made during other permanent subquery transformations).
|
|
|
|
*/
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->stmt_arena= i;
|
2005-09-07 17:39:47 +02:00
|
|
|
|
2005-09-09 18:09:37 +02:00
|
|
|
/*
|
|
|
|
Will write this SP statement into binlog separately
|
|
|
|
(TODO: consider changing the condition to "not inside event union")
|
|
|
|
*/
|
|
|
|
if (thd->prelocked_mode == NON_PRELOCKED)
|
2005-09-07 17:39:47 +02:00
|
|
|
thd->user_var_events_alloc= thd->mem_root;
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
err_status= i->execute(thd, &ip);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2004-05-26 13:28:35 +02:00
|
|
|
if (i->free_list)
|
|
|
|
cleanup_items(i->free_list);
|
2005-09-09 18:09:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
If we've set thd->user_var_events_alloc to mem_root of this SP
|
|
|
|
statement, clean all the events allocated in it.
|
|
|
|
*/
|
|
|
|
if (thd->prelocked_mode == NON_PRELOCKED)
|
|
|
|
{
|
|
|
|
reset_dynamic(&thd->user_var_events);
|
|
|
|
thd->user_var_events_alloc= NULL;//DEBUG
|
|
|
|
}
|
2005-06-23 18:22:08 +02:00
|
|
|
|
2005-08-18 11:23:54 +02:00
|
|
|
/* we should cleanup free_list and memroot, used by instruction */
|
2005-12-01 11:26:46 +01:00
|
|
|
thd->cleanup_after_query();
|
2005-09-09 18:09:37 +02:00
|
|
|
free_root(&execute_mem_root, MYF(0));
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
Check if an exception has occurred and a handler has been found
|
2005-12-07 15:01:17 +01:00
|
|
|
Note: We have to check even if err_status == FALSE, since warnings (and
|
|
|
|
some errors) don't return a non-zero value. We also have to check even
|
|
|
|
if thd->killed != 0, since some errors return with this even when a
|
|
|
|
handler has been found (e.g. "bad data").
|
2005-08-11 14:58:15 +02:00
|
|
|
*/
|
2005-04-05 15:49:10 +02:00
|
|
|
if (ctx)
|
2003-09-16 14:26:08 +02:00
|
|
|
{
|
|
|
|
uint hf;
|
|
|
|
|
2005-08-15 17:15:12 +02:00
|
|
|
switch (ctx->found_handler(&hip, &hf)) {
|
2003-09-16 14:26:08 +02:00
|
|
|
case SP_HANDLER_NONE:
|
|
|
|
break;
|
|
|
|
case SP_HANDLER_CONTINUE:
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->restore_active_arena(&execute_arena, &backup_arena);
|
|
|
|
thd->set_n_backup_active_arena(&execute_arena, &backup_arena);
|
2007-03-07 17:53:46 +01:00
|
|
|
ctx->push_hstack(i->get_cont_dest());
|
2004-10-20 03:04:37 +02:00
|
|
|
// Fall through
|
2003-09-16 14:26:08 +02:00
|
|
|
default:
|
|
|
|
ip= hip;
|
2005-12-07 15:01:17 +01:00
|
|
|
err_status= FALSE;
|
2003-09-16 14:26:08 +02:00
|
|
|
ctx->clear_handler();
|
2005-09-26 18:22:00 +02:00
|
|
|
ctx->enter_handler(hip);
|
2004-10-20 03:04:37 +02:00
|
|
|
thd->clear_error();
|
2006-11-01 18:41:09 +01:00
|
|
|
thd->is_fatal_error= 0;
|
2005-04-05 15:49:10 +02:00
|
|
|
thd->killed= THD::NOT_KILLED;
|
2007-03-15 09:51:35 +01:00
|
|
|
thd->mysys_var->abort= 0;
|
2003-09-16 14:26:08 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2005-12-07 15:01:17 +01:00
|
|
|
} while (!err_status && !thd->killed);
|
2003-03-26 15:02:48 +01:00
|
|
|
|
2007-11-13 15:46:17 +01:00
|
|
|
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
|
|
|
|
thd->profiling.finish_current_query();
|
|
|
|
thd->profiling.start_new_query("tail end of routine");
|
|
|
|
#endif
|
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
/* Restore query context. */
|
|
|
|
|
|
|
|
m_creation_ctx->restore_env(thd, saved_creation_ctx);
|
|
|
|
|
|
|
|
/* Restore arena. */
|
|
|
|
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->restore_active_arena(&execute_arena, &backup_arena);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
thd->spcont->pop_all_cursors(); // To avoid memory leaks after an error
|
2005-08-18 11:23:54 +02: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
|
|
|
/* Restore all saved */
|
|
|
|
old_packet.swap(thd->packet);
|
|
|
|
DBUG_ASSERT(thd->change_list.is_empty());
|
|
|
|
thd->change_list= old_change_list;
|
|
|
|
/* To avoid wiping out thd->change_list on old_change_list destruction */
|
|
|
|
old_change_list.empty();
|
|
|
|
thd->lex= old_lex;
|
|
|
|
thd->query_id= old_query_id;
|
|
|
|
DBUG_ASSERT(!thd->derived_tables);
|
|
|
|
thd->derived_tables= old_derived_tables;
|
2005-07-28 21:39:11 +02:00
|
|
|
thd->variables.sql_mode= save_sql_mode;
|
2006-04-19 12:27:59 +02:00
|
|
|
thd->abort_on_warning= save_abort_on_warning;
|
WL#4165 "Prepared statements: validation".
Add metadata validation to ~20 more SQL commands. Make sure that
these commands actually work in ps-protocol, since until now they
were enabled, but not carefully tested.
Fixes the ml003 bug found by Matthias during internal testing of the
patch.
mysql-test/r/ps_ddl.result:
Update test results (WL#4165)
mysql-test/t/ps_ddl.test:
Cover with tests metadata validation of 26 SQL statements.
sql/mysql_priv.h:
Fix the name in the comment.
sql/sp_head.cc:
Changed the way the observer is removed in case of stored procedures
to support validation prepare stmt from "call p1(<expr>)": whereas
tables used in the expression must be validated, substatements
of p1 must not.
The previous scheme used to silence the observer only in stored
functions and triggers.
sql/sql_class.cc:
Now the observer is silenced in sp_head::execute(). Remove it from
Sub_statement_state.
sql/sql_class.h:
Now the observer is silenced in sp_head::execute(). Remove it from
Sub_statement_state.
sql/sql_parse.cc:
Add CF_REEXECUTION_FRAGILE to 20 more SQLCOMs that need it.
sql/sql_prepare.cc:
Add metadata validation to ~20 new SQLCOMs that need it.
Fix memory leaks with expressions used in SHOW DATABASES and CALL
(and prepared statements).
We need to fix all expressions at prepare, since if these expressions
use subqueries, there are one-time transformations of the parse
tree that must be done at prepare.
List of fixed commands includes: SHOW TABLES, SHOW DATABASES,
SHOW TRIGGERS, SHOW EVENTS, SHOW OPEN TABLES,SHOW KEYS, SHOW FIELDS,
SHOW COLLATIONS, SHOW CHARSETS, SHOW VARIABLES, SHOW TATUS, SHOW TABLE
STATUS, SHOW PROCEDURE STATUS, SHOW FUNCTION STATUS, CALL.
Add comment to set_parameters().
sql/table.h:
Update comments.
2008-04-16 23:04:49 +02:00
|
|
|
thd->m_metadata_observer= save_metadata_observer;
|
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-02 15:21:19 +02:00
|
|
|
thd->stmt_arena= old_arena;
|
2005-06-21 19:15:21 +02:00
|
|
|
state= EXECUTED;
|
2004-07-22 16:46:59 +02:00
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
done:
|
2007-10-19 23:20:38 +02:00
|
|
|
DBUG_PRINT("info", ("err_status: %d killed: %d is_slave_error: %d report_error: %d",
|
|
|
|
err_status, thd->killed, thd->is_slave_error,
|
2007-10-30 18:08:16 +01:00
|
|
|
thd->is_error()));
|
2004-05-26 13:28:35 +02:00
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
if (thd->killed)
|
2005-12-07 15:01:17 +01:00
|
|
|
err_status= TRUE;
|
2006-01-06 00:08:48 +01:00
|
|
|
/*
|
|
|
|
If the DB has changed, the pointer has changed too, but the
|
|
|
|
original thd->db will then have been freed
|
|
|
|
*/
|
2007-08-31 18:42:14 +02:00
|
|
|
if (cur_db_changed && !thd->killed)
|
2003-03-26 15:02:48 +01:00
|
|
|
{
|
2005-12-06 22:57:15 +01:00
|
|
|
/*
|
2007-08-31 18:42:14 +02:00
|
|
|
Force switching back to the saved current database, because it may be
|
|
|
|
NULL. In this case, mysql_change_db() would generate an error.
|
2005-12-06 22:57:15 +01:00
|
|
|
*/
|
2007-08-31 18:42:14 +02:00
|
|
|
|
|
|
|
err_status|= mysql_change_db(thd, &saved_cur_db_name, TRUE);
|
2003-03-26 15:02:48 +01:00
|
|
|
}
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
m_flags&= ~IS_INVOKED;
|
2006-01-06 00:08:48 +01:00
|
|
|
DBUG_PRINT("info",
|
|
|
|
("first free for 0x%lx --: 0x%lx->0x%lx, level: %lu, flags %x",
|
|
|
|
(ulong) m_first_instance,
|
|
|
|
(ulong) m_first_instance->m_first_free_instance,
|
|
|
|
(ulong) this, m_recursion_level, m_flags));
|
2005-11-23 00:11:19 +01:00
|
|
|
/*
|
|
|
|
Check that we have one of following:
|
|
|
|
|
|
|
|
1) there are not free instances which means that this instance is last
|
|
|
|
in the list of instances (pointer to the last instance point on it and
|
|
|
|
ther are not other instances after this one in the list)
|
|
|
|
|
|
|
|
2) There are some free instances which mean that first free instance
|
|
|
|
should go just after this one and recursion level of that free instance
|
2006-01-05 23:47:49 +01:00
|
|
|
should be on 1 more then recursion level of this instance.
|
2005-11-23 00:11:19 +01:00
|
|
|
*/
|
|
|
|
DBUG_ASSERT((m_first_instance->m_first_free_instance == 0 &&
|
|
|
|
this == m_first_instance->m_last_cached_sp &&
|
|
|
|
m_next_cached_sp == 0) ||
|
|
|
|
(m_first_instance->m_first_free_instance != 0 &&
|
|
|
|
m_first_instance->m_first_free_instance == m_next_cached_sp &&
|
|
|
|
m_first_instance->m_first_free_instance->m_recursion_level ==
|
|
|
|
m_recursion_level + 1));
|
|
|
|
m_first_instance->m_first_free_instance= this;
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(err_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
set_routine_security_ctx() changes routine security context, and
|
|
|
|
checks if there is an EXECUTE privilege in new context. If there is
|
|
|
|
no EXECUTE privilege, it changes the context back and returns a
|
|
|
|
error.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread handle
|
|
|
|
@param sp stored routine to change the context for
|
|
|
|
@param is_proc TRUE is procedure, FALSE if function
|
|
|
|
@param save_ctx pointer to an old security context
|
|
|
|
|
|
|
|
@todo
|
|
|
|
- Cache if the definer has the right to use the object on the
|
|
|
|
first usage and only reset the cache if someone does a GRANT
|
|
|
|
statement that 'may' affect this.
|
|
|
|
|
|
|
|
@retval
|
|
|
|
TRUE if there was a error, and the context wasn't changed.
|
|
|
|
@retval
|
|
|
|
FALSE if the context was changed.
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
set_routine_security_ctx(THD *thd, sp_head *sp, bool is_proc,
|
|
|
|
Security_context **save_ctx)
|
|
|
|
{
|
|
|
|
*save_ctx= 0;
|
2007-04-13 22:35:56 +02:00
|
|
|
if (sp->m_chistics->suid != SP_IS_NOT_SUID &&
|
|
|
|
sp->m_security_ctx.change_security_context(thd, &sp->m_definer_user,
|
|
|
|
&sp->m_definer_host,
|
|
|
|
&sp->m_db,
|
|
|
|
save_ctx))
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
If we changed context to run as another user, we need to check the
|
|
|
|
access right for the new context again as someone may have revoked
|
|
|
|
the right to use the procedure from this user.
|
|
|
|
|
|
|
|
TODO:
|
|
|
|
Cache if the definer has the right to use the object on the
|
|
|
|
first usage and only reset the cache if someone does a GRANT
|
|
|
|
statement that 'may' affect this.
|
|
|
|
*/
|
|
|
|
if (*save_ctx &&
|
|
|
|
check_routine_access(thd, EXECUTE_ACL,
|
|
|
|
sp->m_db.str, sp->m_name.str, is_proc, FALSE))
|
|
|
|
{
|
2007-04-13 22:35:56 +02:00
|
|
|
sp->m_security_ctx.restore_security_context(thd, *save_ctx);
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
*save_ctx= 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif // ! NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
|
|
|
|
|
2007-06-14 17:23:55 +02:00
|
|
|
/**
|
|
|
|
Execute trigger stored program.
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
- changes security context for triggers
|
|
|
|
- switch to new memroot
|
|
|
|
- call sp_head::execute
|
|
|
|
- restore old memroot
|
|
|
|
- restores security context
|
|
|
|
|
|
|
|
@param thd Thread handle
|
|
|
|
@param db database name
|
|
|
|
@param table table name
|
|
|
|
@param grant_info GRANT_INFO structure to be filled with
|
|
|
|
information about definer's privileges
|
|
|
|
on subject table
|
|
|
|
|
|
|
|
@todo
|
|
|
|
- TODO: we should create sp_rcontext once per command and reuse it
|
|
|
|
on subsequent executions of a trigger.
|
2007-06-14 17:23:55 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
FALSE on success
|
|
|
|
@retval
|
|
|
|
TRUE on error
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
2007-06-14 17:23:55 +02:00
|
|
|
sp_head::execute_trigger(THD *thd,
|
|
|
|
const LEX_STRING *db_name,
|
|
|
|
const LEX_STRING *table_name,
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
GRANT_INFO *grant_info)
|
|
|
|
{
|
|
|
|
sp_rcontext *octx = thd->spcont;
|
|
|
|
sp_rcontext *nctx = NULL;
|
|
|
|
bool err_status= FALSE;
|
|
|
|
MEM_ROOT call_mem_root;
|
|
|
|
Query_arena call_arena(&call_mem_root, Query_arena::INITIALIZED_FOR_SP);
|
|
|
|
Query_arena backup_arena;
|
|
|
|
|
|
|
|
DBUG_ENTER("sp_head::execute_trigger");
|
|
|
|
DBUG_PRINT("info", ("trigger %s", m_name.str));
|
|
|
|
|
2007-06-14 17:23:55 +02:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
Security_context *save_ctx= NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (m_chistics->suid != SP_IS_NOT_SUID &&
|
|
|
|
m_security_ctx.change_security_context(thd,
|
|
|
|
&m_definer_user,
|
|
|
|
&m_definer_host,
|
|
|
|
&m_db,
|
|
|
|
&save_ctx))
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Fetch information about table-level privileges for subject table into
|
|
|
|
GRANT_INFO instance. The access check itself will happen in
|
|
|
|
Item_trigger_field, where this information will be used along with
|
|
|
|
information about column-level privileges.
|
|
|
|
*/
|
|
|
|
|
|
|
|
fill_effective_table_privileges(thd,
|
|
|
|
grant_info,
|
|
|
|
db_name->str,
|
|
|
|
table_name->str);
|
|
|
|
|
|
|
|
/* Check that the definer has TRIGGER privilege on the subject table. */
|
|
|
|
|
|
|
|
if (!(grant_info->privilege & TRIGGER_ACL))
|
|
|
|
{
|
|
|
|
char priv_desc[128];
|
|
|
|
get_privilege_desc(priv_desc, sizeof(priv_desc), TRIGGER_ACL);
|
|
|
|
|
|
|
|
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), priv_desc,
|
|
|
|
thd->security_ctx->priv_user, thd->security_ctx->host_or_ip,
|
|
|
|
table_name->str);
|
|
|
|
|
|
|
|
m_security_ctx.restore_security_context(thd, save_ctx);
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
#endif // NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
/*
|
|
|
|
Prepare arena and memroot for objects which lifetime is whole
|
|
|
|
duration of trigger call (sp_rcontext, it's tables and items,
|
|
|
|
sp_cursor and Item_cache holders for case expressions). We can't
|
|
|
|
use caller's arena/memroot for those objects because in this case
|
|
|
|
some fixed amount of memory will be consumed for each trigger
|
|
|
|
invocation and so statements which involve lot of them will hog
|
|
|
|
memory.
|
|
|
|
|
|
|
|
TODO: we should create sp_rcontext once per command and reuse it
|
|
|
|
on subsequent executions of a trigger.
|
|
|
|
*/
|
|
|
|
init_sql_alloc(&call_mem_root, MEM_ROOT_BLOCK_SIZE, 0);
|
|
|
|
thd->set_n_backup_active_arena(&call_arena, &backup_arena);
|
|
|
|
|
|
|
|
if (!(nctx= new sp_rcontext(m_pcont, 0, octx)) ||
|
|
|
|
nctx->init(thd))
|
|
|
|
{
|
|
|
|
err_status= TRUE;
|
|
|
|
goto err_with_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
nctx->sp= this;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
thd->spcont= nctx;
|
|
|
|
|
|
|
|
err_status= execute(thd);
|
|
|
|
|
|
|
|
err_with_cleanup:
|
|
|
|
thd->restore_active_arena(&call_arena, &backup_arena);
|
2007-06-14 17:23:55 +02:00
|
|
|
|
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
m_security_ctx.restore_security_context(thd, save_ctx);
|
|
|
|
#endif // NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
delete nctx;
|
|
|
|
call_arena.free_items();
|
|
|
|
free_root(&call_mem_root, MYF(0));
|
|
|
|
thd->spcont= octx;
|
|
|
|
|
2007-05-23 21:24:16 +02:00
|
|
|
if (thd->killed)
|
|
|
|
thd->send_kill_message();
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(err_status);
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Execute a function.
|
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
- evaluate parameters
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
- changes security context for SUID routines
|
|
|
|
- switch to new memroot
|
2005-08-25 15:34:34 +02:00
|
|
|
- call sp_head::execute
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
- restore old memroot
|
2005-08-25 15:34:34 +02:00
|
|
|
- evaluate the return value
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
- restores security context
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread handle
|
|
|
|
@param argp Passed arguments (these are items from containing
|
|
|
|
statement?)
|
|
|
|
@param argcount Number of passed arguments. We need to check if
|
|
|
|
this is correct.
|
|
|
|
@param return_value_fld Save result here.
|
|
|
|
|
|
|
|
@todo
|
|
|
|
We should create sp_rcontext once per command and reuse
|
|
|
|
it on subsequent executions of a function/trigger.
|
|
|
|
|
|
|
|
@todo
|
|
|
|
In future we should associate call arena/mem_root with
|
|
|
|
sp_rcontext and allocate all these objects (and sp_rcontext
|
|
|
|
itself) on it directly rather than juggle with arenas.
|
|
|
|
|
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
FALSE on success
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
TRUE on error
|
2005-08-25 15:34:34 +02:00
|
|
|
*/
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
bool
|
|
|
|
sp_head::execute_function(THD *thd, Item **argp, uint argcount,
|
|
|
|
Field *return_value_fld)
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
2005-08-25 15:34:34 +02:00
|
|
|
ulonglong binlog_save_options;
|
|
|
|
bool need_binlog_call;
|
2006-05-06 11:51:35 +02:00
|
|
|
uint arg_no;
|
2003-02-26 19:22:29 +01:00
|
|
|
sp_rcontext *octx = thd->spcont;
|
|
|
|
sp_rcontext *nctx = NULL;
|
2006-05-06 11:51:35 +02:00
|
|
|
char buf[STRING_BUFFER_USUAL_SIZE];
|
|
|
|
String binlog_buf(buf, sizeof(buf), &my_charset_bin);
|
2005-12-07 15:01:17 +01:00
|
|
|
bool err_status= FALSE;
|
2006-05-06 11:51:35 +02:00
|
|
|
MEM_ROOT call_mem_root;
|
|
|
|
Query_arena call_arena(&call_mem_root, Query_arena::INITIALIZED_FOR_SP);
|
|
|
|
Query_arena backup_arena;
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_ENTER("sp_head::execute_function");
|
|
|
|
DBUG_PRINT("info", ("function %s", m_name.str));
|
|
|
|
|
2006-03-29 13:27:36 +02:00
|
|
|
LINT_INIT(binlog_save_options);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Check that the function is called with all specified arguments.
|
|
|
|
|
|
|
|
If it is not, use my_error() to report an error, or it will not terminate
|
|
|
|
the invoking query properly.
|
|
|
|
*/
|
2006-05-06 11:51:35 +02:00
|
|
|
if (argcount != m_pcont->context_var_count())
|
2003-04-17 13:20:02 +02:00
|
|
|
{
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
2005-08-22 00:13:37 +02:00
|
|
|
Need to use my_error here, or it will not terminate the
|
2005-08-11 14:58:15 +02:00
|
|
|
invoking query properly.
|
|
|
|
*/
|
now my_printf_error is not better then my_error, but my_error call is shorter
used only one implementation of format parser of (printf)
fixed multistatement
include/mysqld_error.h:
newerror messages
mysql-test/t/key.test:
unknown error replaced with real error
mysys/my_error.c:
my_error & my_printf_error use my_vsprintf
sql/field_conv.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/ha_innodb.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/handler.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_cmpfunc.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_func.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_strfunc.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/lock.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/log.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/parse_file.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/procedure.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/protocol.cc:
no need reset thd->lex->found_colon to break multiline sequance now, send_error called too late
sql/repl_failsafe.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/set_var.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/share/czech/errmsg.txt:
new errors converted from unknown error
sql/share/danish/errmsg.txt:
new errors converted from unknown error
sql/share/dutch/errmsg.txt:
new errors converted from unknown error
sql/share/english/errmsg.txt:
new errors converted from unknown error
sql/share/estonian/errmsg.txt:
new errors converted from unknown error
sql/share/french/errmsg.txt:
new errors converted from unknown error
sql/share/german/errmsg.txt:
new errors converted from unknown error
sql/share/greek/errmsg.txt:
new errors converted from unknown error
sql/share/hungarian/errmsg.txt:
new errors converted from unknown error
sql/share/italian/errmsg.txt:
new errors converted from unknown error
sql/share/japanese/errmsg.txt:
new errors converted from unknown error
sql/share/korean/errmsg.txt:
new errors converted from unknown error
sql/share/norwegian-ny/errmsg.txt:
new errors converted from unknown error
sql/share/norwegian/errmsg.txt:
new errors converted from unknown error
sql/share/polish/errmsg.txt:
new errors converted from unknown error
sql/share/portuguese/errmsg.txt:
new errors converted from unknown error
sql/share/romanian/errmsg.txt:
new errors converted from unknown error
sql/share/russian/errmsg.txt:
new errors converted from unknown error
sql/share/serbian/errmsg.txt:
new errors converted from unknown error
sql/share/slovak/errmsg.txt:
new errors converted from unknown error
sql/share/spanish/errmsg.txt:
new errors converted from unknown error
sql/share/swedish/errmsg.txt:
new errors converted from unknown error
sql/share/ukrainian/errmsg.txt:
new errors converted from unknown error
sql/slave.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sp.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sp_head.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_acl.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_analyse.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_base.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_class.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_db.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_delete.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_handler.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_insert.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_load.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_map.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_parse.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
multi-row command fixed
sql/sql_prepare.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
remover send_error ingected from 4.1
sql/sql_rename.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_repl.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_select.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_show.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_table.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_trigger.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_udf.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_update.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_view.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_yacc.yy:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/table.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
strings/my_vsnprintf.c:
* format support added to my_vsprint
2004-11-13 18:35:51 +01:00
|
|
|
my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0),
|
2006-05-06 11:51:35 +02:00
|
|
|
"FUNCTION", m_qname.str, m_pcont->context_var_count(), argcount);
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2003-04-17 13:20:02 +02:00
|
|
|
}
|
2006-05-06 11:51:35 +02:00
|
|
|
/*
|
|
|
|
Prepare arena and memroot for objects which lifetime is whole
|
|
|
|
duration of function call (sp_rcontext, it's tables and items,
|
|
|
|
sp_cursor and Item_cache holders for case expressions).
|
|
|
|
We can't use caller's arena/memroot for those objects because
|
|
|
|
in this case some fixed amount of memory will be consumed for
|
|
|
|
each function/trigger invocation and so statements which involve
|
|
|
|
lot of them will hog memory.
|
|
|
|
TODO: we should create sp_rcontext once per command and reuse
|
|
|
|
it on subsequent executions of a function/trigger.
|
|
|
|
*/
|
|
|
|
init_sql_alloc(&call_mem_root, MEM_ROOT_BLOCK_SIZE, 0);
|
|
|
|
thd->set_n_backup_active_arena(&call_arena, &backup_arena);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
if (!(nctx= new sp_rcontext(m_pcont, return_value_fld, octx)) ||
|
|
|
|
nctx->init(thd))
|
|
|
|
{
|
2006-05-06 11:51:35 +02:00
|
|
|
thd->restore_active_arena(&call_arena, &backup_arena);
|
|
|
|
err_status= TRUE;
|
|
|
|
goto err_with_cleanup;
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
|
|
|
|
2006-05-06 11:51:35 +02:00
|
|
|
/*
|
|
|
|
We have to switch temporarily back to callers arena/memroot.
|
|
|
|
Function arguments belong to the caller and so the may reference
|
|
|
|
memory which they will allocate during calculation long after
|
|
|
|
this function call will be finished (e.g. in Item::cleanup()).
|
|
|
|
*/
|
|
|
|
thd->restore_active_arena(&call_arena, &backup_arena);
|
|
|
|
|
2005-11-22 23:50:37 +01:00
|
|
|
#ifndef DBUG_OFF
|
2005-12-07 15:01:17 +01:00
|
|
|
nctx->sp= this;
|
2005-11-22 23:50:37 +01:00
|
|
|
#endif
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
/* Pass arguments. */
|
2006-05-06 11:51:35 +02:00
|
|
|
for (arg_no= 0; arg_no < argcount; arg_no++)
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
2006-05-06 11:51:35 +02:00
|
|
|
/* Arguments must be fixed in Item_func_sp::fix_fields */
|
|
|
|
DBUG_ASSERT(argp[arg_no]->fixed);
|
2005-08-22 00:13:37 +02:00
|
|
|
|
2006-05-15 19:57:09 +02:00
|
|
|
if ((err_status= nctx->set_variable(thd, arg_no, &(argp[arg_no]))))
|
2006-05-06 11:51:35 +02:00
|
|
|
goto err_with_cleanup;
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
2005-09-13 12:50:21 +02:00
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
/*
|
|
|
|
If row-based binlogging, we don't need to binlog the function's call, let
|
|
|
|
each substatement be binlogged its way.
|
|
|
|
*/
|
|
|
|
need_binlog_call= mysql_bin_log.is_open() &&
|
WL#2977 and WL#2712 global and session-level variable to set the binlog format (row/statement),
and new binlog format called "mixed" (which is statement-based except if only row-based is correct,
in this cset it means if UDF or UUID is used; more cases could be added in later 5.1 release):
SET GLOBAL|SESSION BINLOG_FORMAT=row|statement|mixed|default;
the global default is statement unless cluster is enabled (then it's row) as in 5.1-alpha.
It's not possible to use SET on this variable if a session is currently in row-based mode and has open temporary tables (because CREATE
TEMPORARY TABLE was not binlogged so temp table is not known on slave), or if NDB is enabled (because
NDB does not support such change on-the-fly, though it will later), of if in a stored function (see below).
The added tests test the possibility or impossibility to SET, their effects, and the mixed mode,
including in prepared statements and in stored procedures and functions.
Caveats:
a) The mixed mode will not work for stored functions: in mixed mode, a stored function will
always be binlogged as one call and in a statement-based way (e.g. INSERT VALUES(myfunc()) or SELECT myfunc()).
b) for the same reason, changing the thread's binlog format inside a stored function is
refused with an error message.
c) the same problems apply to triggers; implementing b) for triggers will be done later (will ask
Dmitri).
Additionally, as the binlog format is now changeable by each user for his session, I remove the implication
which was done at startup, where row-based automatically set log-bin-trust-routine-creators to 1
(not possible anymore as a user can now switch to stmt-based and do nasty things again), and automatically
set --innodb-locks-unsafe-for-binlog to 1 (was anyway theoretically incorrect as it disabled
phantom protection).
Plus fixes for compiler warnings.
mysql-test/r/rpl_row_4_bytes.result:
update
mysql-test/t/rpl_row_4_bytes.test:
don't influence next tests
sql/ha_archive.cc:
please pay attention to this structure when you change it...
sql/ha_berkeley.cc:
please pay attention to this structure when you change it...
sql/ha_blackhole.cc:
please pay attention to this structure when you change it...
sql/ha_federated.cc:
please pay attention to this structure when you change it...
sql/ha_heap.cc:
please pay attention to this structure when you change it...
sql/ha_innodb.cc:
please pay attention to this structure when you change it...
sql/ha_myisam.cc:
please pay attention to this structure when you change it...
sql/ha_myisammrg.cc:
please pay attention to this structure when you change it...
sql/ha_ndbcluster_binlog.cc:
no more global 'binlog_row_based'
sql/ha_partition.cc:
please pay attention to this structure when you change it...
sql/handler.cc:
please pay attention to this structure when you change it...
sql/handler.h:
it's good to initialize statically (to get no compiler warning) even if to a null value.
sql/item_func.cc:
UDFs require row-based if this is the "mixed" binlog format.
sql/item_strfunc.cc:
UUID() requires row-based binlogging if this is the "mixed" binlog format
sql/log.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/log.h:
the enum enum_binlog_format moves to log.h from mysqld.cc as we need it in several places.
sql/log_event.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/log_event.h:
this global variable not used anymore
sql/mysql_priv.h:
these global variables not used anymore
sql/mysqld.cc:
simplification in the handling of --binlog-format (but with no user-visible change), thanks to
the new global system variable.
RBR does not anymore turn on --log-bin-trust-function-creators and --innodb-locks-unsafe-for-binlog
as these are global options and RBR is now settable per session.
sql/partition_info.cc:
compiler warnings
sql/set_var.cc:
new class of thread's variable, to handle the binlog_format (like sys_var_thd_enum except
that is_readonly() is overriden for more checks before update).
compiler warnings (ok'd by Serg)
sql/set_var.h:
new class for the thread's binlog_format (see set_var.cc)
sql/share/errmsg.txt:
some messages for when one can't toggle from one binlog format to another
sql/sp_head.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_base.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_class.cc:
When a THD is initialized, we set its current_stmt_binlog_row_based
sql/sql_class.h:
new THD::variables.binlog_format (the value of the session variable set by SET
or inherited from the global value), and THD::current_stmt_binlog_row_based which tells if the
current statement does row-based or statement-based binlogging. Both members are needed
as the 2nd one cannot be derived only from the first one (the statement's type plays a role too),
and the 1st one is needed to reset the 2nd one.
sql/sql_delete.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_insert.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
sql/sql_load.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based.
sql/sql_parse.cc:
when we are done with a statement, we reset the current_stmt_binlog_row_based to the value
derived from THD::variables.binlog_format.
sql/sql_partition.cc:
compiler warning
sql/sql_show.cc:
compiler warning
sql/sql_table.cc:
binlog_row_based -> thd->current_stmt_binlog_row_based
tests/mysql_client_test.c:
compiler warning
mysql-test/r/ndb_binlog_basic2.result:
new result
mysql-test/r/rpl_switch_stm_row_mixed.result:
new result
mysql-test/t/ndb_binlog_basic2.test:
new test to verify that if cluster is enabled, can't change binlog format on the fly.
mysql-test/t/rpl_switch_stm_row_mixed.test:
test to see if one can switch between SBR, RBR, and "mixed" mode, and when one cannot,
and test to see if the switching, and the mixed mode, work properly (using UUID() to test,
as using UDFs is not possible in the testsuite for portability reasons).
2006-02-25 22:21:03 +01:00
|
|
|
(thd->options & OPTION_BIN_LOG) && !thd->current_stmt_binlog_row_based;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2006-05-06 11:51:35 +02:00
|
|
|
/*
|
|
|
|
Remember the original arguments for unrolled replication of functions
|
|
|
|
before they are changed by execution.
|
|
|
|
*/
|
|
|
|
if (need_binlog_call)
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
2006-05-06 11:51:35 +02:00
|
|
|
binlog_buf.length(0);
|
|
|
|
binlog_buf.append(STRING_WITH_LEN("SELECT "));
|
Fix for BUG#19725 "Calls to SF in other database are not replicated
correctly in some cases".
In short, calls to a stored function located in another database
than the default database, may fail to replicate if the call was made
by SET, SELECT, or DO.
Longer: when a stored function is called from a statement which does not go
to binlog ("SET @a=somedb.myfunc()", "SELECT somedb.myfunc()",
"DO somedb.myfunc()"), this crafted statement is binlogged:
"SELECT myfunc();" (accompanied with a mention of the default database
if there is one). So, if "somedb" is not the default database,
the slave would fail to find myfunc(). The fix is to specify the
function's database name in the crafted binlogged statement, like this:
"SELECT somedb.myfunc();". Test added in rpl_sp.test.
mysql-test/r/rpl_sp.result:
Because I moved the SHOW BINLOG EVENTS down a bit, big portions of its
output move. Also, the function's database name appears in
SELECT statements.
mysql-test/t/rpl_sp.test:
Adding test for BUG#19725.
Moving the SHOW BINLOG EVENTS down, it is run at the very end to
test everything.
sql/sp_head.cc:
When binlogging a "SELECT myfunc()" (when a stored function is executed
inside a statement which does not go to the binlog (like a SET,
SELECT, DO), we need to write "SELECT db_of_myfunc().myfunc()",
because the function may be in a database which is not the default
database.
2007-01-08 22:01:06 +01:00
|
|
|
append_identifier(thd, &binlog_buf, m_db.str, m_db.length);
|
|
|
|
binlog_buf.append('.');
|
2006-05-06 11:51:35 +02:00
|
|
|
append_identifier(thd, &binlog_buf, m_name.str, m_name.length);
|
|
|
|
binlog_buf.append('(');
|
|
|
|
for (arg_no= 0; arg_no < argcount; arg_no++)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
2006-05-06 11:51:35 +02:00
|
|
|
String str_value_holder;
|
|
|
|
String *str_value;
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2006-05-06 11:51:35 +02:00
|
|
|
if (arg_no)
|
|
|
|
binlog_buf.append(',');
|
2005-08-22 00:13:37 +02:00
|
|
|
|
2006-11-09 11:27:34 +01:00
|
|
|
str_value= sp_get_item_value(thd, nctx->get_item(arg_no),
|
2006-05-06 11:51:35 +02:00
|
|
|
&str_value_holder);
|
2005-09-13 12:50:21 +02:00
|
|
|
|
2006-05-06 11:51:35 +02:00
|
|
|
if (str_value)
|
|
|
|
binlog_buf.append(*str_value);
|
|
|
|
else
|
|
|
|
binlog_buf.append(STRING_WITH_LEN("NULL"));
|
|
|
|
}
|
|
|
|
binlog_buf.append(')');
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
thd->spcont= nctx;
|
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
Security_context *save_security_ctx;
|
|
|
|
if (set_routine_security_ctx(thd, this, FALSE, &save_security_ctx))
|
|
|
|
{
|
|
|
|
err_status= TRUE;
|
|
|
|
goto err_with_cleanup;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
if (need_binlog_call)
|
2005-09-07 17:39:47 +02:00
|
|
|
{
|
2007-02-26 20:06:10 +01:00
|
|
|
query_id_t q;
|
2005-09-07 17:39:47 +02:00
|
|
|
reset_dynamic(&thd->user_var_events);
|
2007-02-26 20:06:10 +01:00
|
|
|
/*
|
|
|
|
In case of artificially constructed events for function calls
|
|
|
|
we have separate union for each such event and hence can't use
|
|
|
|
query_id of real calling statement as the start of all these
|
|
|
|
unions (this will break logic of replication of user-defined
|
|
|
|
variables). So we use artifical value which is guaranteed to
|
|
|
|
be greater than all query_id's of all statements belonging
|
|
|
|
to previous events/unions.
|
|
|
|
Possible alternative to this is logging of all function invocations
|
|
|
|
as one select and not resetting THD::user_var_events before
|
|
|
|
each invocation.
|
|
|
|
*/
|
|
|
|
VOID(pthread_mutex_lock(&LOCK_thread_count));
|
2007-02-27 17:36:17 +01:00
|
|
|
q= global_query_id;
|
2007-02-26 20:06:10 +01:00
|
|
|
VOID(pthread_mutex_unlock(&LOCK_thread_count));
|
|
|
|
mysql_bin_log.start_union_events(thd, q + 1);
|
2005-12-22 06:39:02 +01:00
|
|
|
binlog_save_options= thd->options;
|
|
|
|
thd->options&= ~OPTION_BIN_LOG;
|
2005-09-07 17:39:47 +02:00
|
|
|
}
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2006-05-06 11:51:35 +02:00
|
|
|
/*
|
|
|
|
Switch to call arena/mem_root so objects like sp_cursor or
|
|
|
|
Item_cache holders for case expressions can be allocated on it.
|
|
|
|
|
|
|
|
TODO: In future we should associate call arena/mem_root with
|
|
|
|
sp_rcontext and allocate all these objects (and sp_rcontext
|
|
|
|
itself) on it directly rather than juggle with arenas.
|
|
|
|
*/
|
|
|
|
thd->set_n_backup_active_arena(&call_arena, &backup_arena);
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
err_status= execute(thd);
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2006-05-06 11:51:35 +02:00
|
|
|
thd->restore_active_arena(&call_arena, &backup_arena);
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
if (need_binlog_call)
|
2005-08-25 15:34:34 +02:00
|
|
|
{
|
2005-12-22 06:39:02 +01:00
|
|
|
mysql_bin_log.stop_union_events(thd);
|
|
|
|
thd->options= binlog_save_options;
|
|
|
|
if (thd->binlog_evt_union.unioned_events)
|
2005-08-25 15:34:34 +02:00
|
|
|
{
|
2006-05-18 11:56:50 +02:00
|
|
|
Query_log_event qinfo(thd, binlog_buf.ptr(), binlog_buf.length(),
|
2005-12-22 06:39:02 +01:00
|
|
|
thd->binlog_evt_union.unioned_events_trans, FALSE);
|
|
|
|
if (mysql_bin_log.write(&qinfo) &&
|
|
|
|
thd->binlog_evt_union.unioned_events_trans)
|
|
|
|
{
|
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
|
|
|
|
"Invoked ROUTINE modified a transactional table but MySQL "
|
|
|
|
"failed to reflect this change in the binary log");
|
|
|
|
}
|
|
|
|
reset_dynamic(&thd->user_var_events);
|
Fixing problems I identified in my auto_increment work pushed in July
(as part of the auto_increment cleanup of WL#3146; let's not be
sad, that monster push still removed serious bugs):
one problem with INSERT DELAYED (unexpected interval releases),
one with stored functions (wrong auto_inc binlogging).
These bugs were not released.
mysql-test/extra/binlog_tests/binlog_insert_delayed.test:
more tests of binlogging of INSERT DELAYED: with multi-row INSERTs.
I identified why sleeps are needed to get a repeatable row-based
binlogged: because without sleeps rows sometimes get groupped
and so generate different row based events.
mysql-test/extra/rpl_tests/rpl_foreign_key.test:
don't forget to drop tables on slave too, otherwise it leaves
an orphan innodb table leading to rpl_insert_id failing sometimes
(like in pushbuild "sapsrv2 -max").
mysql-test/extra/rpl_tests/rpl_insert_id.test:
testing that if some statement does not update any row, it does
not pollute the auto_inc binlog variables of the next statement;
the test has to use stored procedures because with plain statements,
mysql_reset_thd_for_next_command() does the resetting (and thus
there is no problem); mysql_reset_thd_for_next_command() is not
called inside routines.
mysql-test/r/binlog_row_binlog.result:
result additions
mysql-test/r/binlog_statement_insert_delayed.result:
result additions
mysql-test/r/binlog_stm_binlog.result:
result additions
mysql-test/r/rpl_insert_id.result:
result additions
mysql-test/r/rpl_loaddata.result:
With the change to log.cc reverted, the result changes and is better:
the change to log.cc had caused some INSERT_ID events to disappear
though they were necessary (but testsuite could not catch that because
it's single-threaded).
mysql-test/r/rpl_ndb_insert_ignore.result:
NDB is now like other engines regarding INSERT IGNORE: autoincrement
values which caused a duplicate key are re-used for next row, not lost.
rpl_ndb_insert_ignore.result is now identical to rpl_insert_ignore.result.
sql/log.cc:
LOAD DATA INFILE is binlogged as several events, and the last of them must
have the auto_inc id. So it's wrong to reset the auto_inc id after every
binlog write (because then it's lost after the first event of LOAD
DATA INFILE and so missing for the last one)/
Another problem: MYSQL_LOG::write() is not always called (for example
if no row was updated), so we were missing reset in some cases.
sql/sp_head.cc:
SELECT func1(),func2() generates two binlog events, so needs to
clear auto_increment binlog variables after each binlog event
(it would be more natural to clear them in the log write code,
but LOAD DATA INFILE would suffer from this see the cset comment
for log.cc). Without the clearing, the problem is:
> exec func1()
>> call cleanup_after_query() (which does not clear our vars here)
>> binlog SELECT func1()
<
> exec func2()
and so SELECT func2() is binlogged with the auto_inc of SELECT func1().
sql/sql_class.cc:
after every statement we should clear auto_inc variables used for
binlogging, except if this was a function/trigger (in which case
it may be "INSERT SELECT func()", where the cleanup_after_query()
executed in func() should not reset the auto_inc binlog variables
as they'll be necessary when binlogging the INSERT SELECT later).
sql/sql_insert.cc:
- as INSERT DELAYED uses the same TABLE object as the delayed_insert
system thread, we should not call ha_release_auto_increment()
from INSERT DELAYED (and btw it's logical as we reserve nothing
as we don't perform the insert). Calling the function caused us to
release values being used by the delayed_insert thread.
So I do the call only if this is a non-DELAYED INSERT.
- Assuming two INSERT DELAYED which get grouped by the delayed_insert
thread, the second may use values reserved by the first, which is ok
per se, but is a problem in statement-based binlogging:
the 2nd INSERT gets binlogged with the "interval start" value
of the first INSERT (=> duplicate error in slave).
- no reason to ha_release_auto_increment() after every inserted row
in INSERT SELECT; more efficient to do it only when the statement ends
sql/sql_parse.cc:
a comment
2006-09-12 15:42:13 +02:00
|
|
|
/* Forget those values, in case more function calls are binlogged: */
|
|
|
|
thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
|
|
|
|
thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
|
2005-08-25 15:34:34 +02:00
|
|
|
}
|
|
|
|
}
|
2004-09-07 14:29:46 +02:00
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
if (!err_status)
|
2003-10-03 17:38:12 +02:00
|
|
|
{
|
2004-09-07 14:29:46 +02:00
|
|
|
/* We need result only in function but not in trigger */
|
2003-10-03 17:38:12 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!nctx->is_return_value_set())
|
2003-10-03 17:38:12 +02:00
|
|
|
{
|
now my_printf_error is not better then my_error, but my_error call is shorter
used only one implementation of format parser of (printf)
fixed multistatement
include/mysqld_error.h:
newerror messages
mysql-test/t/key.test:
unknown error replaced with real error
mysys/my_error.c:
my_error & my_printf_error use my_vsprintf
sql/field_conv.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/ha_innodb.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/handler.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_cmpfunc.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_func.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_strfunc.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/lock.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/log.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/parse_file.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/procedure.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/protocol.cc:
no need reset thd->lex->found_colon to break multiline sequance now, send_error called too late
sql/repl_failsafe.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/set_var.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/share/czech/errmsg.txt:
new errors converted from unknown error
sql/share/danish/errmsg.txt:
new errors converted from unknown error
sql/share/dutch/errmsg.txt:
new errors converted from unknown error
sql/share/english/errmsg.txt:
new errors converted from unknown error
sql/share/estonian/errmsg.txt:
new errors converted from unknown error
sql/share/french/errmsg.txt:
new errors converted from unknown error
sql/share/german/errmsg.txt:
new errors converted from unknown error
sql/share/greek/errmsg.txt:
new errors converted from unknown error
sql/share/hungarian/errmsg.txt:
new errors converted from unknown error
sql/share/italian/errmsg.txt:
new errors converted from unknown error
sql/share/japanese/errmsg.txt:
new errors converted from unknown error
sql/share/korean/errmsg.txt:
new errors converted from unknown error
sql/share/norwegian-ny/errmsg.txt:
new errors converted from unknown error
sql/share/norwegian/errmsg.txt:
new errors converted from unknown error
sql/share/polish/errmsg.txt:
new errors converted from unknown error
sql/share/portuguese/errmsg.txt:
new errors converted from unknown error
sql/share/romanian/errmsg.txt:
new errors converted from unknown error
sql/share/russian/errmsg.txt:
new errors converted from unknown error
sql/share/serbian/errmsg.txt:
new errors converted from unknown error
sql/share/slovak/errmsg.txt:
new errors converted from unknown error
sql/share/spanish/errmsg.txt:
new errors converted from unknown error
sql/share/swedish/errmsg.txt:
new errors converted from unknown error
sql/share/ukrainian/errmsg.txt:
new errors converted from unknown error
sql/slave.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sp.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sp_head.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_acl.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_analyse.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_base.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_class.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_db.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_delete.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_handler.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_insert.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_load.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_map.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_parse.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
multi-row command fixed
sql/sql_prepare.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
remover send_error ingected from 4.1
sql/sql_rename.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_repl.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_select.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_show.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_table.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_trigger.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_udf.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_update.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_view.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_yacc.yy:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/table.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
strings/my_vsnprintf.c:
* format support added to my_vsprint
2004-11-13 18:35:51 +01:00
|
|
|
my_error(ER_SP_NORETURNEND, MYF(0), m_name.str);
|
2005-12-07 15:01:17 +01:00
|
|
|
err_status= TRUE;
|
2003-10-03 17:38:12 +02:00
|
|
|
}
|
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2007-04-13 22:35:56 +02:00
|
|
|
m_security_ctx.restore_security_context(thd, save_security_ctx);
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
#endif
|
2006-05-06 11:51:35 +02:00
|
|
|
|
|
|
|
err_with_cleanup:
|
2005-12-07 15:01:17 +01:00
|
|
|
delete nctx;
|
2006-05-06 11:51:35 +02:00
|
|
|
call_arena.free_items();
|
|
|
|
free_root(&call_mem_root, MYF(0));
|
2003-02-26 19:22:29 +01:00
|
|
|
thd->spcont= octx;
|
2005-06-03 19:21:12 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(err_status);
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
|
|
|
|
2005-08-22 00:13:37 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-08-25 15:34:34 +02:00
|
|
|
Execute a procedure.
|
|
|
|
|
|
|
|
The function does the following steps:
|
|
|
|
- Set all parameters
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
- changes security context for SUID routines
|
2005-08-25 15:34:34 +02:00
|
|
|
- call sp_head::execute
|
|
|
|
- copy back values of INOUT and OUT parameters
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
- restores security context
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd Thread handle
|
|
|
|
@param args List of values passed as arguments.
|
|
|
|
|
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
FALSE on success
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
TRUE on error
|
2005-08-25 15:34:34 +02:00
|
|
|
*/
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
bool
|
|
|
|
sp_head::execute_procedure(THD *thd, List<Item> *args)
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
bool err_status= FALSE;
|
2006-04-07 16:53:15 +02:00
|
|
|
uint params = m_pcont->context_var_count();
|
2005-08-22 00:13:37 +02:00
|
|
|
sp_rcontext *save_spcont, *octx;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
sp_rcontext *nctx = NULL;
|
2006-03-01 03:49:31 +01:00
|
|
|
bool save_enable_slow_log= false;
|
2006-03-01 16:27:57 +01:00
|
|
|
bool save_log_general= false;
|
2005-08-22 00:13:37 +02:00
|
|
|
DBUG_ENTER("sp_head::execute_procedure");
|
|
|
|
DBUG_PRINT("info", ("procedure %s", m_name.str));
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2003-04-17 13:20:02 +02:00
|
|
|
if (args->elements != params)
|
|
|
|
{
|
now my_printf_error is not better then my_error, but my_error call is shorter
used only one implementation of format parser of (printf)
fixed multistatement
include/mysqld_error.h:
newerror messages
mysql-test/t/key.test:
unknown error replaced with real error
mysys/my_error.c:
my_error & my_printf_error use my_vsprintf
sql/field_conv.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/ha_innodb.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/handler.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_cmpfunc.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_func.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/item_strfunc.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/lock.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/log.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/parse_file.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/procedure.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/protocol.cc:
no need reset thd->lex->found_colon to break multiline sequance now, send_error called too late
sql/repl_failsafe.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/set_var.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/share/czech/errmsg.txt:
new errors converted from unknown error
sql/share/danish/errmsg.txt:
new errors converted from unknown error
sql/share/dutch/errmsg.txt:
new errors converted from unknown error
sql/share/english/errmsg.txt:
new errors converted from unknown error
sql/share/estonian/errmsg.txt:
new errors converted from unknown error
sql/share/french/errmsg.txt:
new errors converted from unknown error
sql/share/german/errmsg.txt:
new errors converted from unknown error
sql/share/greek/errmsg.txt:
new errors converted from unknown error
sql/share/hungarian/errmsg.txt:
new errors converted from unknown error
sql/share/italian/errmsg.txt:
new errors converted from unknown error
sql/share/japanese/errmsg.txt:
new errors converted from unknown error
sql/share/korean/errmsg.txt:
new errors converted from unknown error
sql/share/norwegian-ny/errmsg.txt:
new errors converted from unknown error
sql/share/norwegian/errmsg.txt:
new errors converted from unknown error
sql/share/polish/errmsg.txt:
new errors converted from unknown error
sql/share/portuguese/errmsg.txt:
new errors converted from unknown error
sql/share/romanian/errmsg.txt:
new errors converted from unknown error
sql/share/russian/errmsg.txt:
new errors converted from unknown error
sql/share/serbian/errmsg.txt:
new errors converted from unknown error
sql/share/slovak/errmsg.txt:
new errors converted from unknown error
sql/share/spanish/errmsg.txt:
new errors converted from unknown error
sql/share/swedish/errmsg.txt:
new errors converted from unknown error
sql/share/ukrainian/errmsg.txt:
new errors converted from unknown error
sql/slave.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sp.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sp_head.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_acl.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_analyse.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_base.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_class.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_db.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_delete.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_handler.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_insert.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_load.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_map.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_parse.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
multi-row command fixed
sql/sql_prepare.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
remover send_error ingected from 4.1
sql/sql_rename.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_repl.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_select.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_show.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_table.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_trigger.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_udf.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_update.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_view.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/sql_yacc.yy:
now my_printf_error is not better then my_error, but my_error call is shorter
sql/table.cc:
now my_printf_error is not better then my_error, but my_error call is shorter
strings/my_vsnprintf.c:
* format support added to my_vsprint
2004-11-13 18:35:51 +01:00
|
|
|
my_error(ER_SP_WRONG_NO_OF_ARGS, MYF(0), "PROCEDURE",
|
2005-04-14 14:52:35 +02:00
|
|
|
m_qname.str, params, args->elements);
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2003-04-17 13:20:02 +02:00
|
|
|
}
|
|
|
|
|
2005-08-22 00:13:37 +02:00
|
|
|
save_spcont= octx= thd->spcont;
|
2005-08-18 11:23:54 +02:00
|
|
|
if (! octx)
|
|
|
|
{ // Create a temporary old context
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!(octx= new sp_rcontext(m_pcont, NULL, octx)) ||
|
|
|
|
octx->init(thd))
|
|
|
|
{
|
|
|
|
delete octx; /* Delete octx if it was init() that failed. */
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
2005-11-22 23:50:37 +01:00
|
|
|
#ifndef DBUG_OFF
|
2005-12-07 15:01:17 +01:00
|
|
|
octx->sp= 0;
|
2005-11-22 23:50:37 +01:00
|
|
|
#endif
|
2005-08-18 11:23:54 +02:00
|
|
|
thd->spcont= octx;
|
|
|
|
|
|
|
|
/* set callers_arena to thd, for upper-level function to work */
|
|
|
|
thd->spcont->callers_arena= thd;
|
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!(nctx= new sp_rcontext(m_pcont, NULL, octx)) ||
|
|
|
|
nctx->init(thd))
|
2005-08-22 00:13:37 +02:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
delete nctx; /* Delete nctx if it was init() that failed. */
|
2005-08-22 00:13:37 +02:00
|
|
|
thd->spcont= save_spcont;
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(TRUE);
|
2005-08-22 00:13:37 +02:00
|
|
|
}
|
2005-11-22 23:50:37 +01:00
|
|
|
#ifndef DBUG_OFF
|
2005-12-07 15:01:17 +01:00
|
|
|
nctx->sp= this;
|
2005-11-22 23:50:37 +01:00
|
|
|
#endif
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (params > 0)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
List_iterator<Item> it_args(*args);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
DBUG_PRINT("info",(" %.*s: eval args", (int) m_name.length, m_name.str));
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
for (uint i= 0 ; i < params ; i++)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
Item *arg_item= it_args++;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!arg_item)
|
|
|
|
break;
|
|
|
|
|
2006-05-12 11:55:21 +02:00
|
|
|
sp_variable_t *spvar= m_pcont->find_variable(i);
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
if (!spvar)
|
2005-12-07 15:01:17 +01:00
|
|
|
continue;
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
if (spvar->mode != sp_param_in)
|
2002-12-11 14:24:29 +01:00
|
|
|
{
|
2006-05-12 11:55:21 +02:00
|
|
|
Settable_routine_parameter *srp=
|
|
|
|
arg_item->get_settable_routine_parameter();
|
|
|
|
|
|
|
|
if (!srp)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
my_error(ER_SP_NOT_VAR_ARG, MYF(0), i+1, m_qname.str);
|
|
|
|
err_status= TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2006-05-12 11:55:21 +02:00
|
|
|
|
|
|
|
srp->set_required_privilege(spvar->mode == sp_param_inout);
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
if (spvar->mode == sp_param_out)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
Item_null *null_item= new Item_null();
|
|
|
|
|
|
|
|
if (!null_item ||
|
2006-11-30 02:40:42 +01:00
|
|
|
nctx->set_variable(thd, i, (Item **)&null_item))
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
err_status= TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-15 12:01:55 +02:00
|
|
|
if (nctx->set_variable(thd, i, it_args.ref()))
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
err_status= TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2002-12-11 14:24:29 +01:00
|
|
|
}
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
2003-04-23 21:31:47 +02:00
|
|
|
|
2005-07-30 10:19:57 +02:00
|
|
|
/*
|
|
|
|
Okay, got values for all arguments. Close tables that might be used by
|
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
|
|
|
arguments evaluation. If arguments evaluation required prelocking mode,
|
|
|
|
we'll leave it here.
|
2005-07-30 10:19:57 +02:00
|
|
|
*/
|
|
|
|
if (!thd->in_sub_stmt)
|
2007-11-01 21:52:56 +01:00
|
|
|
close_thread_tables(thd);
|
2005-07-30 10:19:57 +02:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
DBUG_PRINT("info",(" %.*s: eval args done",
|
|
|
|
(int) m_name.length, m_name.str));
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
2006-03-01 16:27:57 +01:00
|
|
|
if (!(m_flags & LOG_SLOW_STATEMENTS) && thd->enable_slow_log)
|
2006-03-01 02:34:22 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Disabling slow log for the execution"));
|
2006-03-01 16:27:57 +01:00
|
|
|
save_enable_slow_log= true;
|
2006-03-01 02:34:22 +01:00
|
|
|
thd->enable_slow_log= FALSE;
|
|
|
|
}
|
2006-03-01 16:27:57 +01:00
|
|
|
if (!(m_flags & LOG_GENERAL_LOG) && !(thd->options & OPTION_LOG_OFF))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Disabling general log for the execution"));
|
|
|
|
save_log_general= true;
|
|
|
|
/* disable this bit */
|
|
|
|
thd->options |= OPTION_LOG_OFF;
|
|
|
|
}
|
2005-08-18 11:23:54 +02:00
|
|
|
thd->spcont= nctx;
|
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
Security_context *save_security_ctx= 0;
|
|
|
|
if (!err_status)
|
|
|
|
err_status= set_routine_security_ctx(thd, this, TRUE, &save_security_ctx);
|
|
|
|
#endif
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!err_status)
|
|
|
|
err_status= execute(thd);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2006-03-01 16:27:57 +01:00
|
|
|
if (save_log_general)
|
|
|
|
thd->options &= ~OPTION_LOG_OFF;
|
|
|
|
if (save_enable_slow_log)
|
|
|
|
thd->enable_slow_log= true;
|
2005-08-18 11:23:54 +02:00
|
|
|
/*
|
|
|
|
In the case when we weren't able to employ reuse mechanism for
|
|
|
|
OUT/INOUT paranmeters, we should reallocate memory. This
|
|
|
|
allocation should be done on the arena which will live through
|
|
|
|
all execution of calling routine.
|
|
|
|
*/
|
|
|
|
thd->spcont->callers_arena= octx->callers_arena;
|
2005-06-03 19:21:12 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (!err_status && params > 0)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
List_iterator<Item> it_args(*args);
|
2003-02-02 17:44:39 +01:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
Copy back all OUT or INOUT values to the previous frame, or
|
|
|
|
set global user variables
|
|
|
|
*/
|
2005-12-07 15:01:17 +01:00
|
|
|
for (uint i= 0 ; i < params ; i++)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
Item *arg_item= it_args++;
|
|
|
|
|
|
|
|
if (!arg_item)
|
|
|
|
break;
|
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_variable_t *spvar= m_pcont->find_variable(i);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2006-04-07 16:53:15 +02:00
|
|
|
if (spvar->mode == sp_param_in)
|
2005-12-07 15:01:17 +01:00
|
|
|
continue;
|
|
|
|
|
2006-05-12 11:55:21 +02:00
|
|
|
Settable_routine_parameter *srp=
|
|
|
|
arg_item->get_settable_routine_parameter();
|
|
|
|
|
|
|
|
DBUG_ASSERT(srp);
|
|
|
|
|
2006-05-15 19:57:10 +02:00
|
|
|
if (srp->set_value(thd, octx, nctx->get_item_addr(i)))
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
2006-05-12 11:55:21 +02:00
|
|
|
err_status= TRUE;
|
|
|
|
break;
|
2003-02-02 17:44:39 +01:00
|
|
|
}
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
|
|
|
if (save_security_ctx)
|
2007-04-13 22:35:56 +02:00
|
|
|
m_security_ctx.restore_security_context(thd, save_security_ctx);
|
Bug#18630: Arguments of suid routine calculated in wrong security
context.
Routine arguments were evaluated in the security context of the routine
itself, not in the caller's context.
The bug is fixed the following way:
- Item_func_sp::find_and_check_access() has been split into two
functions: Item_func_sp::find_and_check_access() itself only
finds the function and check that the caller have EXECUTE privilege
on it. New function set_routine_security_ctx() changes security
context for SUID routines and checks that definer have EXECUTE
privilege too.
- new function sp_head::execute_trigger() is called from
Table_triggers_list::process_triggers() instead of
sp_head::execute_function(), and is effectively just as the
sp_head::execute_function() is, with all non-trigger related code
removed, and added trigger-specific security context switch.
- call to Item_func_sp::find_and_check_access() stays outside
of sp_head::execute_function(), and there is a code in
sql_parse.cc before the call to sp_head::execute_procedure() that
checks that the caller have EXECUTE privilege, but both
sp_head::execute_function() and sp_head::execute_procedure() call
set_routine_security_ctx() after evaluating their parameters,
and restore the context after the body is executed.
mysql-test/r/sp-security.result:
Add test case for bug#18630: Arguments of suid routine calculated
in wrong security context.
mysql-test/t/sp-security.test:
Add result for bug#18630: Arguments of suid routine calculated
in wrong security context.
sql/item_func.cc:
Do not change security context before executing the function, as it
will be changed after argument evaluation.
Do not change security context in Item_func_sp::find_and_check_access().
sql/item_func.h:
Change prototype for Item_func_sp::find_and_check_access().
sql/sp_head.cc:
Add set_routine_security_ctx() function.
Add sp_head::execute_trigger() method.
Change security context in sp_head::execute_trigger(), and in
sp_head::execute_function() and sp_head::execute_procedure()
after argument evaluation.
Move pop_all_cursors() call to sp_head::execute().
sql/sp_head.h:
Add declaration for sp_head::execute_trigger() and
set_routine_security_ctx().
sql/sql_parse.cc:
Do not change security context before executing the procedure, as it
will be changed after argument evaluation.
sql/sql_trigger.cc:
Call new sp_head::execute_trigger() instead of
sp_head::execute_function(), which is responsible to switch
security context.
2006-07-13 15:12:31 +02:00
|
|
|
#endif
|
|
|
|
|
2005-08-22 00:13:37 +02:00
|
|
|
if (!save_spcont)
|
2005-12-07 15:01:17 +01:00
|
|
|
delete octx;
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
delete nctx;
|
2005-08-22 00:13:37 +02:00
|
|
|
thd->spcont= save_spcont;
|
Implement WL#2661 "Prepared Statements: Dynamic SQL in Stored Procedures".
The idea of the patch is to separate statement processing logic,
such as parsing, validation of the parsed tree, execution and cleanup,
from global query processing logic, such as logging, resetting
priorities of a thread, resetting stored procedure cache, resetting
thread count of errors and warnings.
This makes PREPARE and EXECUTE behave similarly to the rest of SQL
statements and allows their use in stored procedures.
This patch contains a change in behaviour:
until recently for each SQL prepared statement command, 2 queries
were written to the general log, e.g.
[Query] prepare stmt from @stmt_text;
[Prepare] select * from t1 <-- contents of @stmt_text
The chagne was necessary to prevent [Prepare] commands from being written
to the general log when executing a stored procedure with Dynamic SQL.
We should consider whether the old behavior is preferrable and probably
restore it.
This patch refixes Bug#7115, Bug#10975 (partially), Bug#10605 (various bugs
in Dynamic SQL reported before it was disabled).
mysql-test/r/not_embedded_server.result:
Since we don't want to log Dynamic SQL in stored procedures,
now the general log gets only one log entry per SQL statement.
mysql-test/r/sp-error.result:
- remove obsolete tests
- a better error message for the case when a stored procedure that
returns a result set is called from a function
mysql-test/r/trigger.result:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
mysql-test/t/sp-error.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a function.
- move the comment to its place (end of file).
mysql-test/t/trigger.test:
- a better error message for the case when a stored procedure that
returns a result set is called from a trigger
sql/item_func.cc:
- we need to pass sql_command explicitly to get_var_with_binlog, because
when creating a query for SQL prepared statement thd->lex->sql_command
points at SQLCOM_EXECUTE, which is not listed in the list of update
queries.
sql/log_event.h:
- remove an extra copy of the previous sentence
sql/mysql_priv.h:
- fix declarations of sql_prepare.cc API
sql/share/errmsg.txt:
- a new error message, when one attempts to execute a prepared statement
which is currently being executed (this can happen only in Dynamic SQL
at the moment).
sql/sp_head.cc:
- extend sp_multi_results_command to return different flags for a
command (and rename it)
- add support for SQLCOM_PREPARE,SQLCOM_EXECUTE, SQLCOM_DEALLOCATE
to sp_get_flags_for_command
- replace multiple boolean sp_head members with uint m_flags
- a fix for a crash when user variables are used in a stored procedure
and binlog is on. A temporary fix for Bug#12637 "SP crashes the server
if it has update query with user var & binlog is enabled", which actually
stands for stored functions: now instead of a crash we break
replication if a user variable is used in a stored function which
is executed in prelocked mode.
sql/sp_head.h:
- replace multiple boolean flags of sp_head with uint m_flags;
- add flag CONTAINS_DYNAMIC_SQL
- use this flag to error if a stored procedure with Dynamic SQL is
called from a function or trigger.
sql/sql_class.cc:
- Statement_map::insert should not delete a statement if it exists,
now it's done externally to be able to handle the case when the
statement being deleted is in use.
- remove extra code (free_list is already reset in free_items)
sql/sql_lex.cc:
- add lex->stmt_prepare_mode; we can't rely on thd->command any more,
because we don't reset it any more (Dynamic SQL requirement is that
PS are as little intrusive as possible).
sql/sql_lex.h:
- declare bool LEX::stmt_prepare_mode
sql/sql_parse.cc:
- move prepared statement code to sql_prepare.cc
- change declarations (refactored code)
- better error message when one attempts to use Dynamic SQL or a
stored procedure that returns a result set in a function or trigger.
sql/sql_prepare.cc:
- major refactoring to ensure PREPARE/EXECUTE commands do not reset global THD
state and allow their use in stored procedures.
- add Prepared_statement::flags and use it to ensure no recursive execution
of a prepared statement is possible
- better comments
sql/sql_yacc.yy:
- enable PREPARE/EXECUTE/DEALLOCATE in stored procedures
- produce an error message on attempt to use PREPARE/EXECUTE/DEALLOCATE
in a stored function or trigger
mysql-test/r/sp-dynamic.result:
- sp-dynamic.test results
mysql-test/t/sp-dynamic.test:
- a new test for PREPARE/EXECUTE/DEALLOCATE in stored procedures.
2005-09-03 01:13:18 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
DBUG_RETURN(err_status);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-19 17:59:44 +01:00
|
|
|
/**
|
2007-12-14 16:52:10 +01:00
|
|
|
Reset lex during parsing, before we parse a sub statement.
|
2007-11-19 17:59:44 +01:00
|
|
|
|
|
|
|
@param thd Thread handler.
|
|
|
|
|
|
|
|
@return Error state
|
|
|
|
@retval true An error occurred.
|
|
|
|
@retval false Success.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
sp_head::reset_lex(THD *thd)
|
|
|
|
{
|
2003-05-23 15:32:31 +02:00
|
|
|
DBUG_ENTER("sp_head::reset_lex");
|
|
|
|
LEX *sublex;
|
2003-06-29 18:15:17 +02:00
|
|
|
LEX *oldlex= thd->lex;
|
2003-05-23 15:32:31 +02:00
|
|
|
|
2007-11-19 17:59:44 +01:00
|
|
|
sublex= new (thd->mem_root)st_lex_local;
|
|
|
|
if (sublex == 0)
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
|
|
|
|
thd->lex= sublex;
|
2003-06-29 18:15:17 +02:00
|
|
|
(void)m_lex.push_front(oldlex);
|
2004-07-22 00:26:33 +02:00
|
|
|
|
2007-04-26 05:38:12 +02:00
|
|
|
/* Reset most stuff. */
|
|
|
|
lex_start(thd);
|
2004-07-22 00:26:33 +02:00
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
/* And keep the SP stuff too */
|
2003-06-29 18:15:17 +02:00
|
|
|
sublex->sphead= oldlex->sphead;
|
|
|
|
sublex->spcont= oldlex->spcont;
|
2004-09-07 14:29:46 +02:00
|
|
|
/* And trigger related stuff too */
|
|
|
|
sublex->trg_chistics= oldlex->trg_chistics;
|
2004-11-24 10:24:02 +01:00
|
|
|
sublex->trg_table_fields.empty();
|
2003-06-29 18:15:17 +02:00
|
|
|
sublex->sp_lex_in_use= FALSE;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
/* Reset type info. */
|
|
|
|
|
|
|
|
sublex->charset= NULL;
|
|
|
|
sublex->length= NULL;
|
|
|
|
sublex->dec= NULL;
|
|
|
|
sublex->interval_list.empty();
|
|
|
|
sublex->type= 0;
|
|
|
|
|
2007-11-19 17:59:44 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/// Restore lex during parsing, after we have parsed a sub statement.
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
void
|
|
|
|
sp_head::restore_lex(THD *thd)
|
|
|
|
{
|
2003-05-23 15:32:31 +02:00
|
|
|
DBUG_ENTER("sp_head::restore_lex");
|
|
|
|
LEX *sublex= thd->lex;
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
LEX *oldlex;
|
|
|
|
|
|
|
|
sublex->set_trg_event_type_for_tables();
|
2003-06-29 18:15:17 +02:00
|
|
|
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
oldlex= (LEX *)m_lex.pop();
|
2003-06-29 18:15:17 +02:00
|
|
|
if (! oldlex)
|
|
|
|
return; // Nothing to restore
|
2003-05-23 15:32:31 +02:00
|
|
|
|
2004-11-24 10:24:02 +01:00
|
|
|
oldlex->trg_table_fields.push_back(&sublex->trg_table_fields);
|
2002-12-13 18:25:36 +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
|
|
|
/*
|
|
|
|
If this substatement needs row-based, the entire routine does too (we
|
|
|
|
cannot switch from statement-based to row-based only for this
|
|
|
|
substatement).
|
|
|
|
*/
|
WL#3339 (Issue warnings when statement-based replication may fail):
Replacing binlog_row_based_if_mixed with variable binlog_stmt_flags
holding several flags and adding member functions to manipulate the
flags.
Added code to generate a warning when an attempt to log an unsafe
statement to the binary log was made. The warning is both pushed to the
SHOW WARNINGS table and written to the error log. The prevent flooding
the error log, the warning is just written to the error log once per
open session.
sql/item_create.cc:
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sp_head.cc:
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sp_head.h:
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sql_base.cc:
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sql_class.cc:
Adding THD::binlog_flags to store thread-specific binary log state.
Adding code to push a warning and write an entry into the error log
when an attempt is made to log an unsafe statement.
sql/sql_class.h:
Adding THD::binlog_flags to store thread-specific binary log state.
Adding BINLOG_FLAG_UNSAFE_STMT_PRINTED to denote that a warning for
an unsafe statement has already been generated for this thread.
sql/sql_insert.cc:
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
sql/sql_lex.cc:
Replacing binlog_row_based_if_mixed with a variable binlog_stmt_flags
holding several flags.
sql/sql_lex.h:
Replacing binlog_row_based_if_mixed with a variable binlog_stmt_flags
holding several flags.
sql/share/errmsg.txt:
Adding error message to indicate that an attempt to log an unsafe
statement was made.
sql/sql_view.cc:
Using {is,set,clear}_stmt_unsafe() member functions instead of
binlog_row_based_if_mixed member variable.
mysql-test/r/binlog_unsafe.result:
New BitKeeper file ``mysql-test/r/binlog_unsafe.result''
mysql-test/t/binlog_unsafe.test:
New BitKeeper file ``mysql-test/t/binlog_unsafe.test''
2007-05-14 14:45:38 +02:00
|
|
|
if (sublex->is_stmt_unsafe())
|
* 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
|
|
|
m_flags|= BINLOG_ROW_BASED_IF_MIXED;
|
|
|
|
|
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 routines which are used by statement to respective set for
|
|
|
|
this 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
|
|
|
*/
|
2005-07-09 19:51:59 +02:00
|
|
|
sp_update_sp_used_routines(&m_sroutines, &sublex->sroutines);
|
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
|
|
|
/*
|
|
|
|
Merge tables used by this statement (but not by its functions or
|
|
|
|
procedures) to multiset of tables used by this routine.
|
|
|
|
*/
|
|
|
|
merge_table_list(thd, sublex->query_tables, sublex);
|
2003-06-29 18:15:17 +02:00
|
|
|
if (! sublex->sp_lex_in_use)
|
2006-05-04 14:30:38 +02:00
|
|
|
{
|
|
|
|
lex_end(sublex);
|
2003-06-29 18:15:17 +02:00
|
|
|
delete sublex;
|
2006-05-04 14:30:38 +02:00
|
|
|
}
|
2003-06-29 18:15:17 +02:00
|
|
|
thd->lex= oldlex;
|
2003-05-23 15:32:31 +02:00
|
|
|
DBUG_VOID_RETURN;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Put the instruction on the backpatch list, associated with the label.
|
|
|
|
*/
|
2002-12-11 14:24:29 +01:00
|
|
|
void
|
2002-12-16 15:40:44 +01:00
|
|
|
sp_head::push_backpatch(sp_instr *i, sp_label_t *lab)
|
2002-12-11 14:24:29 +01:00
|
|
|
{
|
2003-04-02 20:42:28 +02:00
|
|
|
bp_t *bp= (bp_t *)sql_alloc(sizeof(bp_t));
|
2002-12-16 15:40:44 +01:00
|
|
|
|
|
|
|
if (bp)
|
|
|
|
{
|
|
|
|
bp->lab= lab;
|
|
|
|
bp->instr= i;
|
|
|
|
(void)m_backpatch.push_front(bp);
|
|
|
|
}
|
2002-12-11 14:24:29 +01:00
|
|
|
}
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Update all instruction with this label in the backpatch list to
|
|
|
|
the current position.
|
|
|
|
*/
|
2002-12-11 14:24:29 +01:00
|
|
|
void
|
2002-12-16 15:40:44 +01:00
|
|
|
sp_head::backpatch(sp_label_t *lab)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2002-12-16 15:40:44 +01:00
|
|
|
bp_t *bp;
|
2002-12-12 13:14:23 +01:00
|
|
|
uint dest= instructions();
|
2002-12-16 15:40:44 +01:00
|
|
|
List_iterator_fast<bp_t> li(m_backpatch);
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_ENTER("sp_head::backpatch");
|
2002-12-16 15:40:44 +01:00
|
|
|
while ((bp= li++))
|
2004-08-17 20:20:58 +02:00
|
|
|
{
|
2006-04-18 11:07:34 +02:00
|
|
|
if (bp->lab == lab)
|
2008-01-23 21:26:41 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("backpatch: (m_ip %d, label 0x%lx <%s>) to dest %d",
|
|
|
|
bp->instr->m_ip, (ulong) lab, lab->name, dest));
|
2006-04-18 11:07:34 +02:00
|
|
|
bp->instr->backpatch(dest, lab->ctx);
|
2008-01-23 21:26:41 +01:00
|
|
|
}
|
2004-08-17 20:20:58 +02:00
|
|
|
}
|
2008-01-23 21:26:41 +01:00
|
|
|
DBUG_VOID_RETURN;
|
2004-08-17 20:20:58 +02:00
|
|
|
}
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2007-06-10 12:43:57 +02:00
|
|
|
Prepare an instance of Create_field for field creation (fill all necessary
|
2005-12-07 15:01:17 +01:00
|
|
|
attributes).
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param[in] thd Thread handle
|
|
|
|
@param[in] lex Yacc parsing context
|
|
|
|
@param[in] field_type Field type
|
|
|
|
@param[out] field_def An instance of create_field to be filled
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
FALSE on success
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
2005-12-07 15:01:17 +01:00
|
|
|
TRUE on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
sp_head::fill_field_definition(THD *thd, LEX *lex,
|
|
|
|
enum enum_field_types field_type,
|
2007-06-10 12:43:57 +02:00
|
|
|
Create_field *field_def)
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
LEX_STRING cmt = { 0, 0 };
|
|
|
|
uint unused1= 0;
|
|
|
|
int unused2= 0;
|
|
|
|
|
|
|
|
if (field_def->init(thd, (char*) "", field_type, lex->length, lex->dec,
|
|
|
|
lex->type, (Item*) 0, (Item*) 0, &cmt, 0,
|
|
|
|
&lex->interval_list,
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
lex->charset ? lex->charset :
|
|
|
|
thd->variables.collation_database,
|
2005-12-07 15:01:17 +01:00
|
|
|
lex->uint_geom_type))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (field_def->interval_list.elements)
|
|
|
|
field_def->interval= create_typelib(mem_root, field_def,
|
|
|
|
&field_def->interval_list);
|
|
|
|
|
|
|
|
sp_prepare_create_field(thd, field_def);
|
|
|
|
|
|
|
|
if (prepare_create_field(field_def, &unused1, &unused2, &unused2,
|
|
|
|
HA_CAN_GEOMETRY))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
void
|
2006-01-26 17:26:25 +01:00
|
|
|
sp_head::new_cont_backpatch(sp_instr_opt_meta *i)
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
{
|
|
|
|
m_cont_level+= 1;
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
/* Use the cont. destination slot to store the level */
|
|
|
|
i->m_cont_dest= m_cont_level;
|
|
|
|
(void)m_cont_backpatch.push_front(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-01-26 17:26:25 +01:00
|
|
|
sp_head::add_cont_backpatch(sp_instr_opt_meta *i)
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
{
|
|
|
|
i->m_cont_dest= m_cont_level;
|
|
|
|
(void)m_cont_backpatch.push_front(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_head::do_cont_backpatch()
|
|
|
|
{
|
|
|
|
uint dest= instructions();
|
|
|
|
uint lev= m_cont_level--;
|
2006-01-26 17:26:25 +01:00
|
|
|
sp_instr_opt_meta *i;
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
|
|
|
|
while ((i= m_cont_backpatch.head()) && i->m_cont_dest == lev)
|
|
|
|
{
|
|
|
|
i->m_cont_dest= dest;
|
|
|
|
(void)m_cont_backpatch.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-13 16:40:52 +01:00
|
|
|
void
|
2005-11-10 20:25:03 +01:00
|
|
|
sp_head::set_info(longlong created, longlong modified,
|
2004-06-09 14:19:43 +02:00
|
|
|
st_sp_chistics *chistics, ulong sql_mode)
|
2003-12-13 16:40:52 +01:00
|
|
|
{
|
|
|
|
m_created= created;
|
|
|
|
m_modified= modified;
|
2004-11-09 02:58:44 +01:00
|
|
|
m_chistics= (st_sp_chistics *) memdup_root(mem_root, (char*) chistics,
|
|
|
|
sizeof(*chistics));
|
2003-12-13 16:40:52 +01:00
|
|
|
if (m_chistics->comment.length == 0)
|
|
|
|
m_chistics->comment.str= 0;
|
|
|
|
else
|
2004-11-09 02:58:44 +01:00
|
|
|
m_chistics->comment.str= strmake_root(mem_root,
|
2003-12-13 16:40:52 +01:00
|
|
|
m_chistics->comment.str,
|
|
|
|
m_chistics->comment.length);
|
2004-06-09 14:19:43 +02:00
|
|
|
m_sql_mode= sql_mode;
|
2003-12-13 16:40:52 +01:00
|
|
|
}
|
|
|
|
|
2005-11-10 20:25:03 +01:00
|
|
|
|
|
|
|
void
|
2006-01-05 23:47:49 +01:00
|
|
|
sp_head::set_definer(const char *definer, uint definerlen)
|
2005-11-10 20:25:03 +01:00
|
|
|
{
|
2006-09-27 16:21:29 +02:00
|
|
|
char user_name_holder[USERNAME_LENGTH + 1];
|
2006-09-28 15:00:44 +02:00
|
|
|
LEX_STRING user_name= { user_name_holder, USERNAME_LENGTH };
|
2005-11-10 20:25:03 +01:00
|
|
|
|
2006-03-02 13:18:49 +01:00
|
|
|
char host_name_holder[HOSTNAME_LENGTH + 1];
|
2006-05-18 16:57:50 +02:00
|
|
|
LEX_STRING host_name= { host_name_holder, HOSTNAME_LENGTH };
|
2005-11-10 20:25:03 +01:00
|
|
|
|
2006-03-02 13:18:49 +01:00
|
|
|
parse_user(definer, definerlen, user_name.str, &user_name.length,
|
|
|
|
host_name.str, &host_name.length);
|
2005-11-10 20:25:03 +01:00
|
|
|
|
2006-03-02 13:18:49 +01:00
|
|
|
set_definer(&user_name, &host_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_head::set_definer(const LEX_STRING *user_name, const LEX_STRING *host_name)
|
|
|
|
{
|
|
|
|
m_definer_user.str= strmake_root(mem_root, user_name->str, user_name->length);
|
|
|
|
m_definer_user.length= user_name->length;
|
|
|
|
|
|
|
|
m_definer_host.str= strmake_root(mem_root, host_name->str, host_name->length);
|
|
|
|
m_definer_host.length= host_name->length;
|
2005-11-10 20:25:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-11 17:18:59 +01:00
|
|
|
void
|
|
|
|
sp_head::reset_thd_mem_root(THD *thd)
|
|
|
|
{
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_ENTER("sp_head::reset_thd_mem_root");
|
2004-03-11 17:18:59 +01:00
|
|
|
m_thd_root= thd->mem_root;
|
2004-11-09 02:58:44 +01:00
|
|
|
thd->mem_root= &main_mem_root;
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_PRINT("info", ("mem_root 0x%lx moved to thd mem root 0x%lx",
|
|
|
|
(ulong) &mem_root, (ulong) &thd->mem_root));
|
|
|
|
free_list= thd->free_list; // Keep the old list
|
2004-03-11 17:18:59 +01:00
|
|
|
thd->free_list= NULL; // Start a new one
|
|
|
|
m_thd= thd;
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2004-03-11 17:18:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_head::restore_thd_mem_root(THD *thd)
|
|
|
|
{
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_ENTER("sp_head::restore_thd_mem_root");
|
|
|
|
Item *flist= free_list; // The old list
|
2005-09-02 15:21:19 +02:00
|
|
|
set_query_arena(thd); // Get new free_list and mem_root
|
Patch two (the final one) for Bug#7306 "the server side preparedStatement
error for LIMIT placeholder".
The patch adds grammar support for LIMIT ?, ? and changes the
type of ST_SELECT_LEX::select_limit,offset_limit from ha_rows to Item*,
so that it can point to Item_param.
mysql-test/include/ps_modify.inc:
Fix existing tests: now LIMIT can contain placeholders.
mysql-test/include/ps_query.inc:
Fix existing tests: now LIMIT can contain placeholders.
mysql-test/r/ps.result:
Add basic test coverage for LIMIT ?, ? and fix test results.
mysql-test/r/ps_2myisam.result:
Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_3innodb.result:
Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_4heap.result:
Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_5merge.result:
Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_6bdb.result:
Fix test results: now LIMIT can contain placeholders.
mysql-test/r/ps_7ndb.result:
Fix test results: now LIMIT can contain placeholders.
mysql-test/t/ps.test:
Add basic test coverage for LIMIT ?, ?.
sql/item.h:
Add a short-cut for (ulonglong) val_int() to Item.
Add a constructor to Item_int() that accepts ulonglong.
Simplify Item_uint constructor by using the c-tor above.
sql/item_subselect.cc:
Now select_limit has type Item *.
We can safely create an Item in Item_exists_subselect::fix_length_and_dec():
it will be allocated in runtime memory root and freed in the end of
execution.
sql/sp_head.cc:
Add a special initalization state for stored procedures to
be able to easily distinguish the first execution of a stored procedure
from prepared statement prepare.
sql/sql_class.h:
Introduce new state 'INITIALIZED_FOR_SP' to be able to easily distinguish
the first execution of a stored procedure from prepared statement prepare.
sql/sql_derived.cc:
- use unit->set_limit() to set unit->select_limit_cnt, offset_limit_cnt
evreryplace. Add a warning about use of set_limit in
mysql_derived_filling.
sql/sql_error.cc:
- use unit->set_limit() to set unit->select_limit_cnt, offset_limit_cnt
evreryplace.
- this change is also aware of bug#11095 "show warnings limit 0 returns
all rows instead of zero rows", so the one who merges the bugfix from
4.1 can use local version of sql_error.cc.
sql/sql_handler.cc:
- use unit->set_limit() to initalize
unit->select_limit_cnt,offset_limit_cnt everyplace.
sql/sql_lex.cc:
Now ST_SELECT_LEX::select_limit, offset_limit have type Item *
sql/sql_lex.h:
Now ST_SELECT_LEX::select_limit, offset_limit have type Item *
sql/sql_parse.cc:
- use unit->set_limit() to initalize
unit->select_limit_cnt,offset_limit_cnt everyplace.
- we can create an Item_int to set global limit of a statement:
it will be created in the runtime mem root and freed in the end of
execution.
sql/sql_repl.cc:
Use unit->set_limit to initialize limits.
sql/sql_select.cc:
- select_limit is now Item* so the proper way to check for default value
is to compare it with NULL.
sql/sql_union.cc:
Evaluate offset_limit_cnt using the new type of ST_SELECT_LEX::offset_limit
sql/sql_view.cc:
Now ST_SELECT_LEX::select_limit, offset_limit have type Item *
sql/sql_yacc.yy:
Add grammar support for LIMIT ?, ? clause.
2005-06-07 12:11:36 +02:00
|
|
|
state= INITIALIZED_FOR_SP;
|
2004-09-09 05:59:26 +02:00
|
|
|
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_PRINT("info", ("mem_root 0x%lx returned from thd mem root 0x%lx",
|
|
|
|
(ulong) &mem_root, (ulong) &thd->mem_root));
|
2004-03-11 17:18:59 +01:00
|
|
|
thd->free_list= flist; // Restore the old one
|
|
|
|
thd->mem_root= m_thd_root;
|
|
|
|
m_thd= NULL;
|
2004-05-20 01:02:49 +02:00
|
|
|
DBUG_VOID_RETURN;
|
2004-03-11 17:18:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Check if a user has access right to a routine.
|
|
|
|
|
|
|
|
@param thd Thread handler
|
|
|
|
@param sp SP
|
|
|
|
@param full_access Set to 1 if the user has SELECT right to the
|
|
|
|
'mysql.proc' able or is the owner of the routine
|
|
|
|
@retval
|
|
|
|
false ok
|
|
|
|
@retval
|
|
|
|
true error
|
2005-03-15 15:07:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access)
|
2005-03-05 12:35:32 +01:00
|
|
|
{
|
|
|
|
TABLE_LIST tables;
|
|
|
|
bzero((char*) &tables,sizeof(tables));
|
|
|
|
tables.db= (char*) "mysql";
|
|
|
|
tables.table_name= tables.alias= (char*) "proc";
|
2008-01-30 16:27:41 +01:00
|
|
|
*full_access= (!check_table_access(thd, SELECT_ACL, &tables, 1, TRUE) ||
|
2005-09-15 21:29:07 +02:00
|
|
|
(!strcmp(sp->m_definer_user.str,
|
|
|
|
thd->security_ctx->priv_user) &&
|
|
|
|
!strcmp(sp->m_definer_host.str,
|
|
|
|
thd->security_ctx->priv_host)));
|
2005-03-15 15:07:28 +01:00
|
|
|
if (!*full_access)
|
2005-05-17 20:54:20 +02:00
|
|
|
return check_some_routine_access(thd, sp->m_db.str, sp->m_name.str,
|
|
|
|
sp->m_type == TYPE_ENUM_PROCEDURE);
|
2005-03-05 12:35:32 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
/**
|
|
|
|
Implement SHOW CREATE statement for stored routines.
|
|
|
|
|
|
|
|
@param thd Thread context.
|
|
|
|
@param type Stored routine type
|
|
|
|
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION)
|
|
|
|
|
|
|
|
@return Error status.
|
|
|
|
@retval FALSE on success
|
|
|
|
@retval TRUE on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool
|
|
|
|
sp_head::show_create_routine(THD *thd, int type)
|
2003-11-17 18:21:36 +01:00
|
|
|
{
|
2007-05-29 19:22:33 +02:00
|
|
|
const char *col1_caption= type == TYPE_ENUM_PROCEDURE ?
|
|
|
|
"Procedure" : "Function";
|
|
|
|
|
|
|
|
const char *col3_caption= type == TYPE_ENUM_PROCEDURE ?
|
|
|
|
"Create Procedure" : "Create Function";
|
|
|
|
|
|
|
|
bool err_status;
|
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
Protocol *protocol= thd->protocol;
|
2007-05-29 19:22:33 +02:00
|
|
|
List<Item> fields;
|
|
|
|
|
A set of changes aiming to make the Event Scheduler more user-friendly
when there are no up-to-date system tables to support it:
- initialize the scheduler before reporting "Ready for connections".
This ensures that warnings, if any, are printed before "Ready for
connections", and this message is not mangled.
- do not abort the scheduler if there are no system tables
- check the tables once at start up, remember the status and disable
the scheduler if the tables are not up to date.
If one attempts to use the scheduler with bad tables,
issue an error message.
- clean up the behaviour of the module under LOCK TABLES and pre-locking
mode
- make sure implicit commit of Events DDL works as expected.
- add more tests
Collateral clean ups in the events code.
This patch fixes Bug#23631 Events: SHOW VARIABLES doesn't work
when mysql.event is damaged
mysql-test/r/events.result:
Update results.
mysql-test/r/events_bugs.result:
Update results.
mysql-test/r/events_restart_phase1.result:
Update results.
mysql-test/r/events_restart_phase2.result:
Update results.
mysql-test/r/events_restart_phase3.result:
Update results.
mysql-test/r/events_scheduling.result:
Update results.
mysql-test/r/events_time_zone.result:
Update results.
mysql-test/t/events.test:
Add new tests for tampering with mysql.event and some more
tests for sub-statements, LOCK TABLES mode and pre-locking.
mysql-test/t/events_bugs.test:
Move the non-concurrent part of test for Bug 16420 to this file.
mysql-test/t/events_restart_phase1.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase2.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_restart_phase3.test:
Rewrite events_restart_* tests to take into account that now
we check mysql.event table only once, at server startup.
mysql-test/t/events_scheduling.test:
Add more coverage for event_scheduler global variable.
mysql-test/t/events_time_zone.test:
Move the non-concurrent part of the tests for Bug 16420 to
events_bugs.test
sql/event_data_objects.cc:
Move update_timing_fields functionality to Event_db_repository.
Make loading of events from a table record more robust to tampering
with the table - now we do not check mysql.event on every table open.
sql/event_data_objects.h:
Cleanup.
sql/event_db_repository.cc:
Now Event_db_repository is responsible for table I/O only.
All the logic of events DDL is handled outside, in Events class please
refer to the added test coverage to see how this change affected
the behavior of Event Scheduler.
Dependency on sp_head.h and sp.h removed.
Make this module robust to tweaks with mysql.event table.
Move check_system_tables from events.cc to this file
sql/event_db_repository.h:
Cleanup declarations (remove unused ones, change return type to bool
from int).
sql/event_queue.cc:
Update to adapt to the new start up scheme of the Event Scheduler.
sql/event_queue.h:
Cleanup declarations.
sql/event_scheduler.cc:
Make all the error messages uniform:
[SEVERITY] Event Scheduler: [user][schema.event] message
Using append_identifier for error logging was an overkill - we may
need it only if the system character set may have NUL (null character)
as part of a valid identifier, this is currently never the case,
whereas additional quoting did not look nice in the log.
sql/event_scheduler.h:
Cleanup the headers.
sql/events.cc:
Use a different start up procedure of Event Scheduler:
- at start up, try to check the system tables first.
If they are not up-to-date, disable the scheduler.
- try to load all the active events. In case of a load error, abort
start up.
- do not parse an event on start up. Parsing only gives some information
about event validity, but far not all.
Consolidate the business logic of Events DDL in this module.
Now opt_event_scheduler may change after start up and thus is protected
by LOCK_event_metadata mutex.
sql/events.h:
Use all-static-data-members approach to implement Singleton pattern.
sql/mysqld.cc:
New invocation scheme of Events. Move some logic to events.cc.
Initialize the scheduler before reporting "Ready for connections".
sql/set_var.cc:
Clean up sys_var_thd_sql_mode::symbolic_mode_representation
to work with a LEX_STRING.
Move more logic related to @@events_scheduler global variable to Events
module.
sql/set_var.h:
Update declarations.
sql/share/errmsg.txt:
If someone tampered with mysql.event table after the server has
started we no longer give him/her a complete report what was actually
broken. Do not send the user to look at the error log in such case,
as there is nothing there (check_table_intact is not executed).
sql/sp_head.cc:
Update to a new declaration of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_db.cc:
New invocation scheme of Events module.
sql/sql_parse.cc:
Move more logic to Events module. Make sure that we are consistent
in the way access rights are checked for Events DDL: always
after committing the current transaction and checking the system tables.
sql/sql_show.cc:
Update to the new declarations of
sys_var_thd_sql_mode::symbolic_mode_representation
sql/sql_test.cc:
New invocation scheme of events.
sql/table.cc:
mysql.event is a system table.
Update check_table_intact to be concurrent, more verbose, and less smart.
sql/table.h:
Add a helper method.
mysql-test/r/events_trans.result:
New BitKeeper file ``mysql-test/r/events_trans.result''
mysql-test/t/events_trans.test:
New BitKeeper file ``mysql-test/t/events_trans.test'':
test cases for Event Scheduler that require a transactional
storage engine.
2007-04-05 13:24:34 +02:00
|
|
|
LEX_STRING sql_mode;
|
2007-05-29 19:22:33 +02:00
|
|
|
|
2005-03-05 12:35:32 +01:00
|
|
|
bool full_access;
|
2007-05-29 19:22:33 +02:00
|
|
|
|
|
|
|
DBUG_ENTER("sp_head::show_create_routine");
|
|
|
|
DBUG_PRINT("info", ("routine %s", m_name.str));
|
|
|
|
|
|
|
|
DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
|
|
|
|
type == TYPE_ENUM_FUNCTION);
|
2006-01-05 23:47:49 +01:00
|
|
|
|
2005-03-15 15:07:28 +01:00
|
|
|
if (check_show_routine_access(thd, this, &full_access))
|
2007-05-29 19:22:33 +02:00
|
|
|
DBUG_RETURN(TRUE);
|
2004-06-09 14:19:43 +02:00
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
sys_var_thd_sql_mode::symbolic_mode_representation(
|
|
|
|
thd, m_sql_mode, &sql_mode);
|
|
|
|
|
|
|
|
/* Send header. */
|
|
|
|
|
2007-05-30 14:24:21 +02:00
|
|
|
fields.push_back(new Item_empty_string(col1_caption, NAME_CHAR_LEN));
|
2007-05-29 19:22:33 +02:00
|
|
|
fields.push_back(new Item_empty_string("sql_mode", sql_mode.length));
|
|
|
|
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
NOTE: SQL statement field must be not less than 1024 in order not to
|
|
|
|
confuse old clients.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item_empty_string *stmt_fld=
|
|
|
|
new Item_empty_string(col3_caption,
|
|
|
|
max(m_defstr.length, 1024));
|
|
|
|
|
|
|
|
stmt_fld->maybe_null= TRUE;
|
|
|
|
|
|
|
|
fields.push_back(stmt_fld);
|
|
|
|
}
|
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
fields.push_back(new Item_empty_string("character_set_client",
|
|
|
|
MY_CS_NAME_SIZE));
|
|
|
|
|
|
|
|
fields.push_back(new Item_empty_string("collation_connection",
|
|
|
|
MY_CS_NAME_SIZE));
|
|
|
|
|
|
|
|
fields.push_back(new Item_empty_string("Database Collation",
|
|
|
|
MY_CS_NAME_SIZE));
|
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
if (protocol->send_fields(&fields,
|
|
|
|
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
|
|
|
{
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send data. */
|
2006-06-29 22:21:55 +02:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
protocol->prepare_for_resend();
|
2007-05-29 19:22:33 +02:00
|
|
|
|
2003-11-17 18:21:36 +01:00
|
|
|
protocol->store(m_name.str, m_name.length, system_charset_info);
|
2007-05-29 19:22:33 +02:00
|
|
|
protocol->store(sql_mode.str, sql_mode.length, system_charset_info);
|
|
|
|
|
2005-03-05 12:35:32 +01:00
|
|
|
if (full_access)
|
2007-07-12 10:49:39 +02:00
|
|
|
protocol->store(m_defstr.str, m_defstr.length,
|
|
|
|
m_creation_ctx->get_client_cs());
|
2006-06-29 22:21:55 +02:00
|
|
|
else
|
|
|
|
protocol->store_null();
|
2004-06-09 14:19:43 +02:00
|
|
|
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
|
|
|
|
protocol->store(m_creation_ctx->get_client_cs()->csname, system_charset_info);
|
|
|
|
protocol->store(m_creation_ctx->get_connection_cl()->name, system_charset_info);
|
|
|
|
protocol->store(m_creation_ctx->get_db_cl()->name, system_charset_info);
|
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
err_status= protocol->write();
|
|
|
|
|
|
|
|
if (!err_status)
|
2008-02-19 13:58:08 +01:00
|
|
|
my_eof(thd);
|
2007-05-29 19:22:33 +02:00
|
|
|
|
|
|
|
DBUG_RETURN(err_status);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
|
|
|
|
2004-05-26 13:28:35 +02:00
|
|
|
|
2007-05-29 19:22:33 +02:00
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
Add instruction to SP.
|
2004-05-26 13:28:35 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param instr Instruction
|
2004-05-26 13:28:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void sp_head::add_instr(sp_instr *instr)
|
|
|
|
{
|
|
|
|
instr->free_list= m_thd->free_list;
|
|
|
|
m_thd->free_list= 0;
|
2005-06-23 18:22:08 +02:00
|
|
|
/*
|
|
|
|
Memory root of every instruction is designated for permanent
|
|
|
|
transformations (optimizations) made on the parsed tree during
|
|
|
|
the first execution. It points to the memory root of the
|
|
|
|
entire stored procedure, as their life span is equal.
|
|
|
|
*/
|
|
|
|
instr->mem_root= &main_mem_root;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
insert_dynamic(&m_instr, (uchar*)&instr);
|
2003-11-17 18:21:36 +01:00
|
|
|
}
|
2004-08-02 18:05:31 +02:00
|
|
|
|
2005-08-25 15:34:34 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
Do some minimal optimization of the code:
|
2007-10-11 20:37:45 +02:00
|
|
|
-# Mark used instructions
|
|
|
|
-# While doing this, shortcut jumps to jump instructions
|
|
|
|
-# Compact the code, removing unused instructions.
|
2006-01-25 15:11:49 +01:00
|
|
|
|
|
|
|
This is the main mark and move loop; it relies on the following methods
|
|
|
|
in sp_instr and its subclasses:
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
- opt_mark() : Mark instruction as reachable
|
|
|
|
- opt_shortcut_jump(): Shortcut jumps to the final destination;
|
|
|
|
used by opt_mark().
|
|
|
|
- opt_move() : Update moved instruction
|
|
|
|
- set_destination() : Set the new destination (jump instructions only)
|
2005-08-25 15:34:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void sp_head::optimize()
|
2004-08-02 18:05:31 +02:00
|
|
|
{
|
|
|
|
List<sp_instr> bp;
|
|
|
|
sp_instr *i;
|
|
|
|
uint src, dst;
|
|
|
|
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
opt_mark();
|
2004-08-02 18:05:31 +02:00
|
|
|
|
|
|
|
bp.empty();
|
|
|
|
src= dst= 0;
|
|
|
|
while ((i= get_instr(src)))
|
|
|
|
{
|
|
|
|
if (! i->marked)
|
|
|
|
{
|
|
|
|
delete i;
|
|
|
|
src+= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (src != dst)
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
{ // Move the instruction and update prev. jumps
|
2004-08-02 18:05:31 +02:00
|
|
|
sp_instr *ibp;
|
|
|
|
List_iterator_fast<sp_instr> li(bp);
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
set_dynamic(&m_instr, (uchar*)&i, dst);
|
2004-08-02 18:05:31 +02:00
|
|
|
while ((ibp= li++))
|
2006-01-26 17:26:25 +01:00
|
|
|
{
|
|
|
|
sp_instr_opt_meta *im= static_cast<sp_instr_opt_meta *>(ibp);
|
|
|
|
im->set_destination(src, dst);
|
|
|
|
}
|
2004-08-02 18:05:31 +02:00
|
|
|
}
|
|
|
|
i->opt_move(dst, &bp);
|
|
|
|
src+= 1;
|
|
|
|
dst+= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_instr.elements= dst;
|
|
|
|
bp.empty();
|
|
|
|
}
|
|
|
|
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
void sp_head::add_mark_lead(uint ip, List<sp_instr> *leads)
|
|
|
|
{
|
|
|
|
sp_instr *i= get_instr(ip);
|
|
|
|
|
|
|
|
if (i && ! i->marked)
|
|
|
|
leads->push_front(i);
|
|
|
|
}
|
|
|
|
|
2004-08-02 18:05:31 +02:00
|
|
|
void
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp_head::opt_mark()
|
2004-08-02 18:05:31 +02:00
|
|
|
{
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
uint ip;
|
2004-08-02 18:05:31 +02:00
|
|
|
sp_instr *i;
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
List<sp_instr> leads;
|
2004-08-02 18:05:31 +02:00
|
|
|
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
/*
|
|
|
|
Forward flow analysis algorithm in the instruction graph:
|
|
|
|
- first, add the entry point in the graph (the first instruction) to the
|
|
|
|
'leads' list of paths to explore.
|
|
|
|
- while there are still leads to explore:
|
|
|
|
- pick one lead, and follow the path forward. Mark instruction reached.
|
|
|
|
Stop only if the end of the routine is reached, or the path converge
|
|
|
|
to code already explored (marked).
|
|
|
|
- while following a path, collect in the 'leads' list any fork to
|
|
|
|
another path (caused by conditional jumps instructions), so that these
|
|
|
|
paths can be explored as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Add the entry point */
|
|
|
|
i= get_instr(0);
|
|
|
|
leads.push_front(i);
|
|
|
|
|
|
|
|
/* For each path of code ... */
|
|
|
|
while (leads.elements != 0)
|
|
|
|
{
|
|
|
|
i= leads.pop();
|
|
|
|
|
|
|
|
/* Mark the entire path, collecting new leads. */
|
|
|
|
while (i && ! i->marked)
|
|
|
|
{
|
|
|
|
ip= i->opt_mark(this, & leads);
|
|
|
|
i= get_instr(ip);
|
|
|
|
}
|
|
|
|
}
|
2004-08-02 18:05:31 +02: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
|
|
|
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
#ifndef DBUG_OFF
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2006-01-26 17:26:25 +01:00
|
|
|
Return the routine instructions as a result set.
|
2007-10-11 20:37:45 +02:00
|
|
|
@return
|
|
|
|
0 if ok, !=0 on error.
|
2006-01-26 17:26:25 +01:00
|
|
|
*/
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
int
|
|
|
|
sp_head::show_routine_code(THD *thd)
|
|
|
|
{
|
|
|
|
Protocol *protocol= thd->protocol;
|
|
|
|
char buff[2048];
|
|
|
|
String buffer(buff, sizeof(buff), system_charset_info);
|
|
|
|
List<Item> field_list;
|
2005-11-18 16:30:27 +01:00
|
|
|
sp_instr *i;
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
bool full_access;
|
2005-11-22 14:25:44 +01:00
|
|
|
int res= 0;
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
uint ip;
|
|
|
|
DBUG_ENTER("sp_head::show_routine_code");
|
2005-11-18 16:30:27 +01:00
|
|
|
DBUG_PRINT("info", ("procedure: %s", m_name.str));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
|
|
|
|
if (check_show_routine_access(thd, this, &full_access) || !full_access)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
field_list.push_back(new Item_uint("Pos", 9));
|
|
|
|
// 1024 is for not to confuse old clients
|
|
|
|
field_list.push_back(new Item_empty_string("Instruction",
|
|
|
|
max(buffer.length(), 1024)));
|
|
|
|
if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
|
|
|
|
Protocol::SEND_EOF))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
for (ip= 0; (i = get_instr(ip)) ; ip++)
|
|
|
|
{
|
2006-01-26 17:26:25 +01:00
|
|
|
/*
|
|
|
|
Consistency check. If these are different something went wrong
|
|
|
|
during optimization.
|
|
|
|
*/
|
|
|
|
if (ip != i->m_ip)
|
|
|
|
{
|
|
|
|
const char *format= "Instruction at position %u has m_ip=%u";
|
|
|
|
char tmp[sizeof(format) + 2*SP_INSTR_UINT_MAXLEN + 1];
|
|
|
|
|
|
|
|
sprintf(tmp, format, ip, i->m_ip);
|
|
|
|
/*
|
|
|
|
Since this is for debugging purposes only, we don't bother to
|
|
|
|
introduce a special error code for it.
|
|
|
|
*/
|
|
|
|
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, tmp);
|
|
|
|
}
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
protocol->prepare_for_resend();
|
|
|
|
protocol->store((longlong)ip);
|
|
|
|
|
|
|
|
buffer.set("", 0, system_charset_info);
|
|
|
|
i->print(&buffer);
|
2005-11-18 16:30:27 +01:00
|
|
|
protocol->store(buffer.ptr(), buffer.length(), system_charset_info);
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
if ((res= protocol->write()))
|
|
|
|
break;
|
|
|
|
}
|
Patch for the following bugs:
- BUG#11986: Stored routines and triggers can fail if the code
has a non-ascii symbol
- BUG#16291: mysqldump corrupts string-constants with non-ascii-chars
- BUG#19443: INFORMATION_SCHEMA does not support charsets properly
- BUG#21249: Character set of SP-var can be ignored
- BUG#25212: Character set of string constant is ignored (stored routines)
- BUG#25221: Character set of string constant is ignored (triggers)
There were a few general problems that caused these bugs:
1. Character set information of the original (definition) query for views,
triggers, stored routines and events was lost.
2. mysqldump output query in client character set, which can be
inappropriate to encode definition-query.
3. INFORMATION_SCHEMA used strings with mixed encodings to display object
definition;
1. No query-definition-character set.
In order to compile query into execution code, some extra data (such as
environment variables or the database character set) is used. The problem
here was that this context was not preserved. So, on the next load it can
differ from the original one, thus the result will be different.
The context contains the following data:
- client character set;
- connection collation (character set and collation);
- collation of the owner database;
The fix is to store this context and use it each time we parse (compile)
and execute the object (stored routine, trigger, ...).
2. Wrong mysqldump-output.
The original query can contain several encodings (by means of character set
introducers). The problem here was that we tried to convert original query
to the mysqldump-client character set.
Moreover, we stored queries in different character sets for different
objects (views, for one, used UTF8, triggers used original character set).
The solution is
- to store definition queries in the original character set;
- to change SHOW CREATE statement to output definition query in the
binary character set (i.e. without any conversion);
- introduce SHOW CREATE TRIGGER statement;
- to dump special statements to switch the context to the original one
before dumping and restore it afterwards.
Note, in order to preserve the database collation at the creation time,
additional ALTER DATABASE might be used (to temporary switch the database
collation back to the original value). In this case, ALTER DATABASE
privilege will be required. This is a backward-incompatible change.
3. INFORMATION_SCHEMA showed non-UTF8 strings
The fix is to generate UTF8-query during the parsing, store it in the object
and show it in the INFORMATION_SCHEMA.
Basically, the idea is to create a copy of the original query convert it to
UTF8. Character set introducers are removed and all text literals are
converted to UTF8.
This UTF8 query is intended to provide user-readable output. It must not be
used to recreate the object. Specialized SHOW CREATE statements should be
used for this.
The reason for this limitation is the following: the original query can
contain symbols from several character sets (by means of character set
introducers).
Example:
- original query:
CREATE VIEW v1 AS SELECT _cp1251 'Hello' AS c1;
- UTF8 query (for INFORMATION_SCHEMA):
CREATE VIEW v1 AS SELECT 'Hello' AS c1;
client/mysqldump.c:
Set original character set and collation before dumping definition query.
include/my_sys.h:
Move out-parameter to the end of list.
mysql-test/lib/mtr_report.pl:
Ignore server-warnings during the test case.
mysql-test/r/create.result:
Update result file.
mysql-test/r/ctype_cp932_binlog_stm.result:
Update result file.
mysql-test/r/events.result:
Update result file.
mysql-test/r/events_bugs.result:
Update result file.
mysql-test/r/events_grant.result:
Update result file.
mysql-test/r/func_in.result:
Update result file.
mysql-test/r/gis.result:
Update result file.
mysql-test/r/grant.result:
Update result file.
mysql-test/r/information_schema.result:
Update result file.
mysql-test/r/information_schema_db.result:
Update result file.
mysql-test/r/lowercase_view.result:
Update result file.
mysql-test/r/mysqldump.result:
Update result file.
mysql-test/r/ndb_sp.result:
Update result file.
mysql-test/r/ps.result:
Update result file.
mysql-test/r/rpl_replicate_do.result:
Update result file.
mysql-test/r/rpl_sp.result:
Update result file.
mysql-test/r/rpl_trigger.result:
Update result file.
mysql-test/r/rpl_view.result:
Update result file.
mysql-test/r/show_check.result:
Update result file.
mysql-test/r/skip_grants.result:
Update result file.
mysql-test/r/sp-destruct.result:
Update result file.
mysql-test/r/sp-error.result:
Update result file.
mysql-test/r/sp-security.result:
Update result file.
mysql-test/r/sp.result:
Update result file.
mysql-test/r/sql_mode.result:
Update result file.
mysql-test/r/system_mysql_db.result:
Update result file.
mysql-test/r/temp_table.result:
Update result file.
mysql-test/r/trigger-compat.result:
Update result file.
mysql-test/r/trigger-grant.result:
Update result file.
mysql-test/r/trigger.result:
Update result file.
mysql-test/r/view.result:
Update result file.
mysql-test/r/view_grant.result:
Update result file.
mysql-test/t/events.test:
Update test case (new columns added).
mysql-test/t/information_schema.test:
Update test case (new columns added).
mysql-test/t/show_check.test:
Test case for SHOW CREATE TRIGGER in prepared statements and
stored routines.
mysql-test/t/sp-destruct.test:
Update test case (new columns added).
mysql-test/t/sp.test:
Update test case (new columns added).
mysql-test/t/view.test:
Update test.
mysys/charset.c:
Move out-parameter to the end of list.
scripts/mysql_system_tables.sql:
Add new columns to mysql.proc and mysql.event.
scripts/mysql_system_tables_fix.sql:
Add new columns to mysql.proc and mysql.event.
sql/event_data_objects.cc:
Support new attributes for events.
sql/event_data_objects.h:
Support new attributes for events.
sql/event_db_repository.cc:
Support new attributes for events.
sql/event_db_repository.h:
Support new attributes for events.
sql/events.cc:
Add new columns to SHOW CREATE event resultset.
sql/mysql_priv.h:
1. Introduce Object_creation_ctx;
2. Introduce SHOW CREATE TRIGGER;
3. Introduce auxilary functions.
sql/sp.cc:
Add support for new store routines attributes.
sql/sp_head.cc:
Add support for new store routines attributes.
sql/sp_head.h:
Add support for new store routines attributes.
sql/sql_lex.cc:
Generate UTF8-body on parsing/lexing.
sql/sql_lex.h:
1. Generate UTF8-body on parsing/lexing.
2. Introduce SHOW CREATE TRIGGER.
sql/sql_parse.cc:
Introduce SHOW CREATE TRIGGER.
sql/sql_partition.cc:
Update parse_sql().
sql/sql_prepare.cc:
Update parse_sql().
sql/sql_show.cc:
Support new attributes for views
sql/sql_trigger.cc:
Support new attributes for views
sql/sql_trigger.h:
Support new attributes for views
sql/sql_view.cc:
Support new attributes for views
sql/sql_yacc.yy:
1. Add SHOW CREATE TRIGGER statement.
2. Generate UTF8-body for views, stored routines, triggers and events.
sql/table.cc:
Introduce Object_creation_ctx.
sql/table.h:
Introduce Object_creation_ctx.
sql/share/errmsg.txt:
Add new errors.
mysql-test/include/ddl_i18n.check_events.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_sp.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_triggers.inc:
Aux file for test suite.
mysql-test/include/ddl_i18n.check_views.inc:
Aux file for test suite.
mysql-test/include/have_cp1251.inc:
Aux file for test suite.
mysql-test/include/have_cp866.inc:
Aux file for test suite.
mysql-test/include/have_koi8r.inc:
Aux file for test suite.
mysql-test/include/have_utf8.inc:
Aux file for test suite.
mysql-test/r/ddl_i18n_koi8r.result:
Result file.
mysql-test/r/ddl_i18n_utf8.result:
Result file.
mysql-test/r/have_cp1251.require:
Aux file for test suite.
mysql-test/r/have_cp866.require:
Aux file for test suite.
mysql-test/r/have_koi8r.require:
Aux file for test suite.
mysql-test/r/have_utf8.require:
Aux file for test suite.
mysql-test/t/ddl_i18n_koi8r.test:
Complete koi8r test case for the CS patch.
mysql-test/t/ddl_i18n_utf8.test:
Complete utf8 test case for the CS patch.
2007-06-28 19:34:54 +02:00
|
|
|
|
|
|
|
if (!res)
|
2008-02-19 13:58:08 +01:00
|
|
|
my_eof(thd);
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
#endif // ifndef DBUG_OFF
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02: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
|
|
|
Prepare LEX and thread for execution of instruction, if requested open
|
|
|
|
and lock LEX's tables, execute instruction's core function, perform
|
|
|
|
cleanup afterwards.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread context
|
|
|
|
@param nextp out - next instruction
|
|
|
|
@param open_tables if TRUE then check read access to tables in LEX's table
|
|
|
|
list and open and lock them (used in instructions which
|
|
|
|
need to calculate some expression and don't execute
|
|
|
|
complete statement).
|
|
|
|
@param sp_instr instruction for which we prepare context, and which core
|
|
|
|
function execute by calling its exec_core() method.
|
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
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
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
|
|
|
We are not saving/restoring some parts of THD which may need this because
|
|
|
|
we do this once for whole routine execution in sp_head::execute().
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@return
|
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
|
|
|
0/non-0 - Success/Failure
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp,
|
|
|
|
bool open_tables, sp_instr* instr)
|
|
|
|
{
|
|
|
|
int res= 0;
|
2006-11-01 18:41:09 +01:00
|
|
|
DBUG_ENTER("reset_lex_and_exec_core");
|
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
|
|
|
|
(pushing for Andrei)
Bug #27417 thd->no_trans_update.stmt lost value inside of SF-exec-stack
Once had been set the flag might later got reset inside of a stored routine
execution stack.
The reason was in that there was no check if a new statement started at time
of resetting.
The artifact affects most of binlogable DML queries. Notice, that multi-update
is wrapped up within
bug@27716 fix, multi-delete bug@29136.
Fixed with saving parent's statement flag of whether the statement modified
non-transactional table, and unioning (merging) the value with that was gained
in mysql_execute_command.
Resettling thd->no_trans_update members into thd->transaction.`member`;
Asserting code;
Effectively the following properties are held.
1. At the end of a substatement thd->transaction.stmt.modified_non_trans_table
reflects the fact if such a table got modified by the substatement.
That also respects THD::really_abort_on_warnin() requirements.
2. Eventually thd->transaction.stmt.modified_non_trans_table will be computed as
the union of the values of all invoked sub-statements.
That fixes this bug#27417;
Computing of thd->transaction.all.modified_non_trans_table is refined to base to
the stmt's value for all the case including insert .. select statement which
before the patch had an extra issue bug@28960.
Minor issues are covered with mysql_load, mysql_delete, and binloggin of insert in
to temp_table select.
The supplied test verifies limitely, mostly asserts. The ultimate testing is defered
for bug@13270, bug@23333.
mysql-test/r/mix_innodb_myisam_binlog.result:
results changed
mysql-test/t/mix_innodb_myisam_binlog.test:
regression test incl the related bug#28960.
sql/ha_ndbcluster.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.h:
new member added
sql/log.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/set_var.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sp_head.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
and saving and merging stmt's flag at the end of a substatement.
sql/sql_class.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_class.h:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_delete.cc:
correcting basic delete incl truncate branch and multi-delete queries to set
stmt.modified_non_trans_table;
optimization to set the flag at the end of per-row loop;
multi-delete still has an extra issue similar to bug#27716 of multi-update
- to be address with bug_29136 fix.
sql/sql_insert.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_load.cc:
eliminating a separate issue where the stmt flag was saved and re-stored after
write_record that actually could change it and the change would be lost but
should remain permanent;
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_parse.cc:
initialization to transaction.stmt.modified_non_trans_table at the common part
of all types of statements processing - mysql_execute_command().
sql/sql_table.cc:
moving the reset up to the mysql_execute_command() caller
sql/sql_update.cc:
correcting update query case (multi-update part of the issues covered by other
bug#27716 fix)
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
2007-07-30 17:27:36 +02:00
|
|
|
/*
|
|
|
|
The flag is saved at the entry to the following substatement.
|
|
|
|
It's reset further in the common code part.
|
|
|
|
It's merged with the saved parent's value at the exit of this func.
|
|
|
|
*/
|
|
|
|
bool parent_modified_non_trans_table= thd->transaction.stmt.modified_non_trans_table;
|
|
|
|
thd->transaction.stmt.modified_non_trans_table= FALSE;
|
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
|
|
|
DBUG_ASSERT(!thd->derived_tables);
|
|
|
|
DBUG_ASSERT(thd->change_list.is_empty());
|
|
|
|
/*
|
|
|
|
Use our own lex.
|
|
|
|
We should not save old value since it is saved/restored in
|
|
|
|
sp_head::execute() when we are entering/leaving routine.
|
|
|
|
*/
|
|
|
|
thd->lex= m_lex;
|
|
|
|
|
|
|
|
VOID(pthread_mutex_lock(&LOCK_thread_count));
|
2005-03-04 15:46:45 +01:00
|
|
|
thd->query_id= next_query_id();
|
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
|
|
|
VOID(pthread_mutex_unlock(&LOCK_thread_count));
|
|
|
|
|
2005-07-30 10:19:57 +02:00
|
|
|
if (thd->prelocked_mode == NON_PRELOCKED)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
This statement will enter/leave prelocked mode on its own.
|
|
|
|
Entering prelocked mode changes table list and related members
|
|
|
|
of LEX, so we'll need to restore them.
|
|
|
|
*/
|
|
|
|
if (lex_query_tables_own_last)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We've already entered/left prelocked mode with this statement.
|
|
|
|
Attach the list of tables that need to be prelocked and mark m_lex
|
|
|
|
as having such list attached.
|
|
|
|
*/
|
|
|
|
*lex_query_tables_own_last= prelocking_tables;
|
|
|
|
m_lex->mark_as_requiring_prelocking(lex_query_tables_own_last);
|
|
|
|
}
|
|
|
|
}
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
|
2005-07-30 10:19:57 +02:00
|
|
|
reinit_stmt_before_use(thd, m_lex);
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
|
|
|
|
if (open_tables)
|
2007-03-07 17:53:46 +01:00
|
|
|
res= instr->exec_open_and_lock_tables(thd, m_lex->query_tables);
|
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
|
|
|
|
|
|
|
if (!res)
|
2006-11-01 18:41:09 +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
|
|
|
res= instr->exec_core(thd, nextp);
|
2006-11-01 18:41:09 +01:00
|
|
|
DBUG_PRINT("info",("exec_core returned: %d", res));
|
|
|
|
}
|
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
|
|
|
|
|
|
|
m_lex->unit.cleanup();
|
|
|
|
|
Prevent bugs by making DBUG_* expressions syntactically equivalent
to a single statement.
---
Bug#24795: SHOW PROFILE
Profiling is only partially functional on some architectures. Where
there is no getrusage() system call, presently Null values are
returned where it would be required. Notably, Windows needs some love
applied to make it as useful.
Syntax this adds:
SHOW PROFILES
SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n]
where "n" is an integer
and "types" is zero or many (comma-separated) of
"CPU"
"MEMORY" (not presently supported)
"BLOCK IO"
"CONTEXT SWITCHES"
"PAGE FAULTS"
"IPC"
"SWAPS"
"SOURCE"
"ALL"
It also adds a session variable (boolean) "profiling", set to "no"
by default, and (integer) profiling_history_size, set to 15 by
default.
This patch abstracts setting THDs' "proc_info" behind a macro that
can be used as a hook into the profiling code when profiling
support is compiled in. All future code in this line should use
that mechanism for setting thd->proc_info.
---
Tests are now set to omit the statistics.
---
Adds an Information_schema table, "profiling" for access to
"show profile" data.
---
Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795
into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community
---
Fix merge problems.
---
Fixed one bug in the query_source being NULL.
Updated test results.
---
Include more thorough profiling tests.
Improve support for prepared statements.
Use session-specific query IDs, starting at zero.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
Limit the size of captured query text.
No longer log queries that are zero length.
BitKeeper/deleted/.del-profile.result:
Rename: mysql-test/r/profile.result -> BitKeeper/deleted/.del-profile.result
BitKeeper/deleted/.del-profile.test:
Rename: mysql-test/t/profile.test -> BitKeeper/deleted/.del-profile.test
BitKeeper/deleted/.del-sql_profile.cc:
Rename: sql/sql_profile.cc -> BitKeeper/deleted/.del-sql_profile.cc
BitKeeper/deleted/.del-sql_profile.h:
Rename: sql/sql_profile.h -> BitKeeper/deleted/.del-sql_profile.h
configure.in:
Add a configure-time option to enable/disable query profiling. The
default is enabled.
include/my_dbug.h:
DBUG_* statements should be syntactically equivalent to a single
statement.
myisam/mi_open.c:
DBUG_* statements should be syntactically equivalent to a single
statement.
mysql-test/r/information_schema.result:
Updated (re-recorded) tests that I missed somehow. I verified these
for correctness.
mysql-test/r/information_schema_db.result:
Updated test results I missed.
mysql-test/r/mysqlshow.result:
Fix merge problems.
ndb/src/ndbapi/DictCache.cpp:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/ha_archive.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/ha_berkeley.cc:
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/ha_myisam.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/ha_myisammrg.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/ha_ndbcluster.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/item_cmpfunc.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/item_func.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/lock.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/log_event.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/mysql_priv.h:
Use 64-bit constants for the 64-bit bit field.
Add a new option bit for whether profiling is active or not.
sql/mysqld.cc:
Add semicolon to DBUG statement.
Add a new system variable and set it.
---
Set the minimum, which is zero and not 50.
sql/repl_failsafe.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/set_var.cc:
Make a new system global variable and session variable, to determine
behavior of profiling.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/set_var.h:
The THD::options bit field is ulonglong, not ulong.
sql/slave.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sp_head.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_base.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_cache.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
---
Fix merge problems.
sql/sql_class.cc:
Insert a pointer to the current thread in the profiling code.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_class.h:
Create a new system variable, profiling_history_size, and add a
member to THD to hold profiling information about this thread's
execution.
---
Manual merge, undoing first patch.
sql/sql_delete.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_insert.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_lex.cc:
Initialize profiling options to empty.
---
Manual merge, undoing first patch.
sql/sql_lex.h:
Add info to the lexer object so that we can hold data that comes from
parsing statements.
Reuse memory addresses of uints that can't occur in the same state-
ment.
This is dangerous because it involves knowledge of what symbols are
never used together, which is information stored obliquely in another
file.
---
Manual merge, undoing first patch.
sql/sql_parse.cc:
Add hooks to the parser to jump to profiling code.
If profiling is not present, then return an error message upon being
used.
---
Manual merge, undoing first patch.
---
Fix merge problems.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_prepare.cc:
From prepared statement execution, set the query source in the
profiler, as we can't get it from thd .
---
Make it less expensive to limit the size of the queries.
sql/sql_repl.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_select.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_show.cc:
Abstract setting thread-info into a function or macro.
Also, remove "static" qualification on schema_table_store_record()
so that external functions may use it.
---
Manual merge, undoing first patch.
sql/sql_table.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_update.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_view.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_yacc.yy:
Add new lexer symbols and insert new grammatical rules necessary to
retreive profiling information.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/table.h:
Add enum item for query profiling.
BitKeeper/deleted/.del-profiling-master.opt:
New BitKeeper file ``mysql-test/t/profiling-master.opt''
mysql-test/r/profiling.result:
New BitKeeper file ``mysql-test/r/profiling.result''
---
Include more verbose that describes the queries so far.
Include Giuseppe's tests.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
mysql-test/t/profiling.test:
New BitKeeper file ``mysql-test/t/profiling.test''
---
Include more verbose that describes the queries so far.
Include Giuseppe's tests.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
sql/sql_profile.cc:
New BitKeeper file ``sql/sql_profile.cc''
---
If query_source is NULL, as can sometimes happen, then don't try
to copy that memory.
---
Make each new session use its own numbering of query_ids, and not
show the global-pool numbers to the user.
Provide a way for prepared statements to set the query_source.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
Limit the size of captured query text.
No longer log queries that are zero length.
sql/sql_profile.h:
New BitKeeper file ``sql/sql_profile.h''
---
Make each new session use its own numbering of query_ids, and not
show the global-pool numbers to the user.
Provide a way for prepared statements to set the query_source.
---
Make it less expensive to limit the size of the queries.
2007-02-22 16:03:08 +01:00
|
|
|
thd_proc_info(thd, "closing tables");
|
A fix and a test case for Bug#12713 "Error in a stored function called from
a SELECT doesn't cause ROLLBACK of statem".
The idea of the fix is to ensure that we always commit the current
statement at the end of dispatch_command(). In order to not issue
redundant disc syncs, an optimization of the two-phase commit
protocol is implemented to bypass the two phase commit if
the transaction is read-only.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
Update test results.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
Update test results.
mysql-test/suite/rpl_ndb/t/disabled.def:
Disable the tests, for which this changeset reveals a bug:
the injector thread does not always add 'statement commit' to the
rows injected in circular replication set up.
To be investigated separately.
sql/ha_ndbcluster_binlog.cc:
Add close_thread_tables() to run_query: this ensures
that all tables are closed and there is no pending statement transaction.
sql/handler.cc:
Implement optimisation of read-only transactions.
If a transaction consists only of DML statements that do not change
data, we do not perform a two-phase commit for it
(run one phase commit only).
sql/handler.h:
Implement optimisation of read-only transactions.
If a transaction consists only of DML statements that do not change
data, we do not perform a two-phase commit for it
(run one phase commit only).
sql/log.cc:
Mark the binlog transaction read-write whenever it's started.
We never read from binlog, so it's safe and least intrusive to add
this mark up here.
sql/log_event.cc:
Update to the new layout of thd->transaction.
sql/rpl_injector.cc:
Always commit statement transaction before committing the global one.
sql/sp.cc:
Ad comments.
sql/sp_head.cc:
Add comments.
sql/sql_base.cc:
Commit transaction at the end of the statement. Always.
sql/sql_class.cc:
Update thd_ha_data to return the right pointer in the new layout.
Fix select_dumpvar::send_data to properly return operation status.
A test case from commit.inc would lead to an assertion failure in the
diagnostics area (double assignment). Not test otherwise by the test suite.
sql/sql_class.h:
Implement a new layout of storage engine transaction info in which
it is easy to access all members related to the handlerton only
based on ht->slot.
sql/sql_cursor.cc:
Update to the new layout of thd->transaction.
sql/sql_delete.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_do.cc:
Add DO always clears the error, we must rollback the current
statement before this happens. Otherwise the statement will be committed,
and not rolled back in the end.
sql/sql_insert.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_load.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
sql/sql_parse.cc:
Implement optimisation of read-only transactions: bypass 2-phase
commit for them.
Always commit statement transaction before commiting the global one.
Fix an unrelated crash in check_table_access, when called from
information_schema.
sql/sql_partition.cc:
Partitions commit at the end of a DDL operation.
Make sure that send_ok() is done only if the commit has succeeded.
sql/sql_table.cc:
Use ha_autocommit_or_rollback and end_active_trans everywhere.
Add end_trans to mysql_admin_table, so that it leaves no pending
transaction.
sql/sql_udf.cc:
Remvove a redundant call to close_thread_tables()
sql/sql_update.cc:
Remove wrong and now redundant calls to ha_autocommit_or_rollback.
The transaction is committed in one place, at the end of the statement.
Remove calls to mysql_unlock_tables, since some engines count locks
and commit statement transaction in unlock_tables(), which essentially
equates mysql_unlock_tables to ha_autocommit_or_rollback.
Previously it was necessary to unlock tables soon because we wanted
to avoid sending of 'ok' packet to the client under locked tables.
This is no longer necessary, since OK packet is also sent from one place
at the end of transaction.
mysql-test/include/commit.inc:
New BitKeeper file ``mysql-test/include/commit.inc''
mysql-test/r/commit_1innodb.result:
New BitKeeper file ``mysql-test/r/commit_1innodb.result''
mysql-test/t/commit_1innodb.test:
New BitKeeper file ``mysql-test/t/commit_1innodb.test''
2008-02-19 12:43:01 +01:00
|
|
|
/* Here we also commit or rollback the current 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
|
|
|
close_thread_tables(thd);
|
Prevent bugs by making DBUG_* expressions syntactically equivalent
to a single statement.
---
Bug#24795: SHOW PROFILE
Profiling is only partially functional on some architectures. Where
there is no getrusage() system call, presently Null values are
returned where it would be required. Notably, Windows needs some love
applied to make it as useful.
Syntax this adds:
SHOW PROFILES
SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n]
where "n" is an integer
and "types" is zero or many (comma-separated) of
"CPU"
"MEMORY" (not presently supported)
"BLOCK IO"
"CONTEXT SWITCHES"
"PAGE FAULTS"
"IPC"
"SWAPS"
"SOURCE"
"ALL"
It also adds a session variable (boolean) "profiling", set to "no"
by default, and (integer) profiling_history_size, set to 15 by
default.
This patch abstracts setting THDs' "proc_info" behind a macro that
can be used as a hook into the profiling code when profiling
support is compiled in. All future code in this line should use
that mechanism for setting thd->proc_info.
---
Tests are now set to omit the statistics.
---
Adds an Information_schema table, "profiling" for access to
"show profile" data.
---
Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795
into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community
---
Fix merge problems.
---
Fixed one bug in the query_source being NULL.
Updated test results.
---
Include more thorough profiling tests.
Improve support for prepared statements.
Use session-specific query IDs, starting at zero.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
Limit the size of captured query text.
No longer log queries that are zero length.
BitKeeper/deleted/.del-profile.result:
Rename: mysql-test/r/profile.result -> BitKeeper/deleted/.del-profile.result
BitKeeper/deleted/.del-profile.test:
Rename: mysql-test/t/profile.test -> BitKeeper/deleted/.del-profile.test
BitKeeper/deleted/.del-sql_profile.cc:
Rename: sql/sql_profile.cc -> BitKeeper/deleted/.del-sql_profile.cc
BitKeeper/deleted/.del-sql_profile.h:
Rename: sql/sql_profile.h -> BitKeeper/deleted/.del-sql_profile.h
configure.in:
Add a configure-time option to enable/disable query profiling. The
default is enabled.
include/my_dbug.h:
DBUG_* statements should be syntactically equivalent to a single
statement.
myisam/mi_open.c:
DBUG_* statements should be syntactically equivalent to a single
statement.
mysql-test/r/information_schema.result:
Updated (re-recorded) tests that I missed somehow. I verified these
for correctness.
mysql-test/r/information_schema_db.result:
Updated test results I missed.
mysql-test/r/mysqlshow.result:
Fix merge problems.
ndb/src/ndbapi/DictCache.cpp:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/ha_archive.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/ha_berkeley.cc:
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/ha_myisam.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/ha_myisammrg.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/ha_ndbcluster.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/item_cmpfunc.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/item_func.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/lock.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/log_event.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/mysql_priv.h:
Use 64-bit constants for the 64-bit bit field.
Add a new option bit for whether profiling is active or not.
sql/mysqld.cc:
Add semicolon to DBUG statement.
Add a new system variable and set it.
---
Set the minimum, which is zero and not 50.
sql/repl_failsafe.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/set_var.cc:
Make a new system global variable and session variable, to determine
behavior of profiling.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/set_var.h:
The THD::options bit field is ulonglong, not ulong.
sql/slave.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sp_head.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_base.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_cache.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
---
Fix merge problems.
sql/sql_class.cc:
Insert a pointer to the current thread in the profiling code.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_class.h:
Create a new system variable, profiling_history_size, and add a
member to THD to hold profiling information about this thread's
execution.
---
Manual merge, undoing first patch.
sql/sql_delete.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_insert.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_lex.cc:
Initialize profiling options to empty.
---
Manual merge, undoing first patch.
sql/sql_lex.h:
Add info to the lexer object so that we can hold data that comes from
parsing statements.
Reuse memory addresses of uints that can't occur in the same state-
ment.
This is dangerous because it involves knowledge of what symbols are
never used together, which is information stored obliquely in another
file.
---
Manual merge, undoing first patch.
sql/sql_parse.cc:
Add hooks to the parser to jump to profiling code.
If profiling is not present, then return an error message upon being
used.
---
Manual merge, undoing first patch.
---
Fix merge problems.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_prepare.cc:
From prepared statement execution, set the query source in the
profiler, as we can't get it from thd .
---
Make it less expensive to limit the size of the queries.
sql/sql_repl.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_select.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_show.cc:
Abstract setting thread-info into a function or macro.
Also, remove "static" qualification on schema_table_store_record()
so that external functions may use it.
---
Manual merge, undoing first patch.
sql/sql_table.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_update.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_view.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_yacc.yy:
Add new lexer symbols and insert new grammatical rules necessary to
retreive profiling information.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/table.h:
Add enum item for query profiling.
BitKeeper/deleted/.del-profiling-master.opt:
New BitKeeper file ``mysql-test/t/profiling-master.opt''
mysql-test/r/profiling.result:
New BitKeeper file ``mysql-test/r/profiling.result''
---
Include more verbose that describes the queries so far.
Include Giuseppe's tests.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
mysql-test/t/profiling.test:
New BitKeeper file ``mysql-test/t/profiling.test''
---
Include more verbose that describes the queries so far.
Include Giuseppe's tests.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
sql/sql_profile.cc:
New BitKeeper file ``sql/sql_profile.cc''
---
If query_source is NULL, as can sometimes happen, then don't try
to copy that memory.
---
Make each new session use its own numbering of query_ids, and not
show the global-pool numbers to the user.
Provide a way for prepared statements to set the query_source.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
Limit the size of captured query text.
No longer log queries that are zero length.
sql/sql_profile.h:
New BitKeeper file ``sql/sql_profile.h''
---
Make each new session use its own numbering of query_ids, and not
show the global-pool numbers to the user.
Provide a way for prepared statements to set the query_source.
---
Make it less expensive to limit the size of the queries.
2007-02-22 16:03:08 +01:00
|
|
|
thd_proc_info(thd, 0);
|
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
|
|
|
|
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
|
|
|
if (m_lex->query_tables_own_last)
|
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
|
|
|
/*
|
|
|
|
We've entered and left prelocking mode when executing statement
|
|
|
|
stored in m_lex.
|
|
|
|
m_lex->query_tables(->next_global)* list now has a 'tail' - a list
|
|
|
|
of tables that are added for prelocking. (If this is the first
|
|
|
|
execution, the 'tail' was added by open_tables(), otherwise we've
|
|
|
|
attached it above in this function).
|
|
|
|
Now we'll save the 'tail', and detach it.
|
|
|
|
*/
|
|
|
|
lex_query_tables_own_last= m_lex->query_tables_own_last;
|
|
|
|
prelocking_tables= *lex_query_tables_own_last;
|
|
|
|
*lex_query_tables_own_last= NULL;
|
|
|
|
m_lex->mark_as_requiring_prelocking(NULL);
|
2005-07-30 10:19:57 +02: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
|
|
|
thd->rollback_item_tree_changes();
|
2006-06-22 17:29:48 +02:00
|
|
|
/* Update the state of the active arena. */
|
|
|
|
thd->stmt_arena->state= Query_arena::EXECUTED;
|
|
|
|
|
(pushing for Andrei)
Bug #27417 thd->no_trans_update.stmt lost value inside of SF-exec-stack
Once had been set the flag might later got reset inside of a stored routine
execution stack.
The reason was in that there was no check if a new statement started at time
of resetting.
The artifact affects most of binlogable DML queries. Notice, that multi-update
is wrapped up within
bug@27716 fix, multi-delete bug@29136.
Fixed with saving parent's statement flag of whether the statement modified
non-transactional table, and unioning (merging) the value with that was gained
in mysql_execute_command.
Resettling thd->no_trans_update members into thd->transaction.`member`;
Asserting code;
Effectively the following properties are held.
1. At the end of a substatement thd->transaction.stmt.modified_non_trans_table
reflects the fact if such a table got modified by the substatement.
That also respects THD::really_abort_on_warnin() requirements.
2. Eventually thd->transaction.stmt.modified_non_trans_table will be computed as
the union of the values of all invoked sub-statements.
That fixes this bug#27417;
Computing of thd->transaction.all.modified_non_trans_table is refined to base to
the stmt's value for all the case including insert .. select statement which
before the patch had an extra issue bug@28960.
Minor issues are covered with mysql_load, mysql_delete, and binloggin of insert in
to temp_table select.
The supplied test verifies limitely, mostly asserts. The ultimate testing is defered
for bug@13270, bug@23333.
mysql-test/r/mix_innodb_myisam_binlog.result:
results changed
mysql-test/t/mix_innodb_myisam_binlog.test:
regression test incl the related bug#28960.
sql/ha_ndbcluster.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/handler.h:
new member added
sql/log.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/set_var.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sp_head.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
and saving and merging stmt's flag at the end of a substatement.
sql/sql_class.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_class.h:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_delete.cc:
correcting basic delete incl truncate branch and multi-delete queries to set
stmt.modified_non_trans_table;
optimization to set the flag at the end of per-row loop;
multi-delete still has an extra issue similar to bug#27716 of multi-update
- to be address with bug_29136 fix.
sql/sql_insert.cc:
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_load.cc:
eliminating a separate issue where the stmt flag was saved and re-stored after
write_record that actually could change it and the change would be lost but
should remain permanent;
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
sql/sql_parse.cc:
initialization to transaction.stmt.modified_non_trans_table at the common part
of all types of statements processing - mysql_execute_command().
sql/sql_table.cc:
moving the reset up to the mysql_execute_command() caller
sql/sql_update.cc:
correcting update query case (multi-update part of the issues covered by other
bug#27716 fix)
thd->transaction.{all,stmt}.modified_non_trans_table
instead of
thd->no_trans_update.{all,stmt}
2007-07-30 17:27:36 +02:00
|
|
|
/*
|
|
|
|
Merge here with the saved parent's values
|
|
|
|
what is needed from the substatement gained
|
|
|
|
*/
|
|
|
|
thd->transaction.stmt.modified_non_trans_table |= parent_modified_non_trans_table;
|
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
|
|
|
/*
|
|
|
|
Unlike for PS we should not call Item's destructors for newly created
|
|
|
|
items after execution of each instruction in stored routine. This is
|
|
|
|
because SP often create Item (like Item_int, Item_string etc...) when
|
|
|
|
they want to store some value in local variable, pass return value and
|
|
|
|
etc... So their life time should be longer than one instruction.
|
|
|
|
|
|
|
|
cleanup_items() is called in sp_head::execute()
|
|
|
|
*/
|
2007-10-30 18:08:16 +01:00
|
|
|
DBUG_RETURN(res || thd->is_error());
|
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-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
sp_instr class functions
|
|
|
|
*/
|
|
|
|
|
2007-03-07 17:53:46 +01:00
|
|
|
int sp_instr::exec_open_and_lock_tables(THD *thd, TABLE_LIST *tables)
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check whenever we have access to tables for this statement
|
|
|
|
and open and lock them before executing instructions core function.
|
|
|
|
*/
|
2008-01-30 16:27:41 +01:00
|
|
|
if (check_table_access(thd, SELECT_ACL, tables, UINT_MAX, FALSE)
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
|| open_and_lock_tables(thd, tables))
|
|
|
|
result= -1;
|
|
|
|
else
|
|
|
|
result= 0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-07 17:53:46 +01:00
|
|
|
uint sp_instr::get_cont_dest()
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
{
|
2007-03-07 17:53:46 +01:00
|
|
|
return (m_ip+1);
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +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
|
|
|
int sp_instr::exec_core(THD *thd, uint *nextp)
|
2003-06-29 18:15:17 +02: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
|
|
|
DBUG_ASSERT(0);
|
|
|
|
return 0;
|
2003-06-29 18:15:17 +02:00
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
sp_instr_stmt class functions
|
|
|
|
*/
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
int
|
2002-12-11 14:24:29 +01:00
|
|
|
sp_instr_stmt::execute(THD *thd, uint *nextp)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2004-09-17 15:40:38 +02:00
|
|
|
char *query;
|
|
|
|
uint32 query_length;
|
2005-08-25 15:34:34 +02:00
|
|
|
int res;
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_instr_stmt::execute");
|
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
|
|
|
DBUG_PRINT("info", ("command: %d", m_lex_keeper.sql_command()));
|
2004-09-17 15:40:38 +02:00
|
|
|
|
|
|
|
query= thd->query;
|
|
|
|
query_length= thd->query_length;
|
2007-11-13 15:46:17 +01:00
|
|
|
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
|
|
|
|
/* This s-p instr is profilable and will be captured. */
|
|
|
|
thd->profiling.set_query_source(m_query.str, m_query.length);
|
|
|
|
#endif
|
2007-09-28 13:42:37 +02:00
|
|
|
if (!(res= alloc_query(thd, m_query.str, m_query.length)) &&
|
2005-08-27 00:33:06 +02:00
|
|
|
!(res=subst_spvars(thd, this, &m_query)))
|
2004-09-17 15:40:38 +02:00
|
|
|
{
|
2005-08-27 00:33:06 +02:00
|
|
|
/*
|
|
|
|
(the order of query cache and subst_spvars calls is irrelevant because
|
|
|
|
queries with SP vars can't be cached)
|
|
|
|
*/
|
2006-03-01 16:27:57 +01:00
|
|
|
if (unlikely((thd->options & OPTION_LOG_OFF)==0))
|
2007-10-18 20:45:07 +02:00
|
|
|
general_log_write(thd, COM_QUERY, thd->query, thd->query_length);
|
2006-03-01 16:27:57 +01:00
|
|
|
|
2004-09-17 15:40:38 +02:00
|
|
|
if (query_cache_send_result_to_client(thd,
|
|
|
|
thd->query, thd->query_length) <= 0)
|
|
|
|
{
|
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
|
|
|
res= m_lex_keeper.reset_lex_and_exec_core(thd, nextp, FALSE, this);
|
Bug#12713 "Error in a stored function called from a SELECT doesn't
cause ROLLBACK of statement", part 1. Review fixes.
Do not send OK/EOF packets to the client until we reached the end of
the current statement.
This is a consolidation, to keep the functionality that is shared by all
SQL statements in one place in the server.
Currently this functionality includes:
- close_thread_tables()
- log_slow_statement().
After this patch and the subsequent patch for Bug#12713, it shall also include:
- ha_autocommit_or_rollback()
- net_end_statement()
- query_cache_end_of_result().
In future it may also include:
- mysql_reset_thd_for_next_command().
include/mysql_com.h:
Rename now unused members of NET: no_send_ok, no_send_error, report_error.
These were server-specific variables related to the client/server
protocol. They have been made obsolete by this patch.
Previously the same members of NET were used to store the error message
both on the client and on the server.
The error message was stored in net.last_error (client: mysql->net.last_error,
server: thd->net.last_error).
The error code was stored in net.last_errno (client: mysql->net.last_errno,
server: thd->net.last_errno).
The server error code and message are now stored elsewhere
(in the Diagnostics_area), thus NET members are no longer used by the
server.
Rename last_error to client_last_error, last_errno to client_last_errno
to avoid potential bugs introduced by merges.
include/mysql_h.ic:
Update the ABI file to reflect a rename.
Renames do not break the binary compatibility.
libmysql/libmysql.c:
Rename last_error to client_last_error, last_errno to client_last_errno.
This is necessary to ensure no unnoticed bugs introduced by merged
changesets.
Remove net.report_error, net.no_send_ok, net.no_send_error.
libmysql/manager.c:
Rename net.last_errno to net.client_last_errno.
libmysqld/lib_sql.cc:
Rename net.last_errno to net.client_last_errno.
Update the embedded implementation of the client-server protocol to
reflect the refactoring of protocol.cc.
libmysqld/libmysqld.c:
Rename net.last_errno to net.client_last_errno.
mysql-test/r/events.result:
Update to reflect the change in mysql_rm_db(). Now we drop stored
routines and events for a given database name only if there
is a directory for this database name. ha_drop_database() and
query_cache_invalidate() are called likewise.
Previously we would attempt to drop routines/events even if database
directory was not found (it worked, since routines and events are stored
in tables). This fixes Bug 29958 "Weird message on DROP DATABASE if mysql.proc
does not exist".
The change was done because the previous code used to call send_ok()
twice, which led to an assertion failure when asserts against it were
added by this patch.
mysql-test/r/grant.result:
Fix the patch for Bug 16470, now FLUSH PRIVILEGES produces an error
if mysql.procs_priv is missing.
This fixes the assert that send_ok() must not called after send_error()
(the original patch for Bug 16470 was prone to this).
mysql-test/suite/rpl/r/rpl_row_tabledefs_2myisam.result:
Produce a more detailed error message.
mysql-test/suite/rpl/r/rpl_row_tabledefs_3innodb.result:
Produce a more detailed error message.
mysql-test/t/grant.test:
Update the test, now FLUSH PRIVILEGES returns an error if mysql.procs_priv
is missing.
server-tools/instance-manager/mysql_connection.cc:
Rename net.last_errno to net.client_last_errno.
sql/ha_ndbcluster_binlog.cc:
Add asserts.
Use getters to access statement status information.
Add a comment why run_query() is broken. Reset the diagnostics area
in the end of run_query() to fulfill the invariant that the diagnostics_area
is never assigned twice per statement (see the comment in the code
when this can happen). We still do not clear thd->is_fatal_error and
thd->is_slave_error, which may lead to bugs, I consider the whole affair
as something to be dealt with separately.
sql/ha_partition.cc:
fatal_error() doesn't set an error by itself. Perhaps we should
remove this method altogether and instead add a flag to my_error
to set thd->is_fatal_error property.
Meanwhile, this change is a part of inspection made to the entire source
code with the goal to ensure that fatal_error()
is always accompanied by my_error().
sql/item_func.cc:
There is no net.last_error anymore. Remove the obsolete assignment.
sql/log_event.cc:
Use getters to access statement error status information.
sql/log_event_old.cc:
Use getters to access statement error status information.
sql/mysqld.cc:
Previously, if a continue handler for an error was found, my_message_sql()
would not set an error in THD. Since the current statement
must be aborted in any case, find_handler() had a hack to assign
thd->net.report_error to 1.
Remove this hack. Set an error in my_message_sql() even if the continue
handler is found. The error will be cleared anyway when the handler
is executed. This is one action among many in this patch to ensure the
invariant that whenever thd->is_error() is TRUE, we have a message in
thd->main_da.message().
sql/net_serv.cc:
Use a full-blown my_error() in net_serv.cc to report an error,
instead of just setting net->last_errno. This ensures the invariant that
whenever thd->is_error() returns TRUE, we have a message in
thd->main_da.message().
Remove initialization of removed NET members.
sql/opt_range.cc:
Use my_error() instead of just raising thd->net.report_error.
This ensures the invariant that whenever thd->is_error() returns TRUE,
there is a message in thd->main_da.message().
sql/opt_sum.cc:
Move invocation of fatal_error() right next to the place where
we set the error message. That makes it easier to track that whenever
fatal_error() is called, there is a message in THD.
sql/protocol.cc:
Rename send_ok() and send_eof() to net_send_ok() and net_send_eof()
respectively. These functions write directly to the network and are not
for use anywhere outside the client/server protocol code.
Remove the code that was responsible for cases when either there is
no error code, or no error message, or both.
Instead the calling code ensures that they are always present. Asserts
are added to enforce the invariant.
Instead of a direct access to thd->server_status and thd->total_warn_count
use function parameters, since these from now on don't always come directly
from THD.
Introduce net_end_statement(), the single-entry-point replacement API for
send_ok(), send_eof() and net_send_error().
Implement Protocol::end_partial_result_set to use in select_send::abort()
when there is a continue handler.
sql/protocol.h:
Update declarations.
sql/repl_failsafe.cc:
Use getters to access statement status information in THD.
Rename net.last_error to net.client_last_error.
sql/rpl_record.cc:
Set an error message in prepare_record() if there is no default
value for the field -- later we do print this message to the client.
sql/rpl_rli.cc:
Use getters to access statement status information in THD.
sql/slave.cc:
In create_table_from_dump() (a common function that is used in
LOAD MASTER TABLE SQL statement and COM_LOAD_MASTER_DATA), instead of hacks
with no_send_ok, clear the diagnostics area when mysql_rm_table() succeeded.
Update has_temporary_error() to work correctly when no error is set.
This is the case when Incident_log_event is executed: it always returns
an error but does not set an error message.
Use getters to access error status information.
sql/sp_head.cc:
Instead of hacks with no_send_error, work through the diagnostics area
interface to suppress sending of OK/ERROR packets to the client.
Move query_cache_end_of_result before log_slow_statement(), similarly
to how it's done in dispatch_command().
sql/sp_rcontext.cc:
Remove hacks with assignment of thd->net.report_error, they are not
necessary any more (see the changes in mysqld.cc).
sql/sql_acl.cc:
Use getters to access error status information in THD.
sql/sql_base.cc:
Access thd->main_da.sql_errno() only if there is an error. This fixes
a bug when auto-discovery, that was effectively disabled under pre-locking.
sql/sql_binlog.cc:
Remove hacks with no_send_ok/no_send_error, they are not necessary
anymore: the caller is responsible for network communication.
sql/sql_cache.cc:
Disable sending of OK/ERROR/EOF packet in the end of dispatch_command
if the response has been served from the query cache. This raises the
question whether we should store EOF packet in the query cache at all,
or generate it anew for each statement (we should generate it anew), but
this is to be addressed separately.
sql/sql_class.cc:
Implement class Diagnostics_area. Please see comments in sql_class.h
for details.
Fix a subtle coding mistake in select_send::send_data: when on slave,
an error in Item::send() was ignored.
The problem became visible due to asserts that the diagnostics area is
never double assigned.
Remove initialization of removed NET members.
In select_send::abort() do not call select_send::send_eof(). This is
not inheritance-safe. Even if a stored procedure continue handler is
found, the current statement is aborted, not succeeded.
Instead introduce a Protocol API to send the required response,
Protocol::end_partial_result_set().
This simplifies implementation of select_send::send_eof(). No need
to add more asserts that there is no error, there is an assert inside
Diagnostics_area::set_ok_status() already.
Leave no trace of no_send_* in the code.
sql/sql_class.h:
Declare class Diagnostics_area.
Remove the hack with no_send_ok from
Substatement_state.
Provide inline implementations of send_ok/send_eof.
Add commetns.
sql/sql_connect.cc:
Remove hacks with no_send_error.
Since now an error in THD is always set if net->error, it's not necessary
to check both net->error and thd->is_error() in the do_command loop.
Use thd->main_da.message() instead of net->last_errno.
Remove the hack with is_slave_error in sys_init_connect. Since now we do not
reset the diagnostics area in net_send_error (it's reset at the beginning
of the next statement), we can access it safely even after
execute_init_command.
sql/sql_db.cc:
Update the code to satisfy the invariant that the diagnostics area is never
assigned twice.
Incidentally, this fixes Bug 29958 "Weird message on DROP DATABASE if
mysql.proc does not exist".
sql/sql_delete.cc:
Change multi-delete to abort in abort(), as per select_send protocol.
Fixes the merge error with the test for Bug 29136
sql/sql_derived.cc:
Use getters to access error information.
sql/sql_insert.cc:
Use getters to access error information.
sql-common/client.c:
Rename last_error to client_last_error, last_errno to client_last_errno.
sql/sql_parse.cc:
Remove hacks with no_send_error. Deploy net_end_statement().
The story of COM_SHUTDOWN is interesting. Long story short, the server
would become on its death's door, and only no_send_ok/no_send_error assigned
by send_ok()/net_send_error() would hide its babbling from the client.
First of all, COM_QUIT does not require a response. So, the comment saying
"Let's send a response to possible COM_QUIT" is not only groundless
(even mysqladmin shutdown/mysql_shutdown() doesn't send COM_QUIT after
COM_SHUTDOWN), it's plainly incorrect.
Secondly, besides this additional 'OK' packet to respond to a hypothetical
COM_QUIT, there was the following code in dispatch_command():
if (thd->killed)
thd->send_kill_message();
if (thd->is_error()
net_send_error(thd);
This worked out really funny for the thread through which COM_SHUTDOWN
was delivered: we would get COM_SHUTDOWN, say okay, say okay again,
kill everybody, get the kill signal ourselves, and then attempt to say
"Server shutdown in progress" to the client that is very likely long gone.
This all became visible when asserts were added that the Diagnostics_area
is not assigned twice.
Move query_cache_end_of_result() to the end of dispatch_command(), since
net_send_eof() has been moved there. This is safe, query_cache_end_of_result()
is a no-op if there is no started query in the cache.
Consistently use select_send interface to call abort() or send_eof()
depending on the operation result.
Remove thd->fatal_error() from reset_master(), it was a no-op.
in hacks with no_send_error woudl save us
from complete breakage of the client/server protocol.
Consistently use select_send::abort() whenever there is an error,
and select_send::send_eof() in case of success.
The issue became visible due to added asserts.
sql/sql_partition.cc:
Always set an error in THD whenever there is a call to fatal_error().
sql/sql_prepare.cc:
Deploy class Diagnostics_area.
Remove the unnecessary juggling with the protocol in
Select_fetch_protocol_binary::send_eof(). EOF packet format is
protocol-independent.
sql/sql_select.cc:
Call fatal_error() directly in opt_sum_query.
Call my_error() whenever we call thd->fatal_error().
sql/sql_servers.cc:
Use getters to access error information in THD.
sql/sql_show.cc:
Use getters to access error information in THD.
Add comments.
Call my_error() whenever we call fatal_error().
sql/sql_table.cc:
Replace hacks with no_send_ok with the interface of the diagnostics area.
Clear the error if ENOENT error in ha_delete_table().
sql/sql_update.cc:
Introduce multi_update::abort(), which is the proper way to abort a
multi-update. This fixes the merge conflict between this patch and
the patch for Bug 29136.
sql/table.cc:
Use a getter to access error information in THD.
sql/tztime.cc:
Use a getter to access error information in THD.
2007-12-12 16:21:01 +01:00
|
|
|
|
|
|
|
if (thd->main_da.is_eof())
|
|
|
|
net_end_statement(thd);
|
|
|
|
|
|
|
|
query_cache_end_of_result(thd);
|
|
|
|
|
2006-03-01 02:34:22 +01:00
|
|
|
if (!res && unlikely(thd->enable_slow_log))
|
|
|
|
log_slow_statement(thd);
|
2004-09-17 15:40:38 +02: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
|
|
|
else
|
|
|
|
*nextp= m_ip+1;
|
2004-09-17 15:40:38 +02:00
|
|
|
thd->query= query;
|
|
|
|
thd->query_length= query_length;
|
Bug#12713 "Error in a stored function called from a SELECT doesn't
cause ROLLBACK of statement", part 1. Review fixes.
Do not send OK/EOF packets to the client until we reached the end of
the current statement.
This is a consolidation, to keep the functionality that is shared by all
SQL statements in one place in the server.
Currently this functionality includes:
- close_thread_tables()
- log_slow_statement().
After this patch and the subsequent patch for Bug#12713, it shall also include:
- ha_autocommit_or_rollback()
- net_end_statement()
- query_cache_end_of_result().
In future it may also include:
- mysql_reset_thd_for_next_command().
include/mysql_com.h:
Rename now unused members of NET: no_send_ok, no_send_error, report_error.
These were server-specific variables related to the client/server
protocol. They have been made obsolete by this patch.
Previously the same members of NET were used to store the error message
both on the client and on the server.
The error message was stored in net.last_error (client: mysql->net.last_error,
server: thd->net.last_error).
The error code was stored in net.last_errno (client: mysql->net.last_errno,
server: thd->net.last_errno).
The server error code and message are now stored elsewhere
(in the Diagnostics_area), thus NET members are no longer used by the
server.
Rename last_error to client_last_error, last_errno to client_last_errno
to avoid potential bugs introduced by merges.
include/mysql_h.ic:
Update the ABI file to reflect a rename.
Renames do not break the binary compatibility.
libmysql/libmysql.c:
Rename last_error to client_last_error, last_errno to client_last_errno.
This is necessary to ensure no unnoticed bugs introduced by merged
changesets.
Remove net.report_error, net.no_send_ok, net.no_send_error.
libmysql/manager.c:
Rename net.last_errno to net.client_last_errno.
libmysqld/lib_sql.cc:
Rename net.last_errno to net.client_last_errno.
Update the embedded implementation of the client-server protocol to
reflect the refactoring of protocol.cc.
libmysqld/libmysqld.c:
Rename net.last_errno to net.client_last_errno.
mysql-test/r/events.result:
Update to reflect the change in mysql_rm_db(). Now we drop stored
routines and events for a given database name only if there
is a directory for this database name. ha_drop_database() and
query_cache_invalidate() are called likewise.
Previously we would attempt to drop routines/events even if database
directory was not found (it worked, since routines and events are stored
in tables). This fixes Bug 29958 "Weird message on DROP DATABASE if mysql.proc
does not exist".
The change was done because the previous code used to call send_ok()
twice, which led to an assertion failure when asserts against it were
added by this patch.
mysql-test/r/grant.result:
Fix the patch for Bug 16470, now FLUSH PRIVILEGES produces an error
if mysql.procs_priv is missing.
This fixes the assert that send_ok() must not called after send_error()
(the original patch for Bug 16470 was prone to this).
mysql-test/suite/rpl/r/rpl_row_tabledefs_2myisam.result:
Produce a more detailed error message.
mysql-test/suite/rpl/r/rpl_row_tabledefs_3innodb.result:
Produce a more detailed error message.
mysql-test/t/grant.test:
Update the test, now FLUSH PRIVILEGES returns an error if mysql.procs_priv
is missing.
server-tools/instance-manager/mysql_connection.cc:
Rename net.last_errno to net.client_last_errno.
sql/ha_ndbcluster_binlog.cc:
Add asserts.
Use getters to access statement status information.
Add a comment why run_query() is broken. Reset the diagnostics area
in the end of run_query() to fulfill the invariant that the diagnostics_area
is never assigned twice per statement (see the comment in the code
when this can happen). We still do not clear thd->is_fatal_error and
thd->is_slave_error, which may lead to bugs, I consider the whole affair
as something to be dealt with separately.
sql/ha_partition.cc:
fatal_error() doesn't set an error by itself. Perhaps we should
remove this method altogether and instead add a flag to my_error
to set thd->is_fatal_error property.
Meanwhile, this change is a part of inspection made to the entire source
code with the goal to ensure that fatal_error()
is always accompanied by my_error().
sql/item_func.cc:
There is no net.last_error anymore. Remove the obsolete assignment.
sql/log_event.cc:
Use getters to access statement error status information.
sql/log_event_old.cc:
Use getters to access statement error status information.
sql/mysqld.cc:
Previously, if a continue handler for an error was found, my_message_sql()
would not set an error in THD. Since the current statement
must be aborted in any case, find_handler() had a hack to assign
thd->net.report_error to 1.
Remove this hack. Set an error in my_message_sql() even if the continue
handler is found. The error will be cleared anyway when the handler
is executed. This is one action among many in this patch to ensure the
invariant that whenever thd->is_error() is TRUE, we have a message in
thd->main_da.message().
sql/net_serv.cc:
Use a full-blown my_error() in net_serv.cc to report an error,
instead of just setting net->last_errno. This ensures the invariant that
whenever thd->is_error() returns TRUE, we have a message in
thd->main_da.message().
Remove initialization of removed NET members.
sql/opt_range.cc:
Use my_error() instead of just raising thd->net.report_error.
This ensures the invariant that whenever thd->is_error() returns TRUE,
there is a message in thd->main_da.message().
sql/opt_sum.cc:
Move invocation of fatal_error() right next to the place where
we set the error message. That makes it easier to track that whenever
fatal_error() is called, there is a message in THD.
sql/protocol.cc:
Rename send_ok() and send_eof() to net_send_ok() and net_send_eof()
respectively. These functions write directly to the network and are not
for use anywhere outside the client/server protocol code.
Remove the code that was responsible for cases when either there is
no error code, or no error message, or both.
Instead the calling code ensures that they are always present. Asserts
are added to enforce the invariant.
Instead of a direct access to thd->server_status and thd->total_warn_count
use function parameters, since these from now on don't always come directly
from THD.
Introduce net_end_statement(), the single-entry-point replacement API for
send_ok(), send_eof() and net_send_error().
Implement Protocol::end_partial_result_set to use in select_send::abort()
when there is a continue handler.
sql/protocol.h:
Update declarations.
sql/repl_failsafe.cc:
Use getters to access statement status information in THD.
Rename net.last_error to net.client_last_error.
sql/rpl_record.cc:
Set an error message in prepare_record() if there is no default
value for the field -- later we do print this message to the client.
sql/rpl_rli.cc:
Use getters to access statement status information in THD.
sql/slave.cc:
In create_table_from_dump() (a common function that is used in
LOAD MASTER TABLE SQL statement and COM_LOAD_MASTER_DATA), instead of hacks
with no_send_ok, clear the diagnostics area when mysql_rm_table() succeeded.
Update has_temporary_error() to work correctly when no error is set.
This is the case when Incident_log_event is executed: it always returns
an error but does not set an error message.
Use getters to access error status information.
sql/sp_head.cc:
Instead of hacks with no_send_error, work through the diagnostics area
interface to suppress sending of OK/ERROR packets to the client.
Move query_cache_end_of_result before log_slow_statement(), similarly
to how it's done in dispatch_command().
sql/sp_rcontext.cc:
Remove hacks with assignment of thd->net.report_error, they are not
necessary any more (see the changes in mysqld.cc).
sql/sql_acl.cc:
Use getters to access error status information in THD.
sql/sql_base.cc:
Access thd->main_da.sql_errno() only if there is an error. This fixes
a bug when auto-discovery, that was effectively disabled under pre-locking.
sql/sql_binlog.cc:
Remove hacks with no_send_ok/no_send_error, they are not necessary
anymore: the caller is responsible for network communication.
sql/sql_cache.cc:
Disable sending of OK/ERROR/EOF packet in the end of dispatch_command
if the response has been served from the query cache. This raises the
question whether we should store EOF packet in the query cache at all,
or generate it anew for each statement (we should generate it anew), but
this is to be addressed separately.
sql/sql_class.cc:
Implement class Diagnostics_area. Please see comments in sql_class.h
for details.
Fix a subtle coding mistake in select_send::send_data: when on slave,
an error in Item::send() was ignored.
The problem became visible due to asserts that the diagnostics area is
never double assigned.
Remove initialization of removed NET members.
In select_send::abort() do not call select_send::send_eof(). This is
not inheritance-safe. Even if a stored procedure continue handler is
found, the current statement is aborted, not succeeded.
Instead introduce a Protocol API to send the required response,
Protocol::end_partial_result_set().
This simplifies implementation of select_send::send_eof(). No need
to add more asserts that there is no error, there is an assert inside
Diagnostics_area::set_ok_status() already.
Leave no trace of no_send_* in the code.
sql/sql_class.h:
Declare class Diagnostics_area.
Remove the hack with no_send_ok from
Substatement_state.
Provide inline implementations of send_ok/send_eof.
Add commetns.
sql/sql_connect.cc:
Remove hacks with no_send_error.
Since now an error in THD is always set if net->error, it's not necessary
to check both net->error and thd->is_error() in the do_command loop.
Use thd->main_da.message() instead of net->last_errno.
Remove the hack with is_slave_error in sys_init_connect. Since now we do not
reset the diagnostics area in net_send_error (it's reset at the beginning
of the next statement), we can access it safely even after
execute_init_command.
sql/sql_db.cc:
Update the code to satisfy the invariant that the diagnostics area is never
assigned twice.
Incidentally, this fixes Bug 29958 "Weird message on DROP DATABASE if
mysql.proc does not exist".
sql/sql_delete.cc:
Change multi-delete to abort in abort(), as per select_send protocol.
Fixes the merge error with the test for Bug 29136
sql/sql_derived.cc:
Use getters to access error information.
sql/sql_insert.cc:
Use getters to access error information.
sql-common/client.c:
Rename last_error to client_last_error, last_errno to client_last_errno.
sql/sql_parse.cc:
Remove hacks with no_send_error. Deploy net_end_statement().
The story of COM_SHUTDOWN is interesting. Long story short, the server
would become on its death's door, and only no_send_ok/no_send_error assigned
by send_ok()/net_send_error() would hide its babbling from the client.
First of all, COM_QUIT does not require a response. So, the comment saying
"Let's send a response to possible COM_QUIT" is not only groundless
(even mysqladmin shutdown/mysql_shutdown() doesn't send COM_QUIT after
COM_SHUTDOWN), it's plainly incorrect.
Secondly, besides this additional 'OK' packet to respond to a hypothetical
COM_QUIT, there was the following code in dispatch_command():
if (thd->killed)
thd->send_kill_message();
if (thd->is_error()
net_send_error(thd);
This worked out really funny for the thread through which COM_SHUTDOWN
was delivered: we would get COM_SHUTDOWN, say okay, say okay again,
kill everybody, get the kill signal ourselves, and then attempt to say
"Server shutdown in progress" to the client that is very likely long gone.
This all became visible when asserts were added that the Diagnostics_area
is not assigned twice.
Move query_cache_end_of_result() to the end of dispatch_command(), since
net_send_eof() has been moved there. This is safe, query_cache_end_of_result()
is a no-op if there is no started query in the cache.
Consistently use select_send interface to call abort() or send_eof()
depending on the operation result.
Remove thd->fatal_error() from reset_master(), it was a no-op.
in hacks with no_send_error woudl save us
from complete breakage of the client/server protocol.
Consistently use select_send::abort() whenever there is an error,
and select_send::send_eof() in case of success.
The issue became visible due to added asserts.
sql/sql_partition.cc:
Always set an error in THD whenever there is a call to fatal_error().
sql/sql_prepare.cc:
Deploy class Diagnostics_area.
Remove the unnecessary juggling with the protocol in
Select_fetch_protocol_binary::send_eof(). EOF packet format is
protocol-independent.
sql/sql_select.cc:
Call fatal_error() directly in opt_sum_query.
Call my_error() whenever we call thd->fatal_error().
sql/sql_servers.cc:
Use getters to access error information in THD.
sql/sql_show.cc:
Use getters to access error information in THD.
Add comments.
Call my_error() whenever we call fatal_error().
sql/sql_table.cc:
Replace hacks with no_send_ok with the interface of the diagnostics area.
Clear the error if ENOENT error in ha_delete_table().
sql/sql_update.cc:
Introduce multi_update::abort(), which is the proper way to abort a
multi-update. This fixes the merge conflict between this patch and
the patch for Bug 29136.
sql/table.cc:
Use a getter to access error information in THD.
sql/tztime.cc:
Use a getter to access error information in THD.
2007-12-12 16:21:01 +01:00
|
|
|
|
|
|
|
if (!thd->is_error())
|
|
|
|
thd->main_da.reset_diagnostics_area();
|
2004-09-17 15:40:38 +02:00
|
|
|
}
|
2003-10-10 16:57:21 +02:00
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
|
2005-11-22 13:06:52 +01:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_stmt::print(String *str)
|
|
|
|
{
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
uint i, len;
|
|
|
|
|
2005-11-22 13:06:52 +01:00
|
|
|
/* stmt CMD "..." */
|
|
|
|
if (str->reserve(SP_STMT_PRINT_MAXLEN+SP_INSTR_UINT_MAXLEN+8))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("stmt "));
|
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
|
|
|
str->qs_append((uint)m_lex_keeper.sql_command());
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN(" \""));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
len= m_query.length;
|
|
|
|
/*
|
|
|
|
Print the query string (but not too much of it), just to indicate which
|
|
|
|
statement it is.
|
|
|
|
*/
|
2005-11-22 13:06:52 +01:00
|
|
|
if (len > SP_STMT_PRINT_MAXLEN)
|
|
|
|
len= SP_STMT_PRINT_MAXLEN-3;
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
/* Copy the query string and replace '\n' with ' ' in the process */
|
|
|
|
for (i= 0 ; i < len ; i++)
|
2005-11-18 16:30:27 +01:00
|
|
|
{
|
2006-01-05 23:47:49 +01:00
|
|
|
char c= m_query.str[i];
|
|
|
|
if (c == '\n')
|
|
|
|
c= ' ';
|
|
|
|
str->qs_append(c);
|
2005-11-18 16:30:27 +01:00
|
|
|
}
|
2005-11-22 13:06:52 +01:00
|
|
|
if (m_query.length > SP_STMT_PRINT_MAXLEN)
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("...")); /* Indicate truncated string */
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append('"');
|
2004-03-29 11:16:45 +02:00
|
|
|
}
|
2006-01-05 23:47:49 +01:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
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
|
|
|
sp_instr_stmt::exec_core(THD *thd, uint *nextp)
|
2003-10-10 16:57:21 +02: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
|
|
|
int res= mysql_execute_command(thd);
|
|
|
|
*nextp= m_ip+1;
|
2003-10-10 16:57:21 +02:00
|
|
|
return res;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_set class functions
|
|
|
|
*/
|
|
|
|
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
int
|
2002-12-11 14:24:29 +01:00
|
|
|
sp_instr_set::execute(THD *thd, uint *nextp)
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_instr_set::execute");
|
|
|
|
DBUG_PRINT("info", ("offset: %u", m_offset));
|
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
|
|
|
|
|
|
|
DBUG_RETURN(m_lex_keeper.reset_lex_and_exec_core(thd, nextp, TRUE, this));
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02: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
|
|
|
int
|
|
|
|
sp_instr_set::exec_core(THD *thd, uint *nextp)
|
|
|
|
{
|
2006-05-15 12:01:55 +02:00
|
|
|
int res= thd->spcont->set_variable(thd, m_offset, &m_value);
|
2004-07-21 14:53:09 +02:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (res && thd->spcont->found_handler_here())
|
2005-11-08 14:47:33 +01:00
|
|
|
{
|
|
|
|
/*
|
2005-12-07 15:01:17 +01:00
|
|
|
Failed to evaluate the value, and a handler has been found. Reset the
|
|
|
|
variable to NULL.
|
2005-11-08 14:47:33 +01:00
|
|
|
*/
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
if (thd->spcont->set_variable(thd, m_offset, 0))
|
|
|
|
{
|
|
|
|
/* If this also failed, let's abort. */
|
2005-11-08 14:47:33 +01:00
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
sp_rcontext *spcont= thd->spcont;
|
|
|
|
|
2007-06-18 23:54:35 +02:00
|
|
|
thd->spcont= NULL; /* Avoid handlers */
|
2005-11-08 14:47:33 +01:00
|
|
|
my_error(ER_OUT_OF_RESOURCES, MYF(0));
|
|
|
|
spcont->clear_handler();
|
|
|
|
thd->spcont= spcont;
|
|
|
|
}
|
|
|
|
}
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
*nextp = m_ip+1;
|
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
|
|
|
return res;
|
2002-12-11 14:24:29 +01:00
|
|
|
}
|
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_set::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* set name@offset ... */
|
|
|
|
int rsrv = SP_INSTR_UINT_MAXLEN+6;
|
2006-04-07 16:53:15 +02:00
|
|
|
sp_variable_t *var = m_ctx->find_variable(m_offset);
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
|
|
|
|
/* 'var' should always be non-null, but just in case... */
|
|
|
|
if (var)
|
|
|
|
rsrv+= var->name.length;
|
2005-11-18 16:30:27 +01:00
|
|
|
if (str->reserve(rsrv))
|
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("set "));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
if (var)
|
|
|
|
{
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(var->name.str, var->name.length);
|
|
|
|
str->qs_append('@');
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
}
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_offset);
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(' ');
|
2008-02-22 11:30:33 +01:00
|
|
|
m_value->print(str, QT_ORDINARY);
|
2004-03-29 11:16:45 +02:00
|
|
|
}
|
|
|
|
|
2004-09-07 14:29:46 +02:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
sp_instr_set_trigger_field class functions
|
|
|
|
*/
|
|
|
|
|
2004-09-07 14:29:46 +02:00
|
|
|
int
|
|
|
|
sp_instr_set_trigger_field::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_set_trigger_field::execute");
|
2005-07-09 19:51:59 +02:00
|
|
|
DBUG_RETURN(m_lex_keeper.reset_lex_and_exec_core(thd, nextp, TRUE, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_instr_set_trigger_field::exec_core(THD *thd, uint *nextp)
|
|
|
|
{
|
2006-05-15 19:57:10 +02:00
|
|
|
const int res= (trigger_field->set_value(thd, &value) ? -1 : 0);
|
2005-07-09 19:51:59 +02:00
|
|
|
*nextp = m_ip+1;
|
|
|
|
return res;
|
2004-09-07 14:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_instr_set_trigger_field::print(String *str)
|
|
|
|
{
|
2005-11-22 13:24:53 +01:00
|
|
|
str->append(STRING_WITH_LEN("set_trigger_field "));
|
2008-02-22 11:30:33 +01:00
|
|
|
trigger_field->print(str, QT_ORDINARY);
|
2005-11-20 19:47:07 +01:00
|
|
|
str->append(STRING_WITH_LEN(":="));
|
2008-02-22 11:30:33 +01:00
|
|
|
value->print(str, QT_ORDINARY);
|
2004-09-07 14:29:46 +02:00
|
|
|
}
|
|
|
|
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
/*
|
|
|
|
sp_instr_opt_meta
|
|
|
|
*/
|
|
|
|
|
2007-03-07 17:53:46 +01:00
|
|
|
uint sp_instr_opt_meta::get_cont_dest()
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
{
|
2007-03-07 17:53:46 +01:00
|
|
|
return m_cont_dest;
|
Bug#8407 (Stored functions/triggers ignore exception handler)
Bug 18914 (Calling certain SPs from triggers fail)
Bug 20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
Bug 21825 (Incorrect message error deleting records in a table with a
trigger for inserting)
Bug 22580 (DROP TABLE in nested stored procedure causes strange dependency
error)
Bug 25345 (Cursors from Functions)
This fix resolves a long standing issue originally reported with bug 8407,
which affect the behavior of Stored Procedures, Stored Functions and Trigger
in many different ways, causing symptoms reported by all the bugs listed.
In all cases, the root cause of the problem traces back to 8407 and how the
server locks tables involved with sub statements.
Prior to this fix, the implementation of stored routines would:
- compute the transitive closure of all the tables referenced by a top level
statement
- open and lock all the tables involved
- execute the top level statement
"transitive closure of tables" means collecting:
- all the tables,
- all the stored functions,
- all the views,
- all the table triggers
- all the stored procedures
involved, and recursively inspect these objects definition to find more
references to more objects, until the list of every object referenced does
not grow any more.
This mechanism is known as "pre-locking" tables before execution.
The motivation for locking all the tables (possibly) used at once is to
prevent dead locks.
One problem with this approach is that, if the execution path the code
really takes during runtime does not use a given table, and if the table is
missing, the server would not execute the statement.
This in particular has a major impact on triggers, since a missing table
referenced by an update/delete trigger would prevent an insert trigger to run.
Another problem is that stored routines might define SQL exception handlers
to deal with missing tables, but the server implementation would never give
user code a chance to execute this logic, since the routine is never
executed when a missing table cause the pre-locking code to fail.
With this fix, the internal implementation of the pre-locking code has been
relaxed of some constraints, so that failure to open a table does not
necessarily prevent execution of a stored routine.
In particular, the pre-locking mechanism is now behaving as follows:
1) the first step, to compute the transitive closure of all the tables
possibly referenced by a statement, is unchanged.
2) the next step, which is to open all the tables involved, only attempts
to open the tables added by the pre-locking code, but silently fails without
reporting any error or invoking any exception handler is the table is not
present. This is achieved by trapping internal errors with
Prelock_error_handler
3) the locking step only locks tables that were successfully opened.
4) when executing sub statements, the list of tables used by each statements
is evaluated as before. The tables needed by the sub statement are expected
to be already opened and locked. Statement referencing tables that were not
opened in step 2) will fail to find the table in the open list, and only at
this point will execution of the user code fail.
5) when a runtime exception is raised at 4), the instruction continuation
destination (the next instruction to execute in case of SQL continue
handlers) is evaluated.
This is achieved with sp_instr::exec_open_and_lock_tables()
6) if a user exception handler is present in the stored routine, that
handler is invoked as usual, so that ER_NO_SUCH_TABLE exceptions can be
trapped by stored routines. If no handler exists, then the runtime execution
will fail as expected.
With all these changes, a side effect is that view security is impacted, in
two different ways.
First, a view defined as "select stored_function()", where the stored
function references a table that may not exist, is considered valid.
The rationale is that, because the stored function might trap exceptions
during execution and still return a valid result, there is no way to decide
when the view is created if a missing table really cause the view to be invalid.
Secondly, testing for existence of tables is now done later during
execution. View security, which consist of trapping errors and return a
generic ER_VIEW_INVALID (to prevent disclosing information) was only
implemented at very specific phases covering *opening* tables, but not
covering the runtime execution. Because of this existing limitation,
errors that were previously trapped and converted into ER_VIEW_INVALID are
not trapped, causing table names to be reported to the user.
This change is exposing an existing problem, which is independent and will
be resolved separately.
mysql-test/r/information_schema_db.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp-error.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/sp.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/trigger.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/r/view.result:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp-error.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/sp.test:
Revised the pre-locking code implementation, aligned the tests.
mysql-test/t/trigger.test:
Revised the pre-locking code implementation, aligned the tests.
sql/lock.cc:
table->placeholder now checks for schema_table
sql/mysqld.cc:
my_message_sql(): invoke internal exception handlers
sql/sp_head.cc:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sp_head.h:
exec_open_and_lock_tables(): open and lock tables, or return the
continuation destination of this instruction
sql/sql_base.cc:
Prelock_error_handler: delay open table errors until execution
sql/sql_class.cc:
THD: add internal error handler, as an exception mechanism.
sql/sql_class.h:
THD: add internal error handler, as an exception mechanism.
sql/sql_update.cc:
table->placeholder now checks for schema_table
sql/table.cc:
st_table_list::hide_view_error(): masked more errors for view security
sql/table.h:
table->placeholder now checks for schema_table, and unopened tables
2007-03-06 03:42:07 +01:00
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_jump class functions
|
|
|
|
*/
|
|
|
|
|
2003-03-05 19:45:17 +01:00
|
|
|
int
|
|
|
|
sp_instr_jump::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_jump::execute");
|
|
|
|
DBUG_PRINT("info", ("destination: %u", m_dest));
|
|
|
|
|
|
|
|
*nextp= m_dest;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_jump::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* jump dest */
|
|
|
|
if (str->reserve(SP_INSTR_UINT_MAXLEN+5))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("jump "));
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_dest);
|
|
|
|
}
|
|
|
|
|
2004-08-02 18:05:31 +02:00
|
|
|
uint
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp_instr_jump::opt_mark(sp_head *sp, List<sp_instr> *leads)
|
2004-08-02 18:05:31 +02:00
|
|
|
{
|
2004-08-26 12:54:30 +02:00
|
|
|
m_dest= opt_shortcut_jump(sp, this);
|
2004-08-17 20:20:58 +02:00
|
|
|
if (m_dest != m_ip+1) /* Jumping to following instruction? */
|
|
|
|
marked= 1;
|
2004-08-02 18:05:31 +02:00
|
|
|
m_optdest= sp->get_instr(m_dest);
|
|
|
|
return m_dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint
|
2004-08-26 12:54:30 +02:00
|
|
|
sp_instr_jump::opt_shortcut_jump(sp_head *sp, sp_instr *start)
|
2004-08-02 18:05:31 +02:00
|
|
|
{
|
|
|
|
uint dest= m_dest;
|
|
|
|
sp_instr *i;
|
|
|
|
|
|
|
|
while ((i= sp->get_instr(dest)))
|
|
|
|
{
|
2004-08-26 12:54:30 +02:00
|
|
|
uint ndest;
|
2004-08-02 18:05:31 +02:00
|
|
|
|
2005-04-20 15:37:07 +02:00
|
|
|
if (start == i || this == i)
|
2004-08-26 12:54:30 +02:00
|
|
|
break;
|
|
|
|
ndest= i->opt_shortcut_jump(sp, start);
|
2004-08-02 18:05:31 +02:00
|
|
|
if (ndest == dest)
|
|
|
|
break;
|
|
|
|
dest= ndest;
|
|
|
|
}
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_instr_jump::opt_move(uint dst, List<sp_instr> *bp)
|
|
|
|
{
|
|
|
|
if (m_dest > m_ip)
|
|
|
|
bp->push_back(this); // Forward
|
|
|
|
else if (m_optdest)
|
|
|
|
m_dest= m_optdest->m_ip; // Backward
|
|
|
|
m_ip= dst;
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_jump_if_not class functions
|
|
|
|
*/
|
|
|
|
|
2002-12-11 14:24:29 +01:00
|
|
|
int
|
|
|
|
sp_instr_jump_if_not::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
2003-02-12 16:17:03 +01:00
|
|
|
DBUG_ENTER("sp_instr_jump_if_not::execute");
|
|
|
|
DBUG_PRINT("info", ("destination: %u", m_dest));
|
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
|
|
|
DBUG_RETURN(m_lex_keeper.reset_lex_and_exec_core(thd, nextp, TRUE, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_instr_jump_if_not::exec_core(THD *thd, uint *nextp)
|
|
|
|
{
|
2004-08-24 16:07:39 +02:00
|
|
|
Item *it;
|
|
|
|
int res;
|
2002-12-11 14:24:29 +01:00
|
|
|
|
2005-05-09 00:59:10 +02:00
|
|
|
it= sp_prepare_func_item(thd, &m_expr);
|
2004-08-24 16:07:39 +02:00
|
|
|
if (! it)
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
{
|
2004-08-24 16:07:39 +02:00
|
|
|
res= -1;
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
}
|
2002-12-11 14:24:29 +01:00
|
|
|
else
|
2004-08-24 16:07:39 +02:00
|
|
|
{
|
|
|
|
res= 0;
|
2005-05-09 00:59:10 +02:00
|
|
|
if (! it->val_bool())
|
2004-08-24 16:07:39 +02:00
|
|
|
*nextp = m_dest;
|
|
|
|
else
|
|
|
|
*nextp = m_ip+1;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
return res;
|
Simplistic, experimental framework for Stored Procedures (SPs).
Implements creation and dropping of PROCEDUREs, IN, OUT, and INOUT parameters,
single-statement procedures, rudimentary multi-statement (begin-end) prodedures
(when the client can handle it), and local variables.
Missing most of the embedded SQL language, all attributes, FUNCTIONs, error handling,
reparses procedures at each call (no caching), etc, etc.
Certainly buggy too, but procedures can actually be created and called....
sql/Makefile.am:
Added SP files.
sql/item.cc:
Added this*_item() methods for Item_splocal. (SP local variable)
sql/item.h:
Added this*_item() methods for SPs in Item, and the new Item_splocal
class (SP local variable).
sql/lex.h:
Added new symbols for SPs. (Note: SPSET is temporary and will go away later.)
sql/sql_class.cc:
Initialize SP runtime context in THD.
sql/sql_class.h:
Add SP runtime context to THD.
sql/sql_lex.cc:
Init. buf pointer to beginning of command (needed by SPs).
Also initialize SP head and parse time context.
sql/sql_lex.h:
New SQLCOM_ tags for SPs, and added pointer to beginning of command pointer and
SP head and parse-time context to LEX.
sql/sql_parse.cc:
Added SQLCOM_CREATE_PROCEDURE, _CALL, _ALTER_PROCEDURE and _DROP_PROCEDURE cases.
(Still rudimentary and lacking proper error handling...)
sql/sql_yacc.yy:
Lots and lots of additions for SPs...
(Still even more missing, and no error messages...)
2002-12-08 19:59:22 +01:00
|
|
|
}
|
2003-02-26 19:22:29 +01:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_jump_if_not::print(String *str)
|
|
|
|
{
|
2006-01-26 17:26:25 +01:00
|
|
|
/* jump_if_not dest(cont) ... */
|
2006-01-16 15:37:25 +01:00
|
|
|
if (str->reserve(2*SP_INSTR_UINT_MAXLEN+14+32)) // Add some for the expr. too
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("jump_if_not "));
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_dest);
|
2006-01-26 17:26:25 +01:00
|
|
|
str->qs_append('(');
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
str->qs_append(m_cont_dest);
|
2006-01-26 17:26:25 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN(") "));
|
2008-02-22 11:30:33 +01:00
|
|
|
m_expr->print(str, QT_ORDINARY);
|
2004-03-29 11:16:45 +02:00
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-08-02 18:05:31 +02:00
|
|
|
uint
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp_instr_jump_if_not::opt_mark(sp_head *sp, List<sp_instr> *leads)
|
2004-08-02 18:05:31 +02:00
|
|
|
{
|
|
|
|
sp_instr *i;
|
|
|
|
|
|
|
|
marked= 1;
|
|
|
|
if ((i= sp->get_instr(m_dest)))
|
|
|
|
{
|
2004-08-26 12:54:30 +02:00
|
|
|
m_dest= i->opt_shortcut_jump(sp, this);
|
2004-08-02 18:05:31 +02:00
|
|
|
m_optdest= sp->get_instr(m_dest);
|
|
|
|
}
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp->add_mark_lead(m_dest, leads);
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
if ((i= sp->get_instr(m_cont_dest)))
|
|
|
|
{
|
|
|
|
m_cont_dest= i->opt_shortcut_jump(sp, this);
|
|
|
|
m_cont_optdest= sp->get_instr(m_cont_dest);
|
|
|
|
}
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp->add_mark_lead(m_cont_dest, leads);
|
2004-08-02 18:05:31 +02:00
|
|
|
return m_ip+1;
|
|
|
|
}
|
|
|
|
|
Fixed BUG#14498: Stored procedures: hang if undefined variable and exception
The problem was to continue at the right place in the code after the
test expression in a flow control statement fails with an exception
(internally, the test in sp_instr_jump_if_not), and the exception is
caught by a continue handler. Execution must then be resumed after the
the entire flow control statement (END IF, END WHILE, etc).
mysql-test/r/sp.result:
New test case for BUG#14498.
mysql-test/t/sp.test:
New test case for BUG#14498.
(Note that one call is disabled at the moment. Depends on BUG#14643.)
sql/sp_head.cc:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
...and added some comments to the optimizer.
sql/sp_head.h:
Added a continuation destination for sp_instr_jump_if_not, for the case when
an error in the test expression causes a continue handler to catch.
This includes new members in sp_instr_jump_if_not, adjustment of the optmizer
(mark and move methods), and separate backpatching code (since we can't use
the normal one for this).
Also removed the class sp_instr_jump, since it's never used.
sql/sql_yacc.yy:
Added backpatching of the continue destination for all conditional statements
(using sp_instr_jump_if_not).
2005-11-04 15:37:39 +01:00
|
|
|
void
|
|
|
|
sp_instr_jump_if_not::opt_move(uint dst, List<sp_instr> *bp)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
cont. destinations may point backwards after shortcutting jumps
|
|
|
|
during the mark phase. If it's still pointing forwards, only
|
|
|
|
push this for backpatching if sp_instr_jump::opt_move() will not
|
|
|
|
do it (i.e. if the m_dest points backwards).
|
|
|
|
*/
|
|
|
|
if (m_cont_dest > m_ip)
|
|
|
|
{ // Forward
|
|
|
|
if (m_dest < m_ip)
|
|
|
|
bp->push_back(this);
|
|
|
|
}
|
|
|
|
else if (m_cont_optdest)
|
|
|
|
m_cont_dest= m_cont_optdest->m_ip; // Backward
|
|
|
|
/* This will take care of m_dest and m_ip */
|
|
|
|
sp_instr_jump::opt_move(dst, bp);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_freturn class functions
|
|
|
|
*/
|
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
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
int
|
2003-09-16 14:26:08 +02:00
|
|
|
sp_instr_freturn::execute(THD *thd, uint *nextp)
|
2003-02-26 19:22:29 +01:00
|
|
|
{
|
2003-09-16 14:26:08 +02:00
|
|
|
DBUG_ENTER("sp_instr_freturn::execute");
|
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
|
|
|
DBUG_RETURN(m_lex_keeper.reset_lex_and_exec_core(thd, nextp, TRUE, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_instr_freturn::exec_core(THD *thd, uint *nextp)
|
|
|
|
{
|
2005-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
Change <next instruction pointer>, so that this will be the last
|
|
|
|
instruction in the stored function.
|
|
|
|
*/
|
2004-07-21 14:53:09 +02:00
|
|
|
|
2003-02-26 19:22:29 +01:00
|
|
|
*nextp= UINT_MAX;
|
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-12-07 15:01:17 +01:00
|
|
|
/*
|
|
|
|
Evaluate the value of return expression and store it in current runtime
|
|
|
|
context.
|
|
|
|
|
|
|
|
NOTE: It's necessary to evaluate result item right here, because we must
|
|
|
|
do it in scope of execution the current context/block.
|
|
|
|
*/
|
|
|
|
|
2006-05-15 12:01:55 +02:00
|
|
|
return thd->spcont->set_return_value(thd, &m_value);
|
2003-02-26 19:22:29 +01:00
|
|
|
}
|
2003-09-16 14:26:08 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_freturn::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* freturn type expr... */
|
2006-11-30 02:40:42 +01:00
|
|
|
if (str->reserve(1024+8+32)) // Add some for the expr. too
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("freturn "));
|
2004-04-06 13:26:53 +02:00
|
|
|
str->qs_append((uint)m_type);
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(' ');
|
2008-02-22 11:30:33 +01:00
|
|
|
m_value->print(str, QT_ORDINARY);
|
2004-03-29 11:16:45 +02:00
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
sp_instr_hpush_jump class functions
|
|
|
|
*/
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
int
|
|
|
|
sp_instr_hpush_jump::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_hpush_jump::execute");
|
|
|
|
List_iterator_fast<sp_cond_type_t> li(m_cond);
|
|
|
|
sp_cond_type_t *p;
|
|
|
|
|
|
|
|
while ((p= li++))
|
2005-08-19 15:03:21 +02:00
|
|
|
thd->spcont->push_handler(p, m_ip+1, m_type, m_frame);
|
2003-09-16 14:26:08 +02:00
|
|
|
|
|
|
|
*nextp= m_dest;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2006-01-05 23:47:49 +01:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_hpush_jump::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* hpush_jump dest fsize type */
|
|
|
|
if (str->reserve(SP_INSTR_UINT_MAXLEN*2 + 21))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("hpush_jump "));
|
2004-04-05 17:01:19 +02:00
|
|
|
str->qs_append(m_dest);
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(' ');
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_frame);
|
2006-01-05 23:47:49 +01:00
|
|
|
switch (m_type) {
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
case SP_HANDLER_NONE:
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN(" NONE")); // This would be a bug
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
break;
|
|
|
|
case SP_HANDLER_EXIT:
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN(" EXIT"));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
break;
|
|
|
|
case SP_HANDLER_CONTINUE:
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN(" CONTINUE"));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
break;
|
|
|
|
case SP_HANDLER_UNDO:
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN(" UNDO"));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
break;
|
|
|
|
default:
|
2006-01-05 23:47:49 +01:00
|
|
|
// This would be a bug as well
|
|
|
|
str->qs_append(STRING_WITH_LEN(" UNKNOWN:"));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
str->qs_append(m_type);
|
|
|
|
}
|
2004-03-29 11:16:45 +02:00
|
|
|
}
|
|
|
|
|
2006-01-05 23:47:49 +01:00
|
|
|
|
2004-08-02 18:05:31 +02:00
|
|
|
uint
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp_instr_hpush_jump::opt_mark(sp_head *sp, List<sp_instr> *leads)
|
2004-08-02 18:05:31 +02:00
|
|
|
{
|
|
|
|
sp_instr *i;
|
|
|
|
|
|
|
|
marked= 1;
|
|
|
|
if ((i= sp->get_instr(m_dest)))
|
|
|
|
{
|
2004-08-26 12:54:30 +02:00
|
|
|
m_dest= i->opt_shortcut_jump(sp, this);
|
2004-08-02 18:05:31 +02:00
|
|
|
m_optdest= sp->get_instr(m_dest);
|
|
|
|
}
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp->add_mark_lead(m_dest, leads);
|
2004-08-02 18:05:31 +02:00
|
|
|
return m_ip+1;
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_hpop class functions
|
|
|
|
*/
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
int
|
|
|
|
sp_instr_hpop::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_hpop::execute");
|
|
|
|
thd->spcont->pop_handlers(m_count);
|
|
|
|
*nextp= m_ip+1;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_hpop::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* hpop count */
|
|
|
|
if (str->reserve(SP_INSTR_UINT_MAXLEN+5))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("hpop "));
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_count);
|
|
|
|
}
|
|
|
|
|
2004-08-26 12:54:30 +02:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
sp_instr_hreturn class functions
|
|
|
|
*/
|
|
|
|
|
2003-09-16 14:26:08 +02:00
|
|
|
int
|
|
|
|
sp_instr_hreturn::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_hreturn::execute");
|
2004-09-10 11:11:52 +02:00
|
|
|
if (m_dest)
|
|
|
|
*nextp= m_dest;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*nextp= thd->spcont->pop_hstack();
|
|
|
|
}
|
2005-09-26 18:22:00 +02:00
|
|
|
thd->spcont->exit_handler();
|
2003-09-16 14:26:08 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2003-10-10 16:57:21 +02:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_hreturn::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* hreturn framesize dest */
|
|
|
|
if (str->reserve(SP_INSTR_UINT_MAXLEN*2 + 9))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("hreturn "));
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_frame);
|
2004-09-10 11:11:52 +02:00
|
|
|
if (m_dest)
|
2005-09-26 18:46:31 +02:00
|
|
|
{
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(' ');
|
2004-09-10 11:11:52 +02:00
|
|
|
str->qs_append(m_dest);
|
2005-09-26 18:46:31 +02:00
|
|
|
}
|
2004-09-10 11:11:52 +02:00
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-09-10 11:11:52 +02:00
|
|
|
uint
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp_instr_hreturn::opt_mark(sp_head *sp, List<sp_instr> *leads)
|
2004-09-10 11:11:52 +02:00
|
|
|
{
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
marked= 1;
|
2007-05-07 10:23:10 +02:00
|
|
|
|
|
|
|
if (m_dest)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
This is an EXIT handler; next instruction step is in m_dest.
|
|
|
|
*/
|
|
|
|
return m_dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is a CONTINUE handler; next instruction step will come from
|
|
|
|
the handler stack and not from opt_mark.
|
|
|
|
*/
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
return UINT_MAX;
|
2004-03-29 11:16:45 +02:00
|
|
|
}
|
|
|
|
|
2004-09-10 11:11:52 +02:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/*
|
|
|
|
sp_instr_cpush class functions
|
|
|
|
*/
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
|
|
|
sp_instr_cpush::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
2005-09-02 15:21:19 +02:00
|
|
|
Query_arena backup_arena;
|
2003-10-10 16:57:21 +02:00
|
|
|
DBUG_ENTER("sp_instr_cpush::execute");
|
2005-08-18 11:23:54 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
We should create cursors in the callers arena, as
|
|
|
|
it could be (and usually is) used in several instructions.
|
|
|
|
*/
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->set_n_backup_active_arena(thd->spcont->callers_arena, &backup_arena);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2005-06-30 18:07:06 +02:00
|
|
|
thd->spcont->push_cursor(&m_lex_keeper, this);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->restore_active_arena(thd->spcont->callers_arena, &backup_arena);
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
*nextp= m_ip+1;
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_cpush::print(String *str)
|
|
|
|
{
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
LEX_STRING n;
|
|
|
|
my_bool found= m_ctx->find_cursor(m_cursor, &n);
|
2005-11-22 13:06:52 +01:00
|
|
|
/* cpush name@offset */
|
|
|
|
uint rsrv= SP_INSTR_UINT_MAXLEN+7;
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
|
2005-11-18 16:30:27 +01:00
|
|
|
if (found)
|
|
|
|
rsrv+= n.length;
|
|
|
|
if (str->reserve(rsrv))
|
|
|
|
return;
|
2005-11-22 14:25:44 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("cpush "));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
if (found)
|
|
|
|
{
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(n.str, n.length);
|
|
|
|
str->qs_append('@');
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
}
|
|
|
|
str->qs_append(m_cursor);
|
2004-03-29 11:16:45 +02:00
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_cpop class functions
|
|
|
|
*/
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
|
|
|
sp_instr_cpop::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_cpop::execute");
|
|
|
|
thd->spcont->pop_cursors(m_count);
|
|
|
|
*nextp= m_ip+1;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_cpop::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* cpop count */
|
|
|
|
if (str->reserve(SP_INSTR_UINT_MAXLEN+5))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("cpop "));
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_count);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_copen class functions
|
|
|
|
*/
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
@todo
|
|
|
|
Assert that we either have an error or a cursor
|
|
|
|
*/
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
|
|
|
sp_instr_copen::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
/*
|
|
|
|
We don't store a pointer to the cursor in the instruction to be
|
|
|
|
able to reuse the same instruction among different threads in future.
|
|
|
|
*/
|
2003-10-10 16:57:21 +02:00
|
|
|
sp_cursor *c= thd->spcont->get_cursor(m_cursor);
|
|
|
|
int res;
|
|
|
|
DBUG_ENTER("sp_instr_copen::execute");
|
|
|
|
|
|
|
|
if (! c)
|
|
|
|
res= -1;
|
|
|
|
else
|
|
|
|
{
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
sp_lex_keeper *lex_keeper= c->get_lex_keeper();
|
|
|
|
Query_arena *old_arena= thd->stmt_arena;
|
2005-06-30 18:07:06 +02:00
|
|
|
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
/*
|
|
|
|
Get the Query_arena from the cpush instruction, which contains
|
|
|
|
the free_list of the query, so new items (if any) are stored in
|
|
|
|
the right free_list, and we can cleanup after each open.
|
|
|
|
*/
|
|
|
|
thd->stmt_arena= c->get_instr();
|
|
|
|
res= lex_keeper->reset_lex_and_exec_core(thd, nextp, FALSE, this);
|
|
|
|
/* Cleanup the query's items */
|
|
|
|
if (thd->stmt_arena->free_list)
|
|
|
|
cleanup_items(thd->stmt_arena->free_list);
|
|
|
|
thd->stmt_arena= old_arena;
|
|
|
|
/*
|
|
|
|
Work around the fact that errors in selects are not returned properly
|
|
|
|
(but instead converted into a warning), so if a condition handler
|
|
|
|
caught, we have lost the result code.
|
|
|
|
*/
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
uint dummy1, dummy2;
|
2005-06-01 12:18:41 +02:00
|
|
|
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
if (thd->spcont->found_handler(&dummy1, &dummy2))
|
|
|
|
res= -1;
|
2005-06-01 12:18:41 +02:00
|
|
|
}
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
/* TODO: Assert here that we either have an error or a cursor */
|
2003-10-10 16:57:21 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
|
2005-06-05 16:01:20 +02: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
|
|
|
int
|
|
|
|
sp_instr_copen::exec_core(THD *thd, uint *nextp)
|
|
|
|
{
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
sp_cursor *c= thd->spcont->get_cursor(m_cursor);
|
|
|
|
int res= c->open(thd);
|
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
|
|
|
*nextp= m_ip+1;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_copen::print(String *str)
|
|
|
|
{
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
LEX_STRING n;
|
|
|
|
my_bool found= m_ctx->find_cursor(m_cursor, &n);
|
2005-11-22 13:06:52 +01:00
|
|
|
/* copen name@offset */
|
|
|
|
uint rsrv= SP_INSTR_UINT_MAXLEN+7;
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
|
2005-11-18 16:30:27 +01:00
|
|
|
if (found)
|
|
|
|
rsrv+= n.length;
|
|
|
|
if (str->reserve(rsrv))
|
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("copen "));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
if (found)
|
|
|
|
{
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(n.str, n.length);
|
|
|
|
str->qs_append('@');
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
}
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_cursor);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_cclose class functions
|
|
|
|
*/
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
|
|
|
sp_instr_cclose::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
sp_cursor *c= thd->spcont->get_cursor(m_cursor);
|
|
|
|
int res;
|
|
|
|
DBUG_ENTER("sp_instr_cclose::execute");
|
|
|
|
|
|
|
|
if (! c)
|
|
|
|
res= -1;
|
|
|
|
else
|
|
|
|
res= c->close(thd);
|
|
|
|
*nextp= m_ip+1;
|
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_cclose::print(String *str)
|
|
|
|
{
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
LEX_STRING n;
|
|
|
|
my_bool found= m_ctx->find_cursor(m_cursor, &n);
|
2005-11-22 13:06:52 +01:00
|
|
|
/* cclose name@offset */
|
|
|
|
uint rsrv= SP_INSTR_UINT_MAXLEN+8;
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
|
2005-11-18 16:30:27 +01:00
|
|
|
if (found)
|
|
|
|
rsrv+= n.length;
|
|
|
|
if (str->reserve(rsrv))
|
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("cclose "));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
if (found)
|
|
|
|
{
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(n.str, n.length);
|
|
|
|
str->qs_append('@');
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
}
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_cursor);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_cfetch class functions
|
|
|
|
*/
|
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
int
|
|
|
|
sp_instr_cfetch::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
sp_cursor *c= thd->spcont->get_cursor(m_cursor);
|
|
|
|
int res;
|
2005-09-02 15:21:19 +02:00
|
|
|
Query_arena backup_arena;
|
2003-10-10 16:57:21 +02:00
|
|
|
DBUG_ENTER("sp_instr_cfetch::execute");
|
|
|
|
|
A fix and a test case for Bug#6513 "Test Suite: Values inserted by using
cursor is interpreted latin1 character and Bug#9819 "Cursors: Mysql Server
Crash while fetching from table with 5 million records."
A fix for a possible memory leak when fetching into an SP cursor
in a long loop.
The patch uses a common implementation of cursors in the binary protocol and
in stored procedures and implements materialized cursors.
For implementation details, see comments in sql_cursor.cc
include/my_sys.h:
- declaration for multi_alloc_root
libmysqld/Makefile.am:
- drop protocol_cursor.cc, add sql_cursor.cc (replaces the old
implementation of cursors with a new one)
mysql-test/r/ctype_ujis.result:
- test results fixed (a test case for Bug#6513)
mysql-test/r/sp-big.result:
- test results fixed (a test case for Bug#9819)
mysql-test/t/ctype_ujis.test:
Add a test case for Bug#6513 "Test Suite: Values inserted by using cursor is
interpreted latin1 character"
mysql-test/t/sp-big.test:
Add a restricted test case for Bug#9819 "Cursors: Mysql Server Crash
while fetching from table with 5 million records."
mysys/my_alloc.c:
- an implementation of multi_alloc_root; this is largely a copy-paste
from mulalloc.c, but the function is small and there is no easy way
to reuse the existing C function.
sql/Makefile.am:
- add sql_cursor.h, sql_cursor.cc (a new implementation of stored procedure
cursors) and drop protocol_cursor.cc (the old one)
sql/handler.cc:
- now TABLE object has its mem_root always initialized.
Adjust the implementation handler::ha_open
sql/item_subselect.cc:
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/protocol.h:
- drop Protocol_cursor
sql/sp_head.cc:
- move juggling with Query_arena::free_list and Item::next to
sp_eval_func_item, as this is needed in 3 places already.
sql/sp_head.h:
- declare a no-op implementation for cleanup_stmt in sp_instr_cpush.
This method is needed for non-materializing cursors, which are yet not
used in stored procedures.
- declaration for sp_eval_func_item
sql/sp_rcontext.cc:
- reimplement sp_cursor using the new implementation of server side cursors.
- use sp_eval_func_item to assign values of SP variables from the
row fetched from a cursor. This should fix a possible memory leak in
the old implementation of sp_cursor::fetch
sql/sp_rcontext.h:
- reimplement sp_cursor using the new implementation of server side cursors.
sql/sql_class.cc:
- disable the functionality that closes transient cursors at commit/rollback;
transient cursors are not used in 5.0, instead we use materialized ones.
To be enabled in a later version.
sql/sql_class.h:
- adjust to the rename Cursor -> Server_side_cursor
- additional declarations of select_union used in materialized cursors
sql/sql_derived.cc:
- reuse bits of tmp table code in UNION, derived tables, and materialized
cursors
- cleanup comments
sql/sql_lex.h:
- declarations of auxiliary methods used by materialized cursors
- a cleanup in st_select_lex_unit interface
sql/sql_list.h:
- add an array operator new[] to class Sql_alloc
sql/sql_prepare.cc:
- split the tight coupling of cursors and prepared statements to reuse
the same implementation in stored procedures
- cleanups of error processing in Prepared_statement::{prepare,execute}
sql/sql_select.cc:
- move the implementation of sensitive (non-materializing) cursors to
sql_cursor.cc
- make temporary tables self-contained: the table, its record and fields
are allocated in TABLE::mem_root. This implementation is not clean
and resets thd->mem_root several times because of the way create_tmp_table
works (many additional things are done inside it).
- adjust to the changed declaration of st_select_lex_unit::prepare
sql/sql_select.h:
- move the declaration of sensitive (non-materializing) cursors to
sql_cursor.cc
sql/sql_union.cc:
- move pieces of st_select_unit::prepare to select_union and st_table
methods to be able to reuse code in the implementation of materialized
cursors
sql/sql_view.cc:
- adjust to the changed signature of st_select_lex_unit::prepare
sql/table.cc:
- implement auxiliary st_table methods for use with temporary tables
sql/table.h:
- add declarations for auxiliary methods of st_table used to work with
temporary tables
tests/mysql_client_test.c:
- if cursors are materialized, a parallel update of the table used
in the cursor may go through: update the test.
sql/sql_cursor.cc:
New BitKeeper file ``sql/sql_cursor.cc'' -- implementation of server side
cursors
sql/sql_cursor.h:
New BitKeeper file ``sql/sql_cursor.h'' - declarations for
server side cursors.
2005-09-22 00:11:21 +02:00
|
|
|
res= c ? c->fetch(thd, &m_varlist) : -1;
|
2005-08-18 11:23:54 +02:00
|
|
|
|
2003-10-10 16:57:21 +02:00
|
|
|
*nextp= m_ip+1;
|
|
|
|
DBUG_RETURN(res);
|
|
|
|
}
|
2003-12-13 16:40:52 +01:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_cfetch::print(String *str)
|
|
|
|
{
|
2006-04-07 16:53:15 +02:00
|
|
|
List_iterator_fast<struct sp_variable> li(m_varlist);
|
|
|
|
sp_variable_t *pv;
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
LEX_STRING n;
|
|
|
|
my_bool found= m_ctx->find_cursor(m_cursor, &n);
|
2005-11-22 13:06:52 +01:00
|
|
|
/* cfetch name@offset vars... */
|
|
|
|
uint rsrv= SP_INSTR_UINT_MAXLEN+8;
|
2004-03-29 11:16:45 +02:00
|
|
|
|
2005-11-18 16:30:27 +01:00
|
|
|
if (found)
|
|
|
|
rsrv+= n.length;
|
|
|
|
if (str->reserve(rsrv))
|
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("cfetch "));
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
if (found)
|
|
|
|
{
|
2005-11-18 16:30:27 +01:00
|
|
|
str->qs_append(n.str, n.length);
|
|
|
|
str->qs_append('@');
|
Background:
Since long, the compiled code of stored routines has been printed in the trace file
when starting mysqld with the "--debug" flag. (At creation time only, and only in
debug builds of course.) This has been helpful when debugging stored procedure
execution, but it's a bit awkward to use. Also, the printing of some of the
instructions is a bit terse, in particular for sp_instr_stmt where only the command
code was printed.
This improves the printout of several of the instructions, and adds the debugging-
only commands "show procedure code <name>" and "show function code <name>".
(In non-debug builds they are not available.)
sql/lex.h:
New symbol for debug-only command (e.g. show procedure code).
sql/sp_head.cc:
Fixed some minor debug-mode bugs in show_create_*().
New method for debugging: sp_head::show_routine_code() - returns the "assembly code"
for a stored routine as a result set.
Improved the print() methods for many sp_instr* classes, particularly for
sp_instr_stmt where the query string is printed as well (up to a max length, just
to give a hint of which statement it is). Also print the names of variables and
cursors in some instruction.
sql/sp_head.h:
New debugging-only method in sp_head: show_routine_code().
Added offset member to sp_instr_cpush for improved debug printing.
sql/sp_pcontext.cc:
Moved find_pvar(uint i) method from sp_pcontext.h, and made it work for all
frames, not just the first one. (For debugging purposes)
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sp_pcontext.h:
Moved find_pvar(uint i) method to sp_pcontext.cc.
Added a similar find_cursor(uint i, ...) method, for debugging.
sql/sql_lex.h:
Added new sql_command codes for debugging.
sql/sql_parse.cc:
Added new commands for debugging, e.g. "show procedure code".
sql/sql_yacc.yy:
Added new commands for debugging purposes:
"show procedure code ..." and "show function code ...".
These are only enabled in debug builds, otherwise they result in a syntax error.
(I.e. they don't exist)
2005-11-17 11:11:48 +01:00
|
|
|
}
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_cursor);
|
|
|
|
while ((pv= li++))
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
if (str->reserve(pv->name.length+SP_INSTR_UINT_MAXLEN+2))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
|
|
|
str->qs_append(' ');
|
|
|
|
str->qs_append(pv->name.str, pv->name.length);
|
|
|
|
str->qs_append('@');
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(pv->offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
sp_instr_error class functions
|
|
|
|
*/
|
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
int
|
|
|
|
sp_instr_error::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_error::execute");
|
|
|
|
|
2004-11-12 13:34:00 +01:00
|
|
|
my_message(m_errcode, ER(m_errcode), MYF(0));
|
2004-03-29 11:16:45 +02:00
|
|
|
*nextp= m_ip+1;
|
|
|
|
DBUG_RETURN(-1);
|
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2004-03-29 11:16:45 +02:00
|
|
|
void
|
|
|
|
sp_instr_error::print(String *str)
|
|
|
|
{
|
2005-11-22 13:06:52 +01:00
|
|
|
/* error code */
|
|
|
|
if (str->reserve(SP_INSTR_UINT_MAXLEN+6))
|
2005-11-18 16:30:27 +01:00
|
|
|
return;
|
2005-11-22 13:24:53 +01:00
|
|
|
str->qs_append(STRING_WITH_LEN("error "));
|
2004-03-29 11:16:45 +02:00
|
|
|
str->qs_append(m_errcode);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
/**************************************************************************
|
|
|
|
sp_instr_set_case_expr class implementation
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_instr_set_case_expr::execute(THD *thd, uint *nextp)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("sp_instr_set_case_expr::execute");
|
|
|
|
|
|
|
|
DBUG_RETURN(m_lex_keeper.reset_lex_and_exec_core(thd, nextp, TRUE, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sp_instr_set_case_expr::exec_core(THD *thd, uint *nextp)
|
|
|
|
{
|
2006-05-15 12:01:55 +02:00
|
|
|
int res= thd->spcont->set_case_expr(thd, m_case_expr_id, &m_case_expr);
|
2005-12-07 15:01:17 +01:00
|
|
|
|
|
|
|
if (res &&
|
|
|
|
!thd->spcont->get_case_expr(m_case_expr_id) &&
|
|
|
|
thd->spcont->found_handler_here())
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Failed to evaluate the value, the case expression is still not
|
|
|
|
initialized, and a handler has been found. Set to NULL so we can continue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item *null_item= new Item_null();
|
|
|
|
|
|
|
|
if (!null_item ||
|
2006-05-15 12:01:55 +02:00
|
|
|
thd->spcont->set_case_expr(thd, m_case_expr_id, &null_item))
|
2005-12-07 15:01:17 +01:00
|
|
|
{
|
|
|
|
/* If this also failed, we have to abort. */
|
|
|
|
|
|
|
|
sp_rcontext *spcont= thd->spcont;
|
|
|
|
|
2007-06-18 23:54:35 +02:00
|
|
|
thd->spcont= NULL; /* Avoid handlers */
|
2005-12-07 15:01:17 +01:00
|
|
|
my_error(ER_OUT_OF_RESOURCES, MYF(0));
|
|
|
|
spcont->clear_handler();
|
|
|
|
thd->spcont= spcont;
|
|
|
|
}
|
|
|
|
}
|
2006-01-26 17:26:25 +01:00
|
|
|
else
|
|
|
|
*nextp= m_ip+1;
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2006-01-26 17:26:25 +01:00
|
|
|
return res;
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_instr_set_case_expr::print(String *str)
|
|
|
|
{
|
2006-01-26 17:26:25 +01:00
|
|
|
/* set_case_expr (cont) id ... */
|
|
|
|
str->reserve(2*SP_INSTR_UINT_MAXLEN+18+32); // Add some extra for expr too
|
|
|
|
str->qs_append(STRING_WITH_LEN("set_case_expr ("));
|
|
|
|
str->qs_append(m_cont_dest);
|
|
|
|
str->qs_append(STRING_WITH_LEN(") "));
|
2005-12-07 15:01:17 +01:00
|
|
|
str->qs_append(m_case_expr_id);
|
2006-01-20 13:59:22 +01:00
|
|
|
str->qs_append(' ');
|
2008-02-22 11:30:33 +01:00
|
|
|
m_case_expr->print(str, QT_ORDINARY);
|
2005-12-07 15:01:17 +01:00
|
|
|
}
|
|
|
|
|
2006-01-26 17:26:25 +01:00
|
|
|
uint
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp_instr_set_case_expr::opt_mark(sp_head *sp, List<sp_instr> *leads)
|
2006-01-26 17:26:25 +01:00
|
|
|
{
|
|
|
|
sp_instr *i;
|
|
|
|
|
|
|
|
marked= 1;
|
|
|
|
if ((i= sp->get_instr(m_cont_dest)))
|
|
|
|
{
|
|
|
|
m_cont_dest= i->opt_shortcut_jump(sp, this);
|
|
|
|
m_cont_optdest= sp->get_instr(m_cont_dest);
|
|
|
|
}
|
Bug#19194 (Right recursion in parser for CASE causes excessive stack usage,
limitation)
Note to the reviewer
====================
Warning: reviewing this patch is somewhat involved.
Due to the nature of several issues all affecting the same area,
fixing separately each issue is not practical, since each fix can not be
implemented and tested independently.
In particular, the issues with
- rule recursion
- nested case statements
- forward jump resolution (backpatch list)
are tightly coupled (see below).
Definitions
===========
The expression
CASE expr
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Simple Case Expression".
The expression
CASE
WHEN expr THEN expr
WHEN expr THEN expr
...
END
is a "Searched Case Expression".
The statement
CASE expr
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Simple Case Statement".
The statement
CASE
WHEN expr THEN stmts
WHEN expr THEN stmts
...
END CASE
is a "Searched Case Statement".
A "Left Recursive" rule is like
list:
element
| list element
;
A "Right Recursive" rule is like
list:
element
| element list
;
Left and right recursion produces the same language, the difference only
affects the *order* in which the text is parsed.
In a descendant parser (usually written manually), right recursion works
very well, and is typically implemented with a while loop.
In an ascendant parser (yacc/bison) left recursion works very well,
and is implemented naturally by the parser stack.
In both cases, using the wrong type or recursion is very bad and should be
avoided, as it causes technical issues with the parser implementation.
Before this change
==================
The "Simple Case Expression" and "Searched Case Expression" were both
implemented by the "when_list" and "when_list2" rules, which are left
recursive (ok).
These rules, however, used lex->when_list instead of using the parser stack,
which is more complex that necessary, and potentially dangerous because
of other rules using THD::reset_lex.
The "Simple Case Statement" and "Searched Case Statements" were implemented
by the "sp_case", "sp_whens" and in part by "sp_proc_stmt" rules.
Both cases were right recursive (bad).
The grammar involved was convoluted, and is assumed to be the results of
tweaks to get the code generation to work, but is not what someone would
naturally write.
In addition, using a common rule for both "Simple" and "Searched" case
statements was implemented with sp_head::m_flags |= IN_SIMPLE_CASE,
which is a flag and not a stack, and therefore does not take into account
*nested* case statements. This leads to incorrect generated code, and either
a server crash or an incorrect result.
With regards to the backpatch mechanism, a *different* backpatch list was
created for each jump from "WHEN expr THEN stmt" to "END CASE", which
relied on the grammar to be right recursive.
This is a mis-use of the backpatch list, since this list can resolve
multiple references to the same target at once.
The optimizer algorithm used to detect dead code in the "assembly" SQL
instructions, implemented by sp_head::opt_mark(uint ip), was recursive
in some cases (a conditional jump pointing forward to another conditional
jump).
In case of specially crafted code, like
- a long list of "IF expr THEN stmt END IF"
- a long CASE statement
this would actually cause a server crash with a stack overflow.
In general, having a stack that grows proportionally with user data (the
SQL code given by the client in a CREATE PROCEDURE) is to be avoided.
In debug builds only, creating a SP / SF / Trigger which had a significant
amount of code would spend --literally-- several minutes in sp_head::create,
because of the debug code involved with DBUG_PRINT("info", ("Code %s ...
There are several issues with this code:
- in a CASE with 5 000 WHEN, there are 15 000 instructions generated,
which create a sting representation of the code which is 500 000 bytes
long,
- using a String instead of an io stream causes performances to degrade
to a total server freeze, as time is spent doing realloc of a buffer
always too short,
- Printing a 500 000 long string in the debug log is too verbose,
- Generating this string even when DBUG_PRINT is off is useless,
- Having code that potentially can affect the server behavior, used with
#ifdef / #endif is useful in some cases, but is also a bad practice.
After this change
=================
"Case Expressions" (both simple and searched) have been simplified to
not use LEX::when_list, which has been removed.
Considering all the issues affecting case statements, the grammar for these
has been totally re written.
The existing actions, used to generate "assembly" sp_inst* code, have been
preserved but moved in the new grammar, with the following changes:
a) Bison rules are no longer shared between "Simple" and "Searched" case
statements, because a stack instead of a flag is required to handle them.
Nested statements are handled naturally by the parser stack, which by
definition uses the correct rule in the correct context.
Nested statements of the opposite type (simple vs searched) works correctly.
The flag sp_head::IN_SIMPLE_CASE is no longer used.
This is a step towards resolution of WL#2999, which correctly identified
that temporary parsing flags do not belong to sp_head.
The code in the action is shared by mean of the case_stmt_action_xxx()
helpers.
b) The backpatch mechanism, used to resolve forward jumps in the generated
code, has been changed to:
- create a label for the instruction following 'END CASE',
- register each jump at the end of a "WHEN expr THEN stmt" in a *unique*
backpatch list associated with the 'END CASE' label
- resolve all the forward jumps for this label at once.
In addition, the code involving backpatch has been commented, so that a
reader can now understand by reading matching "Registering" and "Resolving"
comments how the forward jumps are resolved and what target they resolve to,
as this is far from evident when reading the code alone.
The implementation of sp_head::opt_mark() has been revised to avoid
recursive calls from jump instructions, and instead add the jump location
to the list of paths to explore during the flow analysis of the instruction
graph, with a call to sp_head::add_mark_lead().
In addition, the flow analysis will stop if an instruction has already
been marked as reachable, which the previous code failed to do in the
recursive case.
sp_head::opt_mark() is now private, to prevent new calls to this method from
being introduced.
The debug code present in sp_head::create() has been removed.
Considering that SHOW PROCEDURE CODE is also available in debug builds,
and can be used anytime regardless of the trace level, as opposed to
"CREATE PROCEDURE" time and only if the trace was on,
removing the code actually makes debugging easier (usable trace).
Tests have been written to cover the parser overflow (big CASE),
and to cover nested CASE statements.
mysql-test/r/sp-code.result:
Test cases for nested CASE statements.
mysql-test/t/sp-code.test:
Test cases for nested CASE statements.
sql/sp_head.cc:
Re factored opt_mark() to avoid recursion, clean up.
sql/sp_head.h:
Re factored opt_mark() to avoid recursion, clean up.
sql/sql_lex.cc:
Removed when_list.
sql/sql_lex.h:
Removed when_list.
sql/sql_yacc.yy:
Minor clean up for case expressions,
Major re write for case statements (Bug#19194).
mysql-test/r/sp_stress_case.result:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.sh:
New test for massive CASE statements.
mysql-test/t/sp_stress_case.test:
New test for massive CASE statements.
2006-11-17 20:14:29 +01:00
|
|
|
sp->add_mark_lead(m_cont_dest, leads);
|
2006-01-26 17:26:25 +01:00
|
|
|
return m_ip+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sp_instr_set_case_expr::opt_move(uint dst, List<sp_instr> *bp)
|
|
|
|
{
|
|
|
|
if (m_cont_dest > m_ip)
|
|
|
|
bp->push_back(this); // Forward
|
|
|
|
else if (m_cont_optdest)
|
|
|
|
m_cont_dest= m_cont_optdest->m_ip; // Backward
|
|
|
|
m_ip= dst;
|
|
|
|
}
|
|
|
|
|
2005-12-07 15:01:17 +01:00
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
/* ------------------------------------------------------------------ */
|
2003-12-13 16:40:52 +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
|
|
|
|
|
|
|
/*
|
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
|
|
|
Structure that represent all instances of one table
|
|
|
|
in optimized multi-set of tables used by routine.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
typedef struct st_sp_table
|
|
|
|
{
|
2006-01-12 23:51:56 +01:00
|
|
|
/*
|
|
|
|
Multi-set key:
|
|
|
|
db_name\0table_name\0alias\0 - for normal tables
|
|
|
|
db_name\0table_name\0 - for temporary tables
|
|
|
|
Note that in both cases we don't take last '\0' into account when
|
|
|
|
we count length of key.
|
|
|
|
*/
|
|
|
|
LEX_STRING qname;
|
2005-05-17 17:08:43 +02:00
|
|
|
uint db_length, table_name_length;
|
|
|
|
bool temp; /* true if corresponds to a temporary table */
|
|
|
|
thr_lock_type lock_type; /* lock type used for prelocking */
|
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
|
|
|
uint lock_count;
|
|
|
|
uint query_lock_count;
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
uint8 trg_event_map;
|
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
|
|
|
} SP_TABLE;
|
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
|
|
|
|
uchar *sp_table_key(const uchar *ptr, size_t *plen, my_bool first)
|
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
|
|
|
{
|
|
|
|
SP_TABLE *tab= (SP_TABLE *)ptr;
|
|
|
|
*plen= tab->qname.length;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
return (uchar *)tab->qname.str;
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-10-11 20:37:45 +02: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
|
|
|
Merge the list of tables used by some query into the multi-set of
|
|
|
|
tables used by routine.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param thd thread context
|
|
|
|
@param table table list
|
|
|
|
@param lex_for_tmp_check LEX of the query for which we are merging
|
|
|
|
table list.
|
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
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@note
|
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
|
|
|
This method will use LEX provided to check whenever we are creating
|
|
|
|
temporary table and mark it as such in target multi-set.
|
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@retval
|
|
|
|
TRUE Success
|
|
|
|
@retval
|
|
|
|
FALSE Error
|
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
|
|
|
*/
|
|
|
|
|
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
|
|
|
bool
|
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
|
|
|
sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check)
|
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
|
|
|
{
|
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
|
|
|
SP_TABLE *tab;
|
|
|
|
|
|
|
|
if (lex_for_tmp_check->sql_command == SQLCOM_DROP_TABLE &&
|
|
|
|
lex_for_tmp_check->drop_temporary)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (uint i= 0 ; i < m_sptabs.records ; i++)
|
|
|
|
{
|
|
|
|
tab= (SP_TABLE *)hash_element(&m_sptabs, i);
|
|
|
|
tab->query_lock_count= 0;
|
|
|
|
}
|
|
|
|
|
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 (; table ; table= table->next_global)
|
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
|
|
|
if (!table->derived && !table->schema_table)
|
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
|
|
|
{
|
2005-05-17 17:08:43 +02:00
|
|
|
char tname[(NAME_LEN + 1) * 3]; // db\0table\0alias\0
|
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
|
|
|
uint tlen, alen;
|
|
|
|
|
|
|
|
tlen= table->db_length;
|
|
|
|
memcpy(tname, table->db, tlen);
|
2005-05-17 17:08:43 +02:00
|
|
|
tname[tlen++]= '\0';
|
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
|
|
|
memcpy(tname+tlen, table->table_name, table->table_name_length);
|
|
|
|
tlen+= table->table_name_length;
|
2005-05-17 17:08:43 +02:00
|
|
|
tname[tlen++]= '\0';
|
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
|
|
|
alen= strlen(table->alias);
|
|
|
|
memcpy(tname+tlen, table->alias, alen);
|
|
|
|
tlen+= alen;
|
|
|
|
tname[tlen]= '\0';
|
|
|
|
|
A fix and a test case for
Bug#21483 "Server abort or deadlock on INSERT DELAYED with another
implicit insert"
Also fixes and adds test cases for bugs:
20497 "Trigger with INSERT DELAYED causes Error 1165"
21714 "Wrong NEW.value and server abort on INSERT DELAYED to a
table with a trigger".
Post-review fixes.
Problem:
In MySQL INSERT DELAYED is a way to pipe all inserts into a
given table through a dedicated thread. This is necessary for
simplistic storage engines like MyISAM, which do not have internal
concurrency control or threading and thus can not
achieve efficient INSERT throughput without support from SQL layer.
DELAYED INSERT works as follows:
For every distinct table, which can accept DELAYED inserts and has
pending data to insert, a dedicated thread is created to write data
to disk. All user connection threads that attempt to
delayed-insert into this table interact with the dedicated thread in
producer/consumer fashion: all records to-be inserted are pushed
into a queue of the dedicated thread, which fetches the records and
writes them.
In this design, client connection threads never open or lock
the delayed insert table.
This functionality was introduced in version 3.23 and does not take
into account existence of triggers, views, or pre-locking.
E.g. if INSERT DELAYED is called from a stored function, which,
in turn, is called from another stored function that uses the delayed
table, a deadlock can occur, because delayed locking by-passes
pre-locking. Besides:
* the delayed thread works directly with the subject table through
the storage engine API and does not invoke triggers
* even if it was patched to invoke triggers, if triggers,
in turn, used other tables, the delayed thread would
have to open and lock involved tables (use pre-locking).
* even if it was patched to use pre-locking, without deadlock
detection the delayed thread could easily lock out user
connection threads in case when the same table is used both
in a trigger and on the right side of the insert query:
the delayed thread would not release locks until all inserts
are complete, and user connection can not complete inserts
without having locks on the tables used on the right side of the
query.
Solution:
These considerations suggest two general alternatives for the
future of INSERT DELAYED:
* it is considered a full-fledged alternative to normal INSERT
* it is regarded as an optimisation that is only relevant
for simplistic engines.
Since we missed our chance to provide complete support of new
features when 5.0 was in development, the first alternative
currently renders infeasible.
However, even the second alternative, which is to detect
new features and convert DELAYED insert into a normal insert,
is not easy to implement.
The catch-22 is that we don't know if the subject table has triggers
or is a view before we open it, and we only open it in the
delayed thread. We don't know if the query involves pre-locking
until we have opened all tables, and we always first create
the delayed thread, and only then open the remaining tables.
This patch detects the problematic scenarios and converts
DELAYED INSERT to a normal INSERT using the following approach:
* if the statement is executed under pre-locking (e.g. from
within a stored function or trigger) or the right
side may require pre-locking, we detect the situation
before creating a delayed insert thread and convert the statement
to a conventional INSERT.
* if the subject table is a view or has triggers, we shutdown
the delayed thread and convert the statement to a conventional
INSERT.
mysql-test/r/insert.result:
Update test results.
mysql-test/t/insert.test:
Add a test case for Bug#21483, Bug#20497, Bug#21714 (INSERT DELAYED
and stored routines, triggers).
sql/sp_head.cc:
Upgrade lock type to TL_WRITE when computing the pre-locking set.
sql/sql_base.cc:
Use a new method.
sql/sql_insert.cc:
INSERT DELAYED and pre-locking:
- if under pre-locking, upgrade the lock type to TL_WRITE
and proceed as a normal write
- if DELAYED table has triggers, also request a lock upgrade.
- make sure errors in the delayed thread are propagated
correctly
sql/sql_lex.h:
Add a method to check if a parsed tree refers to stored
routines.
2007-05-16 07:51:05 +02:00
|
|
|
/*
|
|
|
|
Upgrade the lock type because this table list will be used
|
|
|
|
only in pre-locked mode, in which DELAYED inserts are always
|
|
|
|
converted to normal inserts.
|
|
|
|
*/
|
|
|
|
if (table->lock_type == TL_WRITE_DELAYED)
|
|
|
|
table->lock_type= TL_WRITE;
|
|
|
|
|
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
|
|
|
/*
|
2006-01-12 23:51:56 +01:00
|
|
|
We ignore alias when we check if table was already marked as temporary
|
|
|
|
(and therefore should not be prelocked). Otherwise we will erroneously
|
|
|
|
treat table with same name but with different alias as non-temporary.
|
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
|
|
|
*/
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
if ((tab= (SP_TABLE *)hash_search(&m_sptabs, (uchar *)tname, tlen)) ||
|
|
|
|
((tab= (SP_TABLE *)hash_search(&m_sptabs, (uchar *)tname,
|
2006-01-12 23:51:56 +01:00
|
|
|
tlen - alen - 1)) &&
|
|
|
|
tab->temp))
|
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
|
|
|
{
|
2005-04-15 18:31:47 +02:00
|
|
|
if (tab->lock_type < table->lock_type)
|
|
|
|
tab->lock_type= table->lock_type; // Use the table with the highest lock type
|
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
|
|
|
tab->query_lock_count++;
|
|
|
|
if (tab->query_lock_count > tab->lock_count)
|
|
|
|
tab->lock_count++;
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
tab->trg_event_map|= table->trg_event_map;
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(tab= (SP_TABLE *)thd->calloc(sizeof(SP_TABLE))))
|
|
|
|
return FALSE;
|
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
|
|
|
if (lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE &&
|
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
|
|
|
lex_for_tmp_check->query_tables == table &&
|
|
|
|
lex_for_tmp_check->create_info.options & HA_LEX_CREATE_TMP_TABLE)
|
2006-01-12 23:51:56 +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
|
|
|
tab->temp= TRUE;
|
2006-01-12 23:51:56 +01:00
|
|
|
tab->qname.length= tlen - alen - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tab->qname.length= tlen;
|
|
|
|
tab->qname.str= (char*) thd->memdup(tname, tab->qname.length + 1);
|
|
|
|
if (!tab->qname.str)
|
|
|
|
return FALSE;
|
2005-05-17 17:08:43 +02:00
|
|
|
tab->table_name_length= table->table_name_length;
|
|
|
|
tab->db_length= table->db_length;
|
2005-04-15 18:31:47 +02:00
|
|
|
tab->lock_type= table->lock_type;
|
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
|
|
|
tab->lock_count= tab->query_lock_count= 1;
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
tab->trg_event_map= table->trg_event_map;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
BitKeeper/etc/ignore:
added libmysqld/ha_ndbcluster_cond.cc
---
added debian/defs.mk debian/control
client/completion_hash.cc:
Remove not needed casts
client/my_readline.h:
Remove some old types
client/mysql.cc:
Simplify types
client/mysql_upgrade.c:
Remove some old types
Update call to dirname_part
client/mysqladmin.cc:
Remove some old types
client/mysqlbinlog.cc:
Remove some old types
Change some buffers to be uchar to avoid casts
client/mysqlcheck.c:
Remove some old types
client/mysqldump.c:
Remove some old types
Remove some not needed casts
Change some string lengths to size_t
client/mysqlimport.c:
Remove some old types
client/mysqlshow.c:
Remove some old types
client/mysqlslap.c:
Remove some old types
Remove some not needed casts
client/mysqltest.c:
Removed some old types
Removed some not needed casts
Updated hash-get-key function arguments
Updated parameters to dirname_part()
client/readline.cc:
Removed some old types
Removed some not needed casts
Changed some string lengths to use size_t
client/sql_string.cc:
Removed some old types
dbug/dbug.c:
Removed some old types
Changed some string lengths to use size_t
Changed some prototypes to avoid casts
extra/comp_err.c:
Removed some old types
extra/innochecksum.c:
Removed some old types
extra/my_print_defaults.c:
Removed some old types
extra/mysql_waitpid.c:
Removed some old types
extra/perror.c:
Removed some old types
extra/replace.c:
Removed some old types
Updated parameters to dirname_part()
extra/resolve_stack_dump.c:
Removed some old types
extra/resolveip.c:
Removed some old types
include/config-win.h:
Removed some old types
include/decimal.h:
Changed binary strings to be uchar* instead of char*
include/ft_global.h:
Removed some old types
include/hash.h:
Removed some old types
include/heap.h:
Removed some old types
Changed records_under_level to be 'ulong' instead of 'uint' to clarify usage of variable
include/keycache.h:
Removed some old types
include/m_ctype.h:
Removed some old types
Changed some string lengths to use size_t
Changed character length functions to return uint
unsigned char -> uchar
include/m_string.h:
Removed some old types
Changed some string lengths to use size_t
include/my_alloc.h:
Changed some string lengths to use size_t
include/my_base.h:
Removed some old types
include/my_dbug.h:
Removed some old types
Changed some string lengths to use size_t
Changed db_dump() to take uchar * as argument for memory to reduce number of casts in usage
include/my_getopt.h:
Removed some old types
include/my_global.h:
Removed old types:
my_size_t -> size_t
byte -> uchar
gptr -> uchar *
include/my_list.h:
Removed some old types
include/my_nosys.h:
Removed some old types
include/my_pthread.h:
Removed some old types
include/my_sys.h:
Removed some old types
Changed MY_FILE_ERROR to be in line with new definitions of my_write()/my_read()
Changed some string lengths to use size_t
my_malloc() / my_free() now uses void *
Updated parameters to dirname_part() & my_uncompress()
include/my_tree.h:
Removed some old types
include/my_trie.h:
Removed some old types
include/my_user.h:
Changed some string lengths to use size_t
include/my_vle.h:
Removed some old types
include/my_xml.h:
Removed some old types
Changed some string lengths to use size_t
include/myisam.h:
Removed some old types
include/myisammrg.h:
Removed some old types
include/mysql.h:
Removed some old types
Changed byte streams to use uchar* instead of char*
include/mysql_com.h:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
include/queues.h:
Removed some old types
include/sql_common.h:
Removed some old types
include/sslopt-longopts.h:
Removed some old types
include/violite.h:
Removed some old types
Changed some string lengths to use size_t
libmysql/client_settings.h:
Removed some old types
libmysql/libmysql.c:
Removed some old types
libmysql/manager.c:
Removed some old types
libmysqld/emb_qcache.cc:
Removed some old types
libmysqld/emb_qcache.h:
Removed some old types
libmysqld/lib_sql.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
true -> TRUE, false -> FALSE
mysys/array.c:
Removed some old types
mysys/charset.c:
Changed some string lengths to use size_t
mysys/checksum.c:
Include zlib to get definition for crc32
Removed some old types
mysys/default.c:
Removed some old types
Changed some string lengths to use size_t
mysys/default_modify.c:
Changed some string lengths to use size_t
Removed some not needed casts
mysys/hash.c:
Removed some old types
Changed some string lengths to use size_t
Note: Prototype of hash_key() has changed which may cause problems if client uses hash_init() with a cast for the hash-get-key function.
hash_element now takes 'ulong' as the index type (cleanup)
mysys/list.c:
Removed some old types
mysys/mf_cache.c:
Changed some string lengths to use size_t
mysys/mf_dirname.c:
Removed some old types
Changed some string lengths to use size_t
Added argument to dirname_part() to avoid calculation of length for 'to'
mysys/mf_fn_ext.c:
Removed some old types
Updated parameters to dirname_part()
mysys/mf_format.c:
Removed some old types
Changed some string lengths to use size_t
mysys/mf_getdate.c:
Removed some old types
mysys/mf_iocache.c:
Removed some old types
Changed some string lengths to use size_t
Changed calculation of 'max_length' to be done the same way in all functions
mysys/mf_iocache2.c:
Removed some old types
Changed some string lengths to use size_t
Clean up comments
Removed not needed indentation
mysys/mf_keycache.c:
Removed some old types
mysys/mf_keycaches.c:
Removed some old types
mysys/mf_loadpath.c:
Removed some old types
mysys/mf_pack.c:
Removed some old types
Changed some string lengths to use size_t
Removed some not needed casts
Removed very old VMS code
Updated parameters to dirname_part()
Use result of dirnam_part() to remove call to strcat()
mysys/mf_path.c:
Removed some old types
mysys/mf_radix.c:
Removed some old types
mysys/mf_same.c:
Removed some old types
mysys/mf_sort.c:
Removed some old types
mysys/mf_soundex.c:
Removed some old types
mysys/mf_strip.c:
Removed some old types
mysys/mf_tempdir.c:
Removed some old types
mysys/mf_unixpath.c:
Removed some old types
mysys/mf_wfile.c:
Removed some old types
mysys/mulalloc.c:
Removed some old types
mysys/my_alloc.c:
Removed some old types
Changed some string lengths to use size_t
Use void* as type for allocated memory area
Removed some not needed casts
Changed argument 'Size' to 'length' according coding guidelines
mysys/my_chsize.c:
Changed some buffers to be uchar* to avoid casts
mysys/my_compress.c:
More comments
Removed some old types
Changed string lengths to use size_t
Changed arguments to my_uncompress() to make them easier to understand
Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix)
Changed type of 'pack_data' argument to packfrm() to avoid casts.
mysys/my_conio.c:
Changed some string lengths to use size_t
mysys/my_create.c:
Removed some old types
mysys/my_div.c:
Removed some old types
mysys/my_error.c:
Removed some old types
mysys/my_fopen.c:
Removed some old types
mysys/my_fstream.c:
Removed some old types
Changed some string lengths to use size_t
writen -> written
mysys/my_getopt.c:
Removed some old types
mysys/my_getwd.c:
Removed some old types
More comments
mysys/my_init.c:
Removed some old types
mysys/my_largepage.c:
Removed some old types
Changed some string lengths to use size_t
mysys/my_lib.c:
Removed some old types
mysys/my_lockmem.c:
Removed some old types
mysys/my_malloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/my_memmem.c:
Indentation cleanup
mysys/my_once.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
mysys/my_open.c:
Removed some old types
mysys/my_pread.c:
Removed some old types
Changed all functions to use size_t
Added comment for how my_pread() / my_pwrite() are supposed to work.
Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe.
(If we ever would really need this, it should be enabled only with a flag argument)
mysys/my_quick.c:
Removed some old types
Changed all functions to use size_t
mysys/my_read.c:
Removed some old types
Changed all functions to use size_t
mysys/my_realloc.c:
Removed some old types
Use void* as type for allocated memory area
Changed all functions to use size_t
mysys/my_static.c:
Removed some old types
mysys/my_static.h:
Removed some old types
mysys/my_vle.c:
Removed some old types
mysys/my_wincond.c:
Removed some old types
mysys/my_windac.c:
Removed some old types
mysys/my_write.c:
Removed some old types
Changed all functions to use size_t
mysys/ptr_cmp.c:
Removed some old types
Changed all functions to use size_t
mysys/queues.c:
Removed some old types
mysys/safemalloc.c:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed all functions to use size_t
mysys/string.c:
Removed some old types
Changed all functions to use size_t
mysys/testhash.c:
Removed some old types
mysys/thr_alarm.c:
Removed some old types
mysys/thr_lock.c:
Removed some old types
mysys/tree.c:
Removed some old types
mysys/trie.c:
Removed some old types
mysys/typelib.c:
Removed some old types
plugin/daemon_example/daemon_example.cc:
Removed some old types
regex/reginit.c:
Removed some old types
server-tools/instance-manager/buffer.cc:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/buffer.h:
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/commands.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_map.cc:
Removed some old types
Changed some string lengths to use size_t
Changed buffer to be of type uchar*
server-tools/instance-manager/instance_options.cc:
Changed buffer to be of type uchar*
Replaced alloc_root + strcpy() with strdup_root()
server-tools/instance-manager/mysql_connection.cc:
Changed buffer to be of type uchar*
server-tools/instance-manager/options.cc:
Removed some old types
server-tools/instance-manager/parse.cc:
Changed some string lengths to use size_t
server-tools/instance-manager/parse.h:
Removed some old types
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.cc:
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
server-tools/instance-manager/protocol.h:
Changed some string lengths to use size_t
server-tools/instance-manager/user_map.cc:
Removed some old types
Changed some string lengths to use size_t
sql/derror.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/discover.cc:
Changed in readfrm() and writefrom() the type for argument 'frmdata' to uchar** to avoid casts
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
sql/event_data_objects.cc:
Removed some old types
Added missing casts for alloc() and sprintf()
sql/event_db_repository.cc:
Changed some buffers to be uchar* to avoid casts
Added missing casts for sprintf()
sql/event_queue.cc:
Removed some old types
sql/field.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/field.h:
Removed some old types
Changed memory buffers to be uchar* (except of store() as this would have caused too many other changes).
Changed some string lengths to use size_t
Removed some not needed casts
Changed val_xxx(xxx, new_ptr) to take const pointers
sql/field_conv.cc:
Removed some old types
Added casts required because memory area pointers are now uchar*
sql/filesort.cc:
Initalize variable that was used unitialized in error conditions
sql/gen_lex_hash.cc:
Removed some old types
Changed memory buffers to be uchar*
Changed some string lengths to use size_t
Removed a lot of casts
Safety fix in Field_blob::val_decimal() to not access zero pointer
sql/gstream.h:
Added required cast
sql/ha_ndbcluster.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Added required casts
Removed some not needed casts
sql/ha_ndbcluster.h:
Removed some old types
sql/ha_ndbcluster_binlog.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Replaced sql_alloc() + memcpy() + set end 0 with sql_strmake()
Changed some string lengths to use size_t
Added missing casts for alloc() and sprintf()
sql/ha_ndbcluster_binlog.h:
Removed some old types
sql/ha_ndbcluster_cond.cc:
Removed some old types
Removed some not needed casts
sql/ha_ndbcluster_cond.h:
Removed some old types
sql/ha_partition.cc:
Removed some old types
Changed prototype for change_partition() to avoid casts
sql/ha_partition.h:
Removed some old types
sql/handler.cc:
Removed some old types
Changed some string lengths to use size_t
sql/handler.h:
Removed some old types
Changed some string lengths to use size_t
Changed type for 'frmblob' parameter for discover() and ha_discover() to get fewer casts
sql/hash_filo.h:
Removed some old types
Changed all functions to use size_t
sql/hostname.cc:
Removed some old types
sql/item.cc:
Removed some old types
Changed some string lengths to use size_t
Use strmake() instead of memdup() to create a null terminated string.
Updated calls to new Field()
sql/item.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/item_cmpfunc.h:
Removed some old types
sql/item_create.cc:
Removed some old types
sql/item_func.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added test for failing alloc() in init_result_field()
Remove old confusing comment
Fixed compiler warning
sql/item_func.h:
Removed some old types
sql/item_row.cc:
Removed some old types
sql/item_row.h:
Removed some old types
sql/item_strfunc.cc:
Include zlib (needed becasue we call crc32)
Removed some old types
sql/item_strfunc.h:
Removed some old types
Changed some types to match new function prototypes
sql/item_subselect.cc:
Removed some old types
sql/item_subselect.h:
Removed some old types
sql/item_sum.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/item_sum.h:
Removed some old types
sql/item_timefunc.cc:
Removed some old types
Changed some string lengths to use size_t
sql/item_timefunc.h:
Removed some old types
sql/item_xmlfunc.cc:
Changed some string lengths to use size_t
sql/item_xmlfunc.h:
Removed some old types
sql/key.cc:
Removed some old types
Removed some not needed casts
sql/lock.cc:
Removed some old types
Added some cast to my_multi_malloc() arguments for safety
sql/log.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Changed usage of pwrite() to not assume it holds the cursor position for the file
Made usage of my_read() safer
sql/log_event.cc:
Removed some old types
Added checking of return value of malloc() in pack_info()
Changed some buffers to be uchar* to avoid casts
Removed some 'const' to avoid casts
Added missing casts for alloc() and sprintf()
Added required casts
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
sql/log_event.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/log_event_old.cc:
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/log_event_old.h:
Changed some buffers to be uchar* to avoid casts
sql/mf_iocache.cc:
Removed some old types
sql/my_decimal.cc:
Changed memory area to use uchar*
sql/my_decimal.h:
Changed memory area to use uchar*
sql/mysql_priv.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Changed some string lengths to use size_t
Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid long overflow
Changed some buffers to be uchar* to avoid casts
sql/mysqld.cc:
Removed some old types
sql/net_serv.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Ensure that vio_read()/vio_write() return values are stored in a size_t variable
Removed some not needed casts
sql/opt_range.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/opt_range.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/opt_sum.cc:
Removed some old types
Removed some not needed casts
sql/parse_file.cc:
Removed some old types
Changed some string lengths to use size_t
Changed alloc_root + memcpy + set end 0 -> strmake_root()
sql/parse_file.h:
Removed some old types
sql/partition_info.cc:
Removed some old types
Added missing casts for alloc()
Changed some buffers to be uchar* to avoid casts
sql/partition_info.h:
Changed some buffers to be uchar* to avoid casts
sql/protocol.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/protocol.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/records.cc:
Removed some old types
sql/repl_failsafe.cc:
Removed some old types
Changed some string lengths to use size_t
Added required casts
sql/rpl_filter.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some string lengths to use size_t
sql/rpl_filter.h:
Changed some string lengths to use size_t
sql/rpl_injector.h:
Removed some old types
sql/rpl_record.cc:
Removed some old types
Removed some not needed casts
Changed some buffers to be uchar* to avoid casts
sql/rpl_record.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/rpl_record_old.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/rpl_record_old.h:
Removed some old types
Changed some buffers to be uchar* to avoid cast
sql/rpl_rli.cc:
Removed some old types
sql/rpl_tblmap.cc:
Removed some old types
sql/rpl_tblmap.h:
Removed some old types
sql/rpl_utility.cc:
Removed some old types
sql/rpl_utility.h:
Removed some old types
Changed type of m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length
sql/set_var.cc:
Removed some old types
Updated parameters to dirname_part()
sql/set_var.h:
Removed some old types
sql/slave.cc:
Removed some old types
Changed some string lengths to use size_t
sql/slave.h:
Removed some old types
sql/sp.cc:
Removed some old types
Added missing casts for printf()
sql/sp.h:
Removed some old types
Updated hash-get-key function arguments
sql/sp_cache.cc:
Removed some old types
Added missing casts for printf()
Updated hash-get-key function arguments
sql/sp_head.cc:
Removed some old types
Added missing casts for alloc() and printf()
Added required casts
Updated hash-get-key function arguments
sql/sp_head.h:
Removed some old types
sql/sp_pcontext.cc:
Removed some old types
sql/sp_pcontext.h:
Removed some old types
sql/sql_acl.cc:
Removed some old types
Changed some string lengths to use size_t
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added required casts
sql/sql_analyse.cc:
Changed some buffers to be uchar* to avoid casts
sql/sql_analyse.h:
Changed some buffers to be uchar* to avoid casts
sql/sql_array.h:
Removed some old types
sql/sql_base.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_binlog.cc:
Removed some old types
Added missing casts for printf()
sql/sql_cache.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
Changed some string lengths to use size_t
sql/sql_cache.h:
Removed some old types
Removed reference to not existing function cache_key()
Updated hash-get-key function arguments
sql/sql_class.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc()
Updated hash-get-key function arguments
Moved THD::max_row_length() to table.cc (as it's not depending on THD)
Removed some not needed casts
sql/sql_class.h:
Removed some old types
Changed malloc(), free() and related functions to use void *
Removed some not needed casts
Changed some string lengths to use size_t
Moved max_row_length and max_row_length_blob() to table.cc, as they are not depending on THD
sql/sql_connect.cc:
Removed some old types
Added required casts
sql/sql_db.cc:
Removed some old types
Removed some not needed casts
Added some cast to my_multi_malloc() arguments for safety
Added missing casts for alloc()
sql/sql_delete.cc:
Removed some old types
sql/sql_handler.cc:
Removed some old types
Updated hash-get-key function arguments
Added some cast to my_multi_malloc() arguments for safety
sql/sql_help.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_insert.cc:
Removed some old types
Added missing casts for alloc() and printf()
sql/sql_lex.cc:
Removed some old types
sql/sql_lex.h:
Removed some old types
Removed some not needed casts
sql/sql_list.h:
Removed some old types
Removed some not needed casts
sql/sql_load.cc:
Removed some old types
Removed compiler warning
sql/sql_manager.cc:
Removed some old types
sql/sql_map.cc:
Removed some old types
sql/sql_map.h:
Removed some old types
sql/sql_olap.cc:
Removed some old types
sql/sql_parse.cc:
Removed some old types
Trivial move of code lines to make things more readable
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/sql_partition.cc:
Removed some old types
Removed compiler warnings about not used functions
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_partition.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_plugin.cc:
Removed some old types
Added missing casts for alloc()
Updated hash-get-key function arguments
sql/sql_prepare.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Added missing casts for alloc() and printf()
sql-common/client.c:
Removed some old types
Changed some memory areas to use uchar*
sql-common/my_user.c:
Changed some string lengths to use size_t
sql-common/pack.c:
Changed some buffers to be uchar* to avoid casts
sql/sql_repl.cc:
Added required casts
Changed some buffers to be uchar* to avoid casts
Changed some string lengths to use size_t
sql/sql_select.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some old types
sql/sql_select.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
sql/sql_servers.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_show.cc:
Removed some old types
Added missing casts for alloc()
Removed some not needed casts
sql/sql_string.cc:
Removed some old types
Added required casts
sql/sql_table.cc:
Removed some old types
Removed compiler warning about not used variable
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
sql/sql_test.cc:
Removed some old types
sql/sql_trigger.cc:
Removed some old types
Added missing casts for alloc()
sql/sql_udf.cc:
Removed some old types
Updated hash-get-key function arguments
sql/sql_union.cc:
Removed some old types
sql/sql_update.cc:
Removed some old types
Removed some not needed casts
sql/sql_view.cc:
Removed some old types
sql/sql_yacc.yy:
Removed some old types
Changed some string lengths to use size_t
Added missing casts for alloc()
sql/stacktrace.c:
Removed some old types
sql/stacktrace.h:
Removed some old types
sql/structs.h:
Removed some old types
sql/table.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
Removed setting of LEX_STRING() arguments in declaration
Added required casts
More function comments
Moved max_row_length() here from sql_class.cc/sql_class.h
sql/table.h:
Removed some old types
Changed some string lengths to use size_t
sql/thr_malloc.cc:
Use void* as type for allocated memory area
Changed all functions to use size_t
sql/tzfile.h:
Changed some buffers to be uchar* to avoid casts
sql/tztime.cc:
Changed some buffers to be uchar* to avoid casts
Updated hash-get-key function arguments
Added missing casts for alloc()
Removed some not needed casts
sql/uniques.cc:
Removed some old types
Removed some not needed casts
sql/unireg.cc:
Removed some old types
Changed some buffers to be uchar* to avoid casts
Removed some not needed casts
Added missing casts for alloc()
storage/archive/archive_reader.c:
Removed some old types
storage/archive/azio.c:
Removed some old types
Removed some not needed casts
storage/archive/ha_archive.cc:
Removed some old types
Changed type for 'frmblob' in archive_discover() to match handler
Updated hash-get-key function arguments
Removed some not needed casts
storage/archive/ha_archive.h:
Removed some old types
storage/blackhole/ha_blackhole.cc:
Removed some old types
storage/blackhole/ha_blackhole.h:
Removed some old types
storage/csv/ha_tina.cc:
Removed some old types
Updated hash-get-key function arguments
Changed some buffers to be uchar* to avoid casts
storage/csv/ha_tina.h:
Removed some old types
Removed some not needed casts
storage/csv/transparent_file.cc:
Removed some old types
Changed type of 'bytes_read' to be able to detect read errors
Fixed indentation
storage/csv/transparent_file.h:
Removed some old types
storage/example/ha_example.cc:
Removed some old types
Updated hash-get-key function arguments
storage/example/ha_example.h:
Removed some old types
storage/federated/ha_federated.cc:
Removed some old types
Updated hash-get-key function arguments
Removed some not needed casts
storage/federated/ha_federated.h:
Removed some old types
storage/heap/_check.c:
Changed some buffers to be uchar* to avoid casts
storage/heap/_rectest.c:
Removed some old types
storage/heap/ha_heap.cc:
Removed some old types
storage/heap/ha_heap.h:
Removed some old types
storage/heap/heapdef.h:
Removed some old types
storage/heap/hp_block.c:
Removed some old types
Changed some string lengths to use size_t
storage/heap/hp_clear.c:
Removed some old types
storage/heap/hp_close.c:
Removed some old types
storage/heap/hp_create.c:
Removed some old types
storage/heap/hp_delete.c:
Removed some old types
storage/heap/hp_hash.c:
Removed some old types
storage/heap/hp_info.c:
Removed some old types
storage/heap/hp_open.c:
Removed some old types
storage/heap/hp_rfirst.c:
Removed some old types
storage/heap/hp_rkey.c:
Removed some old types
storage/heap/hp_rlast.c:
Removed some old types
storage/heap/hp_rnext.c:
Removed some old types
storage/heap/hp_rprev.c:
Removed some old types
storage/heap/hp_rrnd.c:
Removed some old types
storage/heap/hp_rsame.c:
Removed some old types
storage/heap/hp_scan.c:
Removed some old types
storage/heap/hp_test1.c:
Removed some old types
storage/heap/hp_test2.c:
Removed some old types
storage/heap/hp_update.c:
Removed some old types
storage/heap/hp_write.c:
Removed some old types
Changed some string lengths to use size_t
storage/innobase/handler/ha_innodb.cc:
Removed some old types
Updated hash-get-key function arguments
Added missing casts for alloc() and printf()
Removed some not needed casts
storage/innobase/handler/ha_innodb.h:
Removed some old types
storage/myisam/ft_boolean_search.c:
Removed some old types
storage/myisam/ft_nlq_search.c:
Removed some old types
storage/myisam/ft_parser.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ft_static.c:
Removed some old types
storage/myisam/ft_stopwords.c:
Removed some old types
storage/myisam/ft_update.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/ftdefs.h:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/fulltext.h:
Removed some old types
storage/myisam/ha_myisam.cc:
Removed some old types
storage/myisam/ha_myisam.h:
Removed some old types
storage/myisam/mi_cache.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_check.c:
Removed some old types
storage/myisam/mi_checksum.c:
Removed some old types
storage/myisam/mi_close.c:
Removed some old types
storage/myisam/mi_create.c:
Removed some old types
storage/myisam/mi_delete.c:
Removed some old types
storage/myisam/mi_delete_all.c:
Removed some old types
storage/myisam/mi_dynrec.c:
Removed some old types
storage/myisam/mi_extra.c:
Removed some old types
storage/myisam/mi_key.c:
Removed some old types
storage/myisam/mi_locking.c:
Removed some old types
storage/myisam/mi_log.c:
Removed some old types
storage/myisam/mi_open.c:
Removed some old types
Removed some not needed casts
Check argument of my_write()/my_pwrite() in functions returning int
Added casting of string lengths to size_t
storage/myisam/mi_packrec.c:
Removed some old types
Changed some buffers to be uchar* to avoid casts
storage/myisam/mi_page.c:
Removed some old types
storage/myisam/mi_preload.c:
Removed some old types
storage/myisam/mi_range.c:
Removed some old types
storage/myisam/mi_rfirst.c:
Removed some old types
storage/myisam/mi_rkey.c:
Removed some old types
storage/myisam/mi_rlast.c:
Removed some old types
storage/myisam/mi_rnext.c:
Removed some old types
storage/myisam/mi_rnext_same.c:
Removed some old types
storage/myisam/mi_rprev.c:
Removed some old types
storage/myisam/mi_rrnd.c:
Removed some old types
storage/myisam/mi_rsame.c:
Removed some old types
storage/myisam/mi_rsamepos.c:
Removed some old types
storage/myisam/mi_scan.c:
Removed some old types
storage/myisam/mi_search.c:
Removed some old types
storage/myisam/mi_static.c:
Removed some old types
storage/myisam/mi_statrec.c:
Removed some old types
storage/myisam/mi_test1.c:
Removed some old types
storage/myisam/mi_test2.c:
Removed some old types
storage/myisam/mi_test3.c:
Removed some old types
storage/myisam/mi_unique.c:
Removed some old types
storage/myisam/mi_update.c:
Removed some old types
storage/myisam/mi_write.c:
Removed some old types
storage/myisam/myisam_ftdump.c:
Removed some old types
storage/myisam/myisamchk.c:
Removed some old types
storage/myisam/myisamdef.h:
Removed some old types
storage/myisam/myisamlog.c:
Removed some old types
Indentation fix
storage/myisam/myisampack.c:
Removed some old types
storage/myisam/rt_index.c:
Removed some old types
storage/myisam/rt_split.c:
Removed some old types
storage/myisam/sort.c:
Removed some old types
storage/myisam/sp_defs.h:
Removed some old types
storage/myisam/sp_key.c:
Removed some old types
storage/myisammrg/ha_myisammrg.cc:
Removed some old types
storage/myisammrg/ha_myisammrg.h:
Removed some old types
storage/myisammrg/myrg_close.c:
Removed some old types
storage/myisammrg/myrg_def.h:
Removed some old types
storage/myisammrg/myrg_delete.c:
Removed some old types
storage/myisammrg/myrg_open.c:
Removed some old types
Updated parameters to dirname_part()
storage/myisammrg/myrg_queue.c:
Removed some old types
storage/myisammrg/myrg_rfirst.c:
Removed some old types
storage/myisammrg/myrg_rkey.c:
Removed some old types
storage/myisammrg/myrg_rlast.c:
Removed some old types
storage/myisammrg/myrg_rnext.c:
Removed some old types
storage/myisammrg/myrg_rnext_same.c:
Removed some old types
storage/myisammrg/myrg_rprev.c:
Removed some old types
storage/myisammrg/myrg_rrnd.c:
Removed some old types
storage/myisammrg/myrg_rsame.c:
Removed some old types
storage/myisammrg/myrg_update.c:
Removed some old types
storage/myisammrg/myrg_write.c:
Removed some old types
storage/ndb/include/util/ndb_opts.h:
Removed some old types
storage/ndb/src/cw/cpcd/main.cpp:
Removed some old types
storage/ndb/src/kernel/vm/Configuration.cpp:
Removed some old types
storage/ndb/src/mgmclient/main.cpp:
Removed some old types
storage/ndb/src/mgmsrv/InitConfigFileParser.cpp:
Removed some old types
Removed old disabled code
storage/ndb/src/mgmsrv/main.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbBlob.cpp:
Removed some old types
storage/ndb/src/ndbapi/NdbOperationDefine.cpp:
Removed not used variable
storage/ndb/src/ndbapi/NdbOperationInt.cpp:
Added required casts
storage/ndb/src/ndbapi/NdbScanOperation.cpp:
Added required casts
storage/ndb/tools/delete_all.cpp:
Removed some old types
storage/ndb/tools/desc.cpp:
Removed some old types
storage/ndb/tools/drop_index.cpp:
Removed some old types
storage/ndb/tools/drop_tab.cpp:
Removed some old types
storage/ndb/tools/listTables.cpp:
Removed some old types
storage/ndb/tools/ndb_config.cpp:
Removed some old types
storage/ndb/tools/restore/consumer_restore.cpp:
Changed some buffers to be uchar* to avoid casts with new defintion of packfrm()
storage/ndb/tools/restore/restore_main.cpp:
Removed some old types
storage/ndb/tools/select_all.cpp:
Removed some old types
storage/ndb/tools/select_count.cpp:
Removed some old types
storage/ndb/tools/waiter.cpp:
Removed some old types
strings/bchange.c:
Changed function to use uchar * and size_t
strings/bcmp.c:
Changed function to use uchar * and size_t
strings/bmove512.c:
Changed function to use uchar * and size_t
strings/bmove_upp.c:
Changed function to use uchar * and size_t
strings/ctype-big5.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-bin.c:
Changed functions to use size_t
strings/ctype-cp932.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-czech.c:
Fixed indentation
Changed functions to use size_t
strings/ctype-euc_kr.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-eucjpms.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-gb2312.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-gbk.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-latin1.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-mb.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-simple.c:
Changed functions to use size_t
Simpler loops for caseup/casedown
unsigned int -> uint
unsigned char -> uchar
strings/ctype-sjis.c:
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-tis620.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-uca.c:
Changed functions to use size_t
unsigned char -> uchar
strings/ctype-ucs2.c:
Moved inclusion of stdarg.h to other includes
usigned char -> uchar
Changed functions to use size_t
Changed character length functions to return uint
strings/ctype-ujis.c:
Changed functions to use size_t
Changed character length functions to return uint
unsigned char -> uchar
strings/ctype-utf8.c:
Changed functions to use size_t
unsigned char -> uchar
Indentation fixes
strings/ctype-win1250ch.c:
Indentation fixes
Changed functions to use size_t
strings/ctype.c:
Changed functions to use size_t
strings/decimal.c:
Changed type for memory argument to uchar *
strings/do_ctype.c:
Indentation fixes
strings/my_strtoll10.c:
unsigned char -> uchar
strings/my_vsnprintf.c:
Changed functions to use size_t
strings/r_strinstr.c:
Removed some old types
Changed functions to use size_t
strings/str_test.c:
Removed some old types
strings/strappend.c:
Changed functions to use size_t
strings/strcont.c:
Removed some old types
strings/strfill.c:
Removed some old types
strings/strinstr.c:
Changed functions to use size_t
strings/strlen.c:
Changed functions to use size_t
strings/strmake.c:
Changed functions to use size_t
strings/strnlen.c:
Changed functions to use size_t
strings/strnmov.c:
Changed functions to use size_t
strings/strto.c:
unsigned char -> uchar
strings/strtod.c:
Changed functions to use size_t
strings/strxnmov.c:
Changed functions to use size_t
strings/xml.c:
Changed functions to use size_t
Indentation fixes
tests/mysql_client_test.c:
Removed some old types
tests/thread_test.c:
Removed some old types
vio/test-ssl.c:
Removed some old types
vio/test-sslclient.c:
Removed some old types
vio/test-sslserver.c:
Removed some old types
vio/vio.c:
Removed some old types
vio/vio_priv.h:
Removed some old types
Changed vio_read()/vio_write() to work with size_t
vio/viosocket.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viossl.c:
Changed vio_read()/vio_write() to work with size_t
Indentation fixes
vio/viosslfactories.c:
Removed some old types
vio/viotest-ssl.c:
Removed some old types
win/README:
More explanations
2007-05-10 11:59:39 +02:00
|
|
|
my_hash_insert(&m_sptabs, (uchar *)tab);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 20:37:45 +02: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
|
|
|
Add tables used by routine to the table list.
|
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
|
|
|
|
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
|
|
|
Converts multi-set of tables used by this routine to table list and adds
|
|
|
|
this list to the end of table list specified by 'query_tables_last_ptr'.
|
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
|
|
|
|
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
|
|
|
Elements of list will be allocated in PS memroot, so this list will be
|
|
|
|
persistent between PS executions.
|
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
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@param[in] thd Thread context
|
|
|
|
@param[in,out] query_tables_last_ptr Pointer to the next_global member of
|
|
|
|
last element of the list where tables
|
|
|
|
will be added (or to its root).
|
|
|
|
@param[in] belong_to_view Uppermost view which uses this routine,
|
|
|
|
0 if none.
|
|
|
|
|
|
|
|
@retval
|
|
|
|
TRUE if some elements were added
|
|
|
|
@retval
|
|
|
|
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
|
|
|
*/
|
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
|
|
|
|
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
|
|
|
bool
|
|
|
|
sp_head::add_used_tables_to_table_list(THD *thd,
|
2005-12-07 10:27:17 +01:00
|
|
|
TABLE_LIST ***query_tables_last_ptr,
|
|
|
|
TABLE_LIST *belong_to_view)
|
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
|
|
|
{
|
|
|
|
uint i;
|
2005-06-15 19:58:35 +02:00
|
|
|
Query_arena *arena, backup;
|
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
|
|
|
bool result= FALSE;
|
|
|
|
DBUG_ENTER("sp_head::add_used_tables_to_table_list");
|
|
|
|
|
|
|
|
/*
|
2005-11-17 01:51:14 +01:00
|
|
|
Use persistent arena for table list allocation to be PS/SP friendly.
|
|
|
|
Note that we also have to copy database/table names and alias to PS/SP
|
|
|
|
memory since current instance of sp_head object can pass away before
|
|
|
|
next execution of PS/SP for which tables are added to prelocking list.
|
|
|
|
This will be fixed by introducing of proper invalidation mechanism
|
|
|
|
once new TDC is ready.
|
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-02 15:21:19 +02:00
|
|
|
arena= thd->activate_stmt_arena_if_needed(&backup);
|
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
|
|
|
|
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
|
|
|
for (i=0 ; i < m_sptabs.records ; i++)
|
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
|
|
|
{
|
2005-11-17 01:51:14 +01:00
|
|
|
char *tab_buff, *key_buff;
|
2005-05-17 17:08:43 +02:00
|
|
|
TABLE_LIST *table;
|
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
|
|
|
SP_TABLE *stab= (SP_TABLE *)hash_element(&m_sptabs, i);
|
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
|
|
|
if (stab->temp)
|
|
|
|
continue;
|
|
|
|
|
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
|
|
|
if (!(tab_buff= (char *)thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST)) *
|
2005-11-17 01:51:14 +01:00
|
|
|
stab->lock_count)) ||
|
|
|
|
!(key_buff= (char*)thd->memdup(stab->qname.str,
|
|
|
|
stab->qname.length + 1)))
|
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
|
|
|
DBUG_RETURN(FALSE);
|
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
|
|
|
|
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
|
|
|
for (uint j= 0; j < stab->lock_count; j++)
|
|
|
|
{
|
|
|
|
table= (TABLE_LIST *)tab_buff;
|
|
|
|
|
2005-11-17 01:51:14 +01:00
|
|
|
table->db= key_buff;
|
2005-05-17 17:08:43 +02:00
|
|
|
table->db_length= stab->db_length;
|
|
|
|
table->table_name= table->db + table->db_length + 1;
|
|
|
|
table->table_name_length= stab->table_name_length;
|
|
|
|
table->alias= table->table_name + table->table_name_length + 1;
|
2005-04-15 18:31:47 +02:00
|
|
|
table->lock_type= stab->lock_type;
|
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
|
|
|
table->cacheable_table= 1;
|
|
|
|
table->prelocking_placeholder= 1;
|
2005-12-07 10:27:17 +01:00
|
|
|
table->belong_to_view= belong_to_view;
|
A fix and a test case for Bug#26141 mixing table types in trigger
causes full table lock on innodb table.
Also fixes Bug#28502 Triggers that update another innodb table
will block on X lock unnecessarily (duplciate).
Code review fixes.
Both bugs' synopses are misleading: InnoDB table is
not X locked. The statements, however, cannot proceed concurrently,
but this happens due to lock conflicts for tables used in triggers,
not for the InnoDB table.
If a user had an InnoDB table, and two triggers, AFTER UPDATE and
AFTER INSERT, competing for different resources (e.g. two distinct
MyISAM tables), then these two triggers would not be able to execute
concurrently. Moreover, INSERTS/UPDATES of the InnoDB table would
not be able to run concurrently.
The problem had other side-effects (see respective bug reports).
This behavior was a consequence of a shortcoming of the pre-locking
algorithm, which would not distinguish between different DML operations
(e.g. INSERT and DELETE) and pre-lock all the tables
that are used by any trigger defined on the subject table.
The idea of the fix is to extend the pre-locking algorithm to keep track,
for each table, what DML operation it is used for and not
load triggers that are known to never be fired.
mysql-test/r/trigger-trans.result:
Update results (Bug#26141)
mysql-test/r/trigger.result:
Update results (Bug#28502)
mysql-test/t/trigger-trans.test:
Add a test case for Bug#26141 mixing table types in trigger causes
full table lock on innodb table.
mysql-test/t/trigger.test:
Add a test case for Bug#28502 Triggers that update another innodb
table will block echo on X lock unnecessarily. Add more test
coverage for triggers.
sql/item.h:
enum trg_event_type is needed in table.h
sql/sp.cc:
Take into account table_list->trg_event_map when determining
what tables to pre-lock.
After this change, if we attempt to fire a
trigger for which we had not pre-locked any tables, error
'Table was not locked with LOCK TABLES' will be printed.
This, however, should never happen, provided the pre-locking
algorithm has no programming bugs.
Previously a trigger key in the sroutines hash was based on the name
of the table the trigger belongs to. This was possible because we would
always add to the pre-locking list all the triggers defined for a table when
handling this table.
Now the key is based on the name of the trigger, owing
to the fact that a trigger name must be unique in the database it
belongs to.
sql/sp_head.cc:
Generate sroutines hash key in init_spname(). This is a convenient
place since there we have all the necessary information and can
avoid an extra alloc.
Maintain and merge trg_event_map when adding and merging elements
of the pre-locking list.
sql/sp_head.h:
Add ,m_sroutines_key member, used when inserting the sphead for a
trigger into the cache of routines used by a statement.
Previously the key was based on the table name the trigger belonged
to, since for a given table we would add to the sroutines list
all the triggers defined on it.
sql/sql_lex.cc:
Introduce a new lex step: set_trg_event_type_for_tables().
It is called when we have finished parsing but before opening
and locking tables. Now this step is used to evaluate for each
TABLE_LIST instance which INSERT/UPDATE/DELETE operation, if any,
it is used in.
In future this method could be extended to aggregate other information
that is hard to aggregate during parsing.
sql/sql_lex.h:
Add declaration for set_trg_event_type_for_tables().
sql/sql_parse.cc:
Call set_trg_event_type_for_tables() after MYSQLparse(). Remove tabs.
sql/sql_prepare.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_trigger.h:
Remove an obsolete member.
sql/sql_view.cc:
Call set_trg_event_type_for_tables() after MYSQLparse().
sql/sql_yacc.yy:
Move assignment of sp_head::m_type before calling sp_head::init_spname(),
one is now used inside another.
sql/table.cc:
Implement TABLE_LIST::set_trg_event_map() - a method that calculates
wh triggers may be fired on this table when executing a statement.
sql/table.h:
Add missing declarations.
Move declaration of trg_event_type from item.h (it will be needed for
trg_event_map bitmap when we start using Bitmap template instead
of uint8).
2007-07-12 20:26:41 +02:00
|
|
|
table->trg_event_map= stab->trg_event_map;
|
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
|
|
|
|
|
|
|
/* Everyting else should be zeroed */
|
|
|
|
|
|
|
|
**query_tables_last_ptr= table;
|
|
|
|
table->prev_global= *query_tables_last_ptr;
|
|
|
|
*query_tables_last_ptr= &table->next_global;
|
|
|
|
|
|
|
|
tab_buff+= ALIGN_SIZE(sizeof(TABLE_LIST));
|
|
|
|
result= TRUE;
|
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
|
|
|
|
if (arena)
|
2005-09-02 15:21:19 +02:00
|
|
|
thd->restore_active_arena(arena, &backup);
|
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
|
|
|
|
|
|
|
DBUG_RETURN(result);
|
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
|
|
|
}
|
|
|
|
|
2005-08-11 14:58:15 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2005-08-11 14:58:15 +02:00
|
|
|
Simple function for adding an explicetly named (systems) table to
|
|
|
|
the global table list, e.g. "mysql", "proc".
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
TABLE_LIST *
|
|
|
|
sp_add_to_query_tables(THD *thd, LEX *lex,
|
|
|
|
const char *db, const char *name,
|
|
|
|
thr_lock_type locktype)
|
|
|
|
{
|
|
|
|
TABLE_LIST *table;
|
|
|
|
|
|
|
|
if (!(table= (TABLE_LIST *)thd->calloc(sizeof(TABLE_LIST))))
|
|
|
|
{
|
2007-11-19 17:59:44 +01:00
|
|
|
thd->fatal_error();
|
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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
table->db_length= strlen(db);
|
|
|
|
table->db= thd->strmake(db, table->db_length);
|
|
|
|
table->table_name_length= strlen(name);
|
|
|
|
table->table_name= thd->strmake(name, table->table_name_length);
|
|
|
|
table->alias= thd->strdup(name);
|
|
|
|
table->lock_type= locktype;
|
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->select_lex= lex->current_select;
|
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
|
|
|
table->cacheable_table= 1;
|
|
|
|
|
|
|
|
lex->add_to_query_tables(table);
|
|
|
|
return table;
|
|
|
|
}
|
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
|
|
|
|