302
299
#define USER_VARS_HASH_SIZE 16
303
300
#define TABLE_OPEN_CACHE_MIN 64
304
301
#define TABLE_OPEN_CACHE_DEFAULT 64
302
#define TABLE_DEF_CACHE_DEFAULT 256
304
We must have room for at least 256 table definitions in the table
305
cache, since otherwise there is no chance prepared
306
statements that use these many tables can work.
307
Prepared statements use table definition cache ids (table_map_id)
308
as table version identifiers. If the table definition
309
cache size is less than the number of tables used in a statement,
310
the contents of the table definition cache is guaranteed to rotate
311
between a prepare and execute. This leads to stable validation
312
errors. In future we shall use more stable version identifiers,
313
for now the only solution is to ensure that the table definition
314
cache can contain at least all tables of a given statement.
316
#define TABLE_DEF_CACHE_MIN 256
307
319
Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
602
614
#define DBUG_SYNC_POINT(lock_name,lock_timeout)
603
615
#endif /* EXTRA_DEBUG */
617
/* Debug Sync Facility. */
618
#if defined(ENABLED_DEBUG_SYNC)
619
/* Macro to be put in the code at synchronization points. */
620
#define DEBUG_SYNC(_thd_, _sync_point_name_) \
621
do { if (unlikely(opt_debug_sync_timeout)) \
622
debug_sync(_thd_, STRING_WITH_LEN(_sync_point_name_)); \
624
/* Command line option --debug-sync-timeout. See mysqld.cc. */
625
extern uint opt_debug_sync_timeout;
626
/* Default WAIT_FOR timeout if command line option is given without argument. */
627
#define DEBUG_SYNC_DEFAULT_WAIT_TIMEOUT 300
628
/* Debug Sync prototypes. See debug_sync.cc. */
629
extern int debug_sync_init(void);
630
extern void debug_sync_end(void);
631
extern void debug_sync_init_thread(THD *thd);
632
extern void debug_sync_end_thread(THD *thd);
633
extern void debug_sync(THD *thd, const char *sync_point_name, size_t name_len);
634
#else /* defined(ENABLED_DEBUG_SYNC) */
635
#define DEBUG_SYNC(_thd_, _sync_point_name_) /* disabled DEBUG_SYNC */
636
#endif /* defined(ENABLED_DEBUG_SYNC) */
605
638
/* BINLOG_DUMP options */
607
640
#define BINLOG_DUMP_NON_BLOCK 1
723
754
const char *calling_file,
724
755
const unsigned int calling_line);
758
Enumerate possible types of a table from re-execution
760
TABLE_LIST class has a member of this type.
761
At prepared statement prepare, this member is assigned a value
762
as of the current state of the database. Before (re-)execution
763
of a prepared statement, we check that the value recorded at
764
prepare matches the type of the object we obtained from the
765
table definition cache.
767
@sa check_and_update_table_version()
769
@sa Prepared_statement::reprepare()
772
enum enum_table_ref_type
774
/** Initial value set by the parser */
777
TABLE_REF_BASE_TABLE,
727
783
External variables
1012
1068
#define SET_ERROR_INJECT_VALUE(x) \
1013
1069
current_thd->error_inject_value= (x)
1014
1070
#define ERROR_INJECT_CRASH(code) \
1015
DBUG_EVALUATE_IF(code, (abort(), 0), 0)
1071
DBUG_EVALUATE_IF(code, (DBUG_ABORT(), 0), 0)
1016
1072
#define ERROR_INJECT_ACTION(code, action) \
1017
1073
(check_and_unset_keyword(code) ? ((action), 0) : 0)
1018
1074
#define ERROR_INJECT(code) \
1057
1113
bool drop_temporary, bool drop_view, bool log_query);
1058
1114
bool quick_rm_table(handlerton *base,const char *db,
1059
1115
const char *table_name, uint flags);
1060
void close_cached_table(THD *thd, TABLE *table);
1061
1116
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
1062
1117
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
1063
1118
char *new_table_name, char *new_table_alias,
1098
1153
bool compare_record(TABLE *table);
1099
1154
bool append_file_to_dir(THD *thd, const char **filename_ptr,
1100
1155
const char *table_name);
1101
void wait_while_table_is_used(THD *thd, TABLE *table,
1102
enum ha_extra_function function);
1103
bool table_cache_init(void);
1104
void table_cache_free(void);
1105
1156
bool table_def_init(void);
1106
1157
void table_def_free(void);
1107
1158
void assign_new_table_id(TABLE_SHARE *share);
1114
1165
#ifndef NO_EMBEDDED_ACCESS_CHECKS
1115
1166
bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv,
1116
1167
bool no_grant, bool no_errors, bool schema_db);
1117
bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
1168
bool check_table_access(THD *thd, ulong requirements, TABLE_LIST *tables,
1118
1169
bool no_errors,
1119
1170
bool any_combination_of_privileges_will_do,
1279
1330
bool tmp_table);
1280
1331
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
1281
1332
uint key_length, uint db_flags, int *error);
1282
void release_table_share(TABLE_SHARE *share, enum release_type type);
1333
void release_table_share(TABLE_SHARE *share);
1283
1334
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
1284
1335
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
1285
1336
uint lock_flags);
1286
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
1287
bool *refresh, uint flags);
1288
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
1289
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
1290
TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
1292
bool lock_table_name_if_not_cached(THD *thd, const char *db,
1293
const char *table_name, TABLE **table);
1294
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
1295
void detach_merge_children(TABLE *table, bool clear_refs);
1296
bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
1297
TABLE_LIST *new_child_list, TABLE_LIST **new_last);
1298
bool reopen_table(TABLE *table);
1299
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
1300
void close_data_files_and_morph_locks(THD *thd, const char *db,
1301
const char *table_name);
1302
void close_handle_and_leave_table_as_lock(TABLE *table);
1337
enum enum_open_table_action {OT_NO_ACTION= 0, OT_BACK_OFF_AND_RETRY,
1338
OT_DISCOVER, OT_REPAIR};
1339
bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
1340
enum_open_table_action *action, uint flags);
1341
bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias,
1342
char *cache_key, uint cache_key_length,
1343
MEM_ROOT *mem_root, uint flags);
1344
TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
1345
TABLE *find_write_locked_table(TABLE *list, const char *db,
1346
const char *table_name);
1303
1347
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
1304
1348
uint db_stat, uint prgflag,
1305
1349
uint ha_open_flags, TABLE *outparam,
1306
1350
TABLE_LIST *table_desc, MEM_ROOT *mem_root);
1307
bool wait_for_tables(THD *thd);
1308
bool table_is_used(TABLE *table, bool wait_for_name_lock);
1309
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
1310
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
1311
1351
void execute_init_command(THD *thd, sys_var_str *init_command_var,
1312
1352
rw_lock_t *var_mutex);
1313
1353
extern Field *not_found_field;
1441
1481
bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
1442
1482
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
1443
1483
void mysql_ha_flush(THD *thd);
1444
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
1484
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables);
1445
1485
void mysql_ha_cleanup(THD *thd);
1447
1487
/* sql_base.cc */
1473
1513
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
1474
1514
SELECT_LEX *lex);
1475
1515
bool add_proc_to_list(THD *thd, Item *item);
1476
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
1516
bool wait_while_table_is_used(THD *thd, TABLE *table,
1517
enum ha_extra_function function);
1477
1518
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
1478
1519
const char *table_name);
1520
void close_all_tables_for_name(THD *thd, TABLE_SHARE *share,
1521
bool remove_from_locked_tables);
1479
1522
void update_non_unique_table_error(TABLE_LIST *update,
1480
1523
const char *operation,
1481
1524
TABLE_LIST *duplicate);
1549
1599
pthread_cond_t *cond);
1550
1600
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
1551
1601
/* open_and_lock_tables with optional derived handling */
1552
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
1602
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived,
1553
1604
/* simple open_and_lock_tables without derived handling */
1554
1605
inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
1556
return open_and_lock_tables_derived(thd, tables, FALSE);
1607
return open_and_lock_tables_derived(thd, tables, FALSE, 0);
1558
1609
/* open_and_lock_tables with derived handling */
1559
1610
inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
1561
return open_and_lock_tables_derived(thd, tables, TRUE);
1612
return open_and_lock_tables_derived(thd, tables, TRUE, 0);
1563
1614
/* simple open_and_lock_tables without derived handling for single table */
1564
1615
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
1565
thr_lock_type lock_type);
1616
thr_lock_type lock_type, uint flags);
1566
1617
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
1567
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
1618
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags,
1568
1620
int decide_logging_format(THD *thd, TABLE_LIST *tables);
1569
1621
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
1570
1622
const char *table_name, bool link_in_list,
1609
1660
uint *fast_alter_partition);
1612
/* bits for last argument to remove_table_from_cache() */
1613
#define RTFC_NO_FLAG 0x0000
1614
#define RTFC_OWNED_BY_THD_FLAG 0x0001
1615
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
1616
#define RTFC_CHECK_KILLED_FLAG 0x0004
1617
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
1663
enum enum_tdc_remove_table_type {TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN,
1664
TDC_RT_REMOVE_UNUSED};
1665
void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
1666
const char *db, const char *table_name);
1620
1668
#define NORMAL_PART_NAME 0
1621
1669
#define TEMP_PART_NAME 1
1943
1989
extern ulong slave_net_timeout, slave_trans_retries;
1944
1990
extern uint max_user_connections;
1945
1991
extern ulong what_to_log,flush_time;
1946
extern ulong query_buff_size, thread_stack;
1992
extern ulong query_buff_size;
1947
1993
extern ulong max_prepared_stmt_count, prepared_stmt_count;
1948
1994
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
1949
1995
extern ulong max_binlog_size, max_relay_log_size;
2019
2065
extern pthread_key(MEM_ROOT**,THR_MALLOC);
2020
2066
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
2021
2067
LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
2022
LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
2068
LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_short,
2023
2069
LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
2024
2070
LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
2025
2071
LOCK_global_system_variables, LOCK_user_conn,
2049
2095
#ifdef MYSQL_SERVER
2050
2096
extern struct system_variables max_system_variables;
2051
2097
extern struct system_status_var global_status_var;
2052
extern struct rand_struct sql_rand;
2098
extern struct my_rnd_struct sql_rand;
2054
2100
extern const char *opt_date_time_formats[];
2055
2101
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
2057
2103
extern String null_string;
2058
extern HASH open_cache, lock_db_cache;
2104
extern HASH table_def_cache, lock_db_cache;
2059
2105
extern TABLE *unused_tables;
2106
extern uint table_cache_count;
2060
2107
extern const char* any_db;
2061
2108
extern struct my_option my_long_options[];
2062
2109
extern const LEX_STRING view_type;
2093
2140
/* mysql_lock_tables() and open_table() flags bits */
2094
2141
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001
2095
2142
#define MYSQL_LOCK_IGNORE_FLUSH 0x0002
2096
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004
2097
#define MYSQL_OPEN_TEMPORARY_ONLY 0x0008
2098
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0010
2099
#define MYSQL_LOCK_PERF_SCHEMA 0x0020
2143
#define MYSQL_OPEN_TEMPORARY_ONLY 0x0004
2144
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0008
2145
#define MYSQL_LOCK_PERF_SCHEMA 0x0010
2146
#define MYSQL_OPEN_TAKE_UPGRADABLE_MDL 0x0020
2148
Do not try to acquire a metadata lock on the table: we
2151
#define MYSQL_OPEN_HAS_MDL_LOCK 0x0040
2153
If in locked tables mode, ignore the locked tables and get
2154
a new instance of the table.
2156
#define MYSQL_OPEN_GET_NEW_TABLE 0x0080
2157
/** Don't look up the table in the list of temporary tables. */
2158
#define MYSQL_OPEN_SKIP_TEMPORARY 0x0100
2160
/** Please refer to the internals manual. */
2161
#define MYSQL_OPEN_REOPEN (MYSQL_LOCK_IGNORE_FLUSH |\
2162
MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK |\
2163
MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |\
2164
MYSQL_OPEN_GET_NEW_TABLE |\
2165
MYSQL_OPEN_SKIP_TEMPORARY |\
2166
MYSQL_OPEN_HAS_MDL_LOCK)
2101
2168
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
2102
2169
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
2103
2170
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
2104
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
2105
bool always_unlock);
2171
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table);
2106
2172
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
2107
2173
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
2108
2174
thr_lock_type new_lock_type);
2125
2191
bool transactional);
2127
2193
/* Lock based on name */
2128
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
2129
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
2130
void unlock_table_name(THD *thd, TABLE_LIST *table_list);
2131
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
2132
2194
bool lock_table_names(THD *thd, TABLE_LIST *table_list);
2133
void unlock_table_names(THD *thd, TABLE_LIST *table_list,
2134
TABLE_LIST *last_table);
2135
bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
2136
bool is_table_name_exclusively_locked_by_this_thread(THD *thd,
2137
TABLE_LIST *table_list);
2138
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
2195
void unlock_table_names(THD *thd);
2142
2198
/* old unireg functions */