Commit graph

257 commits

Author SHA1 Message Date
Alexander Barkov
46d076d67a MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations 2017-04-05 15:02:54 +04:00
Monty
5f0c31f928 MDEV-11597 Assertion when doing select from virtual column with impossible value
- Changed error handlers interface so that they can change error level in
  the handler
- Give warnings and errors when calculating virtual columns
- On insert/update error is fatal in strict mode.
- SELECT and DELETE will only give a warning if a virtual field generates an error
- Added VCOL_UPDATE_FOR_DELETE and VCOL_UPDATE_INDEX_FOR_REPLACE to be able to
  easily detect in update_virtual_fields() if we should use an error
  handler to mask errors or not.
2017-01-11 09:19:45 +02:00
Sergei Golubchik
54ab7db733 cleanup: remove now-unused TABLE::merge_keys 2016-12-12 20:27:37 +01:00
Sergei Golubchik
9a3ec79b53 cleanup: TABLE::update_virtual_fields
Make update_virtual_fields() a method of TABLE, to be consistent
with TABLE::update_default_fields().
2016-12-12 20:27:33 +01:00
Monty
8be53a389c MDEV-6112 multiple triggers per table
This is similar to MysQL Worklog 3253, but with
a different implementation. The disk format and
SQL syntax is identical with MySQL 5.7.

Fetures supported:
- "Any" ammount of any trigger
- Supports FOLLOWS and PRECEDES to be
  able to put triggers in a certain execution order.

Implementation details:
- Class Trigger added to hold information about a trigger.
  Before this trigger information was stored in a set of lists in
  Table_triggers_list and in Table_triggers_list::bodies
- Each Trigger has a next field that poinst to the next Trigger with the
  same action and time.
- When accessing a trigger, we now always access all linked triggers
- The list are now only used to load and save trigger files.
- MySQL trigger test case (trigger_wl3253) added and we execute these
  identically.
- Even more gracefully handling of wrong trigger files than before. This
  is useful if a trigger file uses functions or syntax not provided by
  the server.
- Each trigger now has a "Created" field that shows when the trigger was
  created, with 2 decimals.

Other comments:
- Many of the changes in test files was done because of the new "Created"
  field in the trigger file. This shows up in SHOW ... TRIGGER and when
  using information_schema.trigger.
- Don't check if all memory is released if on uses --gdb;  This is needed
  to be able to get a list from safemalloc of not freed memory while
  debugging.
- Added option to trim_whitespace() to know how many prefix characters
  was skipped.
- Changed a few ulonglong sql_mode to sql_mode_t, to find some wrong usage
  of sql_mode.
2016-10-05 01:11:07 +03:00
Sergei Golubchik
f93a2a3b3b various cleanups
* remove a confusing method name - Field::set_default_expression()
* remove handler::register_columns_for_write()
* rename stuff
* add asserts
* remove unlikely unlikely
* remove redundant if() conditions
* fix mark_unsupported_function() to report the most important violation
* don't scan vfield list for default values (vfields don't have defaults)
* move handling for DROP CONSTRAINT IF EXIST where it belongs
* don't protect engines from Alter_inplace_info::ALTER_ADD_CONSTRAINT
* comments
2016-06-30 11:43:02 +02:00
Michael Widenius
db7edfed17 MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard
MDEV-10134 Add full support for DEFAULT

- Added support for using tables with MySQL 5.7 virtual fields,
  including MySQL 5.7 syntax
- Better error messages also for old cases
- CREATE ... SELECT now also updates timestamp columns
- Blob can now have default values
- Added new system variable "check_constraint_checks", to turn of
  CHECK constraint checking if needed.
- Removed some engine independent tests in suite vcol to only test myisam
- Moved some tests from 'include' to 't'. Should some day be done for all tests.
- FRM version increased to 11 if one uses virtual fields or constraints
- Changed to use a bitmap to check if a field has got a value, instead of
  setting HAS_EXPLICIT_VALUE bit in field flags
- Expressions can now be up to 65K in total
- Ensure we are not refering to uninitialized fields when handling virtual fields or defaults
- Changed check_vcol_func_processor() to return a bitmap of used types
- Had to change some functions that calculated cached value in fix_fields to do
  this in val() or getdate() instead.
- store_now_in_TIME() now takes a THD argument
- fill_record() now updates default values
- Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL
- Automatically generate a name for constraints that doesn't have a name
- Added support for ALTER TABLE DROP CONSTRAINT
- Ensure that partition functions register virtual fields used. This fixes
  some bugs when using virtual fields in a partitioning function
2016-06-30 11:43:02 +02:00
Nirbhay Choubey
7305be2f7e MDEV-5535: Cannot reopen temporary table
mysqld maintains a list of TABLE objects for all temporary
tables created within a session in THD. Here each table is
represented by a TABLE object.

A query referencing a particular temporary table for more
than once, however, failed with ER_CANT_REOPEN_TABLE error
because a TABLE_SHARE was allocate together with the TABLE,
so temporary tables always had only one TABLE per TABLE_SHARE.

This patch lift this restriction by separating TABLE and
TABLE_SHARE objects and storing TABLE_SHAREs for temporary
tables in a list in THD, and TABLEs in a list within their
respective TABLE_SHAREs.
2016-06-10 18:39:43 -04:00
Sergey Vojtovich
7ecb304996 Code cleanups
- unused TABLE_SHARE::deleting and TABLE_LIST::deleting flags were removed
- kill_delayed_threads_for_table() and intern_close_table() are now private
  methods of table cache
- removed free_share flag of closefrm(): it was never used for temporary
  tables and was rarely useful for regular tables
2016-06-10 17:37:12 +04:00
Monty
9c846373f0 Merge commit 'd5822a3ad0657040114cdc185c6387b9eb3a12b2' into 10.2 2016-04-28 16:59:33 +03:00
Igor Babaev
5ff4b21e02 Fixed bug mdev-9897.
This bug revealed a serious problem: if the same partition list
was used in two window specifications then the temporary table created
to calculate window functions contained fields for two identical
partitions. This problem was fixed as well.
2016-04-14 00:47:28 -07:00
Monty
293cb04959 MDEV-9621 INSERT DELAYED fails on insert for tables with many columns
This fix also fixes a connection hang when trying to do INSERT DELAYED to a crashed table.

Added crash_mysqld.inc to allow easy crash+restart of mysqld
2016-04-07 19:31:10 +03:00
Sergei Petrunia
2bd4dc38e0 Merge branch '10.2' into bb-10.2-mdev9543 2016-03-28 22:18:38 +03:00
Monty
260dd476b0 Removed TABLE->sort to make it possible to have multiple active calls to
filesort and init_read_record() for the same table.
This will simplify code for WINDOW FUNCTIONS (MDEV-6115)

- Filesort_info renamed to SORT_INFO and moved to filesort.h
- filesort now returns SORT_INFO
- init_read_record() now takes a SORT_INFO parameter.
- unique declaration is moved to uniques.h
- subselect caching of buffers is now more explicit than before
- filesort_buffer is now reusable even if rec_length has changed.
- filsort_free_buffers() and free_io_cache() calls are removed
- Remove one malloc() when using get_addon_fields()

Other things:
- Added --debug-assert-on-not-freed-memory option to make it easier to
  debug some not-freed-memory issues.
2016-03-22 23:44:52 +02:00
Sergey Vojtovich
3692bd3238 MDEV-9488 - Table cache cleanups
Cleanup now unused arguments of tdc_open_view().
2016-02-26 18:36:31 +04:00
Igor Babaev
2cfc450bf7 This is the consolidated patch for mdev-8646:
"Re-factor the code for post-join operations".

The patch mainly contains the code ported from mysql-5.6 and
created for two essential architectural changes:
1. WL#5558: Resolve ORDER BY execution method at the optimization stage
2. WL#6071: Inline tmp tables into the nested loops algorithm

The first task was implemented for mysql-5.6 by Ole John Aske.
It allows to make all decisions on ORDER BY operation at the optimization
stage.

The second task implemented for mysql-5.6 by Evgeny Potemkin adds JOIN_TAB
nodes for post-join operations that require temporary tables. It allows
to execute these operations within the nested loops algorithm that used to
be used before this task only for join queries. Besides these task moves
all planning on the execution of these operations from the execution phase
to the optimization phase.

Some other re-factoring changes of mysql-5.6 were pulled in, mainly because
it was easier to pull them in than roll them back. In particular all
changes concerning Ref_ptr_array were incorporated.

The port required some changes in the MariaDB code that concerned the
functionality of EXPLAIN and ANALYZE. This was done mainly by Sergey
Petrunia.
2016-02-09 12:35:59 -08:00
Sergei Golubchik
0686c34d22 MDEV-8605 MariaDB not use DEFAULT value even when inserted NULL for NOT NULLABLE column
NOT NULL constraint must be checked *after* the BEFORE triggers.
That is for INSERT and UPDATE statements even NOT NULL fields
must be able to store a NULL temporarily at least while
BEFORE INSERT/UPDATE triggers are running.
2015-12-21 21:30:54 +01:00
Sergei Golubchik
beded7d9c9 Merge branch '10.0' into 10.1 2015-11-19 15:52:14 +01:00
Sergei Golubchik
fb8713385f remove unneded #include's that had a dubious explanation 2015-10-24 19:58:34 +02:00
Sergey Vojtovich
4d1ccc4289 MDEV-7951 - sql_alloc() takes 0.25% in OLTP RO
sql_alloc() has additional costs compared to direct mem_root allocation:
- function call: it is defined in a separate translation unit and can't be
  inlined
- it needs to call pthread_getspecific() to get THD::mem_root

It is called dozens of times implicitely at least by:
- List<>::push_back()
- List<>::push_front()
- new (for Sql_alloc derived classes)
- sql_memdup()

Replaced lots of implicit sql_alloc() calls with direct mem_root allocation,
passing through THD pointer whenever it is needed.

