mariadb/sql
Konstantin Osipov 36290c0923 A pre-requisite patch for the fix for Bug#52044.
This patch also fixes Bug#55452 "SET PASSWORD is
replicated twice in RBR mode".

The goal of this patch is to remove the release of 
metadata locks from close_thread_tables().
This is necessary to not mistakenly release
the locks in the course of a multi-step
operation that involves multiple close_thread_tables()
or close_tables_for_reopen().

On the same token, move statement commit outside 
close_thread_tables().

Other cleanups:
Cleanup COM_FIELD_LIST.
Don't call close_thread_tables() in COM_SHUTDOWN -- there
are no open tables there that can be closed (we leave
the locked tables mode in THD destructor, and this
close_thread_tables() won't leave it anyway).

Make open_and_lock_tables() and open_and_lock_tables_derived()
call close_thread_tables() upon failure.
Remove the calls to close_thread_tables() that are now
unnecessary.

Simplify the back off condition in Open_table_context.

Streamline metadata lock handling in LOCK TABLES 
implementation.

Add asserts to ensure correct life cycle of 
statement transaction in a session.

Remove a piece of dead code that has also become redundant
after the fix for Bug 37521.

mysql-test/r/variables.result:
  Update results: set @@autocommit and statement transaction/
  prelocked mode.
mysql-test/r/view.result:
  A harmless change in CHECK TABLE <view> status for a broken view.
  If previously a failure to prelock all functions used in a view 
  would leave the connection in LTM_PRELOCKED mode, now we call
  close_thread_tables() from open_and_lock_tables()
  and leave prelocked mode, thus some check in mysql_admin_table() that
  works only in prelocked/locked tables mode is no longer activated.
mysql-test/suite/rpl/r/rpl_row_implicit_commit_binlog.result:
  Fixed Bug#55452 "SET PASSWORD is replicated twice in
  RBR mode": extra binlog events are gone from the
  binary log.
mysql-test/t/variables.test:
  Add a test case: set autocommit and statement transaction/prelocked
  mode.
sql/event_data_objects.cc:
  Simplify code in Event_job_data::execute().
  Move sp_head memory management to lex_end().
sql/event_db_repository.cc:
  Move the release of metadata locks outside
  close_thread_tables().
  Make sure we call close_thread_tables() when
  open_and_lock_tables() fails and remove extra
  code from the events data dictionary.
  Use close_mysql_tables(), a new internal
  function to properly close mysql.* tables
  in the data dictionary.
  Contract Event_db_repository::drop_events_by_field,
  drop_schema_events into one function.
  When dropping all events in a schema,
  make sure we don't mistakenly release all
  locks acquired by DROP DATABASE. These
  include locks on the database name
  and the global intention exclusive
  metadata lock.
sql/event_db_repository.h:
  Function open_event_table() does not require an instance 
  of Event_db_repository.
sql/events.cc:
  Use close_mysql_tables() instead of close_thread_tables()
  to bootstrap events, since the latter no longer
  releases metadata locks.
sql/ha_ndbcluster.cc:
  - mysql_rm_table_part2 no longer releases
  acquired metadata locks. Do it in the caller.
sql/ha_ndbcluster_binlog.cc:
  Deploy the new protocol for closing thread
  tables in run_query() and ndb_binlog_index
  code.
sql/handler.cc:
  Assert that we never call ha_commit_trans/
  ha_rollback_trans in sub-statement, which
  is now the case.
sql/handler.h:
  Add an accessor to check whether THD_TRANS object
  is empty (has no transaction started).
sql/log.cc:
  Update a comment.
sql/log_event.cc:
  Since now we commit/rollback statement transaction in 
  mysql_execute_command(), we need a mechanism to communicate
  from Query_log_event::do_apply_event() to mysql_execute_command()
  that the statement transaction should be rolled back, not committed.
  Ideally it would be a virtual method of THD. I hesitate
  to make THD a virtual base class in this already large patch.
  Use a thd->variables.option_bits for now.
  
  Remove a call to close_thread_tables() from the slave IO
  thread. It doesn't open any tables, and the protocol
  for closing thread tables is more complicated now.
  
  Make sure we properly close thread tables, however, 
  in Load_data_log_event, which doesn't
  follow the standard server execution procedure
  with mysql_execute_command().
  @todo: this piece should use Server_runnable
  framework instead.
  Remove an unnecessary call to mysql_unlock_tables().
sql/rpl_rli.cc:
  Update Relay_log_info::slave_close_thread_tables()
  to follow the new close protocol.
sql/set_var.cc:
  Remove an unused header.
sql/slave.cc:
  Remove an unnecessary call to
  close_thread_tables().
sql/sp.cc:
  Remove unnecessary calls to close_thread_tables()
  from SP DDL implementation. The tables will
  be closed by the caller, in mysql_execute_command().
  When dropping all routines in a database, make sure
  to not mistakenly drop all metadata locks acquired
  so far, they include the scoped lock on the schema.
sql/sp_head.cc:
  Correct the protocol that closes thread tables
  in an SP instruction.
  Clear lex->sphead before cleaning up lex
  with lex_end to make sure that we don't
  delete the sphead twice. It's considered
  to be "cleaner" and more in line with
  future changes than calling delete lex->sphead
  in other places that cleanup the lex.
sql/sp_head.h:
  When destroying m_lex_keeper of an instruction,
  don't delete the sphead that all lex objects
  share. 
  @todo: don't store a reference to routine's sp_head
  instance in instruction's lex.
sql/sql_acl.cc:
  Don't call close_thread_tables() where the caller will
  do that for us.
  Fix Bug#55452 "SET PASSWORD is replicated twice in RBR 
  mode" by disabling RBR replication in change_password()
  function.
  Use close_mysql_tables() in bootstrap and ACL reload
  code to make sure we release all metadata locks.
sql/sql_base.cc:
  This is the main part of the patch:
  - remove manipulation with thd->transaction
  and thd->mdl_context from close_thread_tables().
  Now this function is only responsible for closing
  tables, nothing else.
  This is necessary to be able to easily use
  close_thread_tables() in procedures, that
  involve multiple open/close tables, which all
  need to be protected continuously by metadata
  locks.
  Add asserts ensuring that TABLE object
  is only used when is protected by a metadata lock.
  Simplify the back off condition of Open_table_context,
  we no longer need to look at the autocommit mode.
  Make open_and_lock_tables() and open_normal_and_derived_tables()
  close thread tables and release metadata locks acquired so-far 
  upon failure. This simplifies their usage.
  Implement close_mysql_tables().
sql/sql_base.h:
  Add declaration for close_mysql_tables().
sql/sql_class.cc:
  Remove a piece of dead code that has also become redundant
  after the fix for Bug 37521.
  The code became dead when my_eof() was made a non-protocol method,
  but a method that merely modifies the diagnostics area.
  The code became redundant with the fix for Bug#37521, when 
  we started to cal close_thread_tables() before
  Protocol::end_statement().
sql/sql_do.cc:
  Do nothing in DO if inside a substatement
  (the assert moved out of trans_rollback_stmt).
sql/sql_handler.cc:
  Add comments.
sql/sql_insert.cc:
  Remove dead code. 
  Release metadata locks explicitly at the
  end of the delayed insert thread.
sql/sql_lex.cc:
  Add destruction of lex->sphead to lex_end(),
  lex "reset" method called at the end of each statement.
sql/sql_parse.cc:
  Move close_thread_tables() and other related
  cleanups to mysql_execute_command()
  from dispatch_command(). This has become
  possible after the fix for Bug#37521.
  Mark federated SERVER statements as DDL.
  
  Next step: make sure that we don't store
  eof packet in the query cache, and move
  the query cache code outside mysql_parse.
  
  Brush up the code of COM_FIELD_LIST.
  Remove unnecessary calls to close_thread_tables().
  
  When killing a query, don't report "OK"
  if it was a suicide.
sql/sql_parse.h:
  Remove declaration of a function that is now static.
sql/sql_partition.cc:
  Remove an unnecessary call to close_thread_tables().
sql/sql_plugin.cc:
  open_and_lock_tables() will clean up
  after itself after a failure.
  Move close_thread_tables() above
  end: label, and replace with close_mysql_tables(),
  which will also release the metadata lock
  on mysql.plugin.
sql/sql_prepare.cc:
  Now that we no longer release locks in close_thread_tables()
  statement prepare code has become more straightforward.
  Remove the now redundant check for thd->killed() (used
  only by the backup project) from Execute_server_runnable.
  Reorder code to take into account that now mysql_execute_command()
  performs lex->unit.cleanup() and close_thread_tables().
sql/sql_priv.h:
  Add a new option to server options to interact
  between the slave SQL thread and execution
  framework (hack). @todo: use a virtual
  method of class THD instead.
sql/sql_servers.cc:
  Due to Bug 25705 replication of 
  DROP/CREATE/ALTER SERVER is broken.
  Make sure at least we do not attempt to 
  replicate these statements using RBR,
  as this violates the assert in close_mysql_tables().
sql/sql_table.cc:
  Do not release metadata locks in mysql_rm_table_part2,
  this is done by the caller.
  Do not call close_thread_tables() in mysql_create_table(),
  this is done by the caller. 
  Fix a bug in DROP TABLE under LOCK TABLES when,
  upon error in wait_while_table_is_used() we would mistakenly
  release the metadata lock on a non-dropped table.
  Explicitly release metadata locks when doing an implicit
  commit.
sql/sql_trigger.cc:
  Now that we delete lex->sphead in lex_end(),
  zero the trigger's sphead in lex after loading
  the trigger, to avoid double deletion.
sql/sql_udf.cc:
  Use close_mysql_tables() instead of close_thread_tables().
sql/sys_vars.cc:
  Remove code added in scope of WL#4284 which would
  break when we perform set @@session.autocommit along
  with setting other variables and using tables or functions.
  A test case added to variables.test.
sql/transaction.cc:
  Add asserts.
sql/tztime.cc:
  Use close_mysql_tables() rather than close_thread_tables().
2010-07-27 14:25:53 +04:00
..
examples Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
share
add_errmsg
authors.h
client_settings.h
CMakeLists.txt Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
contributors.h
custom_conf.h
datadict.cc
datadict.h
debug_sync.cc
debug_sync.h
derror.cc
derror.h
des_key_file.cc
des_key_file.h
discover.cc
discover.h
event_data_objects.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
event_data_objects.h
event_db_repository.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
event_db_repository.h A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
event_parse_data.cc
event_parse_data.h
event_queue.cc
event_queue.h
event_scheduler.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
event_scheduler.h
events.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
events.h
field.cc
field.h
field_conv.cc
filesort.cc
filesort.h
frm_crypt.cc
frm_crypt.h
gen_lex_hash.cc
gstream.cc
gstream.h
ha_ndbcluster.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
ha_ndbcluster.h
ha_ndbcluster_binlog.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
ha_ndbcluster_binlog.h
ha_ndbcluster_cond.cc
ha_ndbcluster_cond.h
ha_ndbcluster_tables.h
ha_partition.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
ha_partition.h
handler.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
handler.h A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
hash_filo.cc
hash_filo.h
hostname.cc
hostname.h
init.cc
init.h
item.cc
item.h
item_buff.cc
item_cmpfunc.cc
item_cmpfunc.h
item_create.cc
item_create.h
item_func.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
item_func.h
item_geofunc.cc
item_geofunc.h
item_row.cc
item_row.h
item_strfunc.cc
item_strfunc.h
item_subselect.cc
item_subselect.h
item_sum.cc
item_sum.h
item_timefunc.cc
item_timefunc.h
item_xmlfunc.cc
item_xmlfunc.h
key.cc
key.h
keycaches.cc
keycaches.h
lex.h
lex_symbol.h
lock.cc
lock.h
log.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
log.h
log_event.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
log_event.h Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
log_event_old.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
log_event_old.h
main.cc
Makefile.am
mdl.cc Bug #55223 assert in Protocol::end_statement during CREATE DATABASE 2010-07-22 10:00:32 +02:00
mdl.h Bug #55223 assert in Protocol::end_statement during CREATE DATABASE 2010-07-22 10:00:32 +02:00
message.h
message.mc
message.rc
mf_iocache.cc
MSG00001.bin
my_decimal.cc
my_decimal.h
mysqld.cc merge from mysql-trunk-bugfixing 2010-07-19 10:27:53 +02:00
mysqld.h
mysqld_suffix.h
net_serv.cc
nt_servc.cc
nt_servc.h
opt_range.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
opt_range.h Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
opt_sum.cc
parse_file.cc
parse_file.h
partition_element.h
partition_info.cc
partition_info.h
password.c
procedure.cc
procedure.h
protocol.cc
protocol.h
records.cc
records.h
repl_failsafe.cc
repl_failsafe.h
replication.h
rpl_constants.h
rpl_filter.cc
rpl_filter.h
rpl_handler.cc Bug#42733: Type-punning warnings when compiling MySQL -- strict aliasing violations. 2010-07-15 16:29:25 -03:00
rpl_handler.h
rpl_injector.cc
rpl_injector.h
rpl_mi.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
rpl_mi.h
rpl_record.cc
rpl_record.h
rpl_record_old.cc
rpl_record_old.h
rpl_reporting.cc
rpl_reporting.h
rpl_rli.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
rpl_rli.h
rpl_tblmap.cc
rpl_tblmap.h
rpl_utility.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
rpl_utility.h
scheduler.cc
scheduler.h
set_var.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
set_var.h
sha2.cc
slave.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
slave.h
sp.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sp.h
sp_cache.cc
sp_cache.h
sp_head.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sp_head.h A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sp_pcontext.cc
sp_pcontext.h
sp_rcontext.cc
sp_rcontext.h
spatial.cc
spatial.h
sql_acl.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_acl.h
sql_analyse.cc
sql_analyse.h
sql_array.h
sql_audit.cc
sql_audit.h
sql_base.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_base.h A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_binlog.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
sql_binlog.h
sql_bitmap.h
sql_builtin.cc.in
sql_cache.cc
sql_cache.h
sql_class.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_class.h Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
sql_client.cc
sql_connect.cc
sql_connect.h
sql_const.h
sql_crypt.cc
sql_crypt.h
sql_cursor.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_cursor.h
sql_db.cc
sql_db.h
sql_delete.cc
sql_delete.h
sql_derived.cc
sql_derived.h
sql_do.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_do.h
sql_error.cc
sql_error.h
sql_handler.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_handler.h
sql_help.cc
sql_help.h
sql_hset.h
sql_insert.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_insert.h
sql_lex.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_lex.h
sql_list.cc
sql_list.h Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
sql_load.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
sql_load.h
sql_locale.cc
sql_locale.h
sql_manager.cc
sql_manager.h
sql_map.cc
sql_map.h
sql_olap.cc
sql_parse.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_parse.h A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_partition.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_partition.h
sql_plist.h
sql_plugin.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_plugin.h
sql_plugin_services.h
sql_prepare.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_prepare.h
sql_priv.h A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_profile.cc
sql_profile.h
sql_rename.cc
sql_rename.h
sql_repl.cc
sql_repl.h
sql_select.cc Merge of mysql-trunk-bugfixing into mysql-trunk-merge. 2010-07-15 10:47:50 -03:00
sql_select.h
sql_servers.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_servers.h
sql_show.cc Bug #55498 SHOW CREATE TRIGGER takes wrong type of metadata lock 2010-07-23 10:44:55 +02:00
sql_show.h
sql_signal.cc
sql_signal.h
sql_sort.h
sql_state.c
sql_string.cc
sql_string.h
sql_table.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_table.h
sql_tablespace.cc
sql_tablespace.h
sql_test.cc
sql_test.h
sql_time.cc
sql_time.h
sql_trigger.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_trigger.h
sql_truncate.cc
sql_truncate.h
sql_udf.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sql_udf.h
sql_union.cc
sql_union.h
sql_update.cc
sql_update.h
sql_view.cc
sql_view.h
sql_yacc.yy merge from mysql-trunk-bugfixing 2010-07-19 10:27:53 +02:00
strfunc.cc
strfunc.h
structs.h
sys_vars.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
sys_vars.h Bug#45288: pb2 returns a lot of compilation warnings on linux 2010-07-15 14:45:08 -03:00
sys_vars_shared.h
table.cc
table.h
thr_malloc.cc
thr_malloc.h
transaction.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
transaction.h
tzfile.h
tztime.cc A pre-requisite patch for the fix for Bug#52044. 2010-07-27 14:25:53 +04:00
tztime.h
udf_example.c
udf_example.def
uniques.cc
unireg.cc
unireg.h