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 <mysql_version.h>
33
#include <mysql_embed.h>
40
#include <my_base.h> /* Needed by field.h */
42
#include "sql_bitmap.h"
43
#include "sql_array.h"
44
#include "sql_plugin.h"
45
#include "scheduler.h"
48
#define _DTRACE_VERSION 1
57
QT_ORDINARY -- ordinary SQL query.
58
QT_IS -- SQL query to be shown in INFORMATION_SCHEMA (in utf8 and without
59
character set introducers).
67
/* TODO convert all these three maps to Bitmap classes */
68
typedef ulonglong table_map; /* Used for table bits in join */
70
typedef Bitmap<64> key_map; /* Used for finding keys */
72
typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
74
typedef ulong nesting_map; /* Used for flags of nesting constructs */
76
Used to identify NESTED_JOIN structures within a join (applicable only to
77
structures that have not been simplified away and embed more the one
80
typedef ulonglong nested_join_map;
83
typedef ulonglong query_id_t;
84
extern query_id_t global_query_id;
86
/* increment query_id and return it. */
87
inline query_id_t next_query_id() { return global_query_id++; }
89
/* useful constants */
90
extern const key_map key_map_empty;
91
extern key_map key_map_full; /* Should be threaded as const */
92
extern const char *primary_key_name;
94
#include "mysql_com.h"
98
void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size);
99
void *sql_alloc(size_t);
100
void *sql_calloc(size_t);
101
char *sql_strdup(const char *str);
102
char *sql_strmake(const char *str, size_t len);
103
void *sql_memdup(const void * ptr, size_t size);
104
void sql_element_free(void *ptr);
105
char *sql_strmake_with_convert(const char *str, size_t arg_length,
106
CHARSET_INFO *from_cs,
107
size_t max_res_length,
108
CHARSET_INFO *to_cs, size_t *result_length);
109
uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
110
void sql_kill(THD *thd, ulong id, bool only_kill_query);
111
bool net_request_file(NET* net, const char* fname);
112
char* query_table_status(THD *thd,const char *db,const char *table_name);
114
#define x_free(A) { my_free((uchar*) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); }
115
#define safeFree(x) { if(x) { my_free((uchar*) x,MYF(0)); x = NULL; } }
116
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
117
#define all_bits_set(A,B) ((A) & (B) != (B))
120
Generates a warning that a feature is deprecated. After a specified version
121
asserts that the feature is removed.
125
WARN_DEPRECATED(thd, 6,2, "BAD", "'GOOD'");
127
Will result in a warning
129
"The syntax 'BAD' is deprecated and will be removed in MySQL 6.2. Please
132
Note, that in macro arguments BAD is not quoted, while 'GOOD' is.
133
Note, that the version is TWO numbers, separated with a comma
134
(two macro arguments, that is)
136
#define WARN_DEPRECATED(Thd,VerHi,VerLo,Old,New) \
138
compile_time_assert(MYSQL_VERSION_ID < VerHi * 10000 + VerLo * 100); \
140
push_warning_printf((Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \
141
ER_WARN_DEPRECATED_SYNTAX, \
142
ER(ER_WARN_DEPRECATED_SYNTAX_WITH_VER), \
143
(Old), #VerHi "." #VerLo, (New)); \
145
sql_print_warning("The syntax '%s' is deprecated and will be removed " \
146
"in MySQL %s. Please use %s instead.", \
147
(Old), #VerHi "." #VerLo, (New)); \
150
extern CHARSET_INFO *system_charset_info, *files_charset_info ;
151
extern CHARSET_INFO *national_charset_info, *table_alias_charset;
156
DERIVATION_IGNORABLE= 5,
157
DERIVATION_COERCIBLE= 4,
158
DERIVATION_SYSCONST= 3,
159
DERIVATION_IMPLICIT= 2,
161
DERIVATION_EXPLICIT= 0
165
typedef struct my_locale_st
169
const char *description;
171
TYPELIB *month_names;
172
TYPELIB *ab_month_names;
174
TYPELIB *ab_day_names;
176
my_locale_st(uint number_par,
177
const char *name_par, const char *descr_par, bool is_ascii_par,
178
TYPELIB *month_names_par, TYPELIB *ab_month_names_par,
179
TYPELIB *day_names_par, TYPELIB *ab_day_names_par) :
181
name(name_par), description(descr_par), is_ascii(is_ascii_par),
182
month_names(month_names_par), ab_month_names(ab_month_names_par),
183
day_names(day_names_par), ab_day_names(ab_day_names_par)
188
extern MY_LOCALE my_locale_en_US;
189
extern MY_LOCALE *my_locales[];
190
extern MY_LOCALE *my_default_lc_time_names;
192
MY_LOCALE *my_locale_by_name(const char *name);
193
MY_LOCALE *my_locale_by_number(uint number);
195
/*************************************************************************/
198
Object_creation_ctx -- interface for creation context of database objects
199
(views, stored routines, events, triggers). Creation context -- is a set
200
of attributes, that should be fixed at the creation time and then be used
201
each time the object is parsed or executed.
204
class Object_creation_ctx
207
Object_creation_ctx *set_n_backup(THD *thd);
209
void restore_env(THD *thd, Object_creation_ctx *backup_ctx);
212
Object_creation_ctx() {}
213
virtual Object_creation_ctx *create_backup_ctx(THD *thd) const = 0;
215
virtual void change_env(THD *thd) const = 0;
218
virtual ~Object_creation_ctx()
222
/*************************************************************************/
225
Default_object_creation_ctx -- default implementation of
229
class Default_object_creation_ctx : public Object_creation_ctx
232
CHARSET_INFO *get_client_cs()
237
CHARSET_INFO *get_connection_cl()
239
return m_connection_cl;
243
Default_object_creation_ctx(THD *thd);
245
Default_object_creation_ctx(CHARSET_INFO *client_cs,
246
CHARSET_INFO *connection_cl);
249
virtual Object_creation_ctx *create_backup_ctx(THD *thd) const;
251
virtual void change_env(THD *thd) const;
255
client_cs stores the value of character_set_client session variable.
256
The only character set attribute is used.
258
Client character set is included into query context, because we save
259
query in the original character set, which is client character set. So,
260
in order to parse the query properly we have to switch client character
263
CHARSET_INFO *m_client_cs;
266
connection_cl stores the value of collation_connection session
267
variable. Both character set and collation attributes are used.
269
Connection collation is included into query context, becase it defines
270
the character set and collation of text literals in internal
271
representation of query (item-objects).
273
CHARSET_INFO *m_connection_cl;
278
Opening modes for open_temporary_table and open_table_from_share
288
/***************************************************************************
289
Configuration parameters
290
****************************************************************************/
292
#define ACL_CACHE_SIZE 256
293
#define MAX_PASSWORD_LENGTH 32
294
#define HOST_CACHE_SIZE 128
295
#define MAX_ACCEPT_RETRY 10 // Test accept this many times
296
#define MAX_FIELDS_BEFORE_HASH 32
297
#define USER_VARS_HASH_SIZE 16
298
#define TABLE_OPEN_CACHE_MIN 64
299
#define TABLE_OPEN_CACHE_DEFAULT 64
302
Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper
303
Drake, libc6 2.3.6-0ubuntu2, Linux kernel 2.6.15-27-686, on x86. (Added
304
100 bytes as reasonable buffer against growth and other environments'
307
Feel free to raise this by the smallest amount you can to get the
308
"execution_constants" test to pass.
310
#define STACK_MIN_SIZE 12000 ///< Abort if less stack during eval.
312
#define STACK_MIN_SIZE_FOR_OPEN 1024*80
313
#define STACK_BUFF_ALLOC 352 ///< For stack overrun checks
314
#ifndef MYSQLD_NET_RETRY_COUNT
315
#define MYSQLD_NET_RETRY_COUNT 10 ///< Abort read after this many int.
317
#define TEMP_POOL_SIZE 128
319
#define QUERY_ALLOC_BLOCK_SIZE 8192
320
#define QUERY_ALLOC_PREALLOC_SIZE 8192
321
#define TRANS_ALLOC_BLOCK_SIZE 4096
322
#define TRANS_ALLOC_PREALLOC_SIZE 4096
323
#define RANGE_ALLOC_BLOCK_SIZE 4096
324
#define ACL_ALLOC_BLOCK_SIZE 1024
325
#define UDF_ALLOC_BLOCK_SIZE 1024
326
#define TABLE_ALLOC_BLOCK_SIZE 1024
327
#define BDB_LOG_ALLOC_BLOCK_SIZE 1024
328
#define WARN_ALLOC_BLOCK_SIZE 2048
329
#define WARN_ALLOC_PREALLOC_SIZE 1024
330
#define PROFILE_ALLOC_BLOCK_SIZE 2048
331
#define PROFILE_ALLOC_PREALLOC_SIZE 1024
334
The following parameters is to decide when to use an extra cache to
335
optimise seeks when reading a big table in sorted order
337
#define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024)
338
#define MIN_ROWS_TO_USE_TABLE_CACHE 100
339
#define MIN_ROWS_TO_USE_BULK_INSERT 100
342
The following is used to decide if MySQL should use table scanning
343
instead of reading with keys. The number says how many evaluation of the
344
WHERE clause is comparable to reading one extra row from a table.
346
#define TIME_FOR_COMPARE 5 // 5 compares == one read
349
Number of comparisons of table rowids equivalent to reading one row from a
352
#define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2)
355
For sequential disk seeks the cost formula is:
356
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip
358
The cost of average seek
359
DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0.
361
#define DISK_SEEK_BASE_COST ((double)0.9)
363
#define BLOCKS_IN_AVG_SEEK 128
365
#define DISK_SEEK_PROP_COST ((double)0.1/BLOCKS_IN_AVG_SEEK)
369
Number of rows in a reference table when refereed through a not unique key.
370
This value is only used when we don't know anything about the key
373
#define MATCHING_ROWS_IN_OTHER_TABLE 10
375
/** Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used). */
376
#define KEY_DEFAULT_PACK_LENGTH 8
378
/** Characters shown for the command in 'show processlist'. */
379
#define PROCESS_LIST_WIDTH 100
380
/* Characters shown for the command in 'information_schema.processlist' */
381
#define PROCESS_LIST_INFO_WIDTH 65535
383
#define PRECISION_FOR_DOUBLE 53
384
#define PRECISION_FOR_FLOAT 24
387
Default time to wait before aborting a new client connection
388
that does not respond to "initial server greeting" timely
390
#define CONNECT_TIMEOUT 10
392
/* The following can also be changed from the command line */
393
#define DEFAULT_CONCURRENCY 10
394
#define FLUSH_TIME 0 /**< Don't flush tables */
395
#define MAX_CONNECT_ERRORS 10 ///< errors before disabling host
397
#define INTERRUPT_PRIOR 10
398
#define CONNECT_PRIOR 9
400
#define QUERY_PRIOR 6
402
/* Bits from testflag */
403
#define TEST_PRINT_CACHED_TABLES 1
404
#define TEST_NO_KEY_GROUP 2
405
#define TEST_MIT_THREAD 4
406
#define TEST_BLOCKING 8
407
#define TEST_KEEP_TMP_TABLES 16
408
#define TEST_READCHECK 64 /**< Force use of readcheck */
409
#define TEST_NO_EXTRA 128
410
#define TEST_CORE_ON_SIGNAL 256 /**< Give core if signal */
411
#define TEST_NO_STACKTRACE 512
412
#define TEST_SIGINT 1024 /**< Allow sigint on threads */
413
#define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in
418
This is included in the server and in the client.
419
Options for select set by the yacc parser (stored in lex->options).
422
log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD
423
options list are written into binlog. These options can NOT change their
424
values, or it will break replication between version.
426
context is encoded as following:
427
SELECT - SELECT_LEX_NODE::options
429
intern - neither. used only as
430
func(..., select_node->options | thd->options | OPTION_XXX, ...)
432
TODO: separate three contexts above, move them to separate bitfields.
435
#define SELECT_DISTINCT (ULL(1) << 0) // SELECT, user
436
#define SELECT_STRAIGHT_JOIN (ULL(1) << 1) // SELECT, user
437
#define SELECT_DESCRIBE (ULL(1) << 2) // SELECT, user
438
#define SELECT_SMALL_RESULT (ULL(1) << 3) // SELECT, user
439
#define SELECT_BIG_RESULT (ULL(1) << 4) // SELECT, user
440
#define OPTION_FOUND_ROWS (ULL(1) << 5) // SELECT, user
441
#define SELECT_NO_JOIN_CACHE (ULL(1) << 7) // intern
442
#define OPTION_BIG_TABLES (ULL(1) << 8) // THD, user
443
#define OPTION_BIG_SELECTS (ULL(1) << 9) // THD, user
444
#define OPTION_LOG_OFF (ULL(1) << 10) // THD, user
445
#define OPTION_QUOTE_SHOW_CREATE (ULL(1) << 11) // THD, user, unused
446
#define TMP_TABLE_ALL_COLUMNS (ULL(1) << 12) // SELECT, intern
447
#define OPTION_WARNINGS (ULL(1) << 13) // THD, user
448
#define OPTION_AUTO_IS_NULL (ULL(1) << 14) // THD, user, binlog
449
#define OPTION_FOUND_COMMENT (ULL(1) << 15) // SELECT, intern, parser
450
#define OPTION_SAFE_UPDATES (ULL(1) << 16) // THD, user
451
#define OPTION_BUFFER_RESULT (ULL(1) << 17) // SELECT, user
452
#define OPTION_BIN_LOG (ULL(1) << 18) // THD, user
453
#define OPTION_NOT_AUTOCOMMIT (ULL(1) << 19) // THD, user
454
#define OPTION_BEGIN (ULL(1) << 20) // THD, intern
455
#define OPTION_TABLE_LOCK (ULL(1) << 21) // THD, intern
456
#define OPTION_QUICK (ULL(1) << 22) // SELECT (for DELETE)
457
#define OPTION_KEEP_LOG (ULL(1) << 23) // THD, user
459
/* The following is used to detect a conflict with DISTINCT */
460
#define SELECT_ALL (ULL(1) << 24) // SELECT, user, parser
462
/** The following can be set when importing tables in a 'wrong order'
463
to suppress foreign key checks */
464
#define OPTION_NO_FOREIGN_KEY_CHECKS (ULL(1) << 26) // THD, user, binlog
465
/** The following speeds up inserts to InnoDB tables by suppressing unique
466
key checks in some cases */
467
#define OPTION_RELAXED_UNIQUE_CHECKS (ULL(1) << 27) // THD, user, binlog
468
#define SELECT_NO_UNLOCK (ULL(1) << 28) // SELECT, intern
469
#define OPTION_SCHEMA_TABLE (ULL(1) << 29) // SELECT, intern
470
/** Flag set if setup_tables already done */
471
#define OPTION_SETUP_TABLES_DONE (ULL(1) << 30) // intern
472
/** If not set then the thread will ignore all warnings with level notes. */
473
#define OPTION_SQL_NOTES (ULL(1) << 31) // THD, user
475
Force the used temporary table to be a MyISAM table (because we will use
476
fulltext functions when reading from it.
478
#define TMP_TABLE_FORCE_MYISAM (ULL(1) << 32)
479
#define OPTION_PROFILING (ULL(1) << 33)
482
Dont report errors for individual rows,
483
But just report error on commit (or read ofcourse)
485
#define OPTION_ALLOW_BATCH (ULL(1) << 33) // THD, intern (slave)
488
Maximum length of time zone name that we support
489
(Time zone name is char(64) in db). mysqlbinlog needs it.
491
#define MAX_TIME_ZONE_NAME_LENGTH (NAME_LEN + 1)
493
/* The rest of the file is included in the server only */
496
/* Bits for different SQL modes modes (including ANSI mode) */
497
#define MODE_REAL_AS_FLOAT 1
498
#define MODE_PIPES_AS_CONCAT 2
499
#define MODE_ANSI_QUOTES 4
500
#define MODE_IGNORE_SPACE 8
501
#define MODE_NOT_USED 16
502
#define MODE_ONLY_FULL_GROUP_BY 32
503
#define MODE_NO_UNSIGNED_SUBTRACTION 64
504
#define MODE_NO_DIR_IN_CREATE 128
505
#define MODE_POSTGRESQL 256
506
#define MODE_ORACLE 512
507
#define MODE_MSSQL 1024
508
#define MODE_DB2 2048
509
#define MODE_MAXDB 4096
510
#define MODE_NO_KEY_OPTIONS 8192
511
#define MODE_NO_TABLE_OPTIONS 16384
512
#define MODE_NO_FIELD_OPTIONS 32768
513
#define MODE_MYSQL323 65536L
514
#define MODE_MYSQL40 (MODE_MYSQL323*2)
515
#define MODE_ANSI (MODE_MYSQL40*2)
516
#define MODE_NO_AUTO_VALUE_ON_ZERO (MODE_ANSI*2)
517
#define MODE_NO_BACKSLASH_ESCAPES (MODE_NO_AUTO_VALUE_ON_ZERO*2)
518
#define MODE_STRICT_TRANS_TABLES (MODE_NO_BACKSLASH_ESCAPES*2)
519
#define MODE_STRICT_ALL_TABLES (MODE_STRICT_TRANS_TABLES*2)
520
#define MODE_NO_ZERO_IN_DATE (MODE_STRICT_ALL_TABLES*2)
521
#define MODE_NO_ZERO_DATE (MODE_NO_ZERO_IN_DATE*2)
522
#define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2)
523
#define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2)
524
#define MODE_TRADITIONAL (MODE_ERROR_FOR_DIVISION_BY_ZERO*2)
525
#define MODE_NO_AUTO_CREATE_USER (MODE_TRADITIONAL*2)
526
#define MODE_HIGH_NOT_PRECEDENCE (MODE_NO_AUTO_CREATE_USER*2)
527
#define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2)
528
#define MODE_PAD_CHAR_TO_FULL_LENGTH (ULL(1) << 31)
531
/* @@optimizer_switch flags */
532
#define OPTIMIZER_SWITCH_NO_MATERIALIZATION 1
533
#define OPTIMIZER_SWITCH_NO_SEMIJOIN 2
537
Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
538
use strictly more than 64 bits by adding one more define above, you should
539
contact the replication team because the replication code should then be
540
updated (to store more bytes on disk).
542
NOTE: When adding new SQL_MODE types, make sure to also add them to
543
the scripts used for creating the MySQL system tables
544
in scripts/mysql_system_tables.sql and scripts/mysql_system_tables_fix.sql
548
#define RAID_BLOCK_SIZE 1024
550
#define MY_CHARSET_BIN_MB_MAXLEN 1
553
#define UNCACHEABLE_DEPENDENT 1
554
#define UNCACHEABLE_RAND 2
555
#define UNCACHEABLE_SIDEEFFECT 4
556
/// forcing to save JOIN for explain
557
#define UNCACHEABLE_EXPLAIN 8
558
/** Don't evaluate subqueries in prepare even if they're not correlated */
559
#define UNCACHEABLE_PREPARE 16
560
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
561
#define UNCACHEABLE_UNITED 32
563
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
564
#define UNDEF_POS (-1)
567
Sync points allow us to force the server to reach a certain line of code
568
and block there until the client tells the server it is ok to go on.
569
The client tells the server to block with SELECT GET_LOCK()
570
and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
573
#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
574
debug_sync_point(lock_name,lock_timeout)
575
void debug_sync_point(const char* lock_name, uint lock_timeout);
577
#define DBUG_SYNC_POINT(lock_name,lock_timeout)
578
#endif /* EXTRA_DEBUG */
580
/* BINLOG_DUMP options */
582
#define BINLOG_DUMP_NON_BLOCK 1
584
/* sql_show.cc:show_log_files() */
585
#define SHOW_LOG_STATUS_FREE "FREE"
586
#define SHOW_LOG_STATUS_INUSE "IN USE"
590
void view_store_options(THD *thd, TABLE_LIST *table, String *buff);
592
/* Options to add_table_to_list() */
593
#define TL_OPTION_UPDATING 1
594
#define TL_OPTION_FORCE_INDEX 2
595
#define TL_OPTION_IGNORE_LEAVES 4
596
#define TL_OPTION_ALIAS 8
598
/* Some portable defines */
600
#define portable_sizeof_char_ptr 8
602
#define tmp_file_prefix "#sql" /**< Prefix for tmp tables */
603
#define tmp_file_prefix_length 4
605
/* Flags for calc_week() function. */
606
#define WEEK_MONDAY_FIRST 1
608
#define WEEK_FIRST_WEEKDAY 4
610
#define STRING_BUFFER_USUAL_SIZE 80
613
Some defines for exit codes for ::is_equal class functions.
615
#define IS_EQUAL_NO 0
616
#define IS_EQUAL_YES 1
617
#define IS_EQUAL_PACK_LENGTH 2
619
enum enum_parsing_place
630
#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__)
633
enum enum_check_fields
637
CHECK_FIELD_ERROR_FOR_NULL
641
/** Struct to handle simple linked lists. */
642
typedef struct st_sql_list {
647
st_sql_list() {} /* Remove gcc warning */
654
inline void link_in_list(uchar *element,uchar **next_ptr)
661
inline void save_and_clear(struct st_sql_list *save)
666
inline void push_front(struct st_sql_list *save)
668
*save->next= first; /* link current list last */
670
elements+= save->elements;
672
inline void push_back(struct st_sql_list *save)
678
elements+= save->elements;
684
extern pthread_key(THD*, THR_THD);
685
inline THD *_current_thd(void)
687
return my_pthread_getspecific_ptr(THD*,THR_THD);
689
#define current_thd _current_thd()
692
The meat of thd_proc_info(THD*, char*), a macro that packs the last
693
three calling-info parameters.
696
const char *set_thd_proc_info(THD *thd, const char *info,
697
const char *calling_func,
698
const char *calling_file,
699
const unsigned int calling_line);
704
extern ulong server_id, concurrency;
707
typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key,
709
ulonglong *engine_data);
710
#include "sql_string.h"
711
#include "sql_list.h"
713
#include "my_decimal.h"
716
#include "sql_error.h"
717
#include "field.h" /* Field definitions */
718
#include "protocol.h"
721
class user_var_entry;
722
class Security_context;
725
OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
730
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
733
extern my_decimal decimal_zero;
736
void free_items(Item *item);
737
void cleanup_items(Item *item);
739
void close_thread_tables(THD *thd);
741
bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
742
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
743
int mysql_multi_update_prepare(THD *thd);
744
int mysql_multi_delete_prepare(THD *thd);
745
bool mysql_insert_select_prepare(THD *thd);
746
bool update_precheck(THD *thd, TABLE_LIST *tables);
747
bool delete_precheck(THD *thd, TABLE_LIST *tables);
748
bool insert_precheck(THD *thd, TABLE_LIST *tables);
749
bool create_table_precheck(THD *thd, TABLE_LIST *tables,
750
TABLE_LIST *create_table);
751
int append_query_string(CHARSET_INFO *csinfo,
752
String const *from, String *to);
754
bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
755
uint max_byte_length);
756
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
757
uint max_char_length, CHARSET_INFO *cs,
759
bool check_identifier_name(LEX_STRING *str, uint max_char_length,
760
uint err_code, const char *param_for_err_msg);
761
inline bool check_identifier_name(LEX_STRING *str, uint err_code)
763
return check_identifier_name(str, NAME_CHAR_LEN, err_code, "");
765
inline bool check_identifier_name(LEX_STRING *str)
767
return check_identifier_name(str, NAME_CHAR_LEN, 0, "");
770
bool test_if_data_home_dir(const char *dir);
772
bool parse_sql(THD *thd,
773
class Lex_input_stream *lip,
774
class Object_creation_ctx *creation_ctx);
776
enum enum_mysql_completiontype {
777
ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7,
778
COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6
781
bool begin_trans(THD *thd);
782
bool end_active_trans(THD *thd);
783
int end_trans(THD *thd, enum enum_mysql_completiontype completion);
785
Item *negate_expression(THD *thd, Item *expr);
788
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args);
789
void sql_print_error(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
790
void sql_print_warning(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
791
void sql_print_information(const char *format, ...)
792
ATTRIBUTE_FORMAT(printf, 1, 2);
793
typedef void (*sql_print_message_func)(const char *format, ...)
794
ATTRIBUTE_FORMAT(printf, 1, 2);
795
extern sql_print_message_func sql_print_message_handlers[];
797
int error_log_print(enum loglevel level, const char *format,
800
bool slow_log_print(THD *thd, const char *query, uint query_length,
801
ulonglong current_utime);
803
bool general_log_print(THD *thd, enum enum_server_command command,
804
const char *format,...);
806
bool general_log_write(THD *thd, enum enum_server_command command,
807
const char *query, uint query_length);
809
#include "sql_class.h"
810
#include "slave.h" // for tables_ok(), rpl_filter
813
#include "opt_range.h"
817
Error injector Macros to enable easy testing of recovery after failures
818
in various error cases.
820
#ifndef ERROR_INJECT_SUPPORT
822
#define ERROR_INJECT(x) 0
823
#define ERROR_INJECT_ACTION(x,action) 0
824
#define ERROR_INJECT_CRASH(x) 0
825
#define ERROR_INJECT_VALUE(x) 0
826
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
827
#define ERROR_INJECT_VALUE_CRASH(x) 0
828
#define SET_ERROR_INJECT_VALUE(x)
832
inline bool check_and_unset_keyword(const char *dbug_str)
834
const char *extra_str= "-d,";
836
if (_db_strict_keyword_ (dbug_str))
838
strxmov(total_str, extra_str, dbug_str, NullS);
847
check_and_unset_inject_value(int value)
849
THD *thd= current_thd;
850
if (thd->error_inject_value == (uint)value)
852
thd->error_inject_value= 0;
861
These macros are used to insert macros from the application code.
862
The event that activates those error injections can be activated
864
SET SESSION dbug=+d,code;
866
After the error has been injected, the macros will automatically
867
remove the debug code, thus similar to using:
868
SET SESSION dbug=-d,code
871
ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
872
is set when macro is called. ERROR_INJECT_CRASH can be used in
873
if-statements, it will always return FALSE unless of course it
874
crashes in which case it doesn't return at all.
876
ERROR_INJECT_ACTION will inject the action specified in the action
877
parameter of the macro, before performing the action the code will
878
be removed such that no more events occur. ERROR_INJECT_ACTION
879
can also be used in if-statements and always returns FALSE.
880
ERROR_INJECT can be used in a normal if-statement, where the action
881
part is performed in the if-block. The macro returns TRUE if the
882
error was activated and otherwise returns FALSE. If activated the
885
Sometimes it is necessary to perform error inject actions as a serie
886
of events. In this case one can use one variable on the THD object.
887
Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
888
Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
889
ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
890
behaviour as the above described macros except that they use the
891
error inject value instead of a code used by DBUG macros.
893
#define SET_ERROR_INJECT_VALUE(x) \
894
current_thd->error_inject_value= (x)
895
#define ERROR_INJECT_CRASH(code) \
896
DBUG_EVALUATE_IF(code, (abort(), 0), 0)
897
#define ERROR_INJECT_ACTION(code, action) \
898
(check_and_unset_keyword(code) ? ((action), 0) : 0)
899
#define ERROR_INJECT(code) \
900
check_and_unset_keyword(code)
901
#define ERROR_INJECT_VALUE(value) \
902
check_and_unset_inject_value(value)
903
#define ERROR_INJECT_VALUE_ACTION(value,action) \
904
(check_and_unset_inject_value(value) ? (action) : 0)
905
#define ERROR_INJECT_VALUE_CRASH(value) \
906
ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
910
void write_bin_log(THD *thd, bool clear_error,
911
char const *query, ulong query_length);
914
int check_user(THD *thd, enum enum_server_command command,
915
const char *passwd, uint passwd_len, const char *db,
917
pthread_handler_t handle_one_connection(void *arg);
918
bool init_new_connection_handler_thread();
919
void reset_mqh(LEX_USER *lu, bool get_them);
920
bool check_mqh(THD *thd, uint check_command);
921
void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
922
void decrease_user_connections(USER_CONN *uc);
923
void thd_init_client_charset(THD *thd, uint cs_number);
924
bool setup_connection_thread_globals(THD *thd);
925
bool login_connection(THD *thd);
926
void prepare_new_connection_state(THD* thd);
927
void end_connection(THD *thd);
930
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
931
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
932
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
933
bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db);
934
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
935
void mysql_client_binlog_statement(THD *thd);
936
bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
937
my_bool drop_temporary);
938
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
939
bool drop_temporary, bool drop_view, bool log_query);
940
bool quick_rm_table(handlerton *base,const char *db,
941
const char *table_name, uint flags);
942
void close_cached_table(THD *thd, TABLE *table);
943
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
944
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
945
char *new_table_name, char *new_table_alias,
948
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
951
bool mysql_opt_change_db(THD *thd,
952
const LEX_STRING *new_db_name,
953
LEX_STRING *saved_db_name,
955
bool *cur_db_changed);
957
void mysql_parse(THD *thd, const char *inBuf, uint length,
958
const char ** semicolon);
960
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
961
bool is_update_query(enum enum_sql_command command);
962
bool alloc_query(THD *thd, const char *packet, uint packet_length);
963
void mysql_init_select(LEX *lex);
964
void mysql_reset_thd_for_next_command(THD *thd);
965
bool mysql_new_select(LEX *lex, bool move_down);
966
void create_select_for_variable(const char *var_name);
967
void mysql_init_multi_delete(LEX *lex);
968
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
969
void init_max_user_conn(void);
970
void init_update_queries(void);
971
void free_max_user_conn(void);
972
pthread_handler_t handle_bootstrap(void *arg);
973
int mysql_execute_command(THD *thd);
974
bool do_command(THD *thd);
975
bool dispatch_command(enum enum_server_command command, THD *thd,
976
char* packet, uint packet_length);
977
void log_slow_statement(THD *thd);
978
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
979
bool compare_record(TABLE *table);
980
bool append_file_to_dir(THD *thd, const char **filename_ptr,
981
const char *table_name);
982
void wait_while_table_is_used(THD *thd, TABLE *table,
983
enum ha_extra_function function);
984
bool table_cache_init(void);
985
void table_cache_free(void);
986
bool table_def_init(void);
987
void table_def_free(void);
988
void assign_new_table_id(TABLE_SHARE *share);
989
uint cached_open_tables(void);
990
uint cached_table_definitions(void);
991
void kill_mysql(void);
992
void close_connection(THD *thd, uint errcode, bool lock);
993
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables, bool *write_to_binlog);
994
bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
996
bool any_combination_of_privileges_will_do,
999
#endif /* MYSQL_SERVER */
1000
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1001
bool check_global_access(THD *thd, ulong want_access);
1002
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1006
General routine to change field->ptr of a NULL-terminated array of Field
1007
objects. Useful when needed to call val_int, val_str or similar and the
1008
field data is not in table->record[0] but in some other structure.
1009
set_key_field_ptr changes all fields of an index using a key_info object.
1010
All methods presume that there is at least one field to change.
1013
void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
1014
void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
1015
const uchar *old_buf);
1017
bool mysql_checksum_table(THD* thd, TABLE_LIST* table_list,
1018
HA_CHECK_OPT* check_opt);
1019
bool mysql_check_table(THD* thd, TABLE_LIST* table_list,
1020
HA_CHECK_OPT* check_opt);
1021
bool mysql_repair_table(THD* thd, TABLE_LIST* table_list,
1022
HA_CHECK_OPT* check_opt);
1023
bool mysql_analyze_table(THD* thd, TABLE_LIST* table_list,
1024
HA_CHECK_OPT* check_opt);
1025
bool mysql_optimize_table(THD* thd, TABLE_LIST* table_list,
1026
HA_CHECK_OPT* check_opt);
1027
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* table_list,
1028
LEX_STRING *key_cache_name);
1029
bool mysql_preload_keys(THD* thd, TABLE_LIST* table_list);
1030
int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
1031
KEY_CACHE *dst_cache);
1032
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
1034
bool mysql_xa_recover(THD *thd);
1036
bool check_simple_select();
1037
int mysql_alter_tablespace(THD* thd, st_alter_tablespace *ts_info);
1039
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
1040
SORT_FIELD *sortorder);
1041
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
1042
List<Item> &fields, List <Item> &all_fields, ORDER *order);
1043
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
1044
List<Item> &fields, List<Item> &all_fields, ORDER *order,
1045
bool *hidden_group_fields);
1046
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
1047
Item **ref_pointer_array);
1049
bool handle_select(THD *thd, LEX *lex, select_result *result,
1050
ulong setup_tables_done_option);
1051
bool mysql_select(THD *thd, Item ***rref_pointer_array,
1052
TABLE_LIST *tables, uint wild_num, List<Item> &list,
1053
COND *conds, uint og_num, ORDER *order, ORDER *group,
1054
Item *having, ORDER *proc_param, ulonglong select_type,
1055
select_result *result, SELECT_LEX_UNIT *unit,
1056
SELECT_LEX *select_lex);
1057
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
1058
bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
1059
select_result *result);
1060
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
1061
select_result *result);
1062
bool mysql_union(THD *thd, LEX *lex, select_result *result,
1063
SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
1064
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
1066
TABLE_LIST *table));
1067
bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
1068
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
1069
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
1070
Item ***copy_func, Field **from_field,
1072
bool group, bool modify_item,
1073
bool table_cant_handle_bit_fields,
1074
bool make_copy_field,
1075
uint convert_blob_length);
1076
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
1077
int prepare_create_field(Create_field *sql_field,
1079
int *timestamps, int *timestamps_with_niladic,
1080
longlong table_flags);
1081
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
1082
HA_CREATE_INFO *create_info,
1083
Alter_info *alter_info,
1084
bool tmp_table, uint select_field_count);
1085
bool mysql_create_table_no_lock(THD *thd, const char *db,
1086
const char *table_name,
1087
HA_CREATE_INFO *create_info,
1088
Alter_info *alter_info,
1089
bool tmp_table, uint select_field_count);
1091
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
1092
HA_CREATE_INFO *create_info,
1093
TABLE_LIST *table_list,
1094
Alter_info *alter_info,
1095
uint order_num, ORDER *order, bool ignore);
1096
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
1097
bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
1098
TABLE_LIST *src_table,
1099
HA_CREATE_INFO *create_info);
1100
bool mysql_rename_table(handlerton *base, const char *old_db,
1101
const char * old_name, const char *new_db,
1102
const char * new_name, uint flags);
1103
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
1104
Item **conds, uint order_num, ORDER *order);
1105
int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
1106
List<Item> &values,COND *conds,
1107
uint order_num, ORDER *order, ha_rows limit,
1108
enum enum_duplicates handle_duplicates, bool ignore);
1109
bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
1110
List<Item> *fields, List<Item> *values,
1111
COND *conds, ulonglong options,
1112
enum enum_duplicates handle_duplicates, bool ignore,
1113
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
1114
bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
1115
List<Item> &fields, List_item *values,
1116
List<Item> &update_fields,
1117
List<Item> &update_values, enum_duplicates duplic,
1118
COND **where, bool select_insert,
1119
bool check_fields, bool abort_on_warning);
1120
bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
1121
List<List_item> &values, List<Item> &update_fields,
1122
List<Item> &update_values, enum_duplicates flag,
1124
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
1125
TABLE_LIST *table_list);
1126
void prepare_triggers_for_insert_stmt(TABLE *table);
1127
int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
1128
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
1129
SQL_LIST *order, ha_rows rows, ulonglong options,
1130
bool reset_auto_increment);
1131
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
1132
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
1133
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
1135
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
1136
uint key_length, uint db_flags, int *error);
1137
void release_table_share(TABLE_SHARE *share, enum release_type type);
1138
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
1139
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
1141
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
1142
bool *refresh, uint flags);
1143
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
1144
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
1145
TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
1147
bool lock_table_name_if_not_cached(THD *thd, const char *db,
1148
const char *table_name, TABLE **table);
1149
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
1150
void detach_merge_children(TABLE *table, bool clear_refs);
1151
bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
1152
TABLE_LIST *new_child_list, TABLE_LIST **new_last);
1153
bool reopen_table(TABLE *table);
1154
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
1155
void close_data_files_and_morph_locks(THD *thd, const char *db,
1156
const char *table_name);
1157
void close_handle_and_leave_table_as_lock(TABLE *table);
1158
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
1159
uint db_stat, uint prgflag,
1160
uint ha_open_flags, TABLE *outparam,
1161
TABLE_LIST *table_desc, MEM_ROOT *mem_root);
1162
bool wait_for_tables(THD *thd);
1163
bool table_is_used(TABLE *table, bool wait_for_name_lock);
1164
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
1165
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
1166
void execute_init_command(THD *thd, sys_var_str *init_command_var,
1167
rw_lock_t *var_mutex);
1168
extern Field *not_found_field;
1169
extern Field *view_ref_found;
1171
enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
1172
IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
1173
IGNORE_EXCEPT_NON_UNIQUE};
1175
find_field_in_tables(THD *thd, Item_ident *item,
1176
TABLE_LIST *first_table, TABLE_LIST *last_table,
1177
Item **ref, find_item_error_report_type report_error,
1178
bool check_privileges, bool register_tree_change);
1180
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
1181
const char *name, uint length,
1182
const char *item_name, const char *db_name,
1183
const char *table_name, Item **ref,
1184
bool check_privileges, bool allow_rowid,
1185
uint *cached_field_index_ptr,
1186
bool register_tree_change, TABLE_LIST **actual_table);
1188
find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
1189
bool allow_rowid, uint *cached_field_index_ptr);
1191
find_field_in_table_sef(TABLE *table, const char *name);
1193
#endif /* MYSQL_SERVER */
1197
bool mysql_do(THD *thd, List<Item> &values);
1200
bool append_escaped(String *to_str, String *from_str);
1203
bool mysqld_show_open_tables(THD *thd,const char *wild);
1204
bool mysqld_show_logs(THD *thd);
1205
void append_identifier(THD *thd, String *packet, const char *name,
1207
#endif /* MYSQL_SERVER */
1208
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1209
int get_quote_char_for_identifier(THD *thd, const char *name, uint length);
1210
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1212
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
1213
int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
1214
bool mysqld_show_create(THD *thd, TABLE_LIST *table_list);
1215
bool mysqld_show_create_db(THD *thd, char *dbname, HA_CREATE_INFO *create);
1217
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
1218
int mysqld_show_status(THD *thd);
1219
int mysqld_show_variables(THD *thd,const char *wild);
1220
bool mysqld_show_storage_engines(THD *thd);
1221
bool mysqld_show_authors(THD *thd);
1222
bool mysqld_show_contributors(THD *thd);
1223
bool mysqld_show_privileges(THD *thd);
1224
bool mysqld_show_column_types(THD *thd);
1225
bool mysqld_help (THD *thd, const char *text);
1226
void calc_sum_of_all_status(STATUS_VAR *to);
1228
void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
1229
const LEX_STRING *definer_host);
1231
int add_status_vars(SHOW_VAR *list);
1232
void remove_status_vars(SHOW_VAR *list);
1233
void init_status_vars();
1234
void free_status_vars();
1235
void reset_status_vars();
1237
/* information schema */
1238
extern LEX_STRING INFORMATION_SCHEMA_NAME;
1240
extern LEX_STRING MYSQL_SCHEMA_NAME;
1241
extern LEX_STRING GENERAL_LOG_NAME;
1242
extern LEX_STRING SLOW_LOG_NAME;
1244
extern const LEX_STRING partition_keywords[];
1245
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
1246
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
1247
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
1248
enum enum_schema_tables schema_table_idx);
1249
int make_schema_select(THD *thd, SELECT_LEX *sel,
1250
enum enum_schema_tables schema_table_idx);
1251
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
1252
bool get_schema_tables_result(JOIN *join,
1253
enum enum_schema_table_state executed_place);
1254
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
1256
#define is_schema_db(X) \
1257
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
1259
/* sql_prepare.cc */
1261
void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length);
1262
void mysql_stmt_execute(THD *thd, char *packet, uint packet_length);
1263
void mysql_stmt_close(THD *thd, char *packet);
1264
void mysql_sql_stmt_prepare(THD *thd);
1265
void mysql_sql_stmt_execute(THD *thd);
1266
void mysql_sql_stmt_close(THD *thd);
1267
void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length);
1268
void mysql_stmt_reset(THD *thd, char *packet);
1269
void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
1270
void reinit_stmt_before_use(THD *thd, LEX *lex);
1272
/* sql_handler.cc */
1273
bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
1274
bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
1275
bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
1276
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
1277
void mysql_ha_flush(THD *thd);
1278
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
1279
void mysql_ha_cleanup(THD *thd);
1282
#define TMP_TABLE_KEY_EXTRA 8
1283
void set_item_name(Item *item,char *pos,uint length);
1284
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
1285
char *length, char *decimal,
1287
enum ha_storage_media storage_type,
1288
enum column_format_type column_format,
1289
Item *default_value, Item *on_update_value,
1290
LEX_STRING *comment,
1291
char *change, List<String> *interval_list,
1293
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
1294
char *length, char *decimals,
1296
Item *default_value, Item *on_update_value,
1297
LEX_STRING *comment, char *change,
1298
List<String> *interval_list, CHARSET_INFO *cs);
1299
void store_position_for_column(const char *name);
1300
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
1301
bool push_new_name_resolution_context(THD *thd,
1302
TABLE_LIST *left_op,
1303
TABLE_LIST *right_op);
1304
void add_join_on(TABLE_LIST *b,Item *expr);
1305
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
1307
bool add_proc_to_list(THD *thd, Item *item);
1308
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
1309
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
1310
const char *table_name);
1311
void update_non_unique_table_error(TABLE_LIST *update,
1312
const char *operation,
1313
TABLE_LIST *duplicate);
1315
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
1316
table_map read_tables, COND *conds,
1317
bool allow_null_cond, int *error);
1318
extern Item **not_found_item;
1321
A set of constants used for checking non aggregated fields and sum
1322
functions mixture in the ONLY_FULL_GROUP_BY_MODE.
1324
#define NON_AGG_FIELD_USED 1
1325
#define SUM_FUNC_USED 2
1328
This enumeration type is used only by the function find_item_in_list
1329
to return the info on how an item has been resolved against a list
1330
of possibly aliased items.
1331
The item can be resolved:
1332
- against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
1333
- against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS)
1334
- against an aliased field name of the list (RESOLVED_BEHIND_ALIAS)
1335
- ignoring the alias name in cases when SQL requires to ignore aliases
1336
(e.g. when the resolved field reference contains a table name or
1337
when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS)
1339
enum enum_resolution_type {
1341
RESOLVED_IGNORING_ALIAS,
1342
RESOLVED_BEHIND_ALIAS,
1343
RESOLVED_WITH_NO_ALIAS,
1344
RESOLVED_AGAINST_ALIAS
1346
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
1347
find_item_error_report_type report_error,
1348
enum_resolution_type *resolution);
1349
bool get_key_map_from_key_list(key_map *map, TABLE *table,
1350
List<String> *index_list);
1351
bool insert_fields(THD *thd, Name_resolution_context *context,
1352
const char *db_name, const char *table_name,
1353
List_iterator<Item> *it, bool any_privileges);
1354
bool setup_tables(THD *thd, Name_resolution_context *context,
1355
List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
1356
TABLE_LIST **leaves, bool select_insert);
1357
bool setup_tables_and_check_access(THD *thd,
1358
Name_resolution_context *context,
1359
List<TABLE_LIST> *from_clause,
1361
TABLE_LIST **leaves,
1362
bool select_insert);
1363
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
1364
List<Item> *sum_func_list, uint wild_num);
1365
bool setup_fields(THD *thd, Item** ref_pointer_array,
1366
List<Item> &item, enum_mark_columns mark_used_columns,
1367
List<Item> *sum_func_list, bool allow_sum_func);
1368
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
1370
enum_mark_columns mark_used_columns,
1371
List<Item> *sum_func_list,
1372
bool allow_sum_func)
1375
thd->lex->select_lex.no_wrap_view_item= TRUE;
1376
res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
1378
thd->lex->select_lex.no_wrap_view_item= FALSE;
1381
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
1383
int setup_ftfuncs(SELECT_LEX* select);
1384
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
1385
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
1386
pthread_cond_t *cond);
1387
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
1388
/* open_and_lock_tables with optional derived handling */
1389
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
1390
/* simple open_and_lock_tables without derived handling */
1391
inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
1393
return open_and_lock_tables_derived(thd, tables, FALSE);
1395
/* open_and_lock_tables with derived handling */
1396
inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
1398
return open_and_lock_tables_derived(thd, tables, TRUE);
1400
/* simple open_and_lock_tables without derived handling for single table */
1401
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
1402
thr_lock_type lock_type);
1403
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
1404
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
1405
int decide_logging_format(THD *thd, TABLE_LIST *tables);
1406
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
1407
const char *table_name, bool link_in_list,
1408
open_table_mode open_mode);
1409
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
1410
void free_io_cache(TABLE *entry);
1411
void intern_close_table(TABLE *entry);
1412
bool close_thread_table(THD *thd, TABLE **table_ptr);
1413
void close_temporary_tables(THD *thd);
1414
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
1415
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
1416
TABLE_LIST *TABLE_LIST::*link,
1417
const char *db_name,
1418
const char *table_name);
1419
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
1421
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
1422
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
1423
int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
1424
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
1426
void close_temporary(TABLE *table, bool free_share, bool delete_table);
1427
bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
1428
const char *table_name);
1429
void remove_db_from_cache(const char *db);
1430
void flush_tables();
1431
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
1432
char *make_default_log_name(char *buff,const char* log_ext);
1434
/* bits for last argument to remove_table_from_cache() */
1435
#define RTFC_NO_FLAG 0x0000
1436
#define RTFC_OWNED_BY_THD_FLAG 0x0001
1437
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
1438
#define RTFC_CHECK_KILLED_FLAG 0x0004
1439
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
1442
#define NORMAL_PART_NAME 0
1443
#define TEMP_PART_NAME 1
1444
#define RENAMED_PART_NAME 2
1445
void create_partition_name(char *out, const char *in1,
1446
const char *in2, uint name_variant,
1448
void create_subpartition_name(char *out, const char *in1,
1449
const char *in2, const char *in3,
1452
void mem_alloc_error(size_t size);
1454
enum ddl_log_entry_code
1457
DDL_LOG_EXECUTE_CODE:
1458
This is a code that indicates that this is a log entry to
1459
be executed, from this entry a linked list of log entries
1460
can be found and executed.
1462
An entry to be executed in a linked list from an execute log
1464
DDL_IGNORE_LOG_ENTRY_CODE:
1465
An entry that is to be ignored
1467
DDL_LOG_EXECUTE_CODE = 'e',
1468
DDL_LOG_ENTRY_CODE = 'l',
1469
DDL_IGNORE_LOG_ENTRY_CODE = 'i'
1472
enum ddl_log_action_code
1475
The type of action that a DDL_LOG_ENTRY_CODE entry is to
1477
DDL_LOG_DELETE_ACTION:
1479
DDL_LOG_RENAME_ACTION:
1481
DDL_LOG_REPLACE_ACTION:
1482
Rename an entity after removing the previous entry with the
1483
new name, that is replace this entry.
1485
DDL_LOG_DELETE_ACTION = 'd',
1486
DDL_LOG_RENAME_ACTION = 'r',
1487
DDL_LOG_REPLACE_ACTION = 's'
1491
typedef struct st_ddl_log_entry
1494
const char *from_name;
1495
const char *handler_name;
1498
enum ddl_log_entry_code entry_type;
1499
enum ddl_log_action_code action_type;
1501
Most actions have only one phase. REPLACE does however have two
1502
phases. The first phase removes the file with the new name if
1503
there was one there before and the second phase renames the
1504
old name to the new name.
1509
typedef struct st_ddl_log_memory_entry
1512
struct st_ddl_log_memory_entry *next_log_entry;
1513
struct st_ddl_log_memory_entry *prev_log_entry;
1514
struct st_ddl_log_memory_entry *next_active_log_entry;
1515
} DDL_LOG_MEMORY_ENTRY;
1518
bool write_ddl_log_entry(DDL_LOG_ENTRY *ddl_log_entry,
1519
DDL_LOG_MEMORY_ENTRY **active_entry);
1520
bool write_execute_ddl_log_entry(uint first_entry,
1522
DDL_LOG_MEMORY_ENTRY **active_entry);
1523
bool deactivate_ddl_log_entry(uint entry_no);
1524
void release_ddl_log_memory_entry(DDL_LOG_MEMORY_ENTRY *log_entry);
1525
bool sync_ddl_log();
1526
void release_ddl_log();
1527
void execute_ddl_log_recovery();
1528
bool execute_ddl_log_entry(THD *thd, uint first_entry);
1530
extern pthread_mutex_t LOCK_gdl;
1532
#define WFRM_WRITE_SHADOW 1
1533
#define WFRM_INSTALL_SHADOW 2
1534
#define WFRM_PACK_FRM 4
1535
#define WFRM_KEEP_SHARE 8
1537
/* Functions to work with system tables. */
1538
bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
1539
Open_tables_state *backup);
1540
void close_system_tables(THD *thd, Open_tables_state *backup);
1541
TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
1543
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
1544
bool wait_for_refresh, bool wait_for_placeholders);
1545
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
1546
LEX_STRING *connect_string,
1547
bool have_lock = FALSE);
1548
void copy_field_from_tmp_record(Field *field,int offset);
1549
bool fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors);
1550
bool fill_record(THD *thd, Field **field, List<Item> &values, bool ignore_errors);
1551
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
1553
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
1554
const char *db_name,
1555
const char *table_name)
1557
return find_table_in_list(table, &TABLE_LIST::next_global,
1558
db_name, table_name);
1561
inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
1562
const char *db_name,
1563
const char *table_name)
1565
return find_table_in_list(table, &TABLE_LIST::next_local,
1566
db_name, table_name);
1571
bool eval_const_cond(COND *cond);
1574
int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
1575
List<Item> &fields_vars, List<Item> &set_fields,
1576
List<Item> &set_values_list,
1577
enum enum_duplicates handle_duplicates, bool ignore,
1579
int write_record(THD *thd, TABLE *table, COPY_INFO *info);
1581
/* sql_manager.cc */
1582
extern ulong volatile manager_status;
1583
extern bool volatile manager_thread_in_use, mqh_used;
1584
extern pthread_t manager_thread;
1585
pthread_handler_t handle_manager(void *arg);
1586
bool mysql_manager_submit(void (*action)());
1591
void print_where(COND *cond,const char *info, enum_query_type query_type);
1592
void print_cached_tables(void);
1593
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
1594
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
1595
double current_read_time, const char *info);
1596
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
1597
#define EXTRA_DEBUG_DUMP_TABLE_LISTS
1598
#ifdef EXTRA_DEBUG_DUMP_TABLE_LISTS
1599
void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl);
1602
void mysql_print_status();
1605
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
1606
uint *key_length, uint *keypart);
1607
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
1608
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
1610
void key_zero_nulls(uchar *tuple, KEY *key_info);
1611
bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
1612
void key_unpack(String *to,TABLE *form,uint index);
1613
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
1614
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
1615
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
1617
bool init_errmessage(void);
1618
#endif /* MYSQL_SERVER */
1619
void sql_perror(const char *message);
1621
bool fn_format_relative_to_data_home(char * to, const char *name,
1622
const char *dir, const char *extension);
1624
File open_binlog(IO_CACHE *log, const char *log_file_name,
1625
const char **errmsg);
1628
extern void MYSQLerror(const char*);
1629
void refresh_status(THD *thd);
1630
my_bool mysql_rm_tmp_tables(void);
1631
void handle_connection_in_main_thread(THD *thd);
1632
void create_thread_to_handle_connection(THD *thd);
1633
void unlink_thd(THD *thd);
1634
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
1635
void flush_thread_cache();
1638
extern bool check_reserved_words(LEX_STRING *name);
1639
extern enum_field_types agg_field_type(Item **items, uint nitems);
1642
ulonglong find_set(TYPELIB *lib, const char *x, uint length, CHARSET_INFO *cs,
1643
char **err_pos, uint *err_len, bool *set_warning);
1644
uint find_type(const TYPELIB *lib, const char *find, uint length,
1646
uint find_type2(const TYPELIB *lib, const char *find, uint length,
1648
void unhex_type2(TYPELIB *lib);
1649
uint check_word(TYPELIB *lib, const char *val, const char *end,
1650
const char **end_of_word);
1651
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
1652
CHARSET_INFO * const cs);
1655
bool is_keyword(const char *name, uint len);
1657
#define MY_DB_OPT_FILE "db.opt"
1658
bool my_database_names_init(void);
1659
void my_database_names_free(void);
1660
bool check_db_dir_existence(const char *db_name);
1661
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
1662
bool load_db_opt_by_name(THD *thd, const char *db_name,
1663
HA_CREATE_INFO *db_create_info);
1664
CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
1665
bool my_dbopt_init(void);
1666
void my_dbopt_cleanup(void);
1667
extern int creating_database; // How many database locks are made
1668
extern int creating_table; // How many mysql_create_table() are running
1674
extern time_t server_start_time, flush_status_time;
1675
#endif /* MYSQL_SERVER */
1676
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1677
extern uint mysql_data_home_len;
1678
extern char *mysql_data_home,server_version[SERVER_VERSION_LENGTH],
1679
mysql_real_data_home[], mysql_unpacked_real_data_home[];
1680
extern CHARSET_INFO *character_set_filesystem;
1681
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1683
extern char *opt_mysql_tmpdir, mysql_charsets_dir[],
1684
def_ft_boolean_syntax[sizeof(ft_boolean_syntax)];
1685
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
1686
extern MY_TMPDIR mysql_tmpdir_list;
1687
extern const LEX_STRING command_name[];
1688
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
1689
extern const char **errmesg; /* Error messages */
1690
extern const char *myisam_recover_options_str;
1691
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
1692
extern const char * const TRG_EXT;
1693
extern const char * const TRN_EXT;
1694
extern Eq_creator eq_creator;
1695
extern Ne_creator ne_creator;
1696
extern Gt_creator gt_creator;
1697
extern Lt_creator lt_creator;
1698
extern Ge_creator ge_creator;
1699
extern Le_creator le_creator;
1700
extern char language[FN_REFLEN];
1701
#endif /* MYSQL_SERVER */
1702
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1703
extern char reg_ext[FN_EXTLEN];
1704
extern uint reg_ext_length;
1705
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1707
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
1708
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
1709
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
1710
extern const double log_10[309];
1711
extern ulonglong log_10_int[20];
1712
extern ulonglong keybuff_size;
1713
extern ulonglong thd_startup_options;
1714
extern ulong thread_id;
1715
extern ulong binlog_cache_use, binlog_cache_disk_use;
1716
extern ulong aborted_threads,aborted_connects;
1717
extern ulong slave_open_temp_tables;
1718
extern ulong query_cache_size, query_cache_min_res_unit;
1719
extern ulong slow_launch_threads, slow_launch_time;
1720
extern ulong table_cache_size, table_def_size;
1721
extern ulong max_connections,max_connect_errors, connect_timeout;
1722
extern my_bool slave_allow_batching;
1723
extern ulong slave_net_timeout, slave_trans_retries;
1724
extern uint max_user_connections;
1725
extern ulong what_to_log,flush_time;
1726
extern ulong query_buff_size;
1727
extern ulong max_prepared_stmt_count, prepared_stmt_count;
1728
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
1729
extern ulong max_binlog_size, max_relay_log_size;
1730
extern ulong opt_binlog_rows_event_max_size;
1731
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
1732
extern ulong back_log;
1733
#endif /* MYSQL_SERVER */
1734
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1735
extern ulong specialflag;
1736
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1738
extern ulong current_pid;
1739
extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
1740
extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
1741
extern ulong tc_log_page_waits;
1742
extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;
1743
extern uint test_flags,select_errors,ha_open_options;
1744
extern uint protocol_version, mysqld_port, dropping_tables;
1745
extern uint delay_key_write_options;
1746
#endif /* MYSQL_SERVER */
1747
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1748
extern uint lower_case_table_names;
1749
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1751
extern bool opt_endinfo, using_udf_functions;
1752
extern my_bool locked_in_memory;
1753
extern bool opt_using_transactions;
1754
#endif /* MYSQL_SERVER */
1755
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1756
extern bool mysqld_embedded;
1757
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1759
extern bool using_update_log, opt_large_files, server_id_supplied;
1760
extern bool opt_update_log, opt_bin_log, opt_error_log;
1761
extern my_bool opt_log, opt_slow_log;
1762
extern ulong log_output_options;
1763
extern my_bool opt_log_queries_not_using_indexes;
1764
extern bool opt_disable_networking, opt_skip_show_db;
1765
extern my_bool opt_character_set_client_handshake;
1766
extern bool volatile abort_loop, shutdown_in_progress;
1767
extern uint volatile thread_count, thread_running, global_read_lock;
1768
extern uint connection_count;
1769
extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
1770
extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
1771
extern my_bool opt_slave_compressed_protocol, use_temp_pool;
1772
extern ulong slave_exec_mode_options;
1773
extern my_bool opt_readonly, lower_case_file_system;
1774
extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
1775
extern my_bool opt_secure_auth;
1776
extern char* opt_secure_file_priv;
1777
extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
1778
extern my_bool opt_noacl;
1779
extern my_bool opt_old_style_user_limits;
1780
extern uint opt_crash_binlog_innodb;
1781
extern char *shared_memory_base_name, *mysqld_unix_port;
1782
extern my_bool opt_enable_shared_memory;
1783
extern char *default_tz_name;
1784
#endif /* MYSQL_SERVER */
1785
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1786
extern my_bool opt_large_pages;
1787
extern uint opt_large_page_size;
1788
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1790
extern char *opt_logname, *opt_slow_logname;
1791
extern const char *log_output_str;
1793
extern MYSQL_BIN_LOG mysql_bin_log;
1794
extern LOGGER logger;
1795
extern TABLE_LIST general_log, slow_log;
1796
extern FILE *bootstrap_file;
1797
extern int bootstrap_error;
1798
extern FILE *stderror_file;
1799
extern pthread_key(MEM_ROOT**,THR_MALLOC);
1800
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
1801
LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
1802
LOCK_error_log, LOCK_uuid_generator,
1803
LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
1804
LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock,
1805
LOCK_global_system_variables, LOCK_user_conn,
1806
LOCK_prepared_stmt_count,
1807
LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
1808
extern pthread_mutex_t LOCK_server_started;
1809
extern pthread_cond_t COND_server_started;
1810
extern int mysqld_server_started;
1811
extern rw_lock_t LOCK_sys_init_connect, LOCK_sys_init_slave;
1812
extern rw_lock_t LOCK_system_variables_hash;
1813
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
1814
extern pthread_cond_t COND_global_read_lock;
1815
extern pthread_attr_t connection_attrib;
1816
extern I_List<THD> threads;
1817
extern I_List<NAMED_LIST> key_caches;
1818
extern MY_BITMAP temp_pool;
1819
extern String my_empty_string;
1820
extern const String my_null_string;
1821
extern SHOW_VAR status_vars[];
1822
#endif /* MYSQL_SERVER */
1823
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1824
extern struct system_variables global_system_variables;
1825
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
1827
extern struct system_variables max_system_variables;
1828
extern struct system_status_var global_status_var;
1829
extern struct rand_struct sql_rand;
1831
extern const char *opt_date_time_formats[];
1832
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
1834
extern String null_string;
1835
extern HASH open_cache, lock_db_cache;
1836
extern TABLE *unused_tables;
1837
extern const char* any_db;
1838
extern struct my_option my_long_options[];
1839
extern const LEX_STRING view_type;
1840
extern scheduler_functions thread_scheduler;
1841
extern TYPELIB thread_handling_typelib;
1842
extern uint8 uc_update_queries[SQLCOM_END+1];
1843
extern uint sql_command_flags[];
1844
extern TYPELIB log_output_typelib;
1846
/* optional things, have_* variables */
1847
extern SHOW_COMP_OPTION have_community_features;
1849
extern handlerton *myisam_hton;
1850
extern handlerton *heap_hton;
1852
extern SHOW_COMP_OPTION have_symlink, have_dlopen;
1853
extern SHOW_COMP_OPTION have_crypt;
1854
extern SHOW_COMP_OPTION have_compress;
1857
extern pthread_t signal_thread;
1859
MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
1860
uint flags, bool *need_reopen);
1861
/* mysql_lock_tables() and open_table() flags bits */
1862
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001
1863
#define MYSQL_LOCK_IGNORE_FLUSH 0x0002
1864
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004
1865
#define MYSQL_OPEN_TEMPORARY_ONLY 0x0008
1866
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0010
1867
#define MYSQL_LOCK_PERF_SCHEMA 0x0020
1869
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
1870
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
1871
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
1872
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
1873
bool always_unlock);
1874
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
1875
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
1876
thr_lock_type new_lock_type);
1877
bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
1878
MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
1879
TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
1880
TABLE_LIST *haystack);
1881
bool lock_global_read_lock(THD *thd);
1882
void unlock_global_read_lock(THD *thd);
1883
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
1884
bool is_not_commit);
1885
void start_waiting_global_read_lock(THD *thd);
1886
bool make_global_read_lock_block_commit(THD *thd);
1887
bool set_protect_against_global_read_lock(void);
1888
void unset_protect_against_global_read_lock(void);
1889
void broadcast_refresh(void);
1890
int try_transactional_lock(THD *thd, TABLE_LIST *table_list);
1891
int check_transactional_lock(THD *thd, TABLE_LIST *table_list);
1892
int set_handler_table_locks(THD *thd, TABLE_LIST *table_list,
1893
bool transactional);
1895
/* Lock based on name */
1896
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
1897
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
1898
void unlock_table_name(THD *thd, TABLE_LIST *table_list);
1899
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
1900
bool lock_table_names(THD *thd, TABLE_LIST *table_list);
1901
void unlock_table_names(THD *thd, TABLE_LIST *table_list,
1902
TABLE_LIST *last_table);
1903
bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
1904
bool is_table_name_exclusively_locked_by_this_thread(THD *thd,
1905
TABLE_LIST *table_list);
1906
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
1910
/* old unireg functions */
1912
void unireg_init(ulong options);
1913
void unireg_end(void) __attribute__((noreturn));
1914
bool mysql_create_frm(THD *thd, const char *file_name,
1915
const char *db, const char *table,
1916
HA_CREATE_INFO *create_info,
1917
List<Create_field> &create_field,
1918
uint key_count,KEY *key_info,handler *db_type);
1919
int rea_create_table(THD *thd, const char *path,
1920
const char *db, const char *table_name,
1921
HA_CREATE_INFO *create_info,
1922
List<Create_field> &create_field,
1923
uint key_count,KEY *key_info,
1925
int format_number(uint inputflag,uint max_length,char * pos,uint length,
1929
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
1931
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
1933
const char *table_name, const char *path);
1934
void free_table_share(TABLE_SHARE *share);
1935
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
1936
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
1937
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
1938
uint db_stat, uint prgflag, uint ha_open_flags,
1939
TABLE *outparam, open_table_mode open_mode);
1940
int readfrm(const char *name, uchar **data, size_t *length);
1941
int writefrm(const char* name, const uchar* data, size_t len);
1942
int closefrm(TABLE *table, bool free_share);
1943
int read_string(File file, uchar* *to, size_t length);
1944
void free_blobs(TABLE *table);
1945
int set_zone(int nr,int min_zone,int max_zone);
1946
ulong convert_period_to_month(ulong period);
1947
ulong convert_month_to_period(ulong month);
1948
void get_date_from_daynr(long daynr,uint *year, uint *month,
1950
my_time_t TIME_to_timestamp(THD *thd, const MYSQL_TIME *t, my_bool *not_exist);
1951
bool str_to_time_with_warn(const char *str,uint length,MYSQL_TIME *l_time);
1952
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
1953
MYSQL_TIME *l_time, uint flags);
1954
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
1955
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
1957
void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level level,
1958
const char *str_val,
1959
uint str_length, timestamp_type time_type,
1960
const char *field_name);
1962
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, INTERVAL interval);
1963
bool calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign,
1964
longlong *seconds_out, long *microseconds_out);
1966
extern LEX_STRING interval_type_to_name[];
1968
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
1969
const char *format_str,
1970
uint format_length);
1971
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
1972
DATE_TIME_FORMAT *format);
1973
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
1974
timestamp_type type);
1975
extern bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
1976
timestamp_type type, String *str);
1977
void make_datetime(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
1979
void make_date(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
1981
void make_time(const DATE_TIME_FORMAT *format, const MYSQL_TIME *l_time,
1983
int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b);
1984
ulonglong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
1985
Item *warn_item, bool *is_null);
1987
int test_if_number(char *str,int *res,bool allow_wildcards);
1988
void change_byte(uchar *,uint,char,char);
1989
void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
1991
int use_record_cache, bool print_errors);
1992
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table,
1993
bool print_error, uint idx);
1994
void end_read_record(READ_RECORD *info);
1995
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
1996
uint s_length, SQL_SELECT *select,
1997
ha_rows max_rows, bool sort_positions,
1998
ha_rows *examined_rows);
1999
void filesort_free_buffers(TABLE *table, bool full);
2000
void change_double_for_sort(double nr,uchar *to);
2001
double my_double_round(double value, longlong dec, bool dec_unsigned,
2003
int get_quick_record(SQL_SELECT *select);
2005
int calc_weekday(long daynr,bool sunday_first_day_of_week);
2006
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
2007
void find_date(char *pos,uint *vek,uint flag);
2008
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
2009
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
2010
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
2011
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
2012
const char *newname);
2013
ulong next_io_size(ulong pos);
2014
void append_unescaped(String *res, const char *pos, uint length);
2015
int create_frm(THD *thd, const char *name, const char *db, const char *table,
2016
uint reclength, uchar *fileinfo,
2017
HA_CREATE_INFO *create_info, uint keys, KEY *key_info);
2018
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
2019
int rename_file_ext(const char * from,const char * to,const char * ext);
2020
bool check_db_name(LEX_STRING *db);
2021
bool check_column_name(const char *name);
2022
bool check_table_name(const char *name, uint length);
2023
char *get_field(MEM_ROOT *mem, Field *field);
2024
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
2025
char *fn_rext(char *name);
2027
/* Conversion functions */
2028
#endif /* MYSQL_SERVER */
2029
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
2030
uint strconvert(CHARSET_INFO *from_cs, const char *from,
2031
CHARSET_INFO *to_cs, char *to, uint to_length, uint *errors);
2032
uint filename_to_tablename(const char *from, char *to, uint to_length);
2033
uint tablename_to_filename(const char *from, char *to, uint to_length);
2034
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
2036
uint build_table_filename(char *buff, size_t bufflen, const char *db,
2037
const char *table, const char *ext, uint flags);
2039
#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
2040
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9
2042
/* Flags for conversion functions. */
2043
#define FN_FROM_IS_TMP (1 << 0)
2044
#define FN_TO_IS_TMP (1 << 1)
2045
#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP)
2046
#define NO_FRM_RENAME (1 << 2)
2049
Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
2050
LEX_STRING component);
2051
int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
2052
LEX_STRING &name, user_var_entry **out_entry);
2054
bool flush_error_log(void);
2057
void free_list(I_List <i_string_pair> *list);
2058
void free_list(I_List <i_string> *list);
2062
extern void turn_parser_debug_on();
2065
/* Some inline functions for more speed */
2067
inline bool add_item_to_list(THD *thd, Item *item)
2069
return thd->lex->current_select->add_item_to_list(thd, item);
2072
inline bool add_value_to_list(THD *thd, Item *value)
2074
return thd->lex->value_list.push_back(value);
2077
inline bool add_order_to_list(THD *thd, Item *item, bool asc)
2079
return thd->lex->current_select->add_order_to_list(thd, item, asc);
2082
inline bool add_group_to_list(THD *thd, Item *item, bool asc)
2084
return thd->lex->current_select->add_group_to_list(thd, item, asc);
2087
inline void mark_as_null_row(TABLE *table)
2090
table->status|=STATUS_NULL_ROW;
2091
bfill(table->null_flags,table->s->null_bytes,255);
2094
inline void table_case_convert(char * name, uint length)
2096
if (lower_case_table_names)
2097
files_charset_info->cset->casedn(files_charset_info,
2098
name, length, name, length);
2101
inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
2103
return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
2106
inline ulong sql_rnd_with_mutex()
2108
pthread_mutex_lock(&LOCK_thread_count);
2109
ulong tmp=(ulong) (my_rnd(&sql_rand) * 0xffffffff); /* make all bits random */
2110
pthread_mutex_unlock(&LOCK_thread_count);
2114
Comp_creator *comp_eq_creator(bool invert);
2115
Comp_creator *comp_ge_creator(bool invert);
2116
Comp_creator *comp_gt_creator(bool invert);
2117
Comp_creator *comp_le_creator(bool invert);
2118
Comp_creator *comp_lt_creator(bool invert);
2119
Comp_creator *comp_ne_creator(bool invert);
2121
Item * all_any_subquery_creator(Item *left_expr,
2122
chooser_compare_func_creator cmp,
2124
SELECT_LEX *select_lex);
2127
clean/setup table fields and map.
2129
@param table TABLE structure pointer (which should be setup)
2130
@param table_list TABLE_LIST structure pointer (owner of TABLE)
2131
@param tablenr table number
2135
inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
2137
table->used_fields= 0;
2138
table->const_table= 0;
2140
table->status= STATUS_NO_RECORD;
2141
table->maybe_null= table_list->outer_join;
2142
TABLE_LIST *embedding= table_list->embedding;
2143
while (!table->maybe_null && embedding)
2145
table->maybe_null= embedding->outer_join;
2146
embedding= embedding->embedding;
2148
table->tablenr= tablenr;
2149
table->map= (table_map) 1 << tablenr;
2150
table->force_index= table_list->force_index;
2151
table->covering_keys= table->s->keys_for_keyread;
2152
table->merge_keys.clear_all();
2157
convert a hex digit into number.
2160
inline int hexchar_to_int(char c)
2162
if (c <= '9' && c >= '0')
2165
if (c <= 'f' && c >= 'a')
2171
return true if the table was created explicitly.
2173
inline bool is_user_table(TABLE * table)
2175
const char *name= table->s->table_name.str;
2176
return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
2182
This will be slightly slower and perhaps a tiny bit less accurate than
2183
doing it the IEEE754 way but log2() should be available on C99 systems.
2185
static inline double log2(double x)
2187
return (log(x) / M_LN2);
2193
Some functions that are different in the embedded library and the normal
2197
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
2198
void kill_delayed_threads(void);
2199
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
2201
/* Used by handlers to store things in schema tables */
2202
#define IS_FILES_FILE_ID 0
2203
#define IS_FILES_FILE_NAME 1
2204
#define IS_FILES_FILE_TYPE 2
2205
#define IS_FILES_TABLESPACE_NAME 3
2206
#define IS_FILES_TABLE_CATALOG 4
2207
#define IS_FILES_TABLE_SCHEMA 5
2208
#define IS_FILES_TABLE_NAME 6
2209
#define IS_FILES_LOGFILE_GROUP_NAME 7
2210
#define IS_FILES_LOGFILE_GROUP_NUMBER 8
2211
#define IS_FILES_ENGINE 9
2212
#define IS_FILES_FULLTEXT_KEYS 10
2213
#define IS_FILES_DELETED_ROWS 11
2214
#define IS_FILES_UPDATE_COUNT 12
2215
#define IS_FILES_FREE_EXTENTS 13
2216
#define IS_FILES_TOTAL_EXTENTS 14
2217
#define IS_FILES_EXTENT_SIZE 15
2218
#define IS_FILES_INITIAL_SIZE 16
2219
#define IS_FILES_MAXIMUM_SIZE 17
2220
#define IS_FILES_AUTOEXTEND_SIZE 18
2221
#define IS_FILES_CREATION_TIME 19
2222
#define IS_FILES_LAST_UPDATE_TIME 20
2223
#define IS_FILES_LAST_ACCESS_TIME 21
2224
#define IS_FILES_RECOVER_TIME 22
2225
#define IS_FILES_TRANSACTION_COUNTER 23
2226
#define IS_FILES_VERSION 24
2227
#define IS_FILES_ROW_FORMAT 25
2228
#define IS_FILES_TABLE_ROWS 26
2229
#define IS_FILES_AVG_ROW_LENGTH 27
2230
#define IS_FILES_DATA_LENGTH 28
2231
#define IS_FILES_MAX_DATA_LENGTH 29
2232
#define IS_FILES_INDEX_LENGTH 30
2233
#define IS_FILES_DATA_FREE 31
2234
#define IS_FILES_CREATE_TIME 32
2235
#define IS_FILES_UPDATE_TIME 33
2236
#define IS_FILES_CHECK_TIME 34
2237
#define IS_FILES_CHECKSUM 35
2238
#define IS_FILES_STATUS 36
2239
#define IS_FILES_EXTRA 37
2240
void init_fill_schema_files_row(TABLE* table);
2241
bool schema_table_store_record(THD *thd, TABLE *table);
2243
/* sql/item_create.cc */
2244
int item_create_init();
2245
void item_create_cleanup();
2247
inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
2249
lex_str->str= (char *) c_str;
2250
lex_str->length= strlen(c_str);
2253
bool load_charset(MEM_ROOT *mem_root,
2255
CHARSET_INFO *dflt_cs,
2258
bool load_collation(MEM_ROOT *mem_root,
2260
CHARSET_INFO *dflt_cl,
2263
#endif /* MYSQL_SERVER */
2264
#endif /* MYSQL_CLIENT */
2266
#endif /* MYSQL_PRIV_H */