Number of sql_alloc() calls reduced 345 -> 41 per OLTP RO transaction.
pthread_getspecific() overhead dropped 0.76 -> 0.59
sql_alloc() overhed dropped 0.25 -> 0.06
2015-05-13 10:43:14 +04:00
Kristian Nielsen
2de8db6296 Merge MDEV-7936 into 10.1 2015-04-13 14:28:07 +02:00
Kristian Nielsen
60d094aeac MDEV-7936: Assertion `!table || table->in_use == _current_thd()' failed on parallel replication in optimistic mode
Make sure that in parallel replication, we execute wait_for_prior_commit()
before setting table->in_use for a temporary table. Otherwise we can end up
with two parallel replication worker threads competing with each other for
use of a temporary table.

Re-factor the use of find_temporary_table() to be able to handle errors
in the caller (as wait_for_prior_commit() can return error in case of
deadlock kill).
2015-04-13 14:24:18 +02:00
Oleksandr Byelkin
80f03abcca MDEV-7671: Cache VIEW definitions in the TDC
(changes of backported patch are very small: strlen removed, error processing fixed, view open statistics added)
2015-03-11 17:39:15 +01:00
Sergey Vojtovich
6dbc48ca79 MDEV-7324 - Lock-free hash for table definition cache 2014-12-28 19:46:18 +04:00
Alexander Barkov
c6d3f8058d MDEV-7112 Split HA_CREATE_INFO 2014-12-08 10:56:08 +04:00
Sergei Golubchik
f62c12b405 Merge 10.0.14 into 10.1 2014-10-15 12:59:13 +02:00
Sergei Golubchik
8867a499f7 MDEV-6050 MySQL Bug#13036505 62540: TABLE LOCKS WITHIN STORED FUNCTIONS ARE BACK IN 5.5 WITH MIXED AND ROW BI
cherry-pick revno 4053
committer: Gopal Shankar <gopal.shankar@oracle.com>
branch nick: sf_mysql-5.6
timestamp: Fri 2012-07-20 12:25:34 +0530
message:
  Bug#13036505 62540: TABLE LOCKS WITHIN STORED FUNCTIONS ARE BACK IN
                      5.5 WITH MIXED AND ROW BI.
2014-07-31 12:03:20 +02:00
Sergei Golubchik
ce6a63ec41 MDEV-4260 Don't create frm files for temporary tables
* Don't write frm for tmp tables
* pass frm image down to open_table_uncached, when possible
* don't use truncate-by-recreate for temp tables - cannot recreate
  without frm, and delete_all_rows is faster anyway
2014-06-20 15:47:44 +02:00
Michael Widenius
7ffc9da093 Implementation of MDEV-5491: CREATE OR REPLACE TABLE
Using CREATE OR REPLACE TABLE is be identical to

DROP TABLE IF EXISTS table_name;
CREATE TABLE ...;

Except that:

* CREATE OR REPLACE is be atomic (now one can create the same table between drop and create).
* Temporary tables will not shadow the table name for the DROP as the CREATE TABLE tells us already if we are using a temporary table or not.
* If the table was locked with LOCK TABLES, the new table will be locked with the same lock after it's created.

Implementation details:
- We don't anymore open the to-be-created table during CREATE TABLE, which the original code did.
  - There is no need to open a table we are planning to create. It's enough to check if the table exists or not.
- Removed some of duplicated code for CREATE IF NOT EXISTS.
- Give an error when using CREATE OR REPLACE with IF NOT EXISTS (conflicting options).
- As a side effect of the code changes, we don't anymore have to internally re-prepare prepared statements with CREATE TABLE if the table exists.
- Made one code path for all testing if log table are in use.
- Better error message if one tries to create/drop/alter a log table in use
- Added back disabled rpl_row_create_table test as it now seams to work and includes a lot of interesting tests.
- Added HA_LEX_CREATE_REPLACE to mark if we are using CREATE OR REPLACE
- Aligned CREATE OR REPLACE parsing code in sql_yacc.yy for TABLE and VIEW
- Changed interface for drop_temporary_table() to make it more reusable
- Changed Locked_tables_list::init_locked_tables() to work on the table object instead of the table list object. Before this it used a mix of both, which was not good.
- Locked_tables_list::unlock_locked_tables(THD *thd) now requires a valid thd argument. Old usage of calling this with 0 i changed to instead call Locked_tables_list::reset()
- Added functions Locked_tables_list:restore_lock() and Locked_tables_list::add_back_last_deleted_lock() to be able to easily add back a locked table to the lock list.
- Added restart_trans_for_tables() to be able to restart a transaction.
- DROP_ACL is required if one uses CREATE TABLE OR REPLACE.
- Added drop of normal and temporary tables in create_table_imp() if CREATE OR REPLACE was used.
- Added reacquiring of table locks in mysql_create_table() and mysql_create_like_table()




mysql-test/include/commit.inc:
  With new code we get fewer status increments
mysql-test/r/commit_1innodb.result:
  With new code we get fewer status increments
mysql-test/r/create.result:
  Added testing of create or replace with timeout
mysql-test/r/create_or_replace.result:
  Basic testing of CREATE OR REPLACE TABLE
mysql-test/r/partition_exchange.result:
  New error message
mysql-test/r/ps_ddl.result:
  Fewer reprepares with new code
mysql-test/suite/archive/discover.result:
  Don't rediscover archive tables if the .frm file exists
  (Sergei will look at this if there is a better way...)
mysql-test/suite/archive/discover.test:
  Don't rediscover archive tables if the .frm file exists
  (Sergei will look at this if there is a better way...)
mysql-test/suite/funcs_1/r/innodb_views.result:
  New error message
mysql-test/suite/funcs_1/r/memory_views.result:
  New error message
mysql-test/suite/rpl/disabled.def:
  rpl_row_create_table should now be safe to use
mysql-test/suite/rpl/r/rpl_row_create_table.result:
  Updated results after adding back disabled test
mysql-test/suite/rpl/t/rpl_create_if_not_exists.test:
  Added comment
mysql-test/suite/rpl/t/rpl_row_create_table.test:
  Added CREATE OR REPLACE TABLE test
mysql-test/t/create.test:
  Added CREATE OR REPLACE TABLE test
mysql-test/t/create_or_replace-master.opt:
  Create logs
mysql-test/t/create_or_replace.test:
  Basic testing of CREATE OR REPLACE TABLE
mysql-test/t/partition_exchange.test:
  Error number changed as we are now using same code for all log table change issues
mysql-test/t/ps_ddl.test:
  Fewer reprepares with new code
sql/handler.h:
  Moved things around a bit in a structure to get better alignment.
  Added HA_LEX_CREATE_REPLACE to mark if we are using CREATE OR REPLACE
  Added 3 elements to end of HA_CREATE_INFO to be able to store state to add backs locks in case of LOCK TABLES.
sql/log.cc:
  Reimplemented check_if_log_table():
  - Simpler and faster usage
  - Can give error messages
  
  This gives us one code path for allmost all error messages if log tables are in use
sql/log.h:
  New interface for check_if_log_table()
sql/slave.cc:
  More logging
sql/sql_alter.cc:
  New interface for check_if_log_table()
sql/sql_base.cc:
  More documentation
  Changed interface for drop_temporary_table() to make it more reusable
  Changed Locked_tables_list::init_locked_tables() to work on the table object instead of the table list object. Before this it used a mix of both, which was not good.
  Locked_tables_list::unlock_locked_tables(THD *thd) now requires a valid thd argument.  Old usage of calling this with 0 i changed to instead call Locked_tables_list::reset()
  Added functions Locked_tables_list:restore_lock() and Locked_tables_list::add_back_last_deleted_lock() to be able to easily add back a locked table to the lock list.
  Check for command number instead of open_strategy of CREATE TABLE was used.
  Added restart_trans_for_tables() to be able to restart a transaction.  This was needed in "create or replace ... select" between the drop table and the select.
sql/sql_base.h:
  Added and updated function prototypes
sql/sql_class.h:
  Added new prototypes to Locked_tables_list class
  Added extra argument to select_create to avoid double call to eof() or send_error()
  - I needed this in some edge case where the table was not created against expections.
sql/sql_db.cc:
  New interface for check_if_log_table()
sql/sql_insert.cc:
  Remember position to lock information so that we can reaquire table lock for LOCK TABLES + CREATE OR REPLACE TABLE SELECT. Later add back the lock by calling restore_lock().
  Removed one not needed indentation level in create_table_from_items()
  Ensure we don't call send_eof() or abort_result_set() twice.
sql/sql_lex.h:
  Removed variable that I temporarly added in an earlier changeset
sql/sql_parse.cc:
  Removed old test code (marked with QQ)
  Ensure that we have open_strategy set as TABLE_LIST::OPEN_STUB in CREATE TABLE
  Removed some IF NOT EXISTS code as this is now handled in create_table_table_impl().
  Set OPTION_KEEP_LOGS later. This code had to be moved as the test for IF EXISTS has changed place.
  DROP_ACL is required if one uses CREATE TABLE OR REPLACE.
sql/sql_partition_admin.cc:
  New interface for check_if_log_table()
sql/sql_rename.cc:
  New interface for check_if_log_table()
sql/sql_table.cc:
  New interface for check_if_log_table()
  Moved some code in mysql_rm_table() under a common test.
  - Safe as temporary tables doesn't have statistics.
  - !is_temporary_table(table) test was moved out from drop_temporary_table() and merged with upper level code.
  - Added drop of normal and temporary tables in create_table_imp() if CREATE OR REPLACE was used.
  - Added reacquiring of table locks in mysql_create_table() and mysql_create_like_table()
  - In mysql_create_like_table(), restore table->open_strategy() if it was changed.
  - Re-test if table was a view after opening it.
sql/sql_table.h:
  New prototype for mysql_create_table_no_lock()
sql/sql_yacc.yy:
  Added syntax for CREATE OR REPLACE TABLE
  Reuse new code for CREATE OR REPLACE VIEW
sql/table.h:
  Added name for enum type
sql/table_cache.cc:
  More DBUG
2014-01-29 15:37:17 +02:00
Sergei Golubchik
d28d3ba40d 10.0-base merge 2013-12-16 13:02:21 +01:00
Sergei Golubchik
c6d30805db 5.5 merge 2013-11-23 00:50:54 +01:00
Sergei Golubchik
fa3f8a18b2 mysql-5.5.34 merge
(some patches reverted, test case added)
2013-11-19 13:16:25 +01:00
Dmitry Lenev
fc2c669297 Fix for bug#14188793 - "DEADLOCK CAUSED BY ALTER TABLE DOEN'T CLEAR
STATUS OF ROLLBACKED TRANSACTION" and bug #17054007 - "TRANSACTION
IS NOT FULLY ROLLED BACK IN CASE OF INNODB DEADLOCK".

The problem in the first bug report was that although deadlock involving
metadata locks was reported using the same error code and message as InnoDB
deadlock it didn't rollback transaction like the latter. This caused
confusion to users as in some cases after ER_LOCK_DEADLOCK transaction
could have been restarted immediately and in some cases rollback was
required.

The problem in the second bug report was that although InnoDB deadlock
caused transaction rollback in all storage engines it didn't cause release
of metadata locks. So concurrent DDL on the tables used in transaction was
blocked until implicit or explicit COMMIT or ROLLBACK was issued in the
connection which got InnoDB deadlock.

The former issue has stemmed from the fact that when support for detection
and reporting metadata locks deadlocks was added we erroneously assumed
that InnoDB doesn't rollback transaction on deadlock but only last statement
(while this is what happens on InnoDB lock timeout actually) and so didn't
implement rollback of transactions on MDL deadlocks.

The latter issue was caused by the fact that rollback of transaction due
to deadlock is carried out by setting THD::transaction_rollback_request
flag at the point where deadlock is detected and performing rollback
inside of trans_rollback_stmt() call when this flag is set. And
trans_rollback_stmt() is not aware of MDL locks, so no MDL locks are
released.

This patch solves these two problems in the following way:

- In case when MDL deadlock is detect transaction rollback is requested
  by setting THD::transaction_rollback_request flag.

- Code performing rollback of transaction if THD::transaction_rollback_request
  is moved out from trans_rollback_stmt(). Now we handle rollback request
  on the same level as we call trans_rollback_stmt() and release statement/
  transaction MDL locks.
2013-08-20 13:12:34 +04:00
Dmitry Lenev
b07ec61f85 Fix for bug#14188793 - "DEADLOCK CAUSED BY ALTER TABLE DOEN'T CLEAR
STATUS OF ROLLBACKED TRANSACTION" and bug #17054007 - "TRANSACTION
IS NOT FULLY ROLLED BACK IN CASE OF INNODB DEADLOCK".

The problem in the first bug report was that although deadlock involving
metadata locks was reported using the same error code and message as InnoDB
deadlock it didn't rollback transaction like the latter. This caused
confusion to users as in some cases after ER_LOCK_DEADLOCK transaction
could have been restarted immediately and in some cases rollback was
required.

The problem in the second bug report was that although InnoDB deadlock
caused transaction rollback in all storage engines it didn't cause release
of metadata locks. So concurrent DDL on the tables used in transaction was
blocked until implicit or explicit COMMIT or ROLLBACK was issued in the
connection which got InnoDB deadlock.

The former issue has stemmed from the fact that when support for detection
and reporting metadata locks deadlocks was added we erroneously assumed
that InnoDB doesn't rollback transaction on deadlock but only last statement
(while this is what happens on InnoDB lock timeout actually) and so didn't
implement rollback of transactions on MDL deadlocks.

The latter issue was caused by the fact that rollback of transaction due
to deadlock is carried out by setting THD::transaction_rollback_request
flag at the point where deadlock is detected and performing rollback
inside of trans_rollback_stmt() call when this flag is set. And
trans_rollback_stmt() is not aware of MDL locks, so no MDL locks are
released.

This patch solves these two problems in the following way:

- In case when MDL deadlock is detect transaction rollback is requested
  by setting THD::transaction_rollback_request flag.

- Code performing rollback of transaction if THD::transaction_rollback_request
  is moved out from trans_rollback_stmt(). Now we handle rollback request
  on the same level as we call trans_rollback_stmt() and release statement/
  transaction MDL locks.
2013-08-20 13:12:34 +04:00
Sergey Vojtovich
b7f9c89423 MDEV-4702 - Reduce usage of LOCK_open
Following variables do not require LOCK_open protection anymore:
- table_def_cache (renamed to tdc_hash) is protected by rw-lock
  LOCK_tdc_hash;
- table_def_shutdown_in_progress doesn't need LOCK_open protection;
- last_table_id use atomics;
- TABLE_SHARE::ref_count (renamed to TABLE_SHARE::tdc.ref_count)
  is protected by TABLE_SHARE::tdc.LOCK_table_share;
- TABLE_SHARE::next, ::prev (renamed to tdc.next and tdc.prev),
  oldest_unused_share, end_of_unused_share are protected by
  LOCK_unused_shares;
- TABLE_SHARE::m_flush_tickets (renamed to tdc.m_flush_tickets)
  is protected by TABLE_SHARE::tdc.LOCK_table_share;
- refresh_version (renamed to tdc_version) use atomics.
2013-08-14 12:48:50 +04:00
Sergei Golubchik
9747fbb411 MDEV-4786 merge 10.0-monty -> 10.0
remove TDC_RT_REMOVE_NOT_OWN_AND_MARK_NOT_USABLE
2013-08-12 15:46:35 +02:00
Sergei Golubchik
eafb11c821 MDEV-4786 merge 10.0-monty -> 10.0
use get_table_def_key() instead of create_table_def_key() where appropriate
2013-08-12 14:17:51 +02:00
Sergey Vojtovich
e33e9825a4 MDEV-4786 - merge 10.0-monty - 10.0
Fixed main.innodb_mysql_sync failure.

TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE is not same as
TDC_RT_REMOVE_NOT_OWN_AND_MARK_NOT_USABLE. Comment in sql_table.cc says:

      Storage engine has requested exclusive lock only for prepare phase
      and we are not under LOCK TABLES.
      Don't mark TABLE_SHARE as old in this case, as this won't allow opening
      of table by other threads during main phase of in-place ALTER TABLE.

At this moment we hold exclusive metadata lock, all we should do
is purge unused TABLE objects.

sql/sql_base.cc:
  Restore 5.6 behavior of TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE.
sql/sql_base.h:
  Restore 5.6 behavior of TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE.
2013-07-25 13:40:18 +04:00
Sergei Golubchik
b7b5f6f1ab 10.0-monty merge
includes:
* remove some remnants of "Bug#14521864: MYSQL 5.1 TO 5.5 BUGS PARTITIONING"
* introduce LOCK_share, now LOCK_ha_data is strictly for engines
* rea_create_table() always creates .par file (even in "frm-only" mode)
* fix a 5.6 bug, temp file leak on dummy ALTER TABLE
2013-07-21 16:39:19 +02:00
unknown
70092601bc merge of 2876.430.11 & 2876.430.1
CF_PREOPEN_TMP_TABLES & CF_HA_CLOSE & Patch for Bug#11746602 (27480: Extend CREATE TEMPORARY TABLES 
  privilege to allow temp table operations).
2013-06-27 17:42:18 +03:00
Michael Widenius
5f1f2fc0e4 Applied all changes from Igor and Sanja 2013-06-15 18:32:08 +03:00
Sergei Golubchik
050d7d6d75 optimize discovery for cases when the storage engine is known in advance 2013-04-09 16:20:48 +02:00
Sergei Golubchik
f532653c29 remove ha_create_table_from_engine()
replace enum read_frm_op with a bitmap flags.
remove always-unused 'error' argument of get_table_share
2013-04-09 15:41:57 +02:00
Sergei Golubchik
6a839ff40d handlerton::discover_table_existence() method 2013-04-09 15:35:57 +02:00
Sergei Golubchik
934115184b convenience helpers for get_table_share() and tdc_open_view().
Pass db and table_name into a function instead of the table_list,
when only db and table name are needed.
2013-04-09 15:35:24 +02:00
Sergei Golubchik
b0a5dd73fa * remove ha_check_if_table_exists() and get_table_share_with_discover().
* rename check_if_table_exists() -> table_exists() and remove unneeded arguments
2013-04-09 15:35:15 +02:00
Sergei Golubchik
163882665e * don't use 1-8 numbers for open_table_error codes, use an enum.
* print "table doesn't exist in engine" when a table doesn't exist in the engine,
  instead of "file not found" (if no file was involved)
* print a complete filename that cannot be found ('t1.MYI', not 't1')
* it's not an error for a DROP if a table doesn't exist in the engine (or some table
  files cannot be found) - if the DROP succeeded regardless
2013-04-09 15:34:17 +02:00
Sergei Golubchik
5ad68a0d2f don't use I_S constants for open_table_def and get_table_share,
have a specially defined enum with clearly named values
2013-04-09 15:34:09 +02:00
Sergei Golubchik
993ea79f2d 5.5 merge 2013-03-27 23:41:02 +01:00
Michael Widenius
4cace76d4d Automatic merge 2013-03-01 18:09:06 +02:00
Michael Widenius
8ed283d882 Fixed bug MPDEV-628 / LP:989055 - Querying myisam table metadata may corrupt the table.
The issue was that there was that SHOW commands could open the table in the store engine, even in cases
where it should not be allowed to do that (ie, the storage engines meta data for that table was under big changes).

The cases where this should not be allowed are:
- ALTER TABLE DISABLE KEYS
- ALTER TABLE ENABLE KEYS
- REPAIR TABLE
- OPTIMIZE TABLE
- DROP TABLE

This patch adds a new mode, protected_against_usage(). If this is used then the SHOW command will wait until the table
is accessable. This is implemented by re-using the already exising 'version' flag for TABLE_SHARE.
It also added functions to be used to change TABLE_SHARE->version instead of changing it directly.
	


mysql-test/r/myisam-metadata.result:
  Added test case
mysql-test/t/myisam-metadata.test:
  Added test case
sql/mysqld.cc:
  Start from refresh_version 2 as 0 and 1 are reserved.
sql/sql_admin.cc:
  Added MYSQL_OPEN_FOR_REPAIR
  Updated call to wait_while_table_is_used()
sql/sql_base.cc:
  Updated call to wait_while_table_is_used()
  - Allow one to specify how the table should be removed (for all commands except show or for all commands).
  - Don't allow one to reopen the table if one has called share->protect_against_usage()
sql/sql_base.h:
  Added TDC_RT_REMOVE_NOT_OWN_AND_MARK_NOT_USABLE, which is used to mark that no one can reopen this table, except with MYSQL_OPEN_FOR_REPAIR .
  - Added MYSQL_OPEN_FOR_REPAIR
  - Updated prototype for wait_while_table_is_used()
sql/sql_table.cc:
  Updated call to wait_while_table_is_used()
  Use MYSQL_OPEN_FOR_REPAIR for open tables that where repaired.
sql/sql_truncate.cc:
  Updated call to wait_while_table_is_used()
sql/table.cc:
  Use set_refresh_version()
sql/table.h:
  Added functions to be used to change TABLE_SHARE->version instead of changing it directly
2013-03-01 18:01:44 +02:00
Sergei Golubchik
8161c6772d merge with mysql-5.5.30 minus few incorrect or not applicable changesets 2013-02-28 18:42:49 +01:00
unknown
f54a4819b6 Cassandra SE merge 2013-01-10 00:58:36 +02:00
Igor Babaev
f853333e09 Merge 5.5-mwl248 -> 10.0-base 2013-01-08 19:34:33 -08:00
Igor Babaev
7d9df8075e Merge 5.5 -> mwl248 2013-01-08 15:04:14 -08:00
unknown
61412c0c31 pre-merge 2012-12-23 23:37:11 +02:00
Igor Babaev
1b62f0f58c Merge maria-5.5-mwl248 -> 10.0-base. 2012-12-16 21:33:17 -08:00
Igor Babaev
7760efad74 Merge mariadb-5.5 -> 10.0-base. 2012-12-16 16:49:19 -08:00
Igor Babaev
a06224bd15 Addressed all remaining issues from the review of the patch
that introduced engine independent persistent statistics.
In particular:
- added an enumeration type for possible values of the system
  variable use_stat_tables
- renamed KEY::real_rec_per_key to KEY::actual_rec_per_key
- optimized the collection of statistical data for any primary
  key defined only on one column.
2012-12-13 23:05:12 -08:00
unknown
6e8c4d696a MDEV-452 Add full support for auto-initialized/updated timestamp and datetime
Post-review changes according to Monty's review from 28/11/2012.
2012-12-13 22:56:03 +02:00
Igor Babaev
65820439bd Fixed bug mdev-3891.
If a query referenced some system statistical tables, but not all of them,
then executing an ANALYZE command simultaneously with this query could
lead to a deadlock.
The fix prohibited reading statistics from system statistical tables
for such queries.

Removed the function unlock_tables_n_open_system_tables_for_write()
as not used anymore.
Performed some minor refactoring of the code in sql_statistics.cc.
2012-12-12 23:16:54 -08:00
Dmitry Lenev
4235e46ea2 Bug #15954872 "MAKE MDL SUBSYSTEM AND TABLE DEFINITION CACHE
ROBUST AGAINST BUGS IN CALLERS".

Both MDL subsystems and Table Definition Cache code assume
that callers ensure that names of objects passed to them are
not longer than NAME_LEN bytes. Unfortunately due to bugs in
callers this assumption might be broken in some cases. As
result we get nasty bugs causing buffer overruns when we
construct MDL key or TDC key from object names.

This patch makes MDL and TDC code more robust against such
bugs by ensuring that we always checking size of result
buffer when constructing MDL and TDC keys. This doesn't
free its callers from ensuring that both db and table names
are shorter than NAME_LEN bytes. But at least these steps
prevents buffer overruns in case of bug in caller, replacing
them with less harmful behavior.

This is 5.5-only version of patch.

Changed code of MDL_key::mdl_key_init() to take into account
size of buffer for the key.

Introduced new version of create_table_def_key() helper function
which constructs TDC key without risk of result buffer overrun.
Places in code that construct TDC keys were changed to use this
function.

Also changed rm_temporary_table() and open_new_frm() functions
to avoid use of "unsafe" strmov() and strxmov() functions and
use safer strnxmov() instead.
2012-12-11 22:04:30 +04:00
Dmitry Lenev
1874591d27 Bug #15954872 "MAKE MDL SUBSYSTEM AND TABLE DEFINITION CACHE
ROBUST AGAINST BUGS IN CALLERS".

Both MDL subsystems and Table Definition Cache code assume
that callers ensure that names of objects passed to them are
not longer than NAME_LEN bytes. Unfortunately due to bugs in
callers this assumption might be broken in some cases. As
result we get nasty bugs causing buffer overruns when we
construct MDL key or TDC key from object names.

This patch makes MDL and TDC code more robust against such
bugs by ensuring that we always checking size of result
buffer when constructing MDL and TDC keys. This doesn't
free its callers from ensuring that both db and table names
are shorter than NAME_LEN bytes. But at least these steps
prevents buffer overruns in case of bug in caller, replacing
them with less harmful behavior.

This is 5.5-only version of patch.

Changed code of MDL_key::mdl_key_init() to take into account
size of buffer for the key.

Introduced new version of create_table_def_key() helper function
which constructs TDC key without risk of result buffer overrun.
Places in code that construct TDC keys were changed to use this
function.

Also changed rm_temporary_table() and open_new_frm() functions
to avoid use of "unsafe" strmov() and strxmov() functions and
use safer strnxmov() instead.
2012-12-11 22:04:30 +04:00
Igor Babaev
2447bc4c81 Addressed the following issue from the review of the patch for
engine-independent statistics.
When the primary key was dropped or changed statistics on secondary
indexes for the prefixes that included components of the primary 
key was not removed from the table mysql.index_stats.

Also fixed: in the some cases when a column was changed statistics
on the indexes that included this column was not removed from the
table mysql.index_stats.

Also disabled the test mdev-504 for --ps-protocol.
2012-12-08 15:38:15 -08:00
Michael Widenius
33f3a11e2d Implemented MDEV-3941: CREATE TABLE xxx IF NOT EXISTS should not block if table exists.
- Added option to check_if_table_exists() to quickly check if table exists (either SHARE or .FRM)
- Extended lock_table_names() to not wait for meta data locks if CREATE IF NOT EXISTS is used.

mysql-test/r/create.result:
  New test case
mysql-test/t/create.test:
  New test case
sql/sql_base.cc:
  Added option to check_if_table_exists() to quickly check if table exists (either SHARE or .FRM)
  Extended lock_table_names() to not wait for meta data locks if CREATE IF NOT EXISTS is used.
sql/sql_base.h:
  Updated prototype
sql/sql_db.cc:
  Added extra argument to call to check_if_table_exists()
2012-12-16 16:13:17 +02:00
Igor Babaev
f8bfb65b13 Merge 5.5->mwl248 2012-12-04 19:04:25 -08:00
Sergei Golubchik
a48a91d90f 5.3->5.5 merge 2012-11-22 10:19:31 +01:00
unknown
bc4a456758 MDEV-452 Add full support for auto-initialized/updated timestamp and datetime
Generalized support for auto-updated and/or auto-initialized timestamp
and datetime columns. This patch is a reimplementation of MySQL's
"WL#5874: CURRENT_TIMESTAMP as DEFAULT for DATETIME columns". In order to
ease future merges, this implementation reused few function and variable
names from MySQL's patch, however the implementation is quite different.

TODO:
The only unresolved problem in this patch is the semantics of LOAD DATA for
TIMESTAMP and DATETIME columns in the cases when there are missing or NULL
columns. I couldn't fully comprehend the logic behind MySQL's behavior and
its relationship with their own documentation, so I left the results to be
more consistent with all other LOAD cases.

The problematic test cases can be seen by running the test file function_defaults,
and observing the test case differences. Those were left on purpose for discussion.
2012-10-17 15:43:56 +03:00
unknown
245298f25d MDEV-506 Cassandra dynamic columns access 2012-09-28 15:27:16 +03:00
Igor Babaev
b3f09e8aa0 Fixed bug mdev-504.
Opening system statistical tables and reading statistical data from 
them for a regular table should be done after opening and locking 
this regular table.
No test case is provided with this patch.
2012-09-08 12:04:31 -07:00
Igor Babaev
8c499274da Performed re-factoring and re-structuring of the code for mwl#248:
- Moved the definitions of the classes to store data from persistent
    statistical tables into statistics.h, leaving in other internal 
    data structures only references to the corresponding objects.
  - Defined class Column_statistics_collected derived from the class
    Column_statistics. This is a helper class to collect statistics
    on columns.
  - Moved references to read statistics to TABLE SHARE, leaving the
    the reference to the collected statistics in TABLE.
 - Added a new clone method for the class Field allowing to clone
    fields attached to table shares. It was was used to create 
    fields for min/max values in the memory of the table share.
A lso:
  - Added procedures to allocate memory for statistical data in
    the table share memory and in table memory.
Also: 
  - Added a test case demonstrating how ANALYZE could work in parallel
    to collect statistics on different indexes of the same table.
  - Added a test two demonstrate how two connections working 
    simultaneously could allocate memory for statistical data in the 
    table share memory.
2012-07-26 17:50:08 -07:00
Igor Babaev
47fae7f08f Added procedures to delete records by keys from statistical tables.
Now when a table is dropped the statistics on the table is removed 
from the statistical tables. If the table is altered in such a way
that a column is dropped or the type of the column is changed then
statistics on the column is removed from the table column_stat.
It also triggers removal of the statistics on the indexes who use
this column as its component.

Added procedures that changes the names of the tables or columns
in the statistical tables for. 
These procedures are used when tables/columns are renamed.

Also partly re-factored the code that introduced the persistent
statistical tables.

Added test cases into statistics.test to cover the new code.
2012-07-10 16:34:39 -07:00
Igor Babaev
d48b4a83a2 Merge. 2012-05-18 09:50:30 -07:00
Michael Widenius
6d8e329c9a Fixed bug LP:973039 - Assertion `share->in_trans == 0' failed in maria_close on DROP TABLE under LOCK
- 5.5 was missing calls to ha_extra(HA_PREPARE_FOR_DROP | HA_PREPARE_FOR_RENAME);  Lost in merge 5.3 -> 5.5


