mysql-test/r/sp-threads.result:
Testcase for BUG#12228
mysql-test/t/sp-threads.test:
Testcase for BUG#12228
sql/sp_cache.cc:
BUG#12228: Post-review fixes: small code cleanup
sql/sp_cache.h:
BUG#12228: Post-review fixes: fixed the comment
sql/sql_parse.cc:
BUG#12228: Post-review fixes: in mysql_parse, flush obsolete SPs from the caches only if
the query hasn't been handled by the query cache.
sql/sql_prepare.cc:
BUG#12228: Post-review fixes: in mysql_stmt_prepare/execute, flush SP caches
"closer to the execution"
its body, but lets each statement to get/release its own locks. This allows a broader set
of statements to be executed inside PROCEDUREs (but breaks replication)
This patch should fix BUG#8072, BUG#8766, BUG#9563, BUG#11126
mysql-test/r/sp-security.result:
Drop tables this test attempts to create
mysql-test/r/sp-threads.result:
Update test results
mysql-test/r/sp.result:
Disabled a test that triggers BUG#11986, cleanup used tables when tests start.
mysql-test/r/view.result:
Enabled a test case that now works with prelocking-free SPs
mysql-test/t/sp-security.test:
Drop tables this test attempts to create
mysql-test/t/sp.test:
Disabled a test that triggers BUG#11986, cleanup used tables when tests start.
mysql-test/t/view.test:
Enabled a test case that now works with prelocking-free SPs
sql/handler.cc:
Rename: thd->transaction.in_sub_stmt -> thd->in_sub_stmt
sql/item_func.cc:
Rename: thd->transaction.in_sub_stmt -> thd->in_sub_stmt
sql/sp.cc:
Non-prelocked SP execution: Added support for skipping prelocking of procedure body for
"CALL proc(...)" statements.
sql/sp.h:
Non-prelocked SP execution: Added support for skipping prelocking of procedure body for
"CALL proc(...)" statements.
sql/sp_cache.h:
Added comments
sql/sp_head.cc:
Non-prelocked SP execution:
* Try to unlock tables after PROCEDURE arguments have been evaluated.
* Make sp_lex_keeper be able to execute in 2 modes: A) when already in prelocked mode
B) when its statement enters/leaves prelocked mode itself.
sql/sp_head.h:
Non-prelocked SP execution: Make sp_lex_keeper to additionally keep list of tables it
needs to prelock when its statement enters/leaves prelocked mode on its own.
sql/sql_base.cc:
Non-prelocked SP execution: Make open_tables() to
* detect 'CALL proc(...)' and not to do prelocking for procedure body statements.
* Make lex->query_tables_last to point precisely to a boundary in lex->query_tables
list where 'own' tables and views' tables end and added-for-prelocking tables begin.
(it was not true before - view's tables could end up after query_tables_own_last)
sql/sql_class.cc:
Rename: thd->transaction.in_sub_stmt -> thd->in_sub_stmt
sql/sql_class.h:
Rename: thd->transaction.in_sub_stmt -> thd->in_sub_stmt
sql/sql_lex.cc:
Non-prelocked SP execution: More rigourous cleanup in st_lex::cleanup_after_one_table_open()
sql/sql_parse.cc:
Rename: thd->transaction.in_sub_stmt -> thd->in_sub_stmt, remove outdated comments
sql/sql_trigger.h:
Rename: thd->transaction.in_sub_stmt -> thd->in_sub_stmt
of stored routines definitions even if we already have some tables open and
locked. To avoid deadlocks in this case we have to put certain restrictions
on locking of mysql.proc table.
This allows to use stored routines safely under LOCK TABLES without explicitly
mentioning mysql.proc in the list of locked tables. It also fixes bug #11554
"Server crashes on statement indirectly using non-cached function".
mysql-test/r/sp-error.result:
Added test which checks that now we can read stored routines definitions
under LOCK TABLES even if we have not locked mysql.proc explicitly. Also
added check for restrictions which this ability puts on mysql.proc locking.
Updated test for bug #9566 to correspond this new situation.
mysql-test/r/sp-threads.result:
Added test for bug #11554 "Server crashes on statement indirectly using
non-cached function".
mysql-test/t/sp-error.test:
Added test which checks that now we can read stored routines definitions
under LOCK TABLES even if we have not locked mysql.proc explicitly. Also
added check for restrictions which this ability puts on mysql.proc locking.
Updated test for bug #9566 to correspond this new situation.
mysql-test/t/sp-threads.test:
Added test for bug #11554 "Server crashes on statement indirectly using
non-cached function".
sql/lock.cc:
get_lock_data():
To be able to open and lock for reading system tables like 'mysql.proc',
when we already have some tables opened and locked, and avoid deadlocks
we have to disallow write-locking of these tables with any other tables.
sql/mysql_priv.h:
open_table() has new parameter which allows to open table even if some-one
has done a flush or holding namelock on it.
sql/share/errmsg.txt:
Added error message saying that one cannot write-lock some of system tables
with any other tables.
sql/sp.cc:
open_proc_table_for_read()/close_proc_table():
Added functions to be able open and close mysql.proc table when we already
have some tables open and locked.
open_proc_table_for_update():
Added function to simplify opening of mysql.proc for updates.
db_find_routine_aux()/db_find_routine()/db_update_routine()/...
Moved responsibility for opening mysql.proc table from db_find_routine_aux()
one level up, since this level knows better which type of table access for
reading of for update it needs.
sp_function_exists():
Removed unused function.
sql/sp.h:
sp_function_exists():
Removed unused function.
sql/sql_base.cc:
open_table():
Added new parameter which allows to open table even if some-one has done a
flush or holding namelock on it.
open_unireg_entry():
Mark 'mysql.proc' as a system table which has special restrictions on its
locking, but thanks to them can be open and locked even if we already have
some open and locked.
sql/sql_class.cc:
Moved THD members holding information about open and locked tables to separate
Open_tables_state class to be able to save/restore this state easier.
Added THD::push_open_tables_state()/pop_open_tables_state() methods for
saving/restoring this state.
sql/sql_class.h:
Moved THD members holding information about open and locked tables to separate
Open_tables_state class to be able to save/restore this state easier.
Added THD::push_open_tables_state()/pop_open_tables_state() methods for
saving/restoring this state.
sql/sql_lex.cc:
Removed LEX::proc_table member which was not really used.
sql/sql_lex.h:
Removed LEX::proc_table member which was not really used.
sql/sql_table.cc:
open_table() has new parameter which allows to open table even if some-one
has done a flush or holding namelock on it.
sql/table.h:
Added TABLE_SHARE::system_table indicating that this table is system table
like 'mysql.proc' and we want to be able to open and read-lock it even when
we already have some tables open and locked (and because of this we have
to put some restrictions on write locking it).
In order to make multi-delete SP friendly we need to have all table
locks for the elements of main statement table list properly set
at the end of parsing.
Also performed small cleanup: We don't need relink_tables_for_multidelete()
any longer since the only case now when TABLE_LIST::correspondent_table
is non-zero are tables in auxilary table list of multi-delete and these
tables are handled specially in mysql_multi_delete_prepare().
mysql-test/r/sp-threads.result:
Added test case for bug #11158 "Can't perform multi-delete in stored
procedure".
mysql-test/t/sp-threads.test:
Added test case for bug #11158 "Can't perform multi-delete in stored
procedure".
sql/mysql_priv.h:
- Removed third argument from the declaration of multi_delete_precheck()
as nowdays we calculate number of tables in multi-delete from which
we are going to delete rows right at the end of statement parsing.
- Introduced definition of multi_delete_set_locks_and_link_aux_tables()
which is responsible for propagation of proper table locks from
multi-delete's auxilary table list to the main list and binding
corresponding tables in these two lists.
sql/sql_base.cc:
Removed relink_tables_for_multidelete() routine and its invocations.
We don't need them in 5.0 since the only case now when
TABLE_LIST::correspondent_table is non-zero are tables in auxilary table
list of multi-delete and these tables are handled specially in
mysql_multi_delete_prepare().
sql/sql_lex.h:
LEX::table_count
Added description of new role of this LEX member for multi-delete.
Now for this statement we store number of tables from which we should
delete records there.
sql/sql_parse.cc:
multi_delete_precheck():
Moved code which is responsible for iterating through auxilary table
list and binding its elements with corresponding elements of main
table list, and properly updating locks in it to separate function -
multi_delete_set_locks_and_link_aux_tables(). This is because in order
to make multi-delete SP friendly we need to have all locks set properly
at the end of statement parsing. So we are introducing new function
which will be called from parser.
We also calculate number of tables from which we are going to perform
deletions there and store this number for later usage in
LEX::table_count.
Also removed some no longer needed code.
sql/sql_prepare.cc:
mysql_test_multidelete():
Now multi_delete_precheck() takes only two arguments, so we don't
need to pass fake third parameter.
sql/sql_yacc.yy:
delete:
In order to make multi-delete SP friendly we need to have all table
locks for the elements of main statement table list properly set
at the end of parsing.
New more SP-locking friendly approach to handling locks in multi-update.
Now we mark all tables of multi-update as needing write lock at parsing
stage and if possible downgrade lock at execution stage (For its work
SP-locking mechanism needs to know all lock types right after parsing
stage).
mysql-test/r/sp-threads.result:
Added test for bug #9486 "Can't perform multi-update in stored procedure".
mysql-test/t/sp-threads.test:
Added test for bug #9486 "Can't perform multi-update in stored procedure".
sql/sp_head.cc:
SP_TABLE, sp_head::merge_table_list()/add_used_tables_to_table_list():
Since some queries during their execution (e.g. multi-update)
may change type of lock for some of their tables and thus change
lock_type member for some of elements of table list, we should
store type of lock in SP_TABLE struct explicitly instead of using
lock_type member of TABLE_LIST object pointed by SP_TABLE::table.
sql/sql_lex.h:
Removed no longer used LEX::multi_lock_option member.
sql/sql_prepare.cc:
mysql_test_update():
We don't need to bother about LEX::multi_lock_option if we convert
multi-update to update anymore. Since nowdays multi-update uses
TABLE_LIST::lock_type for specifying lock level of updated tables
instead of LEX::multi_lock_option.
sql/sql_update.cc:
mysql_update()/mysql_multi_update_prepare():
Now we mark all tables of multi-update as needing write lock at parsing
stage and if possible downgrade lock at execution stage. Old approach
(don't set lock type until execution stage) was not working well with
SP-locking (For its work SP-locking mechanism needs to know all lock
types right after parsing stage).
mysql_multi_update():
We should return FALSE if no error occurs.
sql/sql_yacc.yy:
update:
Now we mark all tables of multi-update as needing write lock at parsing
stage and if possible downgrade lock at execution stage. Old approach
(don't set lock type until execution stage) was not working well with
SP-locking (For its work SP-locking mechanism needs to know all lock
types right after parsing stage).
...and added new test file, sp-threads, for multiple connection tests
(apart from the security tests that are in sp-security).
sql/sp.cc:
When removing an SP, invalidate the caches even if the
removing thread doesn't have one.