1
/* Copyright (C) 2000-2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20
Mostly this file is used in the server. But a little part of it is used in
21
mysqlbinlog too (definition of SELECT_DISTINCT and others).
22
The consequence is that 90% of the file is wrapped in \#ifndef MYSQL_CLIENT,
23
except the part which must be in the server and in the client.
31
#include <my_global.h>
32
#include <drizzle_version.h>
39
#include <my_base.h> /* Needed by field.h */
41
#include "sql_bitmap.h"
42
#include "sql_array.h"
43
#include "sql_plugin.h"
44
#include "scheduler.h"
47
#define _DTRACE_VERSION 1
56
QT_ORDINARY -- ordinary SQL query.
57
QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without
58
character set introducers).
66
/* TODO convert all these three maps to Bitmap classes */
67
typedef uint64_t table_map; /* Used for table bits in join */
69
typedef Bitmap<64> key_map; /* Used for finding keys */
71
typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
73
typedef uint32_t nesting_map; /* Used for flags of nesting constructs */
75
Used to identify NESTED_JOIN structures within a join (applicable only to
76
structures that have not been simplified away and embed more the one
79
typedef uint64_t nested_join_map;
82
typedef uint64_t query_id_t;
83
extern query_id_t global_query_id;
85
/* increment query_id and return it. */
86
inline query_id_t next_query_id() { return global_query_id++; }
88
/* useful constants */
89
extern const key_map key_map_empty;
90
extern key_map key_map_full; /* Should be threaded as const */
91
extern const char *primary_key_name;
93
#include "drizzle_com.h"
97
void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
98
void *sql_alloc(size_t);
99
void *sql_calloc(size_t);
100
char *sql_strdup(const char *str);
101
char *sql_strmake(const char *str, size_t len);
102
void *sql_memdup(const void * ptr, size_t size);
103
void sql_element_free(void *ptr);
104
char *sql_strmake_with_convert(const char *str, size_t arg_length,
105
CHARSET_INFO *from_cs,
106
size_t max_res_length,
107
CHARSET_INFO *to_cs, size_t *result_length);
108
uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
109
void sql_kill(THD *thd, ulong id, bool only_kill_query);
110
bool net_request_file(NET* net, const char* fname);
111
char* query_table_status(THD *thd,const char *db,const char *table_name);
113
#define x_free(A) { my_free((uchar*) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); }
114
#define safeFree(x) { if(x) { my_free((uchar*) x,MYF(0)); x = NULL; } }
115
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
116
#define all_bits_set(A,B) ((A) & (B) != (B))
118
extern CHARSET_INFO *system_charset_info, *files_charset_info ;
119
extern CHARSET_INFO *national_charset_info, *table_alias_charset;
123
DERIVATION_IGNORABLE= 5,
124
DERIVATION_COERCIBLE= 4,
125
DERIVATION_SYSCONST= 3,
126
DERIVATION_IMPLICIT= 2,
128
DERIVATION_EXPLICIT= 0
132
typedef struct my_locale_st
136
const char *description;
138
TYPELIB *month_names;
139
TYPELIB *ab_month_names;
141
TYPELIB *ab_day_names;
143
my_locale_st(uint number_par,
144
const char *name_par, const char *descr_par, bool is_ascii_par,
145
TYPELIB *month_names_par, TYPELIB *ab_month_names_par,
146
TYPELIB *day_names_par, TYPELIB *ab_day_names_par) :
148
name(name_par), description(descr_par), is_ascii(is_ascii_par),
149
month_names(month_names_par), ab_month_names(ab_month_names_par),
150
day_names(day_names_par), ab_day_names(ab_day_names_par)
155
extern MY_LOCALE my_locale_en_US;
156
extern MY_LOCALE *my_locales[];
157
extern MY_LOCALE *my_default_lc_time_names;
159
MY_LOCALE *my_locale_by_name(const char *name);
160
MY_LOCALE *my_locale_by_number(uint number);
162
/*************************************************************************/
165
Object_creation_ctx -- interface for creation context of database objects
166
(views, stored routines, events, triggers). Creation context -- is a set
167
of attributes, that should be fixed at the creation time and then be used
168
each time the object is parsed or executed.
171
class Object_creation_ctx
174
Object_creation_ctx *set_n_backup(THD *thd);
176
void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
179
Object_creation_ctx() {}
180
virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
182
virtual void change_env(THD *thd) const = 0;
185
virtual ~Object_creation_ctx()
189
/*************************************************************************/
192
Default_object_creation_ctx -- default implementation of
196
class Default_object_creation_ctx : public Object_creation_ctx
199
CHARSET_INFO *get_client_cs()
204
CHARSET_INFO *get_connection_cl()
206
return m_connection_cl;
210
Default_object_creation_ctx(THD *thd);
212
Default_object_creation_ctx(CHARSET_INFO *client_cs,
213
CHARSET_INFO *connection_cl);
216
virtual Object_creation_ctx *create_backup_ctx(THD *thd) const;
218
virtual void change_env(THD *thd) const;
222
client_cs stores the value of character_set_client session variable.
223
The only character set attribute is used.
225
Client character set is included into query context, because we save
226
query in the original character set, which is client character set. So,
227
in order to parse the query properly we have to switch client character
230
CHARSET_INFO *m_client_cs;
233
connection_cl stores the value of collation_connection session
234
variable. Both character set and collation attributes are used.
236
Connection collation is included into query context, becase it defines
237
the character set and collation of text literals in internal
238
representation of query (item-objects).
240
CHARSET_INFO *m_connection_cl;
245
Opening modes for open_temporary_table and open_table_from_share
255
/***************************************************************************
256
Configuration parameters
257
****************************************************************************/
259
#define ACL_CACHE_SIZE 256
260
#define MAX_PASSWORD_LENGTH 32
261
#define HOST_CACHE_SIZE 128
262
#define MAX_ACCEPT_RETRY 10 // Test accept this many times
263
#define MAX_FIELDS_BEFORE_HASH 32
264
#define USER_VARS_HASH_SIZE 16
265
#define TABLE_OPEN_CACHE_MIN 64
266
#define TABLE_OPEN_CACHE_DEFAULT 64
269
Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
270
Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added
271
100 bytes as reasonable buffer against growth and other environments'
274
Feel free to raise this by the smallest amount you can to get the
275
"execution_constants" test to pass.
277
#define STACK_MIN_SIZE 12000 ///< Abort if less stack during eval.
279
#define STACK_MIN_SIZE_FOR_OPEN 1024*80
280
#define STACK_BUFF_ALLOC 352 ///< For stack overrun checks
281
#ifndef MYSQLD_NET_RETRY_COUNT
282
#define MYSQLD_NET_RETRY_COUNT 10 ///< Abort read after this many int.
284
#define TEMP_POOL_SIZE 128
286
#define QUERY_ALLOC_BLOCK_SIZE 8192
287
#define QUERY_ALLOC_PREALLOC_SIZE 8192
288
#define TRANS_ALLOC_BLOCK_SIZE 4096
289
#define TRANS_ALLOC_PREALLOC_SIZE 4096
290
#define RANGE_ALLOC_BLOCK_SIZE 4096
291
#define ACL_ALLOC_BLOCK_SIZE 1024
292
#define UDF_ALLOC_BLOCK_SIZE 1024
293
#define TABLE_ALLOC_BLOCK_SIZE 1024
294
#define BDB_LOG_ALLOC_BLOCK_SIZE 1024
295
#define WARN_ALLOC_BLOCK_SIZE 2048
296
#define WARN_ALLOC_PREALLOC_SIZE 1024
297
#define PROFILE_ALLOC_BLOCK_SIZE 2048
298
#define PROFILE_ALLOC_PREALLOC_SIZE 1024
301
The following parameters is to decide when to use an extra cache to
302
optimise seeks when reading a big table in sorted order
304
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
305
#define MIN_ROWS_TO_USE_TABLE_CACHE 100
306
#define MIN_ROWS_TO_USE_BULK_INSERT 100
309
The following is used to decide if MySQL should use table scanning
310
instead of reading with keys. The number says how many evaluation of the
311
WHERE clause is comparable to reading one extra row from a table.
313
#define TIME_FOR_COMPARE 5 // 5 compares == one read
316
Number of comparisons of table rowids equivalent to reading one row from a
319
#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2)
322
For sequential disk seeks the cost formula is:
323
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
325
The cost of average seek
326
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
328
#define DISK_SEEK_BASE_COST ((double)0.9)
330
#define BLOCKS_IN_AVG_SEEK 128
332
#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
336
Number of rows in a reference table when refereed through a not unique key.
337
This value is only used when we don't know anything about the key
340
#define MATCHING_ROWS_IN_OTHER_TABLE 10
342
/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
343
#define KEY_DEFAULT_PACK_LENGTH 8
345
/** Characters shown for the command in 'show processlist'. */
346
#define PROCESS_LIST_WIDTH 100
347
/* Characters shown for the command in 'information_schema.processlist' */
348
#define PROCESS_LIST_INFO_WIDTH 65535
350
#define PRECISION_FOR_DOUBLE 53
351
#define PRECISION_FOR_FLOAT 24
354
Default time to wait before aborting a new client connection
355
that does not respond to "initial server greeting" timely
357
#define CONNECT_TIMEOUT 10
359
/* The following can also be changed from the command line */
360
#define DEFAULT_CONCURRENCY 10
361
#define FLUSH_TIME 0 /**< Don't flush tables */
362
#define MAX_CONNECT_ERRORS 10 ///< errors before disabling host
364
#define INTERRUPT_PRIOR 10
365
#define CONNECT_PRIOR 9
367
#define QUERY_PRIOR 6
369
/* Bits from testflag */
370
#define TEST_PRINT_CACHED_TABLES 1
371
#define TEST_NO_KEY_GROUP 2
372
#define TEST_MIT_THREAD 4
373
#define TEST_BLOCKING 8
374
#define TEST_KEEP_TMP_TABLES 16
375
#define TEST_READCHECK 64 /**< Force use of readcheck */
376
#define TEST_NO_EXTRA 128
377
#define TEST_CORE_ON_SIGNAL 256 /**< Give core if signal */
378
#define TEST_NO_STACKTRACE 512
379
#define TEST_SIGINT 1024 /**< Allow sigint on threads */
380
#define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in
385
This is included in the server and in the client.
386
Options for select set by the yacc parser (stored in lex->options).
389
log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
390
options list are written into binlog. These options can NOT change their
391
values, or it will break replication between version.
393
context is encoded as following:
394
SELECT - SELECT_LEX_NODE::options
396
intern - neither. used only as
397
func(..., select_node->options | thd->options | OPTION_XXX, ...)
399
TODO: separate three contexts above, move them to separate bitfields.
402
#define SELECT_DISTINCT (1ULL << 0) // SELECT, user
403
#define SELECT_STRAIGHT_JOIN (1ULL << 1) // SELECT, user
404
#define SELECT_DESCRIBE (1ULL << 2) // SELECT, user
405
#define SELECT_SMALL_RESULT (1ULL << 3) // SELECT, user
406
#define SELECT_BIG_RESULT (1ULL << 4) // SELECT, user
407
#define OPTION_FOUND_ROWS (1ULL << 5) // SELECT, user
408
#define SELECT_NO_JOIN_CACHE (1ULL << 7) // intern
409
#define OPTION_BIG_TABLES (1ULL << 8) // THD, user
410
#define OPTION_BIG_SELECTS (1ULL << 9) // THD, user
411
#define OPTION_LOG_OFF (1ULL << 10) // THD, user
412
#define OPTION_QUOTE_SHOW_CREATE (1ULL << 11) // THD, user, unused
413
#define TMP_TABLE_ALL_COLUMNS (1ULL << 12) // SELECT, intern
414
#define OPTION_WARNINGS (1ULL << 13) // THD, user
415
#define OPTION_AUTO_IS_NULL (1ULL << 14) // THD, user, binlog
416
#define OPTION_FOUND_COMMENT (1ULL << 15) // SELECT, intern, parser
417
#define OPTION_SAFE_UPDATES (1ULL << 16) // THD, user
418
#define OPTION_BUFFER_RESULT (1ULL << 17) // SELECT, user
419
#define OPTION_BIN_LOG (1ULL << 18) // THD, user
420
#define OPTION_NOT_AUTOCOMMIT (1ULL << 19) // THD, user
421
#define OPTION_BEGIN (1ULL << 20) // THD, intern
422
#define OPTION_TABLE_LOCK (1ULL << 21) // THD, intern
423
#define OPTION_QUICK (1ULL << 22) // SELECT (for DELETE)
424
#define OPTION_KEEP_LOG (1ULL << 23) // THD, user
426
/* The following is used to detect a conflict with DISTINCT */
427
#define SELECT_ALL (1ULL << 24) // SELECT, user, parser
429
/** The following can be set when importing tables in a 'wrong order'
430
to suppress foreign key checks */
431
#define OPTION_NO_FOREIGN_KEY_CHECKS (1ULL << 26) // THD, user, binlog
432
/** The following speeds up inserts to InnoDB tables by suppressing unique
433
key checks in some cases */
434
#define OPTION_RELAXED_UNIQUE_CHECKS (1ULL << 27) // THD, user, binlog
435
#define SELECT_NO_UNLOCK (1ULL << 28) // SELECT, intern
436
#define OPTION_SCHEMA_TABLE (1ULL << 29) // SELECT, intern
437
/** Flag set if setup_tables already done */
438
#define OPTION_SETUP_TABLES_DONE (1ULL << 30) // intern
439
/** If not set then the thread will ignore all warnings with level notes. */
440
#define OPTION_SQL_NOTES (1ULL << 31) // THD, user
442
Force the used temporary table to be a MyISAM table (because we will use
443
fulltext functions when reading from it.
445
#define TMP_TABLE_FORCE_MYISAM (1ULL << 32)
446
#define OPTION_PROFILING (1ULL << 33)
449
Dont report errors for individual rows,
450
But just report error on commit (or read ofcourse)
452
#define OPTION_ALLOW_BATCH (1ULL << 33) // THD, intern (slave)
455
Maximum length of time zone name that we support
456
(Time zone name is char(64) in db). mysqlbinlog needs it.
458
#define MAX_TIME_ZONE_NAME_LENGTH (NAME_LEN + 1)
460
/* The rest of the file is included in the server only */
463
/* Bits for different SQL modes modes (including ANSI mode) */
464
#define MODE_REAL_AS_FLOAT 1
465
#define MODE_PIPES_AS_CONCAT 2
466
#define MODE_ANSI_QUOTES 4
467
#define MODE_IGNORE_SPACE 8
468
#define MODE_NOT_USED 16
469
#define MODE_ONLY_FULL_GROUP_BY 32
470
#define MODE_NO_UNSIGNED_SUBTRACTION 64
471
#define MODE_NO_DIR_IN_CREATE 128
472
#define MODE_POSTGRESQL 256
473
#define MODE_ORACLE 512
474
#define MODE_MSSQL 1024
475
#define MODE_DB2 2048
476
#define MODE_MAXDB 4096
477
#define MODE_NO_KEY_OPTIONS 8192
478
#define MODE_NO_TABLE_OPTIONS 16384
479
#define MODE_NO_FIELD_OPTIONS 32768
480
#define MODE_MYSQL323 65536L
481
#define MODE_MYSQL40 (MODE_MYSQL323*2)
482
#define MODE_ANSI (MODE_MYSQL40*2)
483
#define MODE_NO_AUTO_VALUE_ON_ZERO (MODE_ANSI*2)
484
#define MODE_NO_BACKSLASH_ESCAPES (MODE_NO_AUTO_VALUE_ON_ZERO*2)
485
#define MODE_STRICT_TRANS_TABLES (MODE_NO_BACKSLASH_ESCAPES*2)
486
#define MODE_STRICT_ALL_TABLES (MODE_STRICT_TRANS_TABLES*2)
487
#define MODE_NO_ZERO_IN_DATE (MODE_STRICT_ALL_TABLES*2)
488
#define MODE_NO_ZERO_DATE (MODE_NO_ZERO_IN_DATE*2)
489
#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2)
490
#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2)
491
#define MODE_TRADITIONAL (MODE_ERROR_FOR_DIVISION_BY_ZERO*2)
492
#define MODE_NO_AUTO_CREATE_USER (MODE_TRADITIONAL*2)
493
#define MODE_HIGH_NOT_PRECEDENCE (MODE_NO_AUTO_CREATE_USER*2)
494
#define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2)
495
#define MODE_PAD_CHAR_TO_FULL_LENGTH (1ULL << 31)
498
/* @@optimizer_switch flags */
499
#define OPTIMIZER_SWITCH_NO_MATERIALIZATION 1
500
#define OPTIMIZER_SWITCH_NO_SEMIJOIN 2
504
Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
505
use strictly more than 64 bits by adding one more define above, you should
506
contact the replication team because the replication code should then be
507
updated (to store more bytes on disk).
509
NOTE: When adding new SQL_MODE types, make sure to also add them to
510
the scripts used for creating the MySQL system tables
511
in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql
515
#define RAID_BLOCK_SIZE 1024
517
#define MY_CHARSET_BIN_MB_MAXLEN 1
520
#define UNCACHEABLE_DEPENDENT 1
521
#define UNCACHEABLE_RAND 2
522
#define UNCACHEABLE_SIDEEFFECT 4
523
/// forcing to save JOIN for explain
524
#define UNCACHEABLE_EXPLAIN 8
525
/** Don't evaluate subqueries in prepare even if they're not correlated */
526
#define UNCACHEABLE_PREPARE 16
527
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
528
#define UNCACHEABLE_UNITED 32
530
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
531
#define UNDEF_POS (-1)
533
/* BINLOG_DUMP options */
535
#define BINLOG_DUMP_NON_BLOCK 1
537
/* sql_show.cc:show_log_files() */
538
#define SHOW_LOG_STATUS_FREE "FREE"
539
#define SHOW_LOG_STATUS_INUSE "IN USE"
543
void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
545
/* Options to add_table_to_list() */
546
#define TL_OPTION_UPDATING 1
547
#define TL_OPTION_FORCE_INDEX 2
548
#define TL_OPTION_IGNORE_LEAVES 4
549
#define TL_OPTION_ALIAS 8
551
/* Some portable defines */
553
#define portable_sizeof_char_ptr 8
555
#define tmp_file_prefix "#sql" /**< Prefix for tmp tables */
556
#define tmp_file_prefix_length 4
558
/* Flags for calc_week() function. */
559
#define WEEK_MONDAY_FIRST 1
561
#define WEEK_FIRST_WEEKDAY 4
563
#define STRING_BUFFER_USUAL_SIZE 80
566
Some defines for exit codes for ::is_equal class functions.
568
#define IS_EQUAL_NO 0
569
#define IS_EQUAL_YES 1
570
#define IS_EQUAL_PACK_LENGTH 2
572
enum enum_parsing_place
583
#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__)
586
enum enum_check_fields
590
CHECK_FIELD_ERROR_FOR_NULL
594
/** Struct to handle simple linked lists. */
595
typedef struct st_sql_list {
600
st_sql_list() {} /* Remove gcc warning */
607
inline void link_in_list(uchar *element,uchar **next_ptr)
614
inline void save_and_clear(struct st_sql_list *save)
619
inline void push_front(struct st_sql_list *save)
621
*save->next= first; /* link current list last */
623
elements+= save->elements;
625
inline void push_back(struct st_sql_list *save)
631
elements+= save->elements;
637
extern pthread_key(THD*, THR_THD);
638
inline THD *_current_thd(void)
640
return (THD *)pthread_getspecific(THR_THD);
642
#define current_thd _current_thd()
645
The meat of thd_proc_info(THD*, char*), a macro that packs the last
646
three calling-info parameters.
649
const char *set_thd_proc_info(THD *thd, const char *info,
650
const char *calling_func,
651
const char *calling_file,
652
const unsigned int calling_line);
657
extern ulong server_id;
660
typedef bool (*qc_engine_callback)(THD *thd, char *table_key,
662
uint64_t *engine_data);
663
#include "sql_string.h"
664
#include "sql_list.h"
666
#include "my_decimal.h"
669
#include "sql_error.h"
671
/* Field definitions */
674
#include "protocol.h"
677
class user_var_entry;
678
class Security_context;
681
OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
686
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
689
extern my_decimal decimal_zero;
692
void free_items(Item *item);
693
void cleanup_items(Item *item);
695
void close_thread_tables(THD *thd);
697
bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
698
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
699
int mysql_multi_update_prepare(THD *thd);
700
int mysql_multi_delete_prepare(THD *thd);
701
bool mysql_insert_select_prepare(THD *thd);
702
bool update_precheck(THD *thd, TABLE_LIST *tables);
703
bool delete_precheck(THD *thd, TABLE_LIST *tables);
704
bool insert_precheck(THD *thd, TABLE_LIST *tables);
705
bool create_table_precheck(THD *thd, TABLE_LIST *tables,
706
TABLE_LIST *create_table);
707
int append_query_string(CHARSET_INFO *csinfo,
708
String const *from, String *to);
710
bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
711
uint max_byte_length);
712
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
713
uint max_char_length, CHARSET_INFO *cs,
715
bool check_identifier_name(LEX_STRING *str, uint max_char_length,
716
uint err_code, const char *param_for_err_msg);
717
inline bool check_identifier_name(LEX_STRING *str, uint err_code)
719
return check_identifier_name(str, NAME_CHAR_LEN, err_code, "");
721
inline bool check_identifier_name(LEX_STRING *str)
723
return check_identifier_name(str, NAME_CHAR_LEN, 0, "");
726
bool test_if_data_home_dir(const char *dir);
728
bool parse_sql(THD *thd,
729
class Lex_input_stream *lip,
730
class Object_creation_ctx *creation_ctx);
732
enum enum_mysql_completiontype {
733
ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7,
734
COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6
737
bool begin_trans(THD *thd);
738
bool end_active_trans(THD *thd);
739
int end_trans(THD *thd, enum enum_mysql_completiontype completion);
741
Item *negate_expression(THD *thd, Item *expr);
744
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
745
void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
746
void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
747
void sql_print_information(const char *format, ...)
748
ATTRIBUTE_FORMAT(printf, 1, 2);
749
typedef void (*sql_print_message_func)(const char *format, ...)
750
ATTRIBUTE_FORMAT(printf, 1, 2);
751
extern sql_print_message_func sql_print_message_handlers[];
753
int error_log_print(enum loglevel level, const char *format,
756
bool slow_log_print(THD *thd, const char *query, uint query_length,
757
uint64_t current_utime);
759
bool general_log_print(THD *thd, enum enum_server_command command,
760
const char *format,...);
762
bool general_log_write(THD *thd, enum enum_server_command command,
763
const char *query, uint query_length);
765
#include "sql_class.h"
766
#include "slave.h" // for tables_ok(), rpl_filter
769
#include "opt_range.h"
773
Error injector Macros to enable easy testing of recovery after failures
774
in various error cases.
776
#ifndef ERROR_INJECT_SUPPORT
778
#define ERROR_INJECT(x) 0
779
#define ERROR_INJECT_ACTION(x,action) 0
780
#define ERROR_INJECT_CRASH(x) 0
781
#define ERROR_INJECT_VALUE(x) 0
782
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
783
#define ERROR_INJECT_VALUE_CRASH(x) 0
784
#define SET_ERROR_INJECT_VALUE(x)
788
inline bool check_and_unset_keyword(const char *dbug_str)
790
const char *extra_str= "-d,";
792
if (_db_strict_keyword_ (dbug_str))
794
strxmov(total_str, extra_str, dbug_str, NullS);
802
check_and_unset_inject_value(int value)
804
THD *thd= current_thd;
805
if (thd->error_inject_value == (uint)value)
807
thd->error_inject_value= 0;
816
These macros are used to insert macros from the application code.
817
The event that activates those error injections can be activated
819
SET SESSION dbug=+d,code;
821
After the error has been injected, the macros will automatically
822
remove the debug code, thus similar to using:
823
SET SESSION dbug=-d,code
826
ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
827
is set when macro is called. ERROR_INJECT_CRASH can be used in
828
if-statements, it will always return false unless of course it
829
crashes in which case it doesn't return at all.
831
ERROR_INJECT_ACTION will inject the action specified in the action
832
parameter of the macro, before performing the action the code will
833
be removed such that no more events occur. ERROR_INJECT_ACTION
834
can also be used in if-statements and always returns FALSE.
835
ERROR_INJECT can be used in a normal if-statement, where the action
836
part is performed in the if-block. The macro returns TRUE if the
837
error was activated and otherwise returns FALSE. If activated the
840
Sometimes it is necessary to perform error inject actions as a serie
841
of events. In this case one can use one variable on the THD object.
842
Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
843
Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
844
ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
845
behaviour as the above described macros except that they use the
846
error inject value instead of a code used by debug macros.
848
#define SET_ERROR_INJECT_VALUE(x) \
849
current_thd->error_inject_value= (x)
850
#define ERROR_INJECT_ACTION(code, action) \
851
(check_and_unset_keyword(code) ? ((action), 0) : 0)
852
#define ERROR_INJECT(code) \
853
check_and_unset_keyword(code)
854
#define ERROR_INJECT_VALUE(value) \
855
check_and_unset_inject_value(value)
856
#define ERROR_INJECT_VALUE_ACTION(value,action) \
857
(check_and_unset_inject_value(value) ? (action) : 0)
858
#define ERROR_INJECT_VALUE_CRASH(value) \
859
ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
863
void write_bin_log(THD *thd, bool clear_error,
864
char const *query, ulong query_length);
867
int check_user(THD *thd, enum enum_server_command command,
868
const char *passwd, uint passwd_len, const char *db,
870
pthread_handler_t handle_one_connection(void *arg);
871
bool init_new_connection_handler_thread();
872
void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
873
void decrease_user_connections(USER_CONN *uc);
874
void thd_init_client_charset(THD *thd, uint cs_number);
875
bool setup_connection_thread_globals(THD *thd);
876
bool login_connection(THD *thd);
877
void prepare_new_connection_state(THD* thd);
878
void end_connection(THD *thd);
881
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
882
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
883
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
884
bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db);
885
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
886
void mysql_client_binlog_statement(THD *thd);
887
bool mysql_rm_table(THD *thd,TABLE_LIST *tables, bool if_exists,
888
bool drop_temporary);
889
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
890
bool drop_temporary, bool drop_view, bool log_query);
891
bool quick_rm_table(handlerton *base,const char *db,
892
const char *table_name, uint flags);
893
void close_cached_table(THD *thd, TABLE *table);
894
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
895
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
896
char *new_table_name, char *new_table_alias,
899
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
902
bool mysql_opt_change_db(THD *thd,
903
const LEX_STRING *new_db_name,
904
LEX_STRING *saved_db_name,
906
bool *cur_db_changed);
908
void mysql_parse(THD *thd, const char *inBuf, uint length,
909
const char ** semicolon);
911
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
912
bool is_update_query(enum enum_sql_command command);
913
bool alloc_query(THD *thd, const char *packet, uint packet_length);
914
void mysql_init_select(LEX *lex);
915
void mysql_reset_thd_for_next_command(THD *thd);
916
bool mysql_new_select(LEX *lex, bool move_down);
917
void create_select_for_variable(const char *var_name);
918
void mysql_init_multi_delete(LEX *lex);
919
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
920
void init_max_user_conn(void);
921
void init_update_queries(void);
922
void free_max_user_conn(void);
923
pthread_handler_t handle_bootstrap(void *arg);
924
int mysql_execute_command(THD *thd);
925
bool do_command(THD *thd);
926
bool dispatch_command(enum enum_server_command command, THD *thd,
927
char* packet, uint packet_length);
928
void log_slow_statement(THD *thd);
929
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
930
bool compare_record(TABLE *table);
931
bool append_file_to_dir(THD *thd, const char **filename_ptr,
932
const char *table_name);
933
void wait_while_table_is_used(THD *thd, TABLE *table,
934
enum ha_extra_function function);
935
bool table_cache_init(void);
936
void table_cache_free(void);
937
bool table_def_init(void);
938
void table_def_free(void);
939
void assign_new_table_id(TABLE_SHARE *share);
940
uint cached_open_tables(void);
941
uint cached_table_definitions(void);
942
void kill_mysql(void);
943
void close_connection(THD *thd, uint errcode, bool lock);
944
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables, bool *write_to_binlog);
945
bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
947
bool any_combination_of_privileges_will_do,
950
#endif /* MYSQL_SERVER */
951
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
952
bool check_global_access(THD *thd, ulong want_access);
953
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
957
General routine to change field->ptr of a NULL-terminated array of Field
958
objects. Useful when needed to call val_int, val_str or similar and the
959
field data is not in table->record[0] but in some other structure.
960
set_key_field_ptr changes all fields of an index using a key_info object.
961
All methods presume that there is at least one field to change.
964
void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
965
void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
966
const uchar *old_buf);
968
bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
969
HA_CHECK_OPT* check_opt);
970
bool mysql_check_table(THD* thd, TABLE_LIST* table_list,
971
HA_CHECK_OPT* check_opt);
972
bool mysql_repair_table(THD* thd, TABLE_LIST* table_list,
973
HA_CHECK_OPT* check_opt);
974
bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
975
HA_CHECK_OPT* check_opt);
976
bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
977
HA_CHECK_OPT* check_opt);
978
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
979
LEX_STRING *key_cache_name);
980
bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
981
int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
982
KEY_CACHE *dst_cache);
983
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
985
bool mysql_xa_recover(THD *thd);
987
bool check_simple_select();
989
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
990
SORT_FIELD *sortorder);
991
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
992
List<Item> &fields, List <Item> &all_fields, ORDER *order);
993
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
994
List<Item> &fields, List<Item> &all_fields, ORDER *order,
995
bool *hidden_group_fields);
996
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
997
Item **ref_pointer_array);
999
bool handle_select(THD *thd, LEX *lex, select_result *result,
1000
ulong setup_tables_done_option);
1001
bool mysql_select(THD *thd, Item ***rref_pointer_array,
1002
TABLE_LIST *tables, uint wild_num, List<Item> &list,
1003
COND *conds, uint og_num, ORDER *order, ORDER *group,
1004
Item *having, ORDER *proc_param, uint64_t select_type,
1005
select_result *result, SELECT_LEX_UNIT *unit,
1006
SELECT_LEX *select_lex);
1007
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
1008
bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
1009
select_result *result);
1010
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
1011
select_result *result);
1012
bool mysql_union(THD *thd, LEX *lex, select_result *result,
1013
SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
1014
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
1016
TABLE_LIST *table));
1017
bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
1018
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
1019
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
1020
Item ***copy_func, Field **from_field,
1022
bool group, bool modify_item,
1023
bool table_cant_handle_bit_fields,
1024
bool make_copy_field,
1025
uint convert_blob_length);
1026
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
1027
int prepare_create_field(Create_field *sql_field,
1029
int *timestamps, int *timestamps_with_niladic,
1030
int64_t table_flags);
1031
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
1032
HA_CREATE_INFO *create_info,
1033
Alter_info *alter_info,
1034
bool tmp_table, uint select_field_count);
1035
bool mysql_create_table_no_lock(THD *thd, const char *db,
1036
const char *table_name,
1037
HA_CREATE_INFO *create_info,
1038
Alter_info *alter_info,
1039
bool tmp_table, uint select_field_count);
1041
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
1042
HA_CREATE_INFO *create_info,
1043
TABLE_LIST *table_list,
1044
Alter_info *alter_info,
1045
uint order_num, ORDER *order, bool ignore);
1046
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
1047
bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
1048
TABLE_LIST *src_table,
1049
HA_CREATE_INFO *create_info);
1050
bool mysql_rename_table(handlerton *base, const char *old_db,
1051
const char * old_name, const char *new_db,
1052
const char * new_name, uint flags);
1053
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
1054
Item **conds, uint order_num, ORDER *order);
1055
int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
1056
List<Item> &values,COND *conds,
1057
uint order_num, ORDER *order, ha_rows limit,
1058
enum enum_duplicates handle_duplicates, bool ignore);
1059
bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
1060
List<Item> *fields, List<Item> *values,
1061
COND *conds, uint64_t options,
1062
enum enum_duplicates handle_duplicates, bool ignore,
1063
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
1064
bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
1065
List<Item> &fields, List_item *values,
1066
List<Item> &update_fields,
1067
List<Item> &update_values, enum_duplicates duplic,
1068
COND **where, bool select_insert,
1069
bool check_fields, bool abort_on_warning);
1070
bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
1071
List<List_item> &values, List<Item> &update_fields,
1072
List<Item> &update_values, enum_duplicates flag,
1074
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
1075
TABLE_LIST *table_list);
1076
void prepare_triggers_for_insert_stmt(TABLE *table);
1077
int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
1078
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
1079
SQL_LIST *order, ha_rows rows, uint64_t options,
1080
bool reset_auto_increment);
1081
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
1082
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
1083
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
1085
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
1086
uint key_length, uint db_flags, int *error);
1087
void release_table_share(TABLE_SHARE *share, enum release_type type);
1088
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
1089
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
1091
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
1092
bool *refresh, uint flags);
1093
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
1094
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
1095
TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
1097
bool lock_table_name_if_not_cached(THD *thd, const char *db,
1098
const char *table_name, TABLE **table);
1099
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
1100
void detach_merge_children(TABLE *table, bool clear_refs);
1101
bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
1102
TABLE_LIST *new_child_list, TABLE_LIST **new_last);
1103
bool reopen_table(TABLE *table);
1104
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
1105
void close_data_files_and_morph_locks(THD *thd, const char *db,
1106
const char *table_name);
1107
void close_handle_and_leave_table_as_lock(TABLE *table);
1108
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
1109
uint db_stat, uint prgflag,
1110
uint ha_open_flags, TABLE *outparam,
1111
TABLE_LIST *table_desc, MEM_ROOT *mem_root);
1112
bool wait_for_tables(THD *thd);
1113
bool table_is_used(TABLE *table, bool wait_for_name_lock);
1114
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
1115
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
1116
void execute_init_command(THD *thd, sys_var_str *init_command_var,
1117
rw_lock_t *var_mutex);
1118
extern Field *not_found_field;
1119
extern Field *view_ref_found;
1121
enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
1122
IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
1123
IGNORE_EXCEPT_NON_UNIQUE};
1125
find_field_in_tables(THD *thd, Item_ident *item,
1126
TABLE_LIST *first_table, TABLE_LIST *last_table,
1127
Item **ref, find_item_error_report_type report_error,
1128
bool check_privileges, bool register_tree_change);
1130
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
1131
const char *name, uint length,
1132
const char *item_name, const char *db_name,
1133
const char *table_name, Item **ref,
1134
bool check_privileges, bool allow_rowid,
1135
uint *cached_field_index_ptr,
1136
bool register_tree_change, TABLE_LIST **actual_table);
1138
find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
1139
bool allow_rowid, uint *cached_field_index_ptr);
1141
find_field_in_table_sef(TABLE *table, const char *name);
1143
#endif /* MYSQL_SERVER */
1147
bool mysql_do(THD *thd, List<Item> &values);
1150
bool append_escaped(String *to_str, String *from_str);
1153
bool mysqld_show_open_tables(THD *thd,const char *wild);
1154
bool mysqld_show_logs(THD *thd);
1155
void append_identifier(THD *thd, String *packet, const char *name,
1157
#endif /* MYSQL_SERVER */
1158
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1159
int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
1160
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1162
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
1163
int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
1164
bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
1165
bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
1167
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
1168
int mysqld_show_status(THD *thd);
1169
int mysqld_show_variables(THD *thd,const char *wild);
1170
bool mysqld_show_storage_engines(THD *thd);
1171
bool mysqld_show_authors(THD *thd);
1172
bool mysqld_show_contributors(THD *thd);
1173
bool mysqld_show_privileges(THD *thd);
1174
bool mysqld_show_column_types(THD *thd);
1175
bool mysqld_help (THD *thd, const char *text);
1176
void calc_sum_of_all_status(STATUS_VAR *to);
1178
void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
1179
const LEX_STRING *definer_host);
1181
int add_status_vars(SHOW_VAR *list);
1182
void remove_status_vars(SHOW_VAR *list);
1183
void init_status_vars();
1184
void free_status_vars();
1185
void reset_status_vars();
1187
/* information schema */
1188
extern LEX_STRING INFORMATION_SCHEMA_NAME;
1190
extern LEX_STRING MYSQL_SCHEMA_NAME;
1191
extern LEX_STRING GENERAL_LOG_NAME;
1192
extern LEX_STRING SLOW_LOG_NAME;
1194
extern const LEX_STRING partition_keywords[];
1195
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
1196
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
1197
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
1198
enum enum_schema_tables schema_table_idx);
1199
int make_schema_select(THD *thd, SELECT_LEX *sel,
1200
enum enum_schema_tables schema_table_idx);
1201
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
1202
bool get_schema_tables_result(JOIN *join,
1203
enum enum_schema_table_state executed_place);
1204
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
1206
#define is_schema_db(X) \
1207
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
1209
/* sql_prepare.cc */
1211
void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length);
1212
void mysql_stmt_execute(THD *thd, char *packet, uint packet_length);
1213
void mysql_stmt_close(THD *thd, char *packet);
1214
void mysql_sql_stmt_prepare(THD *thd);
1215
void mysql_sql_stmt_execute(THD *thd);
1216
void mysql_sql_stmt_close(THD *thd);
1217
void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length);
1218
void mysql_stmt_reset(THD *thd, char *packet);
1219
void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
1220
void reinit_stmt_before_use(THD *thd, LEX *lex);
1222
/* sql_handler.cc */
1223
bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
1224
bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
1225
bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
1226
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
1227
void mysql_ha_flush(THD *thd);
1228
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
1229
void mysql_ha_cleanup(THD *thd);
1232
#define TMP_TABLE_KEY_EXTRA 8
1233
void set_item_name(Item *item,char *pos,uint length);
1234
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
1235
char *length, char *decimal,
1237
enum column_format_type column_format,
1238
Item *default_value, Item *on_update_value,
1239
LEX_STRING *comment,
1240
char *change, List<String> *interval_list,
1242
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
1243
char *length, char *decimals,
1245
Item *default_value, Item *on_update_value,
1246
LEX_STRING *comment, char *change,
1247
List<String> *interval_list, CHARSET_INFO *cs);
1248
void store_position_for_column(const char *name);
1249
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
1250
bool push_new_name_resolution_context(THD *thd,
1251
TABLE_LIST *left_op,
1252
TABLE_LIST *right_op);
1253
void add_join_on(TABLE_LIST *b,Item *expr);
1254
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
1256
bool add_proc_to_list(THD *thd, Item *item);
1257
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
1258
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
1259
const char *table_name);
1260
void update_non_unique_table_error(TABLE_LIST *update,
1261
const char *operation,
1262
TABLE_LIST *duplicate);
1264
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
1265
table_map read_tables, COND *conds,
1266
bool allow_null_cond, int *error);
1267
extern Item **not_found_item;
1270
A set of constants used for checking non aggregated fields and sum
1271
functions mixture in the ONLY_FULL_GROUP_BY_MODE.
1273
#define NON_AGG_FIELD_USED 1
1274
#define SUM_FUNC_USED 2
1277
This enumeration type is used only by the function find_item_in_list
1278
to return the info on how an item has been resolved against a list
1279
of possibly aliased items.
1280
The item can be resolved:
1281
- against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
1282
- against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS)
1283
- against an aliased field name of the list (RESOLVED_BEHIND_ALIAS)
1284
- ignoring the alias name in cases when SQL requires to ignore aliases
1285
(e.g. when the resolved field reference contains a table name or
1286
when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS)
1288
enum enum_resolution_type {
1290
RESOLVED_IGNORING_ALIAS,
1291
RESOLVED_BEHIND_ALIAS,
1292
RESOLVED_WITH_NO_ALIAS,
1293
RESOLVED_AGAINST_ALIAS
1295
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
1296
find_item_error_report_type report_error,
1297
enum_resolution_type *resolution);
1298
bool get_key_map_from_key_list(key_map *map, TABLE *table,
1299
List<String> *index_list);
1300
bool insert_fields(THD *thd, Name_resolution_context *context,
1301
const char *db_name, const char *table_name,
1302
List_iterator<Item> *it, bool any_privileges);
1303
bool setup_tables(THD *thd, Name_resolution_context *context,
1304
List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
1305
TABLE_LIST **leaves, bool select_insert);
1306
bool setup_tables_and_check_access(THD *thd,
1307
Name_resolution_context *context,
1308
List<TABLE_LIST> *from_clause,
1310
TABLE_LIST **leaves,
1311
bool select_insert);
1312
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
1313
List<Item> *sum_func_list, uint wild_num);
1314
bool setup_fields(THD *thd, Item** ref_pointer_array,
1315
List<Item> &item, enum_mark_columns mark_used_columns,
1316
List<Item> *sum_func_list, bool allow_sum_func);
1317
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
1319
enum_mark_columns mark_used_columns,
1320
List<Item> *sum_func_list,
1321
bool allow_sum_func)
1324
res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
1328
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
1330
int setup_ftfuncs(SELECT_LEX* select);
1331
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
1332
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
1333
pthread_cond_t *cond);
1334
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
1335
/* open_and_lock_tables with optional derived handling */
1336
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
1337
/* simple open_and_lock_tables without derived handling */
1338
inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
1340
return open_and_lock_tables_derived(thd, tables, false);
1342
/* open_and_lock_tables with derived handling */
1343
inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
1345
return open_and_lock_tables_derived(thd, tables, true);
1347
/* simple open_and_lock_tables without derived handling for single table */
1348
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
1349
thr_lock_type lock_type);
1350
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
1351
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
1352
int decide_logging_format(THD *thd, TABLE_LIST *tables);
1353
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
1354
const char *table_name, bool link_in_list,
1355
open_table_mode open_mode);
1356
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
1357
void free_io_cache(TABLE *entry);
1358
void intern_close_table(TABLE *entry);
1359
bool close_thread_table(THD *thd, TABLE **table_ptr);
1360
void close_temporary_tables(THD *thd);
1361
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
1362
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
1363
TABLE_LIST *TABLE_LIST::*link,
1364
const char *db_name,
1365
const char *table_name);
1366
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
1368
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
1369
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
1370
int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
1371
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
1373
void close_temporary(TABLE *table, bool free_share, bool delete_table);
1374
bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
1375
const char *table_name);
1376
void remove_db_from_cache(const char *db);
1377
void flush_tables();
1378
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
1379
char *make_default_log_name(char *buff,const char* log_ext);
1381
/* bits for last argument to remove_table_from_cache() */
1382
#define RTFC_NO_FLAG 0x0000
1383
#define RTFC_OWNED_BY_THD_FLAG 0x0001
1384
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
1385
#define RTFC_CHECK_KILLED_FLAG 0x0004
1386
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
1389
#define NORMAL_PART_NAME 0
1390
#define TEMP_PART_NAME 1
1391
#define RENAMED_PART_NAME 2
1393
void mem_alloc_error(size_t size);
1395
#define WFRM_WRITE_SHADOW 1
1396
#define WFRM_INSTALL_SHADOW 2
1397
#define WFRM_PACK_FRM 4
1398
#define WFRM_KEEP_SHARE 8
1400
/* Functions to work with system tables. */
1401
bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
1402
Open_tables_state *backup);
1403
void close_system_tables(THD *thd, Open_tables_state *backup);
1404
TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
1406
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
1407
bool wait_for_refresh, bool wait_for_placeholders);
1408
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
1409
LEX_STRING *connect_string,
1410
bool have_lock= false);
1411
void copy_field_from_tmp_record(Field *field,int offset);
1412
bool fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors);
1413
bool fill_record(THD *thd, Field **field, List<Item> &values, bool ignore_errors);
1414
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
1416
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
1417
const char *db_name,
1418
const char *table_name)
1420
return find_table_in_list(table, &TABLE_LIST::next_global,
1421
db_name, table_name);
1424
inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
1425
const char *db_name,
1426
const char *table_name)
1428
return find_table_in_list(table, &TABLE_LIST::next_local,
1429
db_name, table_name);
1434
bool eval_const_cond(COND *cond);
1437
int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
1438
List<Item> &fields_vars, List<Item> &set_fields,
1439
List<Item> &set_values_list,
1440
enum enum_duplicates handle_duplicates, bool ignore,
1442
int write_record(THD *thd, TABLE *table, COPY_INFO *info);
1446
void print_where(COND *cond,const char *info, enum_query_type query_type);
1447
void print_cached_tables(void);
1448
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
1449
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
1450
double current_read_time, const char *info);
1451
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
1452
void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl);
1453
void mysql_print_status();
1456
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
1457
uint *key_length, uint *keypart);
1458
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
1459
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
1461
void key_zero_nulls(uchar *tuple, KEY *key_info);
1462
bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
1463
void key_unpack(String *to,TABLE *form,uint index);
1464
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
1465
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
1466
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
1468
bool init_errmessage(void);
1469
#endif /* MYSQL_SERVER */
1470
void sql_perror(const char *message);
1472
bool fn_format_relative_to_data_home(char * to, const char *name,
1473
const char *dir, const char *extension);
1475
File open_binlog(IO_CACHE *log, const char *log_file_name,
1476
const char **errmsg);
1479
extern void MYSQLerror(const char*);
1480
void refresh_status(THD *thd);
1481
bool mysql_rm_tmp_tables(void);
1482
void handle_connection_in_main_thread(THD *thd);
1483
void create_thread_to_handle_connection(THD *thd);
1484
void unlink_thd(THD *thd);
1485
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
1486
void flush_thread_cache();
1489
extern bool check_reserved_words(LEX_STRING *name);
1490
extern enum_field_types agg_field_type(Item **items, uint nitems);
1493
uint64_t find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs,
1494
char **err_pos, uint *err_len, bool *set_warning);
1495
uint find_type(const TYPELIB *lib, const char *find, uint length,
1497
uint find_type2(const TYPELIB *lib, const char *find, uint length,
1499
void unhex_type2(TYPELIB *lib);
1500
uint check_word(TYPELIB *lib, const char *val, const char *end,
1501
const char **end_of_word);
1502
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
1503
CHARSET_INFO * const cs);
1506
bool is_keyword(const char *name, uint len);
1508
#define MY_DB_OPT_FILE "db.opt"
1509
bool my_database_names_init(void);
1510
void my_database_names_free(void);
1511
bool check_db_dir_existence(const char *db_name);
1512
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
1513
bool load_db_opt_by_name(THD *thd, const char *db_name,
1514
HA_CREATE_INFO *db_create_info);
1515
CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
1516
bool my_dbopt_init(void);
1517
void my_dbopt_cleanup(void);
1518
extern int creating_database; // How many database locks are made
1519
extern int creating_table; // How many mysql_create_table() are running
1525
extern time_t server_start_time, flush_status_time;
1526
#endif /* MYSQL_SERVER */
1527
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1528
extern uint mysql_data_home_len;
1529
extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
1530
mysql_real_data_home[], mysql_unpacked_real_data_home[];
1531
extern CHARSET_INFO *character_set_filesystem;
1532
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1534
extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
1536
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
1537
extern MY_TMPDIR mysql_tmpdir_list;
1538
extern const LEX_STRING command_name[];
1539
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
1540
extern const char **errmesg; /* Error messages */
1541
extern const char *myisam_recover_options_str;
1542
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
1543
extern const char * const TRG_EXT;
1544
extern const char * const TRN_EXT;
1545
extern Eq_creator eq_creator;
1546
extern Ne_creator ne_creator;
1547
extern Gt_creator gt_creator;
1548
extern Lt_creator lt_creator;
1549
extern Ge_creator ge_creator;
1550
extern Le_creator le_creator;
1551
extern char language[FN_REFLEN];
1552
#endif /* MYSQL_SERVER */
1553
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1554
extern char reg_ext[FN_EXTLEN];
1555
extern uint reg_ext_length;
1556
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1558
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
1559
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
1560
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
1561
extern const double log_10[309];
1562
extern uint64_t log_10_int[20];
1563
extern uint64_t keybuff_size;
1564
extern uint64_t thd_startup_options;
1565
extern ulong thread_id;
1566
extern ulong binlog_cache_use, binlog_cache_disk_use;
1567
extern ulong aborted_threads,aborted_connects;
1568
extern ulong slave_open_temp_tables;
1569
extern ulong slow_launch_threads, slow_launch_time;
1570
extern ulong table_cache_size, table_def_size;
1571
extern ulong max_connections,max_connect_errors, connect_timeout;
1572
extern bool slave_allow_batching;
1573
extern ulong slave_net_timeout, slave_trans_retries;
1574
extern uint max_user_connections;
1575
extern ulong what_to_log,flush_time;
1576
extern ulong query_buff_size;
1577
extern ulong max_prepared_stmt_count, prepared_stmt_count;
1578
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
1579
extern ulong max_binlog_size, max_relay_log_size;
1580
extern ulong opt_binlog_rows_event_max_size;
1581
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
1582
extern ulong back_log;
1583
#endif /* MYSQL_SERVER */
1584
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1585
extern ulong specialflag;
1586
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1588
extern ulong current_pid;
1589
extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
1590
extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
1591
extern ulong tc_log_page_waits;
1592
extern bool relay_log_purge;
1593
extern bool opt_innodb_safe_binlog, opt_innodb;
1594
extern uint test_flags,select_errors,ha_open_options;
1595
extern uint protocol_version, mysqld_port, dropping_tables;
1596
extern uint delay_key_write_options;
1597
#endif /* MYSQL_SERVER */
1598
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1599
extern uint lower_case_table_names;
1600
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1602
extern bool opt_endinfo, using_udf_functions;
1603
extern bool locked_in_memory;
1604
extern bool opt_using_transactions;
1605
#endif /* MYSQL_SERVER */
1606
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1607
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1609
extern bool using_update_log, server_id_supplied;
1610
extern bool opt_update_log, opt_bin_log, opt_error_log;
1611
extern bool opt_log;
1612
extern bool opt_slow_log;
1613
extern ulong log_output_options;
1614
extern bool opt_log_queries_not_using_indexes;
1615
extern bool opt_disable_networking, opt_skip_show_db;
1616
extern bool opt_character_set_client_handshake;
1617
extern bool volatile abort_loop, shutdown_in_progress;
1618
extern uint volatile thread_count, thread_running, global_read_lock;
1619
extern uint connection_count;
1620
extern bool opt_sql_bin_update;
1621
extern bool opt_safe_user_create;
1622
extern bool opt_no_mix_types;
1623
extern bool opt_safe_show_db, opt_myisam_use_mmap;
1624
extern bool opt_local_infile;
1625
extern bool opt_slave_compressed_protocol;
1626
extern bool use_temp_pool;
1627
extern ulong slave_exec_mode_options;
1628
extern bool opt_readonly;
1629
extern bool lower_case_file_system;
1630
extern bool opt_enable_named_pipe;
1631
extern bool opt_sync_frm;
1632
extern bool opt_secure_auth;
1633
extern char* opt_secure_file_priv;
1634
extern bool opt_log_slow_admin_statements;
1635
extern bool opt_log_slow_slave_statements;
1636
extern bool opt_noacl;
1637
extern bool opt_old_style_user_limits;
1638
extern uint opt_crash_binlog_innodb;
1639
extern char *shared_memory_base_name;
1640
extern bool opt_enable_shared_memory;
1641
extern char *default_tz_name;
1642
#endif /* MYSQL_SERVER */
1644
extern char *opt_logname, *opt_slow_logname;
1645
extern const char *log_output_str;
1647
extern MYSQL_BIN_LOG mysql_bin_log;
1648
extern LOGGER logger;
1649
extern TABLE_LIST general_log, slow_log;
1650
extern FILE *bootstrap_file;
1651
extern int bootstrap_error;
1652
extern FILE *stderror_file;
1653
extern pthread_key(MEM_ROOT**,THR_MALLOC);
1654
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_open, LOCK_lock_db,
1655
LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
1656
LOCK_error_log, LOCK_uuid_generator,
1657
LOCK_crypt, LOCK_timezone,
1658
LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
1659
LOCK_global_system_variables, LOCK_user_conn,
1660
LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
1661
extern pthread_mutex_t LOCK_server_started;
1662
extern rw_lock_t LOCK_sys_init_connect, LOCK_sys_init_slave;
1663
extern rw_lock_t LOCK_system_variables_hash;
1664
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
1665
extern pthread_cond_t COND_global_read_lock;
1666
extern pthread_attr_t connection_attrib;
1667
extern I_List<THD> threads;
1668
extern I_List<NAMED_LIST> key_caches;
1669
extern MY_BITMAP temp_pool;
1670
extern String my_empty_string;
1671
extern const String my_null_string;
1672
extern SHOW_VAR status_vars[];
1673
#endif /* MYSQL_SERVER */
1674
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1675
extern struct system_variables global_system_variables;
1676
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1678
extern struct system_variables max_system_variables;
1679
extern struct system_status_var global_status_var;
1680
extern struct rand_struct sql_rand;
1682
extern const char *opt_date_time_formats[];
1683
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
1685
extern String null_string;
1686
extern HASH open_cache, lock_db_cache;
1687
extern TABLE *unused_tables;
1688
extern const char* any_db;
1689
extern struct my_option my_long_options[];
1690
extern const LEX_STRING view_type;
1691
extern scheduler_functions thread_scheduler;
1692
extern TYPELIB thread_handling_typelib;
1693
extern uint8_t uc_update_queries[SQLCOM_END+1];
1694
extern uint sql_command_flags[];
1695
extern TYPELIB log_output_typelib;
1697
/* optional things, have_* variables */
1698
extern SHOW_COMP_OPTION have_community_features;
1700
extern handlerton *myisam_hton;
1701
extern handlerton *heap_hton;
1703
extern SHOW_COMP_OPTION have_symlink;
1704
extern SHOW_COMP_OPTION have_crypt;
1705
extern SHOW_COMP_OPTION have_compress;
1708
extern pthread_t signal_thread;
1710
MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
1711
uint flags, bool *need_reopen);
1712
/* mysql_lock_tables() and open_table() flags bits */
1713
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001
1714
#define MYSQL_LOCK_IGNORE_FLUSH 0x0002
1715
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004
1716
#define MYSQL_OPEN_TEMPORARY_ONLY 0x0008
1717
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0010
1718
#define MYSQL_LOCK_PERF_SCHEMA 0x0020
1720
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
1721
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
1722
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
1723
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
1724
bool always_unlock);
1725
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
1726
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
1727
thr_lock_type new_lock_type);
1728
bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
1729
MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
1730
TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
1731
TABLE_LIST *haystack);
1732
bool lock_global_read_lock(THD *thd);
1733
void unlock_global_read_lock(THD *thd);
1734
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
1735
bool is_not_commit);
1736
void start_waiting_global_read_lock(THD *thd);
1737
bool make_global_read_lock_block_commit(THD *thd);
1738
bool set_protect_against_global_read_lock(void);
1739
void unset_protect_against_global_read_lock(void);
1740
void broadcast_refresh(void);
1741
int try_transactional_lock(THD *thd, TABLE_LIST *table_list);
1742
int check_transactional_lock(THD *thd, TABLE_LIST *table_list);
1743
int set_handler_table_locks(THD *thd, TABLE_LIST *table_list,
1744
bool transactional);
1746
/* Lock based on name */
1747
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
1748
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
1749
void unlock_table_name(THD *thd, TABLE_LIST *table_list);
1750
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
1751
bool lock_table_names(THD *thd, TABLE_LIST *table_list);
1752
void unlock_table_names(THD *thd, TABLE_LIST *table_list,
1753
TABLE_LIST *last_table);
1754
bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
1755
bool is_table_name_exclusively_locked_by_this_thread(THD *thd,
1756
TABLE_LIST *table_list);
1757
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
1761
/* old unireg functions */
1763
void unireg_init(ulong options);
1764
void unireg_end(void) __attribute__((noreturn));
1765
bool mysql_create_frm(THD *thd, const char *file_name,
1766
const char *db, const char *table,
1767
HA_CREATE_INFO *create_info,
1768
List<Create_field> &create_field,
1769
uint key_count,KEY *key_info,handler *db_type);
1770
int rea_create_table(THD *thd, const char *path,
1771
const char *db, const char *table_name,
1772
HA_CREATE_INFO *create_info,
1773
List<Create_field> &create_field,
1774
uint key_count,KEY *key_info,
1776
int format_number(uint inputflag,uint max_length,char * pos,uint length,
1780
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
1782
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
1784
const char *table_name, const char *path);
1785
void free_table_share(TABLE_SHARE *share);
1786
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
1787
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
1788
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
1789
uint db_stat, uint prgflag, uint ha_open_flags,
1790
TABLE *outparam, open_table_mode open_mode);
1791
int readfrm(const char *name, uchar **data, size_t *length);
1792
int writefrm(const char* name, const uchar* data, size_t len);
1793
int closefrm(TABLE *table, bool free_share);
1794
int read_string(File file, uchar* *to, size_t length);
1795
void free_blobs(TABLE *table);
1796
int set_zone(int nr,int min_zone,int max_zone);
1797
ulong convert_period_to_month(ulong period);
1798
ulong convert_month_to_period(ulong month);
1799
void get_date_from_daynr(long daynr,uint *year, uint *month,
1801
my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, bool *not_exist);
1802
bool str_to_time_with_warn(const char *str,uint length,MYSQL_TIME *l_time);
1803
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
1804
MYSQL_TIME *l_time, uint flags);
1805
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
1806
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
1808
void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
1809
const char *str_val,
1810
uint str_length, timestamp_type time_type,
1811
const char *field_name);
1813
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval);
1814
bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign,
1815
int64_t *seconds_out, long *microseconds_out);
1817
extern LEX_STRING interval_type_to_name[];
1819
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
1820
const char *format_str,
1821
uint format_length);
1822
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
1823
DATE_TIME_FORMAT *format);
1824
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
1825
timestamp_type type);
1826
extern bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
1827
timestamp_type type, String *str);
1828
void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
1830
void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
1832
void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
1834
int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
1835
uint64_t get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
1836
Item *warn_item, bool *is_null);
1838
int test_if_number(char *str,int *res,bool allow_wildcards);
1839
void change_byte(uchar *,uint,char,char);
1840
void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
1842
int use_record_cache, bool print_errors);
1843
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
1844
bool print_error, uint idx);
1845
void end_read_record(READ_RECORD *info);
1846
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
1847
uint s_length, SQL_SELECT *select,
1848
ha_rows max_rows, bool sort_positions,
1849
ha_rows *examined_rows);
1850
void filesort_free_buffers(TABLE *table, bool full);
1851
void change_double_for_sort(double nr,uchar *to);
1852
double my_double_round(double value, int64_t dec, bool dec_unsigned,
1854
int get_quick_record(SQL_SELECT *select);
1856
int calc_weekday(long daynr,bool sunday_first_day_of_week);
1857
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
1858
void find_date(char *pos,uint *vek,uint flag);
1859
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
1860
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
1861
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
1862
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
1863
const char *newname);
1864
ulong next_io_size(ulong pos);
1865
void append_unescaped(String *res, const char *pos, uint length);
1866
int create_frm(THD *thd, const char *name, const char *db, const char *table,
1867
uint reclength, uchar *fileinfo,
1868
HA_CREATE_INFO *create_info, uint keys, KEY *key_info);
1869
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
1870
int rename_file_ext(const char * from,const char * to,const char * ext);
1871
bool check_db_name(LEX_STRING *db);
1872
bool check_column_name(const char *name);
1873
bool check_table_name(const char *name, uint length);
1874
char *get_field(MEM_ROOT *mem, Field *field);
1875
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
1876
char *fn_rext(char *name);
1878
/* Conversion functions */
1879
#endif /* MYSQL_SERVER */
1880
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1881
uint strconvert(CHARSET_INFO *from_cs, const char *from,
1882
CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors);
1883
uint filename_to_tablename(const char *from, char *to, uint to_length);
1884
uint tablename_to_filename(const char *from, char *to, uint to_length);
1885
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1887
uint build_table_filename(char *buff, size_t bufflen, const char *db,
1888
const char *table, const char *ext, uint flags);
1890
#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
1891
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9
1893
/* Flags for conversion functions. */
1894
#define FN_FROM_IS_TMP (1 << 0)
1895
#define FN_TO_IS_TMP (1 << 1)
1896
#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP)
1897
#define NO_FRM_RENAME (1 << 2)
1900
Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
1901
LEX_STRING component);
1902
int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
1903
LEX_STRING &name, user_var_entry **out_entry);
1905
bool flush_error_log(void);
1908
void free_list(I_List <i_string_pair> *list);
1909
void free_list(I_List <i_string> *list);
1911
/* Some inline functions for more speed */
1913
inline bool add_item_to_list(THD *thd, Item *item)
1915
return thd->lex->current_select->add_item_to_list(thd, item);
1918
inline bool add_value_to_list(THD *thd, Item *value)
1920
return thd->lex->value_list.push_back(value);
1923
inline bool add_order_to_list(THD *thd, Item *item, bool asc)
1925
return thd->lex->current_select->add_order_to_list(thd, item, asc);
1928
inline bool add_group_to_list(THD *thd, Item *item, bool asc)
1930
return thd->lex->current_select->add_group_to_list(thd, item, asc);
1933
inline void mark_as_null_row(TABLE *table)
1936
table->status|=STATUS_NULL_ROW;
1937
bfill(table->null_flags,table->s->null_bytes,255);
1940
inline void table_case_convert(char * name, uint length)
1942
if (lower_case_table_names)
1943
files_charset_info->cset->casedn(files_charset_info,
1944
name, length, name, length);
1947
inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
1949
return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
1952
inline ulong sql_rnd_with_mutex()
1954
pthread_mutex_lock(&LOCK_thread_count);
1955
ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
1956
pthread_mutex_unlock(&LOCK_thread_count);
1960
Comp_creator *comp_eq_creator(bool invert);
1961
Comp_creator *comp_ge_creator(bool invert);
1962
Comp_creator *comp_gt_creator(bool invert);
1963
Comp_creator *comp_le_creator(bool invert);
1964
Comp_creator *comp_lt_creator(bool invert);
1965
Comp_creator *comp_ne_creator(bool invert);
1967
Item * all_any_subquery_creator(Item *left_expr,
1968
chooser_compare_func_creator cmp,
1970
SELECT_LEX *select_lex);
1973
clean/setup table fields and map.
1975
@param table TABLE structure pointer (which should be setup)
1976
@param table_list TABLE_LIST structure pointer (owner of TABLE)
1977
@param tablenr table number
1981
inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
1983
table->used_fields= 0;
1984
table->const_table= 0;
1986
table->status= STATUS_NO_RECORD;
1987
table->maybe_null= table_list->outer_join;
1988
TABLE_LIST *embedding= table_list->embedding;
1989
while (!table->maybe_null && embedding)
1991
table->maybe_null= embedding->outer_join;
1992
embedding= embedding->embedding;
1994
table->tablenr= tablenr;
1995
table->map= (table_map) 1 << tablenr;
1996
table->force_index= table_list->force_index;
1997
table->covering_keys= table->s->keys_for_keyread;
1998
table->merge_keys.clear_all();
2003
convert a hex digit into number.
2006
inline int hexchar_to_int(char c)
2008
if (c <= '9' && c >= '0')
2011
if (c <= 'f' && c >= 'a')
2017
return true if the table was created explicitly.
2019
inline bool is_user_table(TABLE * table)
2021
const char *name= table->s->table_name.str;
2022
return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
2028
This will be slightly slower and perhaps a tiny bit less accurate than
2029
doing it the IEEE754 way but log2() should be available on C99 systems.
2031
static inline double log2(double x)
2033
return (log(x) / M_LN2);
2039
Some functions that are different in the embedded library and the normal
2043
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
2044
void kill_delayed_threads(void);
2045
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
2047
/* Used by handlers to store things in schema tables */
2048
#define IS_FILES_FILE_ID 0
2049
#define IS_FILES_FILE_NAME 1
2050
#define IS_FILES_FILE_TYPE 2
2051
#define IS_FILES_TABLESPACE_NAME 3
2052
#define IS_FILES_TABLE_CATALOG 4
2053
#define IS_FILES_TABLE_SCHEMA 5
2054
#define IS_FILES_TABLE_NAME 6
2055
#define IS_FILES_LOGFILE_GROUP_NAME 7
2056
#define IS_FILES_LOGFILE_GROUP_NUMBER 8
2057
#define IS_FILES_ENGINE 9
2058
#define IS_FILES_FULLTEXT_KEYS 10
2059
#define IS_FILES_DELETED_ROWS 11
2060
#define IS_FILES_UPDATE_COUNT 12
2061
#define IS_FILES_FREE_EXTENTS 13
2062
#define IS_FILES_TOTAL_EXTENTS 14
2063
#define IS_FILES_EXTENT_SIZE 15
2064
#define IS_FILES_INITIAL_SIZE 16
2065
#define IS_FILES_MAXIMUM_SIZE 17
2066
#define IS_FILES_AUTOEXTEND_SIZE 18
2067
#define IS_FILES_CREATION_TIME 19
2068
#define IS_FILES_LAST_UPDATE_TIME 20
2069
#define IS_FILES_LAST_ACCESS_TIME 21
2070
#define IS_FILES_RECOVER_TIME 22
2071
#define IS_FILES_TRANSACTION_COUNTER 23
2072
#define IS_FILES_VERSION 24
2073
#define IS_FILES_ROW_FORMAT 25
2074
#define IS_FILES_TABLE_ROWS 26
2075
#define IS_FILES_AVG_ROW_LENGTH 27
2076
#define IS_FILES_DATA_LENGTH 28
2077
#define IS_FILES_MAX_DATA_LENGTH 29
2078
#define IS_FILES_INDEX_LENGTH 30
2079
#define IS_FILES_DATA_FREE 31
2080
#define IS_FILES_CREATE_TIME 32
2081
#define IS_FILES_UPDATE_TIME 33
2082
#define IS_FILES_CHECK_TIME 34
2083
#define IS_FILES_CHECKSUM 35
2084
#define IS_FILES_STATUS 36
2085
#define IS_FILES_EXTRA 37
2086
void init_fill_schema_files_row(TABLE* table);
2087
bool schema_table_store_record(THD *thd, TABLE *table);
2089
/* sql/item_create.cc */
2090
int item_create_init();
2091
void item_create_cleanup();
2093
inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
2095
lex_str->str= (char *) c_str;
2096
lex_str->length= strlen(c_str);
2099
bool load_charset(MEM_ROOT *mem_root,
2101
CHARSET_INFO *dflt_cs,
2104
bool load_collation(MEM_ROOT *mem_root,
2106
CHARSET_INFO *dflt_cl,
2109
#endif /* MYSQL_SERVER */
2110
#endif /* MYSQL_CLIENT */
2112
#endif /* MYSQL_PRIV_H */