sql/sql_admin.cc:
  Updated arguments for close_all_tables_for_name
sql/sql_base.h:
  Updated arguments for close_all_tables_for_name
sql/sql_partition.cc:
  Updated arguments for close_all_tables_for_name
sql/sql_table.cc:
  Updated arguments for close_all_tables_for_name
  Removed test of kill, as we have already called 'ha_extra(HA_PREPARE_FOR_DROP)' and the table may be inconsistent.
sql/sql_trigger.cc:
  Updated arguments for close_all_tables_for_name
sql/sql_truncate.cc:
  For truncate that is done with drop + recreate, signal that the table will be dropped.
2012-05-16 18:44:17 +03:00
Igor Babaev
1c0a89afcc The pilot implementation of mwl#250: Use the statistics from persistent
statistical tables instead of the statistics provided by engine.
2012-04-11 17:14:06 -07:00
Igor Babaev
ff3d16fba8 Merge maria-5.3-mwl248 -> 5.5 = maria-5.5-mwl248. 2012-03-19 01:35:32 -07:00
Sergei Golubchik
76f0b94bb0 merge with 5.3
sql/sql_insert.cc:
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
  ******
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
sql/sql_table.cc:
  small cleanup
  ******
  small cleanup
2011-10-19 21:45:18 +02:00
Sergei Golubchik
9809f05199 5.5-merge 2011-07-02 22:08:51 +02:00
Jon Olav Hauglid
bafe24035d Bug #11764779 (former 57649)
FLUSH TABLES under FLUSH TABLES <list> WITH READ LOCK leads 
to assert failure.

This assert was triggered if a statement tried up upgrade a metadata
lock with an active FLUSH TABLE <list> WITH READ LOCK. The assert 
checks that the connection already holds a global intention exclusive
metadata lock. However, FLUSH TABLE <list> WITH READ LOCK does not
acquire this lock in order to be compatible with FLUSH TABLES WITH
READ LOCK. Therefore any metadata lock upgrade caused the assert to
be triggered.

This patch fixes the problem by preventing metadata lock upgrade
if the connection has an active FLUSH TABLE <list> WITH READ LOCK.
ER_TABLE_NOT_LOCKED_FOR_WRITE will instead be reported to the client.

Test case added to flush.test.
2011-03-07 10:08:10 +01:00
Jon Olav Hauglid
c2dc4b022a Bug #11764779 (former 57649)
FLUSH TABLES under FLUSH TABLES <list> WITH READ LOCK leads 
to assert failure.

This assert was triggered if a statement tried up upgrade a metadata
lock with an active FLUSH TABLE <list> WITH READ LOCK. The assert 
checks that the connection already holds a global intention exclusive
metadata lock. However, FLUSH TABLE <list> WITH READ LOCK does not
acquire this lock in order to be compatible with FLUSH TABLES WITH
READ LOCK. Therefore any metadata lock upgrade caused the assert to
be triggered.

This patch fixes the problem by preventing metadata lock upgrade
if the connection has an active FLUSH TABLE <list> WITH READ LOCK.
ER_TABLE_NOT_LOCKED_FOR_WRITE will instead be reported to the client.

Test case added to flush.test.
2011-03-07 10:08:10 +01:00
Sergei Golubchik
65ca700def merge.
checkpoint.
does not compile.
2010-11-25 18:17:28 +01:00
Dmitry Lenev
6bf6272fda Patch that refactors global read lock implementation and fixes
bug #57006 "Deadlock between HANDLER and FLUSH TABLES WITH READ
LOCK" and bug #54673 "It takes too long to get readlock for
'FLUSH TABLES WITH READ LOCK'".

The first bug manifested itself as a deadlock which occurred
when a connection, which had some table open through HANDLER
statement, tried to update some data through DML statement
while another connection tried to execute FLUSH TABLES WITH
READ LOCK concurrently.

What happened was that FTWRL in the second connection managed
to perform first step of GRL acquisition and thus blocked all
upcoming DML. After that it started to wait for table open
through HANDLER statement to be flushed. When the first connection
tried to execute DML it has started to wait for GRL/the second
connection creating deadlock.

The second bug manifested itself as starvation of FLUSH TABLES
WITH READ LOCK statements in cases when there was a constant
stream of concurrent DML statements (in two or more
connections).

This has happened because requests for protection against GRL
which were acquired by DML statements were ignoring presence of
pending GRL and thus the latter was starved.

This patch solves both these problems by re-implementing GRL
using metadata locks.

Similar to the old implementation acquisition of GRL in new
implementation is two-step. During the first step we block
all concurrent DML and DDL statements by acquiring global S
metadata lock (each DML and DDL statement acquires global IX
lock for its duration). During the second step we block commits
by acquiring global S lock in COMMIT namespace (commit code
acquires global IX lock in this namespace).

Note that unlike in old implementation acquisition of
protection against GRL in DML and DDL is semi-automatic.
We assume that any statement which should be blocked by GRL
will either open and acquires write-lock on tables or acquires
metadata locks on objects it is going to modify. For any such
statement global IX metadata lock is automatically acquired
for its duration.

The first problem is solved because waits for GRL become
visible to deadlock detector in metadata locking subsystem
and thus deadlocks like one in the first bug become impossible.

The second problem is solved because global S locks which
are used for GRL implementation are given preference over
IX locks which are acquired by concurrent DML (and we can
switch to fair scheduling in future if needed).

Important change:
FTWRL/GRL no longer blocks DML and DDL on temporary tables.
Before this patch behavior was not consistent in this respect:
in some cases DML/DDL statements on temporary tables were
blocked while in others they were not. Since the main use cases
for FTWRL are various forms of backups and temporary tables are
not preserved during backups we have opted for consistently
allowing DML/DDL on temporary tables during FTWRL/GRL.

Important change:
This patch changes thread state names which are used when
DML/DDL of FTWRL is waiting for global read lock. It is now
either "Waiting for global read lock" or "Waiting for commit
lock" depending on the stage on which FTWRL is.

Incompatible change:
To solve deadlock in events code which was exposed by this
patch we have to replace LOCK_event_metadata mutex with
metadata locks on events. As result we have to prohibit
DDL on events under LOCK TABLES.

This patch also adds extensive test coverage for interaction
of DML/DDL and FTWRL.

Performance of new and old global read lock implementations
in sysbench tests were compared. There were no significant
difference between new and old implementations.

mysql-test/include/check_ftwrl_compatible.inc:
  Added helper script which allows to check that a statement is
  compatible with FLUSH TABLES WITH READ LOCK.
mysql-test/include/check_ftwrl_incompatible.inc:
  Added helper script which allows to check that a statement is
  incompatible with FLUSH TABLES WITH READ LOCK.
mysql-test/include/handler.inc:
  Adjusted test case to the fact that now DROP TABLE closes
  open HANDLERs for the table to be dropped before checking
  if there active FTWRL in this connection.
mysql-test/include/wait_show_condition.inc:
  Fixed small error in the timeout message. The correct name
  of variable used as parameter for this script is "$condition"
  and not "$wait_condition".
mysql-test/r/delayed.result:
  Added test coverage for scenario which triggered assert in
  metadata locking subsystem.
mysql-test/r/events_2.result:
  Updated test results after prohibiting event DDL operations
  under LOCK TABLES.
mysql-test/r/flush.result:
  Added test coverage for bug #57006 "Deadlock between HANDLER
  and FLUSH TABLES WITH READ LOCK".
mysql-test/r/flush_read_lock.result:
  Added test coverage for various aspects of FLUSH TABLES WITH
  READ LOCK functionality.
mysql-test/r/flush_read_lock_kill.result:
  Adjusted test case after replacing custom global read lock
  implementation with one based on metadata locks. Use new
  debug_sync point. Do not disable concurrent inserts as now
  InnoDB we always use InnoDB table.
mysql-test/r/handler_innodb.result:
  Adjusted test case to the fact that now DROP TABLE closes
  open HANDLERs for the table to be dropped before checking
  if there active FTWRL in this connection.
mysql-test/r/handler_myisam.result:
  Adjusted test case to the fact that now DROP TABLE closes
  open HANDLERs for the table to be dropped before checking
  if there active FTWRL in this connection.
mysql-test/r/mdl_sync.result:
  Adjusted test case after replacing custom global read lock
  implementation with one based on metadata locks. Replaced
  usage of GRL-specific debug_sync's with appropriate sync
  points in MDL subsystem.
mysql-test/suite/perfschema/r/dml_setup_instruments.result:
  Updated test results after removing global
  COND_global_read_lock condition variable.
mysql-test/suite/perfschema/r/func_file_io.result:
  Ensure that this test doesn't affect subsequent tests.
  At the end of its execution enable back P_S instrumentation
  which this test disables at some point.
mysql-test/suite/perfschema/r/func_mutex.result:
  Ensure that this test doesn't affect subsequent tests.
  At the end of its execution enable back P_S instrumentation
  which this test disables at some point.
mysql-test/suite/perfschema/r/global_read_lock.result:
  Adjusted test case to take into account that new GRL
  implementation is based on MDL.
mysql-test/suite/perfschema/r/server_init.result:
  Adjusted test case after replacing custom global read
  lock implementation with one based on MDL and replacing
  LOCK_event_metadata mutex with metadata lock.
mysql-test/suite/perfschema/t/func_file_io.test:
  Ensure that this test doesn't affect subsequent tests.
  At the end of its execution enable back P_S instrumentation
  which this test disables at some point.
mysql-test/suite/perfschema/t/func_mutex.test:
  Ensure that this test doesn't affect subsequent tests.
  At the end of its execution enable back P_S instrumentation
  which this test disables at some point.
mysql-test/suite/perfschema/t/global_read_lock.test:
  Adjusted test case to take into account that new GRL
  implementation is based on MDL.
mysql-test/suite/perfschema/t/server_init.test:
  Adjusted test case after replacing custom global read
  lock implementation with one based on MDL and replacing
  LOCK_event_metadata mutex with metadata lock.
mysql-test/suite/rpl/r/rpl_tmp_table_and_DDL.result:
  Updated test results after prohibiting event DDL under
  LOCK TABLES.
mysql-test/t/delayed.test:
  Added test coverage for scenario which triggered assert in
  metadata locking subsystem.
mysql-test/t/events_2.test:
  Updated test case after prohibiting event DDL operations
  under LOCK TABLES.
mysql-test/t/flush.test:
  Added test coverage for bug #57006 "Deadlock between HANDLER
  and FLUSH TABLES WITH READ LOCK".
mysql-test/t/flush_block_commit.test:
  Adjusted test case after changing thread state name which
  is used when COMMIT waits for FLUSH TABLES WITH READ LOCK
  from "Waiting for release of readlock" to "Waiting for commit
  lock".
mysql-test/t/flush_block_commit_notembedded.test:
  Adjusted test case after changing thread state name which is
  used when DML waits for FLUSH TABLES WITH READ LOCK. Now we
  use "Waiting for global read lock" in this case.
mysql-test/t/flush_read_lock.test:
  Added test coverage for various aspects of FLUSH TABLES WITH
  READ LOCK functionality.
mysql-test/t/flush_read_lock_kill-master.opt:
  We no longer need to use make_global_read_lock_block_commit_loop
  debug tag in this test. Instead we rely on an appropriate
  debug_sync point in MDL code.
mysql-test/t/flush_read_lock_kill.test:
  Adjusted test case after replacing custom global read lock
  implementation with one based on metadata locks. Use new
  debug_sync point. Do not disable concurrent inserts as now
  InnoDB we always use InnoDB table.
mysql-test/t/lock_multi.test:
  Adjusted test case after changing thread state names which
  are used when DML or DDL waits for FLUSH TABLES WITH READ
  LOCK to "Waiting for global read lock".
mysql-test/t/mdl_sync.test:
  Adjusted test case after replacing custom global read lock
  implementation with one based on metadata locks. Replaced
  usage of GRL-specific debug_sync's with appropriate sync
  points in MDL subsystem. Updated thread state names which
  are used when DDL waits for FTWRL.
mysql-test/t/trigger_notembedded.test:
  Adjusted test case after changing thread state names which
  are used when DML or DDL waits for FLUSH TABLES WITH READ
  LOCK to "Waiting for global read lock".
sql/event_data_objects.cc:
  Removed Event_queue_element::status/last_executed_changed
  members and Event_queue_element::update_timing_fields()
  method. We no longer use this class for updating mysql.events
  once event is chosen for execution. Accesses to instances of
  this class in scheduler thread require protection by
  Event_queue::LOCK_event_queue mutex and we try to avoid
  updating table while holding this lock.
sql/event_data_objects.h:
  Removed Event_queue_element::status/last_executed_changed
  members and Event_queue_element::update_timing_fields()
  method. We no longer use this class for updating mysql.events
  once event is chosen for execution. Accesses to instances of
  this class in scheduler thread require protection by
  Event_queue::LOCK_event_queue mutex and we try to avoid
  updating table while holding this lock.
sql/event_db_repository.cc:
  - Changed Event_db_repository methods to not release all
    metadata locks once they are done updating mysql.events
    table. This allows to keep metadata lock protecting
    against GRL and lock protecting particular event around
    until corresponding DDL statement is written to the binary
    log.
  - Removed logic for conditional update of "status" and
    "last_executed" fields from update_timing_fields_for_event()
    method. In the only case when this method is called now
    "last_executed" is always modified and tracking change
    of "status" is too much hassle.
