2011-03-07 10:08:10 +01:00
|
|
|
/* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
|
|
|
|
#ifndef SQL_BASE_INCLUDED
|
|
|
|
#define SQL_BASE_INCLUDED
|
|
|
|
|
|
|
|
#include "unireg.h" // REQUIRED: for other includes
|
|
|
|
#include "sql_trigger.h" /* trg_event_type */
|
|
|
|
#include "sql_class.h" /* enum_mark_columns */
|
|
|
|
#include "mysqld.h" /* key_map */
|
|
|
|
|
|
|
|
class Item_ident;
|
2010-04-12 15:17:37 +02:00
|
|
|
struct Name_resolution_context;
|
2010-03-31 16:05:33 +02:00
|
|
|
class Open_table_context;
|
|
|
|
class Open_tables_state;
|
|
|
|
class Prelocking_strategy;
|
2010-04-12 15:17:37 +02:00
|
|
|
struct TABLE_LIST;
|
2010-03-31 16:05:33 +02:00
|
|
|
class THD;
|
2010-04-12 15:17:37 +02:00
|
|
|
struct handlerton;
|
2010-03-31 16:05:33 +02:00
|
|
|
struct TABLE;
|
|
|
|
|
|
|
|
typedef class st_select_lex SELECT_LEX;
|
|
|
|
|
|
|
|
typedef struct st_lock_param_type ALTER_PARTITION_PARAM_TYPE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This enumeration type is used only by the function find_item_in_list
|
|
|
|
to return the info on how an item has been resolved against a list
|
|
|
|
of possibly aliased items.
|
|
|
|
The item can be resolved:
|
|
|
|
- against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
|
|
|
|
- against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS)
|
|
|
|
- against an aliased field name of the list (RESOLVED_BEHIND_ALIAS)
|
|
|
|
- ignoring the alias name in cases when SQL requires to ignore aliases
|
|
|
|
(e.g. when the resolved field reference contains a table name or
|
|
|
|
when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS)
|
|
|
|
*/
|
|
|
|
enum enum_resolution_type {
|
|
|
|
NOT_RESOLVED=0,
|
|
|
|
RESOLVED_IGNORING_ALIAS,
|
|
|
|
RESOLVED_BEHIND_ALIAS,
|
|
|
|
RESOLVED_WITH_NO_ALIAS,
|
|
|
|
RESOLVED_AGAINST_ALIAS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
|
|
|
|
IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
|
|
|
|
IGNORE_EXCEPT_NON_UNIQUE};
|
|
|
|
|
|
|
|
enum enum_tdc_remove_table_type {TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN,
|
|
|
|
TDC_RT_REMOVE_UNUSED};
|
|
|
|
|
|
|
|
/* bits for last argument to remove_table_from_cache() */
|
|
|
|
#define RTFC_NO_FLAG 0x0000
|
|
|
|
#define RTFC_OWNED_BY_THD_FLAG 0x0001
|
|
|
|
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
|
|
|
|
#define RTFC_CHECK_KILLED_FLAG 0x0004
|
|
|
|
|
|
|
|
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
|
2010-08-12 15:50:23 +02:00
|
|
|
extern mysql_mutex_t LOCK_open;
|
2010-03-31 16:05:33 +02:00
|
|
|
bool table_cache_init(void);
|
|
|
|
void table_cache_free(void);
|
|
|
|
bool table_def_init(void);
|
|
|
|
void table_def_free(void);
|
|
|
|
void table_def_start_shutdown(void);
|
|
|
|
void assign_new_table_id(TABLE_SHARE *share);
|
|
|
|
uint cached_open_tables(void);
|
|
|
|
uint cached_table_definitions(void);
|
2010-08-31 11:52:56 +02:00
|
|
|
uint create_table_def_key(THD *thd, char *key,
|
|
|
|
const TABLE_LIST *table_list,
|
2010-03-31 16:05:33 +02:00
|
|
|
bool tmp_table);
|
|
|
|
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
|
|
|
uint key_length, uint db_flags, int *error,
|
|
|
|
my_hash_value_type hash_value);
|
|
|
|
void release_table_share(TABLE_SHARE *share);
|
|
|
|
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
|
|
|
|
|
|
|
|
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
|
|
|
|
uint lock_flags);
|
2010-08-13 11:51:48 +02:00
|
|
|
|
|
|
|
/* mysql_lock_tables() and open_table() flags bits */
|
|
|
|
#define MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK 0x0001
|
|
|
|
#define MYSQL_OPEN_IGNORE_FLUSH 0x0002
|
|
|
|
#define MYSQL_OPEN_TEMPORARY_ONLY 0x0004
|
|
|
|
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
|
|
|
|
#define MYSQL_LOCK_LOG_TABLE 0x0010
|
|
|
|
/**
|
|
|
|
Do not try to acquire a metadata lock on the table: we
|
|
|
|
already have one.
|
|
|
|
*/
|
|
|
|
#define MYSQL_OPEN_HAS_MDL_LOCK 0x0020
|
|
|
|
/**
|
|
|
|
If in locked tables mode, ignore the locked tables and get
|
|
|
|
a new instance of the table.
|
|
|
|
*/
|
|
|
|
#define MYSQL_OPEN_GET_NEW_TABLE 0x0040
|
|
|
|
/** Don't look up the table in the list of temporary tables. */
|
|
|
|
#define MYSQL_OPEN_SKIP_TEMPORARY 0x0080
|
|
|
|
/** Fail instead of waiting when conficting metadata lock is discovered. */
|
|
|
|
#define MYSQL_OPEN_FAIL_ON_MDL_CONFLICT 0x0100
|
|
|
|
/** Open tables using MDL_SHARED lock instead of one specified in parser. */
|
|
|
|
#define MYSQL_OPEN_FORCE_SHARED_MDL 0x0200
|
|
|
|
/**
|
|
|
|
Open tables using MDL_SHARED_HIGH_PRIO lock instead of one specified
|
|
|
|
in parser.
|
|
|
|
*/
|
|
|
|
#define MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL 0x0400
|
|
|
|
/**
|
|
|
|
When opening or locking the table, use the maximum timeout
|
|
|
|
(LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value.
|
|
|
|
*/
|
|
|
|
#define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800
|
2010-09-09 16:29:14 +02:00
|
|
|
/**
|
|
|
|
When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to
|
|
|
|
be open do not acquire global and schema-scope IX locks.
|
|
|
|
*/
|
|
|
|
#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000
|
2011-10-19 21:45:18 +02:00
|
|
|
#define MYSQL_LOCK_NOT_TEMPORARY 0x2000
|
2010-08-13 11:51:48 +02:00
|
|
|
|
|
|
|
/** Please refer to the internals manual. */
|
|
|
|
#define MYSQL_OPEN_REOPEN (MYSQL_OPEN_IGNORE_FLUSH |\
|
|
|
|
MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK |\
|
|
|
|
MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |\
|
|
|
|
MYSQL_LOCK_IGNORE_TIMEOUT |\
|
|
|
|
MYSQL_OPEN_GET_NEW_TABLE |\
|
|
|
|
MYSQL_OPEN_SKIP_TEMPORARY |\
|
|
|
|
MYSQL_OPEN_HAS_MDL_LOCK)
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
|
2010-06-01 12:49:35 +02:00
|
|
|
Open_table_context *ot_ctx);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
|
|
|
|
uint db_stat, uint prgflag,
|
|
|
|
uint ha_open_flags, TABLE *outparam, TABLE_LIST *table_desc,
|
|
|
|
MEM_ROOT *mem_root);
|
|
|
|
|
|
|
|
bool get_key_map_from_key_list(key_map *map, TABLE *table,
|
|
|
|
List<String> *index_list);
|
2010-08-31 12:03:36 +02:00
|
|
|
TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
|
|
|
|
const char *table_name,
|
|
|
|
bool add_to_temporary_tables_list);
|
2010-03-31 16:05:33 +02:00
|
|
|
TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
|
|
|
|
TABLE *find_write_locked_table(TABLE *list, const char *db,
|
|
|
|
const char *table_name);
|
Committing on behalf or Dmitry Lenev:
Fix for bug #46947 "Embedded SELECT without FOR UPDATE is
causing a lock", with after-review fixes.
SELECT statements with subqueries referencing InnoDB tables
were acquiring shared locks on rows in these tables when they
were executed in REPEATABLE-READ mode and with statement or
mixed mode binary logging turned on.
This was a regression which were introduced when fixing
bug 39843.
The problem was that for tables belonging to subqueries
parser set TL_READ_DEFAULT as a lock type. In cases when
statement/mixed binary logging at open_tables() time this
type of lock was converted to TL_READ_NO_INSERT lock at
open_tables() time and caused InnoDB engine to acquire
shared locks on reads from these tables. Although in some
cases such behavior was correct (e.g. for subqueries in
DELETE) in case of SELECT it has caused unnecessary locking.
This patch tries to solve this problem by rethinking our
approach to how we handle locking for SELECT and subqueries.
Now we always set TL_READ_DEFAULT lock type for all cases
when we read data. When at open_tables() time this lock
is interpreted as TL_READ_NO_INSERT or TL_READ depending
on whether this statement as a whole or call to function
which uses particular table should be written to the
binary log or not (if yes then statement should be properly
serialized with concurrent statements and stronger lock
should be acquired).
Test coverage is added for both InnoDB and MyISAM.
This patch introduces an "incompatible" change in locking
scheme for subqueries used in SELECT ... FOR UPDATE and
SELECT .. IN SHARE MODE.
In 4.1 the server would use a snapshot InnoDB read for
subqueries in SELECT FOR UPDATE and SELECT .. IN SHARE MODE
statements, regardless of whether the binary log is on or off.
If the user required a different type of read (i.e. locking read),
he/she could request so explicitly by providing FOR UPDATE/IN SHARE MODE
clause for each individual subquery.
On of the patches for 5.0 broke this behaviour (which was not documented
or tested), and started to use locking reads fora all subqueries in SELECT ...
FOR UPDATE/IN SHARE MODE. This patch restored 4.1 behaviour.
mysql-test/include/check_concurrent_insert.inc:
Added auxiliary script which allows to check if statement
reading table allows concurrent inserts in it.
mysql-test/include/check_no_concurrent_insert.inc:
Added auxiliary script which allows to check that statement
reading table doesn't allow concurrent inserts in it.
mysql-test/include/check_no_row_lock.inc:
Added auxiliary script which allows to check if statement
reading table doesn't take locks on its rows.
mysql-test/include/check_shared_row_lock.inc:
Added auxiliary script which allows to check if statement
reading table takes shared locks on some of its rows.
mysql-test/r/bug39022.result:
After bug #46947 'Embedded SELECT without FOR UPDATE is
causing a lock' was fixed test case for bug 39022 has to
be adjusted in order to trigger execution path on which
original problem was encountered.
mysql-test/r/innodb_mysql_lock2.result:
Added coverage for handling of locking in various cases when
we read data from InnoDB tables (includes test case for
bug #46947 'Embedded SELECT without FOR UPDATE is causing a
lock').
mysql-test/r/lock_sync.result:
Added coverage for handling of locking in various cases when
we read data from MyISAM tables.
mysql-test/t/bug39022.test:
After bug #46947 'Embedded SELECT without FOR UPDATE is
causing a lock' was fixed test case for bug 39022 has to
be adjusted in order to trigger execution path on which
original problem was encountered.
mysql-test/t/innodb_mysql_lock2.test:
Added coverage for handling of locking in various cases when
we read data from InnoDB tables (includes test case for
bug #46947 'Embedded SELECT without FOR UPDATE is causing a
lock').
mysql-test/t/lock_sync.test:
Added coverage for handling of locking in various cases when
we read data from MyISAM tables.
sql/log_event.cc:
Since LEX::lock_option member was removed we no longer can
rely on its value in Load_log_event::print_query() to
determine that log event correponds to LOAD DATA CONCURRENT
statement (this was not correct in all situations anyway).
A new Load_log_event's member was introduced as a replacement.
It is initialized at event object construction time and
explicitly indicates whether LOAD DATA was concurrent.
sql/log_event.h:
Since LEX::lock_option member was removed we no longer can
rely on its value in Load_log_event::print_query() to
determine that log event correponds to LOAD DATA CONCURRENT
statement (this was not correct in all situations anyway).
A new Load_log_event's member was introduced as a replacement.
It is initialized at event object construction time and
explicitly indicates whether LOAD DATA was concurrent.
sql/sp_head.cc:
sp_head::reset_lex():
Before parsing substatement reset part of parser state
which needs this (e.g. set Yacc_state::m_lock_type to
default value).
sql/sql_acl.cc:
Since LEX::reset_n_backup_query_tables_list() now also
resets LEX::sql_command member (as it became part of
Query_tables_list class) we have to restore it in cases
when while working with proxy Query_table_list we assume
that LEX::sql_command still corresponds to original SQL
command being executed (for example, when we are logging
statement to the binary log while having Query_tables_list
reset and backed up).
sql/sql_base.cc:
Changed read_lock_type_for_table() to return a weak TL_READ
type of lock in cases when we are executing statement which
won't update tables directly and table doesn't belong to
statement's prelocking list and thus can't be used by a
stored function. It is OK to do so since in this case table
won't be used by statement or function call which will be
written to the binary log, so serializability requirements
for it can be relaxed.
One of results from this change is that SELECTs on InnoDB
tables no longer takes shared row locks for tables which
are used in subqueries (i.e. bug #46947 is fixed).
Another result is that for similar SELECTs on MyISAM tables
concurrent inserts are allowed.
In order to implement this change signature of
read_lock_type_for_table() function was changed to take
pointers to Query_tables_list and TABLE_LIST objects.
sql/sql_base.h:
- Function read_lock_type_for_table() now takes pointers
to Query_tables_list and TABLE_LIST elements as its
arguments since to correctly determine lock type it needs
to know what statement is being performed and whether table
element for which lock type to be determined belongs to
prelocking list.
sql/sql_lex.cc:
- Removed LEX::lock_option and st_select_lex::lock_option
members. Places in parser that were using them now use
Yacc_state::m_lock_type instead.
- To emphasize that LEX::sql_command member is used during
process of opening and locking of tables it was moved to
Query_tables_list class. It is now reset by
Query_tables_list::reset_query_tables_list() method.
sql/sql_lex.h:
- Removed st_select_lex::lock_option member as there is no
real need for per-SELECT lock type (HIGH_PRIORITY option
should apply to the whole statement. FOR UPDATE/LOCK IN
SHARE MODE clauses can be handled without this member).
The main effect which was achieved by introduction of this
member, i.e. using TL_READ_DEFAULT lock type for
subqueries, is now achieved by setting LEX::lock_option
(or rather its replacement - Yacc_state::m_lock_type) to
TL_READ_DEFAULT in almost all cases.
- To emphasize that LEX::sql_command member is used during
process of opening and locking of tables it was moved to
Query_tables_list class.
- Replaced LEX::lock_option with Yacc_state::m_lock_type
in order to emphasize that this value is relevant only
during parsing. Unlike for LEX::lock_option the default
value for Yacc_state::m_lock_type is TL_READ_DEFAULT.
Note that for cases when it is OK to take a "weak" read
lock (e.g. simple SELECT) this lock type will be converted
to TL_READ at open_tables() time. So this change won't
cause negative change in behavior for such statements.
OTOH this change ensures that, for example, for SELECTs
which are used in stored functions TL_READ_NO_INSERT lock
is taken when necessary and as result calls to such stored
functions can be written to the binary log with correct
serialization.
sql/sql_load.cc:
Load_log_event constructor now requires a parameter that
indicates whether LOAD DATA is concurrent.
sql/sql_parse.cc:
LEX::lock_option was replaced with Yacc_state::m_lock_type.
And instead of resetting the latter implicitly in
mysql_init_multi_delete() we do it explicitly in the
places in parser which call this function.
sql/sql_priv.h:
- To be able more easily distinguish high-priority SELECTs
in st_select_lex::print() method added flag for
HIGH_PRIORITY option.
sql/sql_select.cc:
Changed code not to rely on LEX::lock_option to determine
that it is high-priority SELECT. It was replaced with
Yacc_state::m_lock_type which is accessible only at
parse time. So instead of LEX::lock_option we now rely
on a newly introduced flag for st_select_lex::options -
SELECT_HIGH_PRIORITY.
sql/sql_show.cc:
Since LEX::reset_n_backup_query_tables_list() now also
resets LEX::sql_command member (as it became part of
Query_tables_list class) we have to restore it in cases
when while working with proxy Query_table_list we assume
that LEX::sql_command still corresponds to original SQL
command being executed.
sql/sql_table.cc:
Since LEX::reset_query_tables_list() now also resets
LEX::sql_command member (as it became part of
Query_tables_list class) we have to restore value of this
member when this method is called by mysql_admin_table(),
to make this code safe for re-execution.
sql/sql_trigger.cc:
Since LEX::reset_n_backup_query_tables_list() now also
resets LEX::sql_command member (as it became part of
Query_tables_list class) we have to restore it in cases
when while working with proxy Query_table_list we assume
that LEX::sql_command still corresponds to original SQL
command being executed (for example, when we are logging
statement to the binary log while having Query_tables_list
reset and backed up).
sql/sql_update.cc:
Function read_lock_type_for_table() now takes pointers
to Query_tables_list and TABLE_LIST elements as its
arguments since to correctly determine lock type it needs
to know what statement is being performed and whether table
element for which lock type to be determined belongs to
prelocking list.
sql/sql_yacc.yy:
- Removed st_select_lex::lock_option member as there is no
real need for per-SELECT lock type (HIGH_PRIORITY option
should apply to the whole statement. FOR UPDATE/LOCK IN
SHARE MODE clauses can be handled without this member).
The main effect which was achieved by introduction of this
member, i.e. using TL_READ_DEFAULT lock type for
subqueries, is now achieved by setting LEX::lock_option
(or rather its replacement - Yacc_state::m_lock_type) to
TL_READ_DEFAULT in almost all cases.
- Replaced LEX::lock_option with Yacc_state::m_lock_type
in order to emphasize that this value is relevant only
during parsing. Unlike for LEX::lock_option the default
value for Yacc_state::m_lock_type is TL_READ_DEFAULT.
Note that for cases when it is OK to take a "weak" read
lock (e.g. simple SELECT) this lock type will be converted
to TL_READ at open_tables() time. So this change won't
cause negative change in behavior for such statements.
OTOH this change ensures that, for example, for SELECTs
which are used in stored functions TL_READ_NO_INSERT lock
is taken when necessary and as result calls to such stored
functions can be written to the binary log with correct
serialization.
- To be able more easily distinguish high-priority SELECTs
in st_select_lex::print() method we now use new flag
in st_select_lex::options bit-field.
2010-04-28 12:04:11 +02:00
|
|
|
thr_lock_type read_lock_type_for_table(THD *thd,
|
|
|
|
Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list);
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
my_bool mysql_rm_tmp_tables(void);
|
|
|
|
bool rm_temporary_table(handlerton *base, char *path);
|
|
|
|
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables,
|
2010-11-11 18:11:05 +01:00
|
|
|
const MDL_savepoint &start_of_statement_svp);
|
2010-03-31 16:05:33 +02:00
|
|
|
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
|
|
|
|
TABLE_LIST *TABLE_LIST::*link,
|
|
|
|
const char *db_name,
|
|
|
|
const char *table_name);
|
|
|
|
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
|
2010-08-31 11:52:56 +02:00
|
|
|
TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
|
|
|
|
TABLE *find_temporary_table(THD *thd, const char *table_key,
|
|
|
|
uint table_key_length);
|
2010-03-31 16:05:33 +02:00
|
|
|
void close_thread_tables(THD *thd);
|
|
|
|
bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
|
|
|
|
List<Item> &values,
|
|
|
|
bool ignore_errors,
|
|
|
|
Table_triggers_list *triggers,
|
|
|
|
enum trg_event_type event);
|
|
|
|
bool fill_record_n_invoke_before_triggers(THD *thd, Field **field,
|
|
|
|
List<Item> &values,
|
|
|
|
bool ignore_errors,
|
|
|
|
Table_triggers_list *triggers,
|
|
|
|
enum trg_event_type event);
|
|
|
|
bool insert_fields(THD *thd, Name_resolution_context *context,
|
|
|
|
const char *db_name, const char *table_name,
|
|
|
|
List_iterator<Item> *it, bool any_privileges);
|
2011-10-19 21:45:18 +02:00
|
|
|
void make_leaves_list(List<TABLE_LIST> &list, TABLE_LIST *tables,
|
|
|
|
bool full_table_list, TABLE_LIST *boundary);
|
2010-03-31 16:05:33 +02:00
|
|
|
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
|
|
|
|
List<Item> *sum_func_list, uint wild_num);
|
|
|
|
bool setup_fields(THD *thd, Item** ref_pointer_array,
|
|
|
|
List<Item> &item, enum_mark_columns mark_used_columns,
|
|
|
|
List<Item> *sum_func_list, bool allow_sum_func);
|
2011-10-19 21:45:18 +02:00
|
|
|
void unfix_fields(List<Item> &items);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool fill_record(THD *thd, Field **field, List<Item> &values,
|
2010-11-25 18:17:28 +01:00
|
|
|
bool ignore_errors, bool use_value);
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
Field *
|
|
|
|
find_field_in_tables(THD *thd, Item_ident *item,
|
|
|
|
TABLE_LIST *first_table, TABLE_LIST *last_table,
|
|
|
|
Item **ref, find_item_error_report_type report_error,
|
|
|
|
bool check_privileges, bool register_tree_change);
|
|
|
|
Field *
|
|
|
|
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
|
|
|
|
const char *name, uint length,
|
|
|
|
const char *item_name, const char *db_name,
|
|
|
|
const char *table_name, Item **ref,
|
|
|
|
bool check_privileges, bool allow_rowid,
|
|
|
|
uint *cached_field_index_ptr,
|
|
|
|
bool register_tree_change, TABLE_LIST **actual_table);
|
|
|
|
Field *
|
|
|
|
find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
|
|
|
|
bool allow_rowid, uint *cached_field_index_ptr);
|
|
|
|
Field *
|
|
|
|
find_field_in_table_sef(TABLE *table, const char *name);
|
|
|
|
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
|
|
|
|
find_item_error_report_type report_error,
|
|
|
|
enum_resolution_type *resolution);
|
|
|
|
bool setup_tables(THD *thd, Name_resolution_context *context,
|
|
|
|
List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
|
2011-10-19 21:45:18 +02:00
|
|
|
List<TABLE_LIST> &leaves, bool select_insert,
|
|
|
|
bool full_table_list);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool setup_tables_and_check_access(THD *thd,
|
|
|
|
Name_resolution_context *context,
|
|
|
|
List<TABLE_LIST> *from_clause,
|
|
|
|
TABLE_LIST *tables,
|
2011-10-19 21:45:18 +02:00
|
|
|
List<TABLE_LIST> &leaves,
|
2010-03-31 16:05:33 +02:00
|
|
|
bool select_insert,
|
|
|
|
ulong want_access_first,
|
2011-10-19 21:45:18 +02:00
|
|
|
ulong want_access,
|
|
|
|
bool full_table_list);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool wait_while_table_is_used(THD *thd, TABLE *table,
|
|
|
|
enum ha_extra_function function);
|
|
|
|
|
|
|
|
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
|
|
|
|
const char *table_name);
|
|
|
|
void update_non_unique_table_error(TABLE_LIST *update,
|
|
|
|
const char *operation,
|
|
|
|
TABLE_LIST *duplicate);
|
2011-10-19 21:45:18 +02:00
|
|
|
int setup_conds(THD *thd, TABLE_LIST *tables, List<TABLE_LIST> &leaves,
|
2010-03-31 16:05:33 +02:00
|
|
|
COND **conds);
|
2011-10-19 21:45:18 +02:00
|
|
|
void wrap_ident(THD *thd, Item **conds);
|
2010-03-31 16:05:33 +02:00
|
|
|
int setup_ftfuncs(SELECT_LEX* select);
|
|
|
|
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
|
2010-07-01 15:53:46 +02:00
|
|
|
bool lock_table_names(THD *thd, TABLE_LIST *table_list,
|
|
|
|
TABLE_LIST *table_list_end, ulong lock_wait_timeout,
|
|
|
|
uint flags);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags,
|
|
|
|
Prelocking_strategy *prelocking_strategy);
|
|
|
|
/* open_and_lock_tables with optional derived handling */
|
|
|
|
bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
|
|
|
|
bool derived, uint flags,
|
|
|
|
Prelocking_strategy *prelocking_strategy);
|
|
|
|
/* simple open_and_lock_tables without derived handling for single table */
|
|
|
|
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
|
2010-09-15 16:15:31 +02:00
|
|
|
thr_lock_type lock_type, uint flags,
|
|
|
|
Prelocking_strategy *prelocking_strategy);
|
2011-10-19 21:45:18 +02:00
|
|
|
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags,
|
|
|
|
uint dt_phases);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags);
|
|
|
|
int decide_logging_format(THD *thd, TABLE_LIST *tables);
|
|
|
|
void free_io_cache(TABLE *entry);
|
|
|
|
void intern_close_table(TABLE *entry);
|
|
|
|
bool close_thread_table(THD *thd, TABLE **table_ptr);
|
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 17:56:50 +02:00
|
|
|
bool close_temporary_tables(THD *thd);
|
2010-03-31 16:05:33 +02:00
|
|
|
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
|
|
|
bool check_alias);
|
2010-08-20 04:59:58 +02:00
|
|
|
int drop_temporary_table(THD *thd, TABLE_LIST *table_list, bool *is_trans);
|
2010-03-31 16:05:33 +02:00
|
|
|
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
|
|
|
|
bool delete_table);
|
|
|
|
void close_temporary(TABLE *table, bool free_share, bool delete_table);
|
|
|
|
bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
|
|
|
|
const char *table_name);
|
|
|
|
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
|
|
|
|
|
2012-09-28 14:27:16 +02:00
|
|
|
class Open_tables_backup;
|
2010-03-31 16:05:33 +02:00
|
|
|
/* Functions to work with system tables. */
|
|
|
|
bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
|
|
|
|
Open_tables_backup *backup);
|
|
|
|
void close_system_tables(THD *thd, Open_tables_backup *backup);
|
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 12:25:53 +02:00
|
|
|
void close_mysql_tables(THD *thd);
|
2010-03-31 16:05:33 +02:00
|
|
|
TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
|
|
|
|
TABLE *open_log_table(THD *thd, TABLE_LIST *one_table, Open_tables_backup *backup);
|
|
|
|
void close_log_table(THD *thd, Open_tables_backup *backup);
|
|
|
|
|
|
|
|
TABLE *open_performance_schema_table(THD *thd, TABLE_LIST *one_table,
|
|
|
|
Open_tables_state *backup);
|
|
|
|
void close_performance_schema_table(THD *thd, Open_tables_state *backup);
|
|
|
|
|
2010-08-12 15:50:23 +02:00
|
|
|
bool close_cached_tables(THD *thd, TABLE_LIST *tables,
|
2010-07-27 15:34:58 +02:00
|
|
|
bool wait_for_refresh, ulong timeout);
|
2010-08-12 18:44:41 +02:00
|
|
|
bool close_cached_connection_tables(THD *thd, LEX_STRING *connect_string);
|
2010-03-31 16:05:33 +02:00
|
|
|
void close_all_tables_for_name(THD *thd, TABLE_SHARE *share,
|
2012-05-16 17:44:17 +02:00
|
|
|
ha_extra_function extra);
|
2010-03-31 16:05:33 +02:00
|
|
|
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
|
|
|
|
void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
|
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 20:33:47 +02:00
|
|
|
const char *db, const char *table_name,
|
|
|
|
bool has_lock);
|
2010-03-31 16:05:33 +02:00
|
|
|
bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias,
|
|
|
|
char *cache_key, uint cache_key_length,
|
|
|
|
MEM_ROOT *mem_root, uint flags);
|
2010-06-10 13:43:32 +02:00
|
|
|
void tdc_flush_unused_tables();
|
2011-03-07 10:08:10 +01:00
|
|
|
TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
|
2010-03-31 16:05:33 +02:00
|
|
|
const char *table_name,
|
|
|
|
bool no_error);
|
|
|
|
void mark_tmp_table_for_reuse(TABLE *table);
|
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 17:28:18 +02:00
|
|
|
bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool *exists);
|
2010-11-25 18:17:28 +01:00
|
|
|
int update_virtual_fields(THD *thd, TABLE *table, bool ignore_stored= FALSE);
|
2011-10-19 21:45:18 +02:00
|
|
|
int dynamic_column_error_message(enum_dyncol_func_result rc);
|
2010-03-31 16:05:33 +02:00
|
|
|
|
|
|
|
extern TABLE *unused_tables;
|
|
|
|
extern Item **not_found_item;
|
|
|
|
extern Field *not_found_field;
|
|
|
|
extern Field *view_ref_found;
|
|
|
|
extern HASH table_def_cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
clean/setup table fields and map.
|
|
|
|
|
|
|
|
@param table TABLE structure pointer (which should be setup)
|
|
|
|
@param table_list TABLE_LIST structure pointer (owner of TABLE)
|
|
|
|
@param tablenr table number
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
|
|
|
|
{
|
|
|
|
table->used_fields= 0;
|
2011-10-19 21:45:18 +02:00
|
|
|
table_list->reset_const_table();
|
2010-03-31 16:05:33 +02:00
|
|
|
table->null_row= 0;
|
|
|
|
table->status= STATUS_NO_RECORD;
|
|
|
|
table->maybe_null= table_list->outer_join;
|
|
|
|
TABLE_LIST *embedding= table_list->embedding;
|
|
|
|
while (!table->maybe_null && embedding)
|
|
|
|
{
|
|
|
|
table->maybe_null= embedding->outer_join;
|
|
|
|
embedding= embedding->embedding;
|
|
|
|
}
|
|
|
|
table->tablenr= tablenr;
|
|
|
|
table->map= (table_map) 1 << tablenr;
|
|
|
|
table->force_index= table_list->force_index;
|
|
|
|
table->force_index_order= table->force_index_group= 0;
|
|
|
|
table->covering_keys= table->s->keys_for_keyread;
|
|
|
|
table->merge_keys.clear_all();
|
2011-10-19 21:45:18 +02:00
|
|
|
TABLE_LIST *orig= table_list->select_lex ?
|
|
|
|
table_list->select_lex->master_unit()->derived : 0;
|
|
|
|
if (!orig || !orig->is_merged_derived())
|
|
|
|
{
|
|
|
|
/* Tables merged from derived were set up already.*/
|
|
|
|
table->covering_keys= table->s->keys_for_keyread;
|
|
|
|
table->merge_keys.clear_all();
|
|
|
|
}
|
2010-03-31 16:05:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
|
|
|
|
const char *db_name,
|
|
|
|
const char *table_name)
|
|
|
|
{
|
|
|
|
return find_table_in_list(table, &TABLE_LIST::next_global,
|
|
|
|
db_name, table_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
|
|
|
|
const char *db_name,
|
|
|
|
const char *table_name)
|
|
|
|
{
|
|
|
|
return find_table_in_list(table, &TABLE_LIST::next_local,
|
|
|
|
db_name, table_name);
|
|
|
|
}
|
|
|
|
|
2010-06-01 12:19:05 +02:00
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
|
|
|
|
List<Item> &item,
|
|
|
|
enum_mark_columns mark_used_columns,
|
|
|
|
List<Item> *sum_func_list,
|
|
|
|
bool allow_sum_func)
|
|
|
|
{
|
|
|
|
bool res;
|
|
|
|
thd->lex->select_lex.no_wrap_view_item= TRUE;
|
|
|
|
res= setup_fields(thd, ref_pointer_array, item, mark_used_columns,
|
|
|
|
sum_func_list, allow_sum_func);
|
|
|
|
thd->lex->select_lex.no_wrap_view_item= FALSE;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-06-01 12:19:05 +02:00
|
|
|
/**
|
|
|
|
An abstract class for a strategy specifying how the prelocking
|
|
|
|
algorithm should extend the prelocking set while processing
|
|
|
|
already existing elements in the set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Prelocking_strategy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Prelocking_strategy() { }
|
|
|
|
|
|
|
|
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
Sroutine_hash_entry *rt, sp_head *sp,
|
|
|
|
bool *need_prelocking) = 0;
|
|
|
|
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list, bool *need_prelocking) = 0;
|
|
|
|
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list, bool *need_prelocking)= 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
A Strategy for prelocking algorithm suitable for DML statements.
|
|
|
|
|
|
|
|
Ensures that all tables used by all statement's SF/SP/triggers and
|
|
|
|
required for foreign key checks are prelocked and SF/SPs used are
|
|
|
|
cached.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DML_prelocking_strategy : public Prelocking_strategy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
Sroutine_hash_entry *rt, sp_head *sp,
|
|
|
|
bool *need_prelocking);
|
|
|
|
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list, bool *need_prelocking);
|
|
|
|
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list, bool *need_prelocking);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
A strategy for prelocking algorithm to be used for LOCK TABLES
|
|
|
|
statement.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Lock_tables_prelocking_strategy : public DML_prelocking_strategy
|
|
|
|
{
|
|
|
|
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list, bool *need_prelocking);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Strategy for prelocking algorithm to be used for ALTER TABLE statements.
|
|
|
|
|
|
|
|
Unlike DML or LOCK TABLES strategy, it doesn't
|
|
|
|
prelock triggers, views or stored routines, since they are not
|
|
|
|
used during ALTER.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Alter_table_prelocking_strategy : public Prelocking_strategy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Alter_table_prelocking_strategy(Alter_info *alter_info)
|
|
|
|
: m_alter_info(alter_info)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual bool handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
Sroutine_hash_entry *rt, sp_head *sp,
|
|
|
|
bool *need_prelocking);
|
|
|
|
virtual bool handle_table(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list, bool *need_prelocking);
|
|
|
|
virtual bool handle_view(THD *thd, Query_tables_list *prelocking_ctx,
|
|
|
|
TABLE_LIST *table_list, bool *need_prelocking);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Alter_info *m_alter_info;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
inline bool
|
|
|
|
open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags)
|
|
|
|
{
|
|
|
|
DML_prelocking_strategy prelocking_strategy;
|
|
|
|
|
|
|
|
return open_tables(thd, tables, counter, flags, &prelocking_strategy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-15 16:15:31 +02:00
|
|
|
inline TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
|
|
|
|
thr_lock_type lock_type, uint flags)
|
|
|
|
{
|
|
|
|
DML_prelocking_strategy prelocking_strategy;
|
|
|
|
|
|
|
|
return open_n_lock_single_table(thd, table_l, lock_type, flags,
|
|
|
|
&prelocking_strategy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
/* open_and_lock_tables with derived handling */
|
|
|
|
inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables,
|
|
|
|
bool derived, uint flags)
|
|
|
|
{
|
|
|
|
DML_prelocking_strategy prelocking_strategy;
|
|
|
|
|
|
|
|
return open_and_lock_tables(thd, tables, derived, flags,
|
|
|
|
&prelocking_strategy);
|
|
|
|
}
|
|
|
|
|
2010-06-01 12:19:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
A context of open_tables() function, used to recover
|
|
|
|
from a failed open_table() or open_routine() attempt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Open_table_context
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum enum_open_table_action
|
|
|
|
{
|
|
|
|
OT_NO_ACTION= 0,
|
2010-08-12 15:50:23 +02:00
|
|
|
OT_BACKOFF_AND_RETRY,
|
2010-07-27 15:34:58 +02:00
|
|
|
OT_REOPEN_TABLES,
|
2010-06-01 12:19:05 +02:00
|
|
|
OT_DISCOVER,
|
|
|
|
OT_REPAIR
|
|
|
|
};
|
2010-06-01 12:49:35 +02:00
|
|
|
Open_table_context(THD *thd, uint flags);
|
2010-06-01 12:19:05 +02:00
|
|
|
|
|
|
|
bool recover_from_failed_open(THD *thd);
|
|
|
|
bool request_backoff_action(enum_open_table_action action_arg,
|
2010-06-07 09:06:55 +02:00
|
|
|
TABLE_LIST *table);
|
2010-06-01 12:19:05 +02:00
|
|
|
|
|
|
|
bool can_recover_from_failed_open() const
|
|
|
|
{ return m_action != OT_NO_ACTION; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
When doing a back-off, we close all tables acquired by this
|
|
|
|
statement. Return an MDL savepoint taken at the beginning of
|
|
|
|
the statement, so that we can rollback to it before waiting on
|
|
|
|
locks.
|
|
|
|
*/
|
2010-11-11 18:11:05 +01:00
|
|
|
const MDL_savepoint &start_of_statement_svp() const
|
2010-06-01 12:19:05 +02:00
|
|
|
{
|
|
|
|
return m_start_of_statement_svp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ulong get_timeout() const
|
|
|
|
{
|
|
|
|
return m_timeout;
|
|
|
|
}
|
|
|
|
|
2010-06-01 12:49:35 +02:00
|
|
|
uint get_flags() const { return m_flags; }
|
2010-11-11 18:11:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set flag indicating that we have already acquired metadata lock
|
|
|
|
protecting this statement against GRL while opening tables.
|
|
|
|
*/
|
|
|
|
void set_has_protection_against_grl()
|
|
|
|
{
|
|
|
|
m_has_protection_against_grl= TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_protection_against_grl() const
|
|
|
|
{
|
|
|
|
return m_has_protection_against_grl;
|
|
|
|
}
|
|
|
|
|
2010-06-01 12:19:05 +02:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
For OT_DISCOVER and OT_REPAIR actions, the table list element for
|
|
|
|
the table which definition should be re-discovered or which
|
|
|
|
should be repaired.
|
|
|
|
*/
|
|
|
|
TABLE_LIST *m_failed_table;
|
2010-11-11 18:11:05 +01:00
|
|
|
MDL_savepoint m_start_of_statement_svp;
|
2010-06-01 12:19:05 +02:00
|
|
|
/**
|
|
|
|
Lock timeout in seconds. Initialized to LONG_TIMEOUT when opening system
|
|
|
|
tables or to the "lock_wait_timeout" system variable for regular tables.
|
|
|
|
*/
|
2010-06-01 12:49:35 +02:00
|
|
|
ulong m_timeout;
|
|
|
|
/* open_table() flags. */
|
|
|
|
uint m_flags;
|
|
|
|
/** Back off action. */
|
|
|
|
enum enum_open_table_action m_action;
|
|
|
|
/**
|
|
|
|
Whether we had any locks when this context was created.
|
|
|
|
If we did, they are from the previous statement of a transaction,
|
|
|
|
and we can't safely do back-off (and release them).
|
|
|
|
*/
|
|
|
|
bool m_has_locks;
|
2010-11-11 18:11:05 +01:00
|
|
|
/**
|
|
|
|
Indicates that in the process of opening tables we have acquired
|
|
|
|
protection against global read lock.
|
|
|
|
*/
|
|
|
|
bool m_has_protection_against_grl;
|
2010-06-01 12:19:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-08-19 11:33:37 +02:00
|
|
|
/**
|
|
|
|
This internal handler is used to trap ER_NO_SUCH_TABLE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class No_such_table_error_handler : public Internal_error_handler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
No_such_table_error_handler()
|
|
|
|
: m_handled_errors(0), m_unhandled_errors(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool handle_condition(THD *thd,
|
|
|
|
uint sql_errno,
|
|
|
|
const char* sqlstate,
|
|
|
|
MYSQL_ERROR::enum_warning_level level,
|
|
|
|
const char* msg,
|
|
|
|
MYSQL_ERROR ** cond_hdl);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns TRUE if one or more ER_NO_SUCH_TABLE errors have been
|
|
|
|
trapped and no other errors have been seen. FALSE otherwise.
|
|
|
|
*/
|
|
|
|
bool safely_trapped_errors();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_handled_errors;
|
|
|
|
int m_unhandled_errors;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
#endif /* SQL_BASE_INCLUDED */
|