sql/event_db_repository.h:
  Removed logic for conditional update of "status" and
  "last_executed" fields from Event_db_repository::
  update_timing_fields_for_event() method.
  In the only case when this method is called now "last_executed"
  is always modified and tracking change of "status" field is
  too much hassle.
sql/event_queue.cc:
  Changed event scheduler code not to update mysql.events
  table while holding Event_queue::LOCK_event_queue mutex.
  Doing so led to a deadlock with a new GRL implementation.
  This deadlock didn't occur with old implementation due to
  fact that code acquiring protection against GRL ignored
  pending GRL requests (which lead to GRL starvation).
  One of goals of new implementation is to disallow GRL
  starvation and so we have to solve problem with this
  deadlock in a different way.
sql/events.cc:
  Changed methods of Events class to acquire protection
  against GRL while perfoming DDL statement and keep it
  until statement is written to the binary log.
  Unfortunately this step together with new GRL implementation
  exposed deadlock involving Events::LOCK_event_metadata
  and GRL. To solve it Events::LOCK_event_metadata mutex was
  replaced with a metadata lock on event. As a side-effect
  events DDL has to be prohibited under LOCK TABLES even in
  cases when mysql.events table was explicitly locked for
  write.
sql/events.h:
  Replaced Events::LOCK_event_metadata mutex with a metadata
  lock on event.
sql/ha_ndbcluster.cc:
  Updated code after replacing custom global read lock
  implementation with one based on MDL. Since MDL subsystem
  should now be able to detect deadlocks involving metadata
  locks and GRL there is no need for special handling of
  active GRL.
sql/handler.cc:
  Replaced custom implementation of global read lock with
  one based on metadata locks. Consequently when doing
  commit instead of calling method of Global_read_lock
  class to acquire protection against GRL we simply acquire
  IX in COMMIT namespace.
sql/lock.cc:
  Replaced custom implementation of global read lock with
  one based on metadata locks. This step allows to expose
  wait for GRL to deadlock detector of MDL subsystem and
  thus succesfully resolve deadlocks similar to one behind
  bug #57006 "Deadlock between HANDLER and FLUSH TABLES
  WITH READ LOCK". It also solves problem with GRL starvation
  described in bug #54673 "It takes too long to get readlock
  for 'FLUSH TABLES WITH READ LOCK'" since metadata locks used
  by GRL give preference to FTWRL statement instead of DML
  statements (if needed in future this can be changed to
  fair scheduling).
  
  Similar to old implementation of acquisition of GRL is
  two-step. During the first step we block all concurrent
  DML and DDL statements by acquiring global S metadata lock
  (each DML and DDL statement acquires global IX lock for
  its duration). During the second step we block commits by
  acquiring global S lock in COMMIT namespace (commit code
  acquires global IX lock in this namespace).
  
  Note that unlike in old implementation acquisition of
  protection against GRL in DML and DDL is semi-automatic.
  We assume that any statement which should be blocked by GRL
  will either open and acquires write-lock on tables or acquires
  metadata locks on objects it is going to modify. For any such
  statement global IX metadata lock is automatically acquired
  for its duration.
  
  To support this change:
  - Global_read_lock::lock/unlock_global_read_lock and
    make_global_read_lock_block_commit methods were changed
    accordingly.
  - Global_read_lock::wait_if_global_read_lock() and
    start_waiting_global_read_lock() methods were dropped.
    It is now responsibility of code acquiring metadata locks
    opening tables to acquire protection against GRL by
    explicitly taking global IX lock with statement duration.
  - Global variables, mutex and condition variable used by
    old implementation was removed.
  - lock_routine_name() was changed to use statement duration for
    its global IX lock. It was also renamed to lock_object_name()
    as it now also used to take metadata locks on events.
  - Global_read_lock::set_explicit_lock_duration() was added which
    allows not to release locks used for GRL when leaving prelocked
    mode.
sql/lock.h:
  - Renamed lock_routine_name() to lock_object_name() and changed
    its signature to allow its usage for events.
  - Removed broadcast_refresh() function. It is no longer needed
    with new GRL implementation.
sql/log_event.cc:
  Release metadata locks with statement duration at the end
  of processing legacy event for LOAD DATA. This ensures that
  replication thread processing such event properly releases
  its protection against global read lock.
sql/mdl.cc:
  Changed MDL subsystem to support new MDL-based implementation
  of global read lock.
  
  Added COMMIT and EVENTS namespaces for metadata locks. Changed
  thread state name for GLOBAL namespace to "Waiting for global
  read lock".
  
  Optimized MDL_map::find_or_insert() method to avoid taking
  m_mutex mutex when looking up MDL_lock objects for GLOBAL
  or COMMIT namespaces. We keep pre-created MDL_lock objects
  for these namespaces around and simply return pointers to
  these global objects when needed.
  
  Changed MDL_lock/MDL_scoped_lock to properly handle
  notification of insert delayed handler threads when FTWRL
  takes global S lock.
  
  Introduced concept of lock duration. In addition to locks with
  transaction duration which work in the way which is similar to
  how locks worked before (i.e. they are released at the end of
  transaction), locks with statement and explicit duration were
  introduced.
  Locks with statement duration are automatically released at the
  end of statement. Locks with explicit duration require explicit
  release and obsolete concept of transactional sentinel.
  
  * Changed MDL_request and MDL_ticket classes to support notion
    of duration.
  * Changed MDL_context to keep locks with different duration in
    different lists. Changed code handling ticket list to take
    this into account.
  * Changed methods responsible for releasing locks to take into
    account duration of tickets. Particularly public
    MDL_context::release_lock() method now only can release
    tickets with explicit duration (there is still internal
    method which allows to specify duration). To release locks
    with statement or transaction duration one have to use
    release_statement/transactional_locks() methods.
  * Concept of savepoint for MDL subsystem now has to take into
    account locks with statement duration. Consequently
    MDL_savepoint class was introduced and methods working with
    savepoints were updated accordingly.
  * Added methods which allow to set duration for one or all
    locks in the context.
sql/mdl.h:
  Changed MDL subsystem to support new MDL-based implementation
  of global read lock.
  
  Added COMMIT and EVENTS namespaces for metadata locks.
  
  Introduced concept of lock duration. In addition to locks with
  transaction duration which work in the way which is similar to
  how locks worked before (i.e. they are released at the end of
  transaction), locks with statement and explicit duration were
  introduced.
  Locks with statement duration are automatically released at the
  end of statement. Locks with explicit duration require explicit
  release and obsolete concept of transactional sentinel.
  
  * Changed MDL_request and MDL_ticket classes to support notion
    of duration.
  * Changed MDL_context to keep locks with different duration in
    different lists. Changed code handling ticket list to take
    this into account.
  * Changed methods responsible for releasing locks to take into
    account duration of tickets. Particularly public
    MDL_context::release_lock() method now only can release
    tickets with explicit duration (there is still internal
    method which allows to specify duration). To release locks
    with statement or transaction duration one have to use
    release_statement/transactional_locks() methods.
  * Concept of savepoint for MDL subsystem now has to take into
    account locks with statement duration. Consequently
    MDL_savepoint class was introduced and methods working with
    savepoints were updated accordingly.
  * Added methods which allow to set duration for one or all
    locks in the context.
sql/mysqld.cc:
  Removed global mutex and condition variables which were used
  by old implementation of GRL.
  Also we no longer need to initialize Events::LOCK_event_metadata
  mutex as it was replaced with metadata locks on events.
sql/mysqld.h:
  Removed global variable, mutex and condition variables which
  were used by old implementation of GRL.
sql/rpl_rli.cc:
  When slave thread closes tables which were open for handling
  of RBR events ensure that it releases global IX lock which
  was acquired as protection against GRL.
sql/sp.cc:
  Adjusted code to the new signature of lock_object/routine_name(),
  to the fact that one now needs specify duration of lock when
  initializing MDL_request and to the fact that savepoints for MDL
  subsystem are now represented by MDL_savepoint class.
sql/sp_head.cc:
  Ensure that statements in stored procedures release statement
  metadata locks and thus release their protectiong against GRL
  in proper moment in time.
  Adjusted code to the fact that one now needs specify duration
  of lock when initializing MDL_request.
sql/sql_admin.cc:
  Adjusted code to the fact that one now needs specify duration
  of lock when initializing MDL_request.
sql/sql_base.cc:
  - Implemented support for new approach to acquiring protection
    against global read lock. We no longer acquire such protection
    explicitly on the basis of statement flags. Instead we always
    rely on code which is responsible for acquiring metadata locks
    on object to be changed acquiring this protection. This is
    achieved by acquiring global IX metadata lock with statement
    duration. Code doing this also responsible for checking that
    current connection has no active GRL by calling an
    Global_read_lock::can_acquire_protection() method.
    Changed code in open_table() and lock_table_names()
    accordingly.
    Note that as result of this change DDL and DML on temporary
    tables is always compatible with GRL (before it was
    incompatible in some cases and compatible in other cases).
  - To speed-up code acquiring protection against GRL introduced
    m_has_protection_against_grl member in Open_table_context
    class. It indicates that protection was already acquired
    sometime during open_tables() execution and new attempts
    can be skipped.
  - Thanks to new GRL implementation calls to broadcast_refresh()
    became unnecessary and were removed.
  - Adjusted code to the fact that one now needs specify duration
    of lock when initializing MDL_request and to the fact that
    savepoints for MDL subsystem are now represented by
    MDL_savepoint class.
sql/sql_base.h:
  Adjusted code to the fact that savepoints for MDL subsystem are
  now represented by MDL_savepoint class.
  Also introduced Open_table_context::m_has_protection_against_grl
  member which allows to avoid acquiring protection against GRL
  while opening tables if such protection was already acquired.
sql/sql_class.cc:
  Changed THD::leave_locked_tables_mode() after transactional
  sentinel for metadata locks was obsoleted by introduction of
  locks with explicit duration.
sql/sql_class.h:
  - Adjusted code to the fact that savepoints for MDL subsystem
    are now represented by MDL_savepoint class.
  - Changed Global_read_lock class according to changes in
    global read lock implementation:
    * wait_if_global_read_lock and start_waiting_global_read_lock
      are now gone. Instead code needing protection against GRL
      has to acquire global IX metadata lock with statement
      duration itself. To help it new can_acquire_protection()
      was introduced. Also as result of the above change
      m_protection_count member is gone too.
    * Added m_mdl_blocks_commits_lock member to store metadata
      lock blocking commits.
    * Adjusted code to the fact that concept of transactional
      sentinel was obsoleted by concept of lock duration.
  - Removed CF_PROTECT_AGAINST_GRL flag as it is no longer
    necessary. New GRL implementation acquires protection
    against global read lock automagically when statement
    acquires metadata locks on tables or other objects it
    is going to change.
sql/sql_db.cc:
  Adjusted code to the fact that one now needs specify duration
  of lock when initializing MDL_request.
sql/sql_handler.cc:
  Removed call to broadcast_refresh() function. It is no longer
  needed with new GRL implementation.
  Adjusted code after introducing duration concept for metadata
  locks. Particularly to the fact transactional sentinel was
  replaced with explicit duration.
sql/sql_handler.h:
  Renamed mysql_ha_move_tickets_after_trans_sentinel() to
  mysql_ha_set_explicit_lock_duration() after transactional
  sentinel was obsoleted by locks with explicit duration.
sql/sql_insert.cc:
  Adjusted code handling delaying inserts after switching to
  new GRL implementation. Now connection thread initiating
  delayed insert has to acquire global IX lock in addition
  to metadata lock on table being inserted into. This IX lock
  protects against GRL and similarly to SW lock on table being
  inserted into has to be passed to handler thread in order to
  avoid deadlocks.
sql/sql_lex.cc:
  LEX::protect_against_global_read_lock member is no longer
  necessary since protection against GRL is automatically
  taken by code acquiring metadata locks/opening tables.
sql/sql_lex.h:
  LEX::protect_against_global_read_lock member is no longer
  necessary since protection against GRL is automatically
  taken by code acquiring metadata locks/opening tables.
sql/sql_parse.cc:
  - Implemented support for new approach to acquiring protection
    against global read lock. We no longer acquire such protection
    explicitly on the basis of statement flags. Instead we always
    rely on code which is responsible for acquiring metadata locks
    on object to be changed acquiring this protection. This is
    achieved by acquiring global IX metadata lock with statement
    duration. This lock is automatically released at the end of
    statement execution.
  - Changed implementation of CREATE/DROP PROCEDURE/FUNCTION not
    to release metadata locks and thus protection against of GRL
    in the middle of statement execution.
  - Adjusted code to the fact that one now needs specify duration
    of lock when initializing MDL_request and to the fact that
    savepoints for MDL subsystem are now represented by
    MDL_savepoint class.
sql/sql_prepare.cc:
  Adjusted code to the to the fact that savepoints for MDL
  subsystem are now represented by MDL_savepoint class.
sql/sql_rename.cc:
  With new GRL implementation there is no need to explicitly
  acquire protection against GRL before renaming tables.
  This happens automatically in code which acquires metadata
  locks on tables being renamed.
sql/sql_show.cc:
  Adjusted code to the fact that one now needs specify duration
  of lock when initializing MDL_request and to the fact that
  savepoints for MDL subsystem are now represented by
  MDL_savepoint class.
sql/sql_table.cc:
  - With new GRL implementation there is no need to explicitly
    acquire protection against GRL before dropping tables.
    This happens automatically in code which acquires metadata
    locks on tables being dropped.
  - Changed mysql_alter_table() not to release lock on new table
    name explicitly and to rely on automatic release of locks
    at the end of statement instead. This was necessary since
    now MDL_context::release_lock() is supported only for locks
    for explicit duration.
sql/sql_trigger.cc:
  With new GRL implementation there is no need to explicitly
  acquire protection against GRL before changing table triggers.
  This happens automatically in code which acquires metadata
  locks on tables which triggers are to be changed.
sql/sql_update.cc:
  Fix bug exposed by GRL testing. During prepare phase acquire
  only S metadata locks instead of SW locks to keep prepare of
  multi-UPDATE compatible with concurrent LOCK TABLES WRITE
  and global read lock.
sql/sql_view.cc:
  With new GRL implementation there is no need to explicitly
  acquire protection against GRL before creating view.
  This happens automatically in code which acquires metadata
  lock on view to be created.
sql/sql_yacc.yy:
  LEX::protect_against_global_read_lock member is no longer
  necessary since protection against GRL is automatically
  taken by code acquiring metadata locks/opening tables.
sql/table.cc:
  Adjusted code to the fact that one now needs specify duration
  of lock when initializing MDL_request.
sql/table.h:
  Adjusted code to the fact that one now needs specify duration
  of lock when initializing MDL_request.
sql/transaction.cc:
  Replaced custom implementation of global read lock with
  one based on metadata locks. Consequently when doing
  commit instead of calling method of Global_read_lock
  class to acquire protection against GRL we simply acquire
  IX in COMMIT namespace.
  Also adjusted code to the fact that MDL savepoint is now
  represented by MDL_savepoint class.
2010-11-11 20:11:05 +03:00
Dmitry Lenev
378cdc58c1 Patch that refactors global read lock implementation and fixes
bug #57006 "Deadlock between HANDLER and FLUSH TABLES WITH READ
LOCK" and bug #54673 "It takes too long to get readlock for
'FLUSH TABLES WITH READ LOCK'".

The first bug manifested itself as a deadlock which occurred
when a connection, which had some table open through HANDLER
statement, tried to update some data through DML statement
while another connection tried to execute FLUSH TABLES WITH
READ LOCK concurrently.

What happened was that FTWRL in the second connection managed
to perform first step of GRL acquisition and thus blocked all
upcoming DML. After that it started to wait for table open
through HANDLER statement to be flushed. When the first connection
tried to execute DML it has started to wait for GRL/the second
connection creating deadlock.

The second bug manifested itself as starvation of FLUSH TABLES
WITH READ LOCK statements in cases when there was a constant
stream of concurrent DML statements (in two or more
connections).

This has happened because requests for protection against GRL
which were acquired by DML statements were ignoring presence of
pending GRL and thus the latter was starved.

This patch solves both these problems by re-implementing GRL
using metadata locks.

Similar to the old implementation acquisition of GRL in new
implementation is two-step. During the first step we block
all concurrent DML and DDL statements by acquiring global S
metadata lock (each DML and DDL statement acquires global IX
lock for its duration). During the second step we block commits
by acquiring global S lock in COMMIT namespace (commit code
acquires global IX lock in this namespace).

Note that unlike in old implementation acquisition of
protection against GRL in DML and DDL is semi-automatic.
We assume that any statement which should be blocked by GRL
will either open and acquires write-lock on tables or acquires
metadata locks on objects it is going to modify. For any such
statement global IX metadata lock is automatically acquired
for its duration.

The first problem is solved because waits for GRL become
visible to deadlock detector in metadata locking subsystem
and thus deadlocks like one in the first bug become impossible.

The second problem is solved because global S locks which
are used for GRL implementation are given preference over
IX locks which are acquired by concurrent DML (and we can
switch to fair scheduling in future if needed).

Important change:
FTWRL/GRL no longer blocks DML and DDL on temporary tables.
Before this patch behavior was not consistent in this respect:
in some cases DML/DDL statements on temporary tables were
blocked while in others they were not. Since the main use cases
for FTWRL are various forms of backups and temporary tables are
not preserved during backups we have opted for consistently
allowing DML/DDL on temporary tables during FTWRL/GRL.

Important change:
This patch changes thread state names which are used when
DML/DDL of FTWRL is waiting for global read lock. It is now
either "Waiting for global read lock" or "Waiting for commit
lock" depending on the stage on which FTWRL is.

Incompatible change:
To solve deadlock in events code which was exposed by this
patch we have to replace LOCK_event_metadata mutex with
metadata locks on events. As result we have to prohibit
DDL on events under LOCK TABLES.

This patch also adds extensive test coverage for interaction
of DML/DDL and FTWRL.

Performance of new and old global read lock implementations
in sysbench tests were compared. There were no significant
difference between new and old implementations.
2010-11-11 20:11:05 +03:00
Konstantin Osipov
881da26b83 Remove a dead declaration. 2010-10-27 22:57:44 +04:00
Konstantin Osipov
09b07bfae1 Remove a dead declaration. 2010-10-27 22:57:44 +04:00
Dmitry Lenev
476939cb45 Reverted a temporary workaround for bug #56405 "Deadlock
in the MDL deadlock detector".

It is no longer needed as a better fix for this bug has
been pushed.
2010-09-30 17:29:12 +04:00
Dmitry Lenev
8322cad015 Reverted a temporary workaround for bug #56405 "Deadlock
in the MDL deadlock detector".

It is no longer needed as a better fix for this bug has
been pushed.
2010-09-30 17:29:12 +04:00
Jon Olav Hauglid
bf55d1fcf0 Merge from mysql-5.5-bugteam to mysql-5.5-runtime 2010-09-30 12:43:43 +02:00
Jon Olav Hauglid
a53f61e6e8 Merge from mysql-5.5-bugteam to mysql-5.5-runtime 2010-09-30 12:43:43 +02:00
Dmitry Lenev
e86bbbda55 Fix for bug #56251 "Deadlock with INSERT DELAYED and MERGE
tables".

Attempting to issue an INSERT DELAYED statement for a MERGE
table might have caused a deadlock if it happened as part of
a transaction or under LOCK TABLES, and there was a concurrent
DDL or LOCK TABLES ... WRITE statement which tried to lock one
of its underlying tables.

The problem occurred when a delayed insert handler thread tried
to open a MERGE table and discovered that to do this it had also
to open all underlying tables and hence acquire metadata
locks on them. Since metadata locks on the underlying tables were
not pre-acquired by the connection thread executing INSERT DELAYED,
attempts to do so might lead to waiting. In this case the
connection thread had to wait for the delayed insert thread.
If the thread which was preventing the lock on the underlying table
from being acquired had to wait for the connection thread (due to
this or other metadata locks), a deadlock occurred. 
This deadlock was not detected by the MDL deadlock detector since 
waiting for the handler thread by the connection thread is not
represented in the wait-for graph.

This patch solves the problem by ensuring that the delayed
insert handler thread never tries to open underlying tables 
of a MERGE table. Instead open_tables() is aborted right after
the parent table is opened and a ER_DELAYED_NOT_SUPPORTED 
error is emitted (which is passed to the connection thread and
ultimately to the user).

mysql-test/r/merge.result:
  Added test for bug #56251 "Deadlock with INSERT DELAYED and
  MERGE tables".
mysql-test/t/merge.test:
  Added test for bug #56251 "Deadlock with INSERT DELAYED and
  MERGE tables".
sql/sql_base.cc:
  Changed open_n_lock_single_table() to take prelocking strategy
  as an argument instead of always using DML_prelocking_strategy.
sql/sql_base.h:
  Changed open_n_lock_single_table() to take prelocking strategy
  as an argument instead of always using DML_prelocking_strategy.
  Added a version of this function which is compatible with old
  signature.
sql/sql_insert.cc:
  When opening MERGE table in delayed insert thread stop and emit
  ER_DELAYED_NOT_SUPPORTED right after opening main table and
  before opening underlying tables. This ensures that we won't
  try to acquire metadata lock on underlying tables which might
  lead to a deadlock.
  This is achieved by using special prelocking strategy which
  abort open_tables() process as soon as we discover that we
  have opened table with engine which doesn't support delayed
  inserts.
2010-09-15 18:15:31 +04:00
Dmitry Lenev
6d5065a9f4 Fix for bug #56251 "Deadlock with INSERT DELAYED and MERGE
tables".

Attempting to issue an INSERT DELAYED statement for a MERGE
table might have caused a deadlock if it happened as part of
a transaction or under LOCK TABLES, and there was a concurrent
DDL or LOCK TABLES ... WRITE statement which tried to lock one
of its underlying tables.

The problem occurred when a delayed insert handler thread tried
to open a MERGE table and discovered that to do this it had also
to open all underlying tables and hence acquire metadata
locks on them. Since metadata locks on the underlying tables were
not pre-acquired by the connection thread executing INSERT DELAYED,
attempts to do so might lead to waiting. In this case the
connection thread had to wait for the delayed insert thread.
If the thread which was preventing the lock on the underlying table
from being acquired had to wait for the connection thread (due to
this or other metadata locks), a deadlock occurred. 
This deadlock was not detected by the MDL deadlock detector since 
waiting for the handler thread by the connection thread is not
represented in the wait-for graph.

This patch solves the problem by ensuring that the delayed
insert handler thread never tries to open underlying tables 
of a MERGE table. Instead open_tables() is aborted right after
the parent table is opened and a ER_DELAYED_NOT_SUPPORTED 
error is emitted (which is passed to the connection thread and
ultimately to the user).
2010-09-15 18:15:31 +04:00
Dmitry Lenev
65a438d87a Fix for bug #55273 "FLUSH TABLE tm WITH READ LOCK for Merge
table causes assert failure".

Attempting to use FLUSH TABLE table_list WITH READ LOCK
statement for a MERGE table led to an assertion failure if
one of its children was not present in the list of tables
to be flushed. The problem was not visible in non-debug builds.

The assertion failure was caused by the fact that in such
situations FLUSH TABLES table_list WITH READ LOCK implementation
tried to use (e.g. lock) such child tables without acquiring
metadata lock on them. This happened because when opening tables
we assumed metadata locks on all tables were already acquired
earlier during statement execution and a such assumption was
false for MERGE children.

This patch fixes the problem by ensuring at open_tables() time
that we try to acquire metadata locks on all tables to be opened. 
For normal tables such requests are satisfied instantly since
locks are already acquired for them. For MERGE children metadata
locks are acquired in normal fashion.

Note that FLUSH TABLES merge_table WITH READ LOCK will lock for
read both the MERGE table and its children but will flush only 
the MERGE table. To flush children one has to mention them in table
list explicitly. This is expected behavior and it is consistent with
usage patterns for this statement (e.g. in mysqlhotcopy script).

mysql-test/r/flush.result:
  Added test case for bug #55273 "FLUSH TABLE tm WITH READ LOCK
  for Merge table causes assert failure".
mysql-test/t/flush.test:
  Added test case for bug #55273 "FLUSH TABLE tm WITH READ LOCK
  for Merge table causes assert failure".
sql/sql_base.cc:
  Changed lock_table_names() to support newly introduced
  MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK flag.
sql/sql_base.h:
  Introduced MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK flag for
  open_tables() and lock_table_names() which allows to skip
  acquiring of global and schema-scope locks when SNW, SNRW or
  X metadata locks are acquired.
sql/sql_reload.cc:
  Changed "FLUSH TABLES table_list WITH READ LOCK" code not to
  cause assert about missing metadata locks when MERGE table is
  flushed without one of its underlying tables.
  To achieve this we no longer call open_and_lock_tables() with
  MYSQL_OPEN_HAS_MDL_LOCK flag so this function automatically
  acquires metadata locks on MERGE children if such lock has
  not been already acquired at earlier stage. Instead we call
  this function with MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK flag to
  suppress acquiring of global IX lock in order to keep FLUSH
  TABLES  table_list WITH READ LOCK compatible with FLUSH TABLE
  WITH READ LOCK.
  Also changed implementation to use lock_table_names() function
  for pre-acquiring of metadata locks instead of custom code.
  To implement this change moved setting of open_type member for
  table list elements to parser.
sql/sql_yacc.yy:
  Now we set acceptable type of table for FLUSH TABLES table_list
  WITH READ LOCK at parsing time instead of execution time.
2010-09-09 18:29:14 +04:00
Dmitry Lenev
3326614df1 Fix for bug #55273 "FLUSH TABLE tm WITH READ LOCK for Merge
table causes assert failure".

Attempting to use FLUSH TABLE table_list WITH READ LOCK
statement for a MERGE table led to an assertion failure if
one of its children was not present in the list of tables
to be flushed. The problem was not visible in non-debug builds.

The assertion failure was caused by the fact that in such
situations FLUSH TABLES table_list WITH READ LOCK implementation
tried to use (e.g. lock) such child tables without acquiring
metadata lock on them. This happened because when opening tables
we assumed metadata locks on all tables were already acquired
earlier during statement execution and a such assumption was
false for MERGE children.

This patch fixes the problem by ensuring at open_tables() time
that we try to acquire metadata locks on all tables to be opened. 
For normal tables such requests are satisfied instantly since
locks are already acquired for them. For MERGE children metadata
locks are acquired in normal fashion.

Note that FLUSH TABLES merge_table WITH READ LOCK will lock for
read both the MERGE table and its children but will flush only 
the MERGE table. To flush children one has to mention them in table
list explicitly. This is expected behavior and it is consistent with
usage patterns for this statement (e.g. in mysqlhotcopy script).
2010-09-09 18:29:14 +04:00
Dmitry Lenev
f052fa3aad A temporary workaround for bug #56405 "Deadlock in the
MDL deadlock detector".

Deadlock could have occurred when workload containing mix
of DML, DDL and FLUSH TABLES statements affecting same
set of tables was executed in heavily concurrent environment.

This deadlock occurred when several connections tried to
perform deadlock detection in metadata locking subsystem.
The first connection started traversing wait-for graph,
encountered sub-graph representing wait for flush, acquired
LOCK_open and dived into sub-graph inspection. When it has
encounterd sub-graph corresponding to wait for metadata lock
and blocked while trying to acquire rd-lock on
MDL_lock::m_rwlock (*) protecting this subgraph, since some
other thread had wr-lock on it. When this wr-lock was released
it could have happened (if there was other pending wr-lock
against this rwlock) that rd-lock from the first connection
was left unsatisfied but at the same time new rd-lock request
from the second connection sneaked in and was satisfied (for
this to be possible second rd- request should come exactly
after wr-lock is released but before pending wr-lock manages
to grab rwlock, which is possible both on Linux and in our
own rwlock implementation). If this second connection
continued traversing wait-for graph and encountered sub-graph
representing wait for flush it tried to acquire LOCK_open
and thus deadlock was created.

This patch tries to workaround this problem but not allowing
deadlock detector to lock LOCK_open mutex if some other thread
doing deadlock detection already owns it and current search
depth is greater than 0. Instead deadlock is reported.

Other possible solutions are either known to have negative
effects on performance or require much more time for proper
implementation and testing.

No test case is provided as this bug is very hard to repeat
in MTR environment but is repeatable with the help of RQG
tests.

sql/mdl.cc:
  Moved Deadlock_detection_visitor::m_current_search_depth to
  parent class to make it available in
  TABLE_SHARE::visit_subgraph().
  Added MDL_wait_for_graph_visitor::abort_traversal() method
  which allows to abort traversal of a wait-for graph and
  report a deadlock.
sql/mdl.h:
  Moved Deadlock_detection_visitor::m_current_search_depth to
  parent class to make it available in
  TABLE_SHARE::visit_subgraph().
  Added MDL_wait_for_graph_visitor::abort_traversal() method
  which allows to abort traversal of a wait-for graph and
  report a deadlock.
sql/sql_base.cc:
  Added dd_owns_lock_open counter and mutex protecting it to
  track number of connections which do deadlock detection and
  own or try to acquire LOCK_open.
sql/sql_base.h:
  Added dd_owns_lock_open counter and mutex protecting it to
  track number of connections which do deadlock detection and
  own or try to acquire LOCK_open.
sql/table.cc:
  Workaround bug #56405 but not allowing MDL deadlock detector
  to lock LOCK_open mutex if some other thread doing deadlock
  detection already owns it and current search depth is greater
  than 0. Instead report deadlock.
2010-09-06 21:29:02 +04:00
Dmitry Lenev
ac35157899 A temporary workaround for bug #56405 "Deadlock in the
MDL deadlock detector".

Deadlock could have occurred when workload containing mix
of DML, DDL and FLUSH TABLES statements affecting same
set of tables was executed in heavily concurrent environment.

This deadlock occurred when several connections tried to
perform deadlock detection in metadata locking subsystem.
The first connection started traversing wait-for graph,
encountered sub-graph representing wait for flush, acquired
LOCK_open and dived into sub-graph inspection. When it has
encounterd sub-graph corresponding to wait for metadata lock
and blocked while trying to acquire rd-lock on
MDL_lock::m_rwlock (*) protecting this subgraph, since some
other thread had wr-lock on it. When this wr-lock was released
it could have happened (if there was other pending wr-lock
against this rwlock) that rd-lock from the first connection
was left unsatisfied but at the same time new rd-lock request
from the second connection sneaked in and was satisfied (for
this to be possible second rd- request should come exactly
after wr-lock is released but before pending wr-lock manages
to grab rwlock, which is possible both on Linux and in our
own rwlock implementation). If this second connection
continued traversing wait-for graph and encountered sub-graph
representing wait for flush it tried to acquire LOCK_open
and thus deadlock was created.

This patch tries to workaround this problem but not allowing
deadlock detector to lock LOCK_open mutex if some other thread
doing deadlock detection already owns it and current search
depth is greater than 0. Instead deadlock is reported.

Other possible solutions are either known to have negative
effects on performance or require much more time for proper
implementation and testing.

No test case is provided as this bug is very hard to repeat
in MTR environment but is repeatable with the help of RQG
tests.
2010-09-06 21:29:02 +04:00
Alexander Nozdrin
cc0925f5d9 Bug#27480 (Extend CREATE TEMPORARY TABLES privilege
to allow temp table operations) -- prerequisite patch #3.

Rename open_temporary_table() to open_table_uncached().
open_temporary_table() will be introduced in following patches
to open temporary tables for a statement.
2010-08-31 14:03:36 +04:00
Alexander Nozdrin
d2159e37f2 Bug#27480 (Extend CREATE TEMPORARY TABLES privilege
to allow temp table operations) -- prerequisite patch #3.

Rename open_temporary_table() to open_table_uncached().
open_temporary_table() will be introduced in following patches
to open temporary tables for a statement.
2010-08-31 14:03:36 +04:00
Alexander Nozdrin
b4badf8013 Remove unused enum (enum open_table_mode).
It was added by mistake during backport from 6.0.
2010-08-31 13:53:49 +04:00
Alexander Nozdrin
1f1eba3c68 Remove unused enum (enum open_table_mode).
It was added by mistake during backport from 6.0.
2010-08-31 13:53:49 +04:00
Alexander Nozdrin
65c5e8dcbf Bug#27480 (Extend CREATE TEMPORARY TABLES privilege
to allow temp table operations) -- prerequisite patch #2.

Introduce a new form of find_temporary_table() function:
find_temporary_table() by a table key. It will be used
in further patches.

Replace find_temporary_table(table_list->db, table_list->name)
by more appropiate find_temporary_table(table_list) across
the codebase.
2010-08-31 13:52:56 +04:00
Alexander Nozdrin
2e462c8f99 Bug#27480 (Extend CREATE TEMPORARY TABLES privilege
to allow temp table operations) -- prerequisite patch #2.

Introduce a new form of find_temporary_table() function:
find_temporary_table() by a table key. It will be used
in further patches.

Replace find_temporary_table(table_list->db, table_list->name)
by more appropiate find_temporary_table(table_list) across
the codebase.
2010-08-31 13:52:56 +04:00
Jon Olav Hauglid
02863b4180 Merge from mysql-5.5-runtime to mysql-5.5-bugfixing. 2010-08-20 10:24:32 +02:00
Jon Olav Hauglid
39ac44d660 Merge from mysql-5.5-runtime to mysql-5.5-bugfixing. 2010-08-20 10:24:32 +02:00
Alfranio Correia
ac6026ce27 BUG#53452 Inconsistent behavior of binlog_direct_non_transactional_updates with
temp table
            
This patch introduces two key changes in the replication's behavior.
            
Firstly, it reverts part of BUG#51894 which puts any update to temporary tables
into the trx-cache. Now, updates to temporary tables are handled according to
the type of their engines as a regular table.
            
Secondly, an unsafe mixed statement, (i.e. a statement that access transactional
table as well non-transactional or temporary table, and writes to any of them),
are written into the trx-cache in order to minimize errors in the execution when
the statement logging format is in use.
            
Such changes has a direct impact on which statements are classified as unsafe
statements and thus part of BUG#53259 is reverted.
2010-08-20 03:59:58 +01:00
Alfranio Correia
c6d4915f3c BUG#53452 Inconsistent behavior of binlog_direct_non_transactional_updates with
temp table
            
This patch introduces two key changes in the replication's behavior.
            
Firstly, it reverts part of BUG#51894 which puts any update to temporary tables
into the trx-cache. Now, updates to temporary tables are handled according to
the type of their engines as a regular table.
            
Secondly, an unsafe mixed statement, (i.e. a statement that access transactional
table as well non-transactional or temporary table, and writes to any of them),
are written into the trx-cache in order to minimize errors in the execution when
the statement logging format is in use.
            
Such changes has a direct impact on which statements are classified as unsafe
statements and thus part of BUG#53259 is reverted.
2010-08-20 03:59:58 +01:00
Jon Olav Hauglid
41caa7f483 Bug #56085 Embedded server tests fails with assert in
check_if_table_exists()

This assert was triggered when the server tried to load plugins
while running in embedded server mode. In embedded server mode,
check_if_table_exists() was used to check if mysql.plugin existed
so that ER_NO_SUCH_TABLE could be silently ignored.
The problem was that this check was done without acquiring a metadata
lock on mysql.plugin first. This triggered the assert.

This patch fixes the problem by removing the call to
check_if_table_exists() from plugin_load(). Instead an error handler
which traps ER_NO_SUCH_TABLE is installed before trying to open
mysql.plugin when running in embedded server mode.

No test coverage added since this assert was triggered by 
existing tests running in embedded server mode.


sql/sql_base.cc:
  Renamed Prelock_error_handler to No_such_table_error_handler
  and moved the declaration to sql_base.h to make it usable
  in plugin_load().
sql/sql_base.h:
  Renamed Prelock_error_handler to No_such_table_error_handler
  and moved the declaration to sql_base.h to make it usable
  in plugin_load().
sql/sql_plugin.cc:
  Removed call to check_if_table_exists() used to check for mysql.plugin 
  in plugin_load() for embedded server. Instead install error handler
  which traps ER_NO_SUCH_TABLE during open_and_lock_tables().
2010-08-19 11:33:37 +02:00
Jon Olav Hauglid
b02f5dd8bc Bug #56085 Embedded server tests fails with assert in
check_if_table_exists()

This assert was triggered when the server tried to load plugins
while running in embedded server mode. In embedded server mode,
check_if_table_exists() was used to check if mysql.plugin existed
so that ER_NO_SUCH_TABLE could be silently ignored.
The problem was that this check was done without acquiring a metadata
lock on mysql.plugin first. This triggered the assert.

This patch fixes the problem by removing the call to
check_if_table_exists() from plugin_load(). Instead an error handler
which traps ER_NO_SUCH_TABLE is installed before trying to open
mysql.plugin when running in embedded server mode.

No test coverage added since this assert was triggered by 
existing tests running in embedded server mode.
2010-08-19 11:33:37 +02:00
Jon Olav Hauglid
eb498cce4d Manual merge from mysql-5.5-bugfixing to mysql-5.5-runtime. 2010-08-18 13:29:04 +02:00
Jon Olav Hauglid
5139bf6c8f Manual merge from mysql-5.5-bugfixing to mysql-5.5-runtime. 2010-08-18 13:29:04 +02:00
Konstantin Osipov
8ce6e98aa3 Extract reload_acl_and_cache() and flush_tables_with_read_lock()
into an own implementation file.
2010-08-13 13:51:48 +04:00
Konstantin Osipov
4e935a5329 Extract reload_acl_and_cache() and flush_tables_with_read_lock()
into an own implementation file.
2010-08-13 13:51:48 +04:00
Mattias Jonsson
daf0e6b725 Bug#53676: Unexpected errors and possible table
corruption on ADD PARTITION and LOCK TABLE
Bug#53770: Server crash at handler.cc:2076 on
           LOAD DATA after timed out COALESCE PARTITION

5.5 fix for:
Bug#51042: REORGANIZE PARTITION can leave table in an
           inconsistent state in case of crash
Needs to be back-ported to 5.1

5.5 fix for:
Bug#50418: DROP PARTITION does not interact with
           transactions

Main problem was non-persistent operations done
before meta-data lock was taken (53770+53676).
And 53676 needed to keep the table/partitions opened and locked
while copying the data to the new partitions.

Also added thorough tests to spot some additional bugs
in the ddl_log code, which could result in bad state
between the .frm and partitions.

Collapsed patch, includes all fixes required from the reviewers.

mysql-test/r/partition_innodb.result:
  updated result with new test
mysql-test/suite/parts/inc/partition_crash.inc:
  crash test include file
mysql-test/suite/parts/inc/partition_crash_add.inc:
  test all states in fast_alter_partition_table
  ADD PARTITION branch
mysql-test/suite/parts/inc/partition_crash_change.inc:
  test all states in fast_alter_partition_table
  CHANGE PARTITION branch
mysql-test/suite/parts/inc/partition_crash_drop.inc:
  test all states in fast_alter_partition_table
  DROP PARTITION branch
mysql-test/suite/parts/inc/partition_fail.inc:
  recovery test including injecting errors
mysql-test/suite/parts/inc/partition_fail_add.inc:
  test all states in fast_alter_partition_table
  ADD PARTITION branch
mysql-test/suite/parts/inc/partition_fail_change.inc:
  test all states in fast_alter_partition_table
  CHANGE PARTITION branch
mysql-test/suite/parts/inc/partition_fail_drop.inc:
  test all states in fast_alter_partition_table
  DROP PARTITION branch
mysql-test/suite/parts/inc/partition_mgm_crash.inc:
  include file that runs all crash and failure injection tests.
mysql-test/suite/parts/r/partition_debug_innodb.result:
  new test result file
mysql-test/suite/parts/r/partition_debug_myisam.result:
  new test result file
mysql-test/suite/parts/r/partition_special_innodb.result:
  updated result
mysql-test/suite/parts/r/partition_special_myisam.result:
  updated result
mysql-test/suite/parts/t/partition_debug_innodb-master.opt:
  opt file for using with crashing tests of partitioned innodb
mysql-test/suite/parts/t/partition_debug_innodb.test:
  partitioned innodb test that require debug builds
mysql-test/suite/parts/t/partition_debug_myisam-master.opt:
  opt file for using with crashing tests of partitioned myisam
mysql-test/suite/parts/t/partition_debug_myisam.test:
  partitioned myisam test that require debug builds
mysql-test/suite/parts/t/partition_special_innodb-master.opt:
  added innodb-file-per-table to easier verify partition status on disk
mysql-test/suite/parts/t/partition_special_innodb.test:
  added test case
mysql-test/suite/parts/t/partition_special_myisam.test:
  added test case
mysql-test/t/partition_innodb.test:
  added test case
sql/sql_base.cc:
  Moved alter_close_tables to sql_partition.cc
sql/sql_base.h:
  removed some non existing and duplicated functions.
sql/sql_partition.cc:
  fast_alter_partition_table:
  Spletted abort_and_upgrad_lock_and_close_table
  to its parts (wait_while_table_is_used and
  alter_close_tables) and always have
  wait_while_table_is_used before any persistent
  operations (including logs, which will be executed
  on failure) and alter_close_tables after
  create/read/write operations and before
  drop operations.
  
  moved alter_close_tables here from sql_base.cc
  
  Added error injections for better test coverage.
  
  write_log_final_change_partition:
  fixed a log_entry linking bug (delete_frm was not
  linked to change/drop partition)
  and drop partition must be executed before
  change partition (change partition can rename a
  partition to an old name, like REORG p1 INTO (p1,p2).
  
  write_log_add_change_partition:
  need to use drop_frm first, and relinking that entry
  and reusing its execute entry.
sql/sql_table.cc:
  added initialization of next_active_log_entry.
sql/table.h:
  removed a duplicate declaration.
2010-08-13 09:50:25 +02:00
Mattias Jonsson
9a7a64acdb Bug#53676: Unexpected errors and possible table
corruption on ADD PARTITION and LOCK TABLE
Bug#53770: Server crash at handler.cc:2076 on
           LOAD DATA after timed out COALESCE PARTITION

5.5 fix for:
Bug#51042: REORGANIZE PARTITION can leave table in an
           inconsistent state in case of crash
Needs to be back-ported to 5.1

5.5 fix for:
Bug#50418: DROP PARTITION does not interact with
           transactions

Main problem was non-persistent operations done
before meta-data lock was taken (53770+53676).
And 53676 needed to keep the table/partitions opened and locked
while copying the data to the new partitions.

Also added thorough tests to spot some additional bugs
in the ddl_log code, which could result in bad state
between the .frm and partitions.

Collapsed patch, includes all fixes required from the reviewers.
2010-08-13 09:50:25 +02:00
Konstantin Osipov
82759db0cc Remove dead code.
sql/sql_base.h:
  Remove an unused parameter.
sql/sql_servers.cc:
  Remove an unused parameter.
2010-08-12 20:44:41 +04:00
Konstantin Osipov
7349ddae6f Remove dead code. 2010-08-12 20:44:41 +04:00
Konstantin Osipov
29c4873ad5 Commit on behalf of Dmitry Lenev.
Merge his patch for Bug#52044 into 5.5, and apply 
review comments.
2010-08-12 17:50:23 +04:00
Konstantin Osipov
8673d2b20f Commit on behalf of Dmitry Lenev.
Merge his patch for Bug#52044 into 5.5, and apply 
review comments.
2010-08-12 17:50:23 +04:00
Konstantin Osipov
523066987d A fix for Bug#41158 "DROP TABLE holds LOCK_open during unlink()".
Remove acquisition of LOCK_open around file system operations,
since such operations are now protected by metadata locks.
Rework table discovery algorithm to not require LOCK_open.

No new tests added since all MDL locking operations are covered
in lock.test and mdl_sync.test, and as long as these tests
pass despite the increased concurrency, consistency must be
unaffected.

mysql-test/t/disabled.def:
  Disable NDB tests due to Bug#55799.
sql/datadict.cc:
  No longer necessary to protect ha_create_table() with
  LOCK_open. Serial execution is now ensured by metadata
  locks.
sql/ha_ndbcluster.cc:
  Do not manipulate with LOCK_open in cluster code.
sql/ha_ndbcluster_binlog.cc:
  Do not manipulate with LOCK_open in cluster code.
sql/ha_ndbcluster_binlog.h:
  Update function signature.
sql/handler.cc:
  Implement ha_check_if_table_exists().
  @todo: some engines provide ha_table_exists_in_engine()
  handlerton call, for those we perhaps shouldn't
  call ha_discover(), to be more efficient.
  Since currently it's only NDB, postpone till
  integration with NDB.
sql/handler.h:
  Declare ha_check_if_table_exists() function.
sql/mdl.cc:
  Remove an obsolete comment.
sql/sql_base.cc:
  Update to a new signature of close_cached_tables():
  from now on we always call it without LOCK_open.
  Update comments.
  Remove get_table_share_with_create(), we should
  not attempt to create a table under LOCK_open.
  Introduce get_table_share_with_discover() instead,
  which would request a back off action if the table
  exists in engine.
  Remove acquisition of LOCK_open for 
  data dictionary operations, such as check_if_table_exists().
  Do not use get_table_share_with_create/discover for views,
  where it's not needed.
  Make tdc_remove_table() optionally acquire LOCK_open
  to simplify usage of this function.
  Use the right mutex in the partitioning code when
  manipulating with thd->open_tables.
sql/sql_base.h:
  Update signatures of changes functions.
sql/sql_insert.cc:
  Do not wrap quick_rm_table() with LOCK_open acquisition, 
  this is unnecessary.
sql/sql_parse.cc:
  Update to the new calling convention of tdc_remove_table().
  Update to the new signature of close_cached_tables().
  Update comments.
sql/sql_rename.cc:
  Update to the new calling convention of tdc_remove_table().
  Remove acquisition of LOCK_open around filesystem
  operations.
sql/sql_show.cc:
  Remove get_trigger_table_impl().
  Do not acquire LOCK_open for a dirty read of the trigger
  file.
sql/sql_table.cc:
  Do not acquire LOCK_open for filesystem operations.
sql/sql_trigger.cc:
  Do not require LOCK_open for trigger file I/O.
sql/sql_truncate.cc:
  Update to the new signature of tdc_remove_table().
sql/sql_view.cc:
  Do not require LOCK_open for view I/O.
  Use tdc_remove_table() to expel view share.
  Update comments.
sql/sys_vars.cc:
  Update to the new signature of close_cached_tables().
2010-08-09 22:33:47 +04:00
Konstantin Osipov
f8bfa3287d A fix for Bug#41158 "DROP TABLE holds LOCK_open during unlink()".
Remove acquisition of LOCK_open around file system operations,
since such operations are now protected by metadata locks.
Rework table discovery algorithm to not require LOCK_open.

No new tests added since all MDL locking operations are covered
in lock.test and mdl_sync.test, and as long as these tests
pass despite the increased concurrency, consistency must be
unaffected.
2010-08-09 22:33:47 +04:00
Konstantin Osipov
a91a5ee3bf Cleanup: remove unused declarations from sql_base.h.
sql/sql_base.cc:
  Update a comment to not refer to a non-existing
  function.
sql/sql_base.h:
  Remove unused declarations (bad merge with the header
  files split worklog).
sql/sql_test.cc:
  Cleanup: remove unused declarations.
2010-08-04 20:29:13 +04:00
Konstantin Osipov
6a447d1047 Cleanup: remove unused declarations from sql_base.h. 2010-08-04 20:29:13 +04:00
Konstantin Osipov
d85c628180 Merge trunk-bugfixing -> trunk-runtime. 2010-07-29 14:18:13 +04:00
Konstantin Osipov
14b769cfc6 Merge trunk-bugfixing -> trunk-runtime. 2010-07-29 14:18:13 +04:00
Dmitry Lenev
00496b7acd Fix for bug #52044 "FLUSH TABLES WITH READ LOCK and FLUSH
TABLES <list> WITH READ LOCK are incompatible".

The problem was that FLUSH TABLES <list> WITH READ LOCK
which was issued when other connection has acquired global
read lock using FLUSH TABLES WITH READ LOCK was blocked
and has to wait until global read lock is released.

This issue stemmed from the fact that FLUSH TABLES <list>
WITH READ LOCK implementation has acquired X metadata locks
on tables to be flushed. Since these locks required acquiring
of global IX lock this statement was incompatible with global
read lock.

This patch addresses problem by using SNW metadata type of
lock for tables to be flushed by FLUSH TABLES <list> WITH
READ LOCK. It is OK to acquire them without global IX lock
as long as we won't try to upgrade those locks. Since SNW
locks allow concurrent statements using same table FLUSH
TABLE <list> WITH READ LOCK now has to wait until old
versions of tables to be flushed go away after acquiring
metadata locks. Since such waiting can lead to deadlock
MDL deadlock detector was extended to take into account
waits for flush and resolve such deadlocks.

As a bonus code in open_tables() which was responsible for
waiting old versions of tables to go away was refactored.
Now when we encounter old version of table in open_table()
we don't back-off and wait for all old version to go away,
but instead wait for this particular table to be flushed.
Such approach supported by deadlock detection should reduce
number of scenarios in which FLUSH TABLES aborts concurrent
multi-statement transactions.

Note that active FLUSH TABLES <list> WITH READ LOCK still
blocks concurrent FLUSH TABLES WITH READ LOCK statement
as the former keeps tables open and thus prevents the
latter statement from doing flush.

mysql-test/include/handler.inc:
  Adjusted test case after changing status which is set
  when FLUSH TABLES waits for tables to be flushed from
  "Flushing tables" to "Waiting for table".
mysql-test/r/flush.result:
  Added test which checks that "flush tables <list> with
  read lock" is compatible with active "flush tables with
  read lock" but not vice-versa. This test also covers
  bug #52044 "FLUSH TABLES WITH READ LOCK and FLUSH TABLES
  <list> WITH READ LOCK are incompatible".
mysql-test/r/mdl_sync.result:
  Added scenarios in which wait for table to be flushed
  causes deadlocks to the coverage of MDL deadlock detector.
mysql-test/suite/perfschema/r/dml_setup_instruments.result:
  Adjusted test results after removal of COND_refresh
  condition variable.
mysql-test/suite/perfschema/r/server_init.result:
  Adjusted test and its results after removal of COND_refresh
  condition variable.
mysql-test/suite/perfschema/t/server_init.test:
  Adjusted test and its results after removal of COND_refresh
  condition variable.
mysql-test/t/flush.test:
  Added test which checks that "flush tables <list> with
  read lock" is compatible with active "flush tables with
  read lock" but not vice-versa. This test also covers
  bug #52044 "FLUSH TABLES WITH READ LOCK and FLUSH TABLES
  <list> WITH READ LOCK are incompatible".
mysql-test/t/kill.test:
  Adjusted test case after changing status which is set
  when FLUSH TABLES waits for tables to be flushed from
  "Flushing tables" to "Waiting for table".
mysql-test/t/lock_multi.test:
  Adjusted test case after changing status which is set
  when FLUSH TABLES waits for tables to be flushed from
  "Flushing tables" to "Waiting for table".
mysql-test/t/mdl_sync.test:
  Added scenarios in which wait for table to be flushed
  causes deadlocks to the coverage of MDL deadlock detector.
sql/ha_ndbcluster.cc:
  Adjusted code after adding one more parameter for
  close_cached_tables() call - timeout for waiting for
  table to be flushed.
sql/ha_ndbcluster_binlog.cc:
  Adjusted code after adding one more parameter for
  close_cached_tables() call - timeout for waiting for
  table to be flushed.
sql/lock.cc:
  Removed COND_refresh condition variable. See comment
  for sql_base.cc for details.
sql/mdl.cc:
  Now MDL deadlock detector takes into account information
  about waits for table flushes when searching for deadlock.
  To implement this change:
  - Declaration of enum_deadlock_weight and
    Deadlock_detection_visitor were moved to mdl.h header
    to make them available to the code in table.cc which
    implements deadlock detector traversal through edges
    of waiters graph representing waiting for flush.
  - Since now MDL_context may wait not only for metadata
    lock but also for table to be flushed an abstract
    Wait_for_edge class was introduced. Its descendants
    MDL_ticket and Flush_ticket incapsulate specifics
    of inspecting waiters graph when following through
    edge representing wait of particular type.
  
  We no longer require global IX metadata lock when acquiring
  SNW or SNRW locks. Such locks are needed only when metadata
  locks of these types are upgraded to X locks. This allows
  to use SNW locks in FLUSH TABLES <list> WITH READ LOCK
  implementation and keep the latter compatible with global
  read lock.
sql/mdl.h:
  Now MDL deadlock detector takes into account information
  about waits for table flushes when searching for deadlock.
  To implement this change:
  - Declaration of enum_deadlock_weight and
    Deadlock_detection_visitor were moved to mdl.h header
    to make them available to the code in table.cc which
    implements deadlock detector traversal through edges
    of waiters graph representing waiting for flush.
  - Since now MDL_context may wait not only for metadata
    lock but also for table to be flushed an abstract
    Wait_for_edge class was introduced. Its descendants
    MDL_ticket and Flush_ticket incapsulate specifics
    of inspecting waiters graph when following through
    edge representing wait of particular type.
  - Deadlock_detection_visitor now has m_table_shares_visited
    member which allows to support recursive locking for
    LOCK_open. This is required when deadlock detector
    inspects waiters graph which contains several edges
    representing waits for flushes or needs to come through
    the such edge more than once.
sql/mysqld.cc:
  Removed COND_refresh condition variable. See comment
  for sql_base.cc for details.
sql/mysqld.h:
  Removed COND_refresh condition variable. See comment
  for sql_base.cc for details.
sql/sql_base.cc:
  Changed approach to how threads are waiting for table
  to be flushed. Now thread that wants to wait for old
  table to go away subscribes for notification by adding
  Flush_ticket to table's share and waits using
  MDL_context::m_wait object. Once table gets flushed
  (i.e. all tables are closed and table share is ready
  to be destroyed) all such waiters are notified
  individually.
  Thanks to this change MDL deadlock detector can take
  such waits into account.
  
  To implement this/as result of this change:
  - tdc_wait_for_old_versions() was replaced with
    tdc_wait_for_old_version() which waits for individual
    old share to go away and which is called by open_table()
    after finding out that share is outdated. We don't
    need to perform back-off before such waiting thanks
    to the fact that deadlock detector now sees such waits.
  - As result Open_table_ctx::m_mdl_requests became
    unnecessary and was removed. We no longer allocate
    copies of MDL_request objects on MEM_ROOT when
    MYSQL_OPEN_FORCE_SHARED/SHARED_HIGH_PRIO flags are
    in effect.
  - close_cached_tables() and tdc_wait_for_old_version()
    share code which implements waiting for share to be
    flushed - the both use TABLE_SHARE::wait_until_flush()
    method. Thanks to this close_cached_tables() supports
    timeouts and has extra parameter for this.
  - Open_table_context::OT_MDL_CONFLICT enum element was
    renamed to OT_CONFLICT as it is now also used in cases
    when back-off is required to resolve deadlock caused
    by waiting for flush and not metadata lock.
  - In cases when we discover that current connection tries
    to open tables from different generation we now simply
    back-off and restart process of opening tables. To
    support this Open_table_context::OT_REOPEN_TABLES enum
    element was added.
  - COND_refresh condition variable became unnecessary and
    was removed.
  - mysql_notify_thread_having_shared_lock() no longer wakes
    up connections waiting for flush as all such connections
    can be waken up by deadlock detector if necessary.
sql/sql_base.h:
  - close_cached_tables() now has one more parameter -
    timeout for waiting for table to be flushed.
  - Open_table_context::OT_MDL_CONFLICT enum element was
    renamed to OT_CONFLICT as it is now also used in cases
    when back-off is required to resolve deadlock caused
    by waiting for flush and not metadata lock.
    Added new OT_REOPEN_TABLES enum element to be used in
    cases when we need to restart open tables process even
    in the middle of transaction.
  - Open_table_ctx::m_mdl_requests became unnecessary and
    was removed.
sql/sql_class.h:
  Added assert ensuring that we won't use LOCK_open mutex
  with THD::enter_cond(). Otherwise deadlocks can arise in
  MDL deadlock detector.
sql/sql_parse.cc:
  Changed FLUSH TABLES <list> WITH READ LOCK to take SNW
  metadata locks instead of X locks on tables to be flushed.
  Since we no longer require global IX lock to be taken
  when SNW locks are taken this makes this statement
  compatible with FLUSH TABLES WITH READ LOCK statement.
  Since SNW locks allow other connections to have table
  opened FLUSH TABLES <list> WITH READ LOCK now has to
  wait during open_tables() for old version to go away.
  Such waits can lead to deadlocks which will be detected
  by MDL deadlock detector which now takes waits for table
  to be flushed into account.
  
  Also adjusted code after adding one more parameter for
  close_cached_tables() call - timeout for waiting for
  table to be flushed.
sql/sql_yacc.yy:
  FLUSH TABLES <list> WITH READ LOCK now needs only SNW
  metadata locks on tables.
sql/sys_vars.cc:
  Adjusted code after adding one more parameter for
  close_cached_tables() call - timeout for waiting for
  table to be flushed.
sql/table.cc:
  Implemented new approach to how threads are waiting for
  table to be flushed. Now thread that wants to wait for
  old table to go away subscribes for notification by
  adding Flush_ticket to table's share and waits using
  MDL_context::m_wait object. Once table gets flushed
  (i.e. all tables are closed and table share is ready
  to be destroyed) all such waiters are notified
  individually. This change allows to make such waits
  visible inside of MDL deadlock detector.
  To do it:
  
  - Added list of waiters/Flush_tickets to TABLE_SHARE
    class.
  - Changed free_table_share() to postpone freeing of
    share memory until last waiter goes away and to
    wake up subscribed waiters.
  - Added TABLE_SHARE::wait_until_flushed() method which
    implements subscription to the list of waiters for
    table to be flushed and waiting for this event.
  
  Implemented interface which allows to expose waits for
  flushes to MDL deadlock detector:
  
  - Introduced Flush_ticket class a descendant of
    Wait_for_edge class.
  - Added TABLE_SHARE::find_deadlock() method which allows
    deadlock detector to find out what contexts are still
    using old version of table in question (i.e. to find
    out what contexts are waited for by owner of
    Flush_ticket).
sql/table.h:
  In order to support new strategy of waiting for table flush
  (see comment for table.cc for details) added list of
  waiters/Flush_tickets to TABLE_SHARE class.
  
  Implemented interface which allows to expose waits for
  flushes to MDL deadlock detector:
  - Introduced Flush_ticket class a descendant of
    Wait_for_edge class.
  - Added TABLE_SHARE::find_deadlock() method which allows
    deadlock detector to find out what contexts are still
    using old version of table in question (i.e. to find
    out what contexts are waited for by owner of
    Flush_ticket).
2010-07-27 17:34:58 +04:00
Dmitry Lenev
5fff906edd Fix for bug #52044 "FLUSH TABLES WITH READ LOCK and FLUSH
TABLES <list> WITH READ LOCK are incompatible".

The problem was that FLUSH TABLES <list> WITH READ LOCK
which was issued when other connection has acquired global
read lock using FLUSH TABLES WITH READ LOCK was blocked
and has to wait until global read lock is released.

This issue stemmed from the fact that FLUSH TABLES <list>
WITH READ LOCK implementation has acquired X metadata locks
on tables to be flushed. Since these locks required acquiring
of global IX lock this statement was incompatible with global
read lock.

This patch addresses problem by using SNW metadata type of
lock for tables to be flushed by FLUSH TABLES <list> WITH
READ LOCK. It is OK to acquire them without global IX lock
as long as we won't try to upgrade those locks. Since SNW
locks allow concurrent statements using same table FLUSH
TABLE <list> WITH READ LOCK now has to wait until old
versions of tables to be flushed go away after acquiring
metadata locks. Since such waiting can lead to deadlock
MDL deadlock detector was extended to take into account
waits for flush and resolve such deadlocks.

As a bonus code in open_tables() which was responsible for
waiting old versions of tables to go away was refactored.
Now when we encounter old version of table in open_table()
we don't back-off and wait for all old version to go away,
but instead wait for this particular table to be flushed.
Such approach supported by deadlock detection should reduce
number of scenarios in which FLUSH TABLES aborts concurrent
multi-statement transactions.

Note that active FLUSH TABLES <list> WITH READ LOCK still
blocks concurrent FLUSH TABLES WITH READ LOCK statement
as the former keeps tables open and thus prevents the
latter statement from doing flush.
2010-07-27 17:34:58 +04:00
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
Konstantin Osipov
ec2c3bf2c1 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.
2010-07-27 14:25:53 +04:00
Luis Soares
9a714c935f BUG#55387: binlog.binlog_tmp_table crashes the server
sporadically

There are two problems:

1. When closing temporary tables, during the THD clean up - and
   after the session connection was already closed, there is a
   chance we can push an error into the THD diagnostics area, if
   the writing of the implicit DROP event to the binary log fails
   for some reason. As a consequence an assertion can be
   triggered, because at that point the diagnostics area is
   already set.

2. Using push_warning with MYSQL_ERROR::WARN_LEVEL_ERROR is a 
   bug.

Given that close_temporary_tables is mostly called from
THD::cleanup - ie, with the session already closed, we fix
problem #1 by allowing the diagnostics area to be
overwritten. There is one other place in the code that calls
close_temporary_tables - while applying Start_log_event_v3. To
cover that case, we make close_temporary_tables to return the
error, thus, propagating upwards in the stack.

To fix problem #2, we replace push_warning with sql_print_error.

sql/log_event.cc:
  Added handling of error returned by close_temporary_tables to
  Start_log_event_v3::do_apply_event.
sql/sql_base.cc:
  Three changes to close_temporary_tables:
  1. it returns a boolean now (instead of void)
  2. it uses sql_print_error instead of push_warning when writing to
     binary log fails
  3. we set can_overwrite_status before writing to the binary log,
     thence not risking triggering an assertion by any other push
     into diagnostics area happening inside mysql_bin_log.write.
sql/sql_base.h:
  Changed the interface of close_temporary_tables so that it returns
  bool instead of void.
2010-07-22 16:56:50 +01:00
Luis Soares
2773385dd7 BUG#55387: binlog.binlog_tmp_table crashes the server
sporadically

There are two problems:

1. When closing temporary tables, during the THD clean up - and
   after the session connection was already closed, there is a
   chance we can push an error into the THD diagnostics area, if
   the writing of the implicit DROP event to the binary log fails
   for some reason. As a consequence an assertion can be
   triggered, because at that point the diagnostics area is
   already set.

2. Using push_warning with MYSQL_ERROR::WARN_LEVEL_ERROR is a 
   bug.

Given that close_temporary_tables is mostly called from
THD::cleanup - ie, with the session already closed, we fix
problem #1 by allowing the diagnostics area to be
overwritten. There is one other place in the code that calls
close_temporary_tables - while applying Start_log_event_v3. To
cover that case, we make close_temporary_tables to return the
error, thus, propagating upwards in the stack.

To fix problem #2, we replace push_warning with sql_print_error.
2010-07-22 16:56:50 +01:00
Dmitry Lenev
10582e2abe A follow-up for 5.5 version of fix for bug#54360 "Deadlock
DROP/ALTER/CREATE DATABASE with open HANDLER".

Remove wait_for_condition() which became unused after 
database locks were replaced with MDL scoped locks.
If one needs functionality provided by this call one can 
always use THD::enter_cond()/exit_cond() methods.

Also removed an unused include from sql_db.cc and updated 
comment describing one of used includes to reflect current
situation.
2010-07-01 18:58:47 +04:00
Dmitry Lenev
8ad1aa562f A follow-up for 5.5 version of fix for bug#54360 "Deadlock
DROP/ALTER/CREATE DATABASE with open HANDLER".

Remove wait_for_condition() which became unused after 
database locks were replaced with MDL scoped locks.
If one needs functionality provided by this call one can 
always use THD::enter_cond()/exit_cond() methods.

Also removed an unused include from sql_db.cc and updated 
comment describing one of used includes to reflect current
situation.
2010-07-01 18:58:47 +04:00
Jon Olav Hauglid
9ff272fbbd A 5.5 version of the fix for Bug #54360 "Deadlock DROP/ALTER/CREATE
DATABASE with open HANDLER"

Remove LOCK_create_db, database name locks, and use metadata locks instead.
This exposes CREATE/DROP/ALTER DATABASE statements to the graph-based
deadlock detector in MDL, and paves the way for a safe, deadlock-free
implementation of RENAME DATABASE.

Database DDL statements will now take exclusive metadata locks on
the database name, while table/view/routine DDL statements take
intention exclusive locks on the database name. This prevents race
conditions between database DDL and table/view/routine DDL.
(e.g. DROP DATABASE with concurrent CREATE/ALTER/DROP TABLE)

By adding database name locks, this patch implements
WL#4450 "DDL locking: CREATE/DROP DATABASE must use database locks" and
WL#4985 "DDL locking: namespace/hierarchical locks".

The patch also changes code to use init_one_table() where appropriate.
The new lock_table_names() function requires TABLE_LIST::db_length to
be set correctly, and this is taken care of by init_one_table().

This patch also adds a simple template to help work with 
the mysys HASH data structure.

Most of the patch was written by Konstantin Osipov.
2010-07-01 15:53:46 +02:00
Jon Olav Hauglid
41a3dfe490 A 5.5 version of the fix for Bug #54360 "Deadlock DROP/ALTER/CREATE
DATABASE with open HANDLER"

Remove LOCK_create_db, database name locks, and use metadata locks instead.
This exposes CREATE/DROP/ALTER DATABASE statements to the graph-based
deadlock detector in MDL, and paves the way for a safe, deadlock-free
implementation of RENAME DATABASE.

Database DDL statements will now take exclusive metadata locks on
the database name, while table/view/routine DDL statements take
intention exclusive locks on the database name. This prevents race
conditions between database DDL and table/view/routine DDL.
(e.g. DROP DATABASE with concurrent CREATE/ALTER/DROP TABLE)

By adding database name locks, this patch implements
WL#4450 "DDL locking: CREATE/DROP DATABASE must use database locks" and
WL#4985 "DDL locking: namespace/hierarchical locks".

The patch also changes code to use init_one_table() where appropriate.
The new lock_table_names() function requires TABLE_LIST::db_length to
be set correctly, and this is taken care of by init_one_table().

This patch also adds a simple template to help work with 
the mysys HASH data structure.

Most of the patch was written by Konstantin Osipov.
2010-07-01 15:53:46 +02:00
Konstantin Osipov
33c57e2f9e WL#5419 "LOCK_open scalability: make tdc_refresh_version
an atomic counter"

Split the large LOCK_open section in open_table(). 
Do not call open_table_from_share() under LOCK_open.
Remove thd->version.

This fixes
Bug#50589 "Server hang on a query evaluated using a temporary 
table"
Bug#51557 "LOCK_open and kernel_mutex are not happy together"
Bug#49463 "LOCK_table and innodb are not nice when handler 
instances are created".

This patch has effect on storage engines that rely on
ha_open() PSEA method being called under LOCK_open.
In particular:

1) NDB is broken and left unfixed. NDB relies on LOCK_open
being kept as part of ha_open(), since it uses auto-discovery.
While previously the NDB open code was race-prone, now
it simply fails on asserts.

2) HEAP engine had a race in ha_heap::open() when
a share for the same table could be added twice
to the list of shares, or a dangling reference to a share
stored in HEAP handler. This patch aims to address this
problem by 'pinning' the newly created share in the 
internal HEAP engine share list until at least one
handler instance is created using that share.


include/heap.h:
  Add members to HP_CREATE_INFO.
  Declare heap_release_share().
sql/lock.cc:
  Remove thd->version, use thd->open_tables->s->version instead.
sql/repl_failsafe.cc:
  Remove thd->version.
sql/sql_base.cc:
  - close_thread_table(): move handler cleanup code outside the critical section protected by LOCK_open.
  - remove thd->version
  - split the large critical section in open_table() that
  opens a new table from share and is protected by LOCK_open
  into 2 critical sections, thus reducing the critical path.
  - make check_if_table_exists() acquire LOCK_open internally.
  - use thd->open_tables->s->version instead of thd->refresh_version to make sure that all tables in
  thd->open_tables are in the same refresh series.
sql/sql_base.h:
  Add declaration for check_if_table_exists().
sql/sql_class.cc:
  Remove init_open_tables_state(), it's now equal to
  reset_open_tables_state().
sql/sql_class.h:
  Remove thd->version, THD::init_open_tables_state().
sql/sql_plugin.cc:
  Use table->m_needs_reopen to mark the table as stale
  rather than manipulate with thd->version, which is no more.
sql/sql_udf.cc:
  Use table->m_needs_reopen to mark the table as stale
  rather than manipulate with thd->version, which is no more.
sql/table.h:
  Remove an unused variable.
sql/tztime.cc:
  Use table->m_needs_reopen to mark the table as stale
  rather than manipulate with thd->version, which is no more.
storage/heap/CMakeLists.txt:
  Add heap tests to cmake build files.
storage/heap/ha_heap.cc:
  Fix a race when ha_heap::ha_open() could insert two 
  HP_SHARE objects into the internal share list or store
  a dangling reference to a share in ha_heap instance,
  or wrongly set implicit_emptied.
storage/heap/hp_create.c:
  Optionally pin a newly created share in the list of shares
  by increasing its open_count. This is necessary to 
  make sure that a newly created share doesn't disappear while
  a HP_INFO object is being created to reference it.
storage/heap/hp_open.c:
  When adding a new HP_INFO object to the list of objects
  in the heap share, make sure the open_count is not increased
  twice.
storage/heap/hp_test1.c:
  Adjust the test to new function signatures.
storage/heap/hp_test2.c:
  Adjust the test to new function signatures.
2010-06-11 19:28:18 +04:00
Konstantin Osipov
b140456601 WL#5419 "LOCK_open scalability: make tdc_refresh_version
an atomic counter"

Split the large LOCK_open section in open_table(). 
Do not call open_table_from_share() under LOCK_open.
Remove thd->version.

This fixes
Bug#50589 "Server hang on a query evaluated using a temporary 
table"
Bug#51557 "LOCK_open and kernel_mutex are not happy together"
Bug#49463 "LOCK_table and innodb are not nice when handler 
instances are created".

This patch has effect on storage engines that rely on
ha_open() PSEA method being called under LOCK_open.
In particular:

1) NDB is broken and left unfixed. NDB relies on LOCK_open
being kept as part of ha_open(), since it uses auto-discovery.
While previously the NDB open code was race-prone, now
it simply fails on asserts.

2) HEAP engine had a race in ha_heap::open() when
a share for the same table could be added twice
to the list of shares, or a dangling reference to a share
stored in HEAP handler. This patch aims to address this
problem by 'pinning' the newly created share in the 
internal HEAP engine share list until at least one
handler instance is created using that share.
2010-06-11 19:28:18 +04:00
Konstantin Osipov
90a87cd52d A pre-requisite for WL#5419 "LOCK_open scalability:
make tdc_refresh_version an 
atomic counter".
Backport the trivial changes from mysql-trunk-iplus.
2010-06-10 15:43:32 +04:00
Konstantin Osipov
41d95c5049 A pre-requisite for WL#5419 "LOCK_open scalability:
make tdc_refresh_version an 
atomic counter".
Backport the trivial changes from mysql-trunk-iplus.
2010-06-10 15:43:32 +04:00
Dmitry Lenev
9dbd9ce185 Patch that changes approach to how we acquire metadata
locks for DML statements and changes the way MDL locks
are acquired/granted in contended case.

Instead of backing-off when a lock conflict is encountered
and waiting for it to go away before restarting open_tables()
process we now wait for lock to be released without releasing
any previously acquired locks. If conflicting lock goes away
we resume opening tables. If waiting leads to a deadlock we
try to resolve it by backing-off and restarting open_tables()
immediately.

As result both waiting for possibility to acquire and
acquiring of a metadata lock now always happen within the
same MDL API call. This has allowed to make release of a lock
and granting it to the most appropriate pending request an
atomic operation.
Thanks to this it became possible to wake up during release
of lock only those waiters which requests can be satisfied
at the moment as well as wake up only one waiter in case
when granting its request would prevent all other requests
from being satisfied. This solves thundering herd problem
which occured in cases when we were releasing some lock and
woke up many waiters for SNRW or X locks (this was the issue
in bug#52289 "performance regression for MyISAM in sysbench
OLTP_RW test".
This also allowed to implement more fair (FIFO) scheduling
among waiters with the same priority.
It also opens the door for introducing new types of requests
for metadata locks such as low-prio SNRW lock which is
necessary in order to support LOCK TABLES LOW_PRIORITY WRITE.

Notice that after this sometimes can report ER_LOCK_DEADLOCK
error in cases in which it has not happened before.
Particularly we will always report this error if waiting for
conflicting lock has happened in the middle of transaction
and resulted in a deadlock. Before this patch the error was
not reported if deadlock could have been resolved by backing
off all metadata locks acquired by the current statement.

mysql-test/r/mdl_sync.result:
  Added test coverage for some aspects of deadlock handling in
  metadata locking subsystem.
  Adjusted test case after removing back-off in general case
  when conflicting metadata lock is encountered during
  open_tables() (now this happens only if waiting for
  conflicting lock to go away leads to a deadlock).
mysql-test/r/sp_sync.result:
  Adjusted test case after removing back-off in general case
  when conflicting metadata lock is encountered during
  open_tables() (now this happens only if waiting for
  conflicting lock to go away leads to a deadlock).
mysql-test/suite/perfschema/r/dml_setup_instruments.result:
  Adjusted test results after renaming MDL_context::
  m_waiting_for_lock rwlock to m_LOCK_waiting_for.
mysql-test/suite/rpl/r/rpl_sp.result:
  Adjusted test case after implementing new approach to
  acquiring metadata locks in open_tables(). We no longer
  release all MDL locks acquired by statement before waiting
  for conflicting lock to go away. As result DROP FUNCTION
  statement has to wait for DML statement which managed to
  acquire metadata lock on function being dropped and now
  waits for other conflicting metadata lock to go away.
mysql-test/suite/rpl/t/rpl_sp.test:
  Adjusted test case after implementing new approach to
  acquiring metadata locks in open_tables(). We no longer
  release all MDL locks acquired by statement before waiting
  for conflicting lock to go away. As result DROP FUNCTION
  statement has to wait for DML statement which managed to
  acquire metadata lock on function being dropped and now
  waits for other conflicting metadata lock to go away.
mysql-test/t/mdl_sync.test:
  Added test coverage for some aspects of deadlock handling in
  metadata locking subsystem.
  Adjusted test case after removing back-off in general case
  when conflicting metadata lock is encountered during
  open_tables() (now this happens only if waiting for
  conflicting lock to go away leads to a deadlock).
mysql-test/t/sp_sync.test:
  Adjusted test case after removing back-off in general case
  when conflicting metadata lock is encountered during
  open_tables() (now this happens only if waiting for
  conflicting lock to go away leads to a deadlock).
sql/mdl.cc:
  Changed MDL subsystem to support new approach to acquring
  metadata locks in open tables and more fair and efficient
  scheduling of metadata locks. To implement this:
  - Made releasing of the lock and granting it to the most
    appropriate pending request atomic operation. As result it
    became possible to wake up only those waiters requests from
    which can be satisfied at the moment as well as wake-up
    only one waiter in case when granting its request would
    prevent all other requests from being satisfied.
    This solved thundering herd problem which occured in cases
    when we were releasing some lock and woke up many waiters
    for SNRW or X locks (this was the issue in Bug #52289
    "performance regression for MyISAM in sysbench OLTP_RW
    test".
    To emphasize above changes wake_up_waiters() was renamed
    to MDL_context::reschedule_waiters().
  - Changed code to add tickets for new requests to the back of
    waiters queue and to select tickets to be satisfied from
    the head of the queue if possible (this makes scheduling of
    requests with the same priority fair). To be able to do
    this efficiently we now use for waiting and granted queues
    version of I_P_List class which provides fast push_back()
    method.
  - Members and methods of MDL_context related to sending
    and waiting for signal were moved to separate MDL_wait
    class.
  - Since in order to avoid race conditions we must grant the
    lock only to the context which was not chosen as a victim
    of deadlock, killed or aborted due to timeout
    MDL_wait::set_status() (former awake()) was changed not to
    send signal if signal slot is already occupied and to
    indicate this fact through its return value. As another
    consequence MDL_wait::timed_wait() method was changed to
    handle timeout (optionally) and abort due to kill as
    signals which make signal slot occupied.
  - Renamed MDL_context::acquire_lock_impl() to acquire_lock().
    Changed it to be able correctly process requests for shared
    locks when there are open HANDLERs, made this method more
    optimized for acquisition of shared locks. As part of this
    change moved code common between try_acquire_lock() and
    acquire_lock() to new try_acquire_lock_impl() method.
    Also adjusted acquire_lock()'s code to take into account
    the fact that in cases when lock is granted as result of
    MDL_context::reschedule_waiters() call (i.e. when it is
    granted after waiting for lock conflict to go away)
    updating MDL_lock state is responsibility of the thread
    calling reschedule_waiters().
  - Changed MDL_context::find_deadlock() to send VICTIM
    signal even if victim is the context which has initiated
    deadlock detection. This is required in order to avoid
    races in cases when the same context simultaneously is
    chosen as a victim and its request for lock is satisfied.
    As result return value of this method became unnecessary
    and it was changed to return void.
    Adjusted MDL_lock::find_deadlock() method to take into
    account that now there can be a discrepancy between
    MDL_context::m_waiting_for value being set and real state
    of the ticket this member points to.
  - Renamed MDL_context::m_waiting_for_lock to m_LOCK_waiting_for
    and MDL_context::stop_waiting() to done_waiting_for().
  - Finally, removed MDL_context::wait_for_lock() method.
sql/mdl.h:
  Changed MDL subsystem to support new approach to acquring
  metadata locks in open tables and more fair and efficient
  scheduling of metadata locks. To implement this:
  - Members and methods of MDL_context related to sending
    and waiting for signal were moved to separate MDL_wait
    class.
  - Since now in order to avoid race conditions we must grant
    the lock only to the context which was not chosen as a
    victim of deadlock, killed or aborted due to timeout
    MDL_wait::set_status (former awake()) was changed not to
    send signal if signal slot is already occupied and to
    indicate this fact through its return value.
    Also NORMAL_WAKE_UP signal became GRANTED, and timeouts
    and aborts due to kill became full blown signals rather
    than simple return values.
  - MDL_wait::timed_wait() now takes extra parameter that
    indicates whether signal should be set if timeout is
    reached.
  - Enabled fast push_back() operation in MDL_context::m_tickets
    list to make move_ticket_after_trans_sentinel() method more
    efficient.
  - Removed MDL_context::wait_for_lock() method.
  - Renamed MDL_context::m_waiting_for_lock to m_LOCK_waiting_for
    and MDL_context::stop_waiting() to done_waiting_for().
  - MDL_context::acquire_lock_impl() became acquire_lock().
  - Introduced MDL_context::try_acquire_lock_impl() as a
    place for code shared by try_acquire_lock and
    acquire_lock().
  - Due to fact that now VICTIM signal is sent even if victim
    is the context which has initiated deadlock detection
    find_deadlock() no longer needs a return value.
sql/sql_base.cc:
  Implemented new approach to acquiring metadata locks in
  open_tables(). We no longer perform back-off when conflicting
  metadata lock is encountered. Instead we wait for this lock
  to go away while holding all locks which were acquired so
  far. Back-off is only used in situation when further waiting
  will cause a deadlock which could be avoided by performing
  back-off and restarting open_tables() process. Absence of
  waiting between back-off and restart of acquiring metadata
  locks can't lead to livelocks as MDL subsystem was changed
  to make release of lock and granting it to waiting lock
  an atomic action, so back-off will automatically give way
  to other participants of deadlock loop.
  Accordingly:
  - open_table_get_mdl_lock() and open_and_process_routine()
    were changed to wait for conflicting metadata lock to
    go away without back-off. Only if such wait leads to a
    deadlock back-off is requested. As part of this change
    new error handler class was introduced which converts,
    if possible, ER_LOCK_DEADLOCK error to a request for
    back-off and re-start of open_tables() process.
  - Open_table_context::recover_from_failed_open() was changed
    not to wait in case of metadata lock conflict. Instead we
    immediately proceed to re-acquiring locks.
  - Open_table_context::request_backoff_action() now always
    emits error if back-off is requested in the middle of
    transaction as we can't be sure that releasing lock
    which were acquired only by current statement will
    resolve a deadlock. Before this patch such situations were
    successfully detected thanks to the fact that we called
    MDL_context::wait_for_lock() method in
    recover_from_failed_open().
  - In order to avoid deadlocks open_tables() code was adjusted
    to flush open HANDLERs for which there are pending requests
    for X locks before restarting the process of acquiring
    metadata locks.
  - Changed close_tables_for_reopen() not to reset MDL_request
    for tables belonging to the tail of prelocking list. It is
    no longer necessary as these MDL_request objects won't be
    used for any waiting.
  - Adjusted comment in tdc_wait_for_old_version() to avoid
    mentioning removed MDL_context::wait_for_lock() method.
sql/sql_base.h:
  As we no longer wait for conflicting metadata lock away in
  Open_table_context::recover_from_failed_open() method,
  Open_table_context::OT_WAIT_MDL_LOCK action was renamed to
  OT_MDL_CONFLICT.
  Also Open_table_context::m_failed_mdl_request became
  unnecessary and was removed.
sql/sql_plist.h:
  Extended I_P_List template to support efficient push_back()
  operation if it is parameterized with an appropriate policy
  class.
sql/sql_show.cc:
  Adjusted code after removal of MDL_context::wait_for_lock()
  method. Now if one needs to acquire metadata lock with waiting
  one has to use a variant of MDL_context::acquire_lock() method.
2010-06-07 11:06:55 +04:00
Dmitry Lenev
571acc878b Patch that changes approach to how we acquire metadata
locks for DML statements and changes the way MDL locks
are acquired/granted in contended case.

Instead of backing-off when a lock conflict is encountered
and waiting for it to go away before restarting open_tables()
process we now wait for lock to be released without releasing
any previously acquired locks. If conflicting lock goes away
we resume opening tables. If waiting leads to a deadlock we
try to resolve it by backing-off and restarting open_tables()
immediately.

As result both waiting for possibility to acquire and
acquiring of a metadata lock now always happen within the
same MDL API call. This has allowed to make release of a lock
and granting it to the most appropriate pending request an
atomic operation.
Thanks to this it became possible to wake up during release
of lock only those waiters which requests can be satisfied
at the moment as well as wake up only one waiter in case
when granting its request would prevent all other requests
from being satisfied. This solves thundering herd problem
which occured in cases when we were releasing some lock and
woke up many waiters for SNRW or X locks (this was the issue
in bug#52289 "performance regression for MyISAM in sysbench
OLTP_RW test".
This also allowed to implement more fair (FIFO) scheduling
among waiters with the same priority.
It also opens the door for introducing new types of requests
for metadata locks such as low-prio SNRW lock which is
necessary in order to support LOCK TABLES LOW_PRIORITY WRITE.

Notice that after this sometimes can report ER_LOCK_DEADLOCK
error in cases in which it has not happened before.
Particularly we will always report this error if waiting for
conflicting lock has happened in the middle of transaction
and resulted in a deadlock. Before this patch the error was
not reported if deadlock could have been resolved by backing
off all metadata locks acquired by the current statement.
2010-06-07 11:06:55 +04:00
Jon Olav Hauglid
142a162c66 manual merge from mysql-trunk-bugfixing
Conflicts:
Text conflict in mysql-test/r/archive.result
Contents conflict in mysql-test/r/innodb_bug38231.result
Text conflict in mysql-test/r/mdl_sync.result
Text conflict in mysql-test/suite/binlog/t/disabled.def
Text conflict in mysql-test/suite/rpl_ndb/r/rpl_ndb_binlog_format_errors.result
Text conflict in mysql-test/t/archive.test
Contents conflict in mysql-test/t/innodb_bug38231.test
Text conflict in mysql-test/t/mdl_sync.test
Text conflict in sql/sp_head.cc
Text conflict in sql/sql_show.cc
Text conflict in sql/table.cc
Text conflict in sql/table.h
2010-06-06 13:19:29 +02:00
Jon Olav Hauglid
1af11051bf manual merge from mysql-trunk-bugfixing
Conflicts:
Text conflict in mysql-test/r/archive.result
Contents conflict in mysql-test/r/innodb_bug38231.result
Text conflict in mysql-test/r/mdl_sync.result
Text conflict in mysql-test/suite/binlog/t/disabled.def
Text conflict in mysql-test/suite/rpl_ndb/r/rpl_ndb_binlog_format_errors.result
Text conflict in mysql-test/t/archive.test
Contents conflict in mysql-test/t/innodb_bug38231.test
Text conflict in mysql-test/t/mdl_sync.test
Text conflict in sql/sp_head.cc
Text conflict in sql/sql_show.cc
Text conflict in sql/table.cc
Text conflict in sql/table.h
2010-06-06 13:19:29 +02:00
Konstantin Osipov
5fa66315e9 A follow up patch for the fix for Bug#51263 "Deadlock between
transactional SELECT and ALTER TABLE ...  REBUILD PARTITION".

Make open flags part of Open_table_context.
This allows to simplify some code and (in future)
enforce the invariant that we don't, say, request a back 
off on the table when there is MYSQL_OPEN_IGNORE_FLUSH 
flag.



sql/sql_base.cc:
  open_table() flags are part of Open_table_context.
  Remove dead code that would check for OPEN_VIEW_NO_PARSE,
  which is not an open table flag.
sql/sql_base.h:
  Move flags to Open_table_context. Reorder Open_table_context
  members to compact the structure footprint.
sql/sql_insert.cc:
  Update with a new calling signature of open_table().
sql/sql_table.cc:
  Update with a new calling signature of open_table().
2010-06-01 14:49:35 +04:00
Konstantin Osipov
559e3889f2 A follow up patch for the fix for Bug#51263 "Deadlock between
transactional SELECT and ALTER TABLE ...  REBUILD PARTITION".

Make open flags part of Open_table_context.
This allows to simplify some code and (in future)
enforce the invariant that we don't, say, request a back 
off on the table when there is MYSQL_OPEN_IGNORE_FLUSH 
flag.
2010-06-01 14:49:35 +04:00
Konstantin Osipov
a96d23a57a A follow up patch for the fix for Bug#51263 "Deadlock between
transactional SELECT and ALTER TABLE ...  REBUILD PARTITION".

Move declarations of sql_base.cc classes to sql_base.h
(previously declared in sql_class.h).
Became possible after a header file split.





sql/sql_base.cc:
  Make sql_base.h the first include in sql_base.cc.
sql/sql_base.h:
  Add declarations of Prelocking_strategy and Open_table_context.
sql/sql_class.h:
  Remove declarations of Prelocking_strategy and Open_table_context
  (moved).
2010-06-01 14:19:05 +04:00
Konstantin Osipov
8b0c705c39 A follow up patch for the fix for Bug#51263 "Deadlock between
transactional SELECT and ALTER TABLE ...  REBUILD PARTITION".

Move declarations of sql_base.cc classes to sql_base.h
(previously declared in sql_class.h).
Became possible after a header file split.
2010-06-01 14:19:05 +04:00
Alexander Nozdrin
59a9912963 Auto-merge from mysql-trunk. 2010-05-28 09:47:58 +04:00
Alexander Nozdrin
4e633ec234 Auto-merge from mysql-trunk. 2010-05-28 09:47:58 +04:00
Dmitry Lenev
94ee84548d Small clean-up. Removed standalone enum_open_table_action enum
type, which some time ago became part of Open_table_context class.
Apparently standalone enum type was erroneously re-introduced
during one of merges.
2010-05-13 13:36:49 +04:00
Dmitry Lenev
017d66b5c8 Small clean-up. Removed standalone enum_open_table_action enum
type, which some time ago became part of Open_table_context class.
Apparently standalone enum type was erroneously re-introduced
during one of merges.
2010-05-13 13:36:49 +04:00
Alexey Kopytov
e118ec409f Manual merge from mysql-5.1-bugteam to mysql-trunk-merge.
Conflicts:

Text conflict in sql/sql_base.cc
Text conflict in sql/sql_partition.cc
Text conflict in sql/sql_priv.h
Text conflict in sql/sql_show.cc
2010-05-11 20:02:50 +04:00