1
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
2
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
3
4
This program is free software; you can redistribute it and/or modify
4
5
it under the terms of the GNU General Public License as published by
12
13
You should have received a copy of the GNU General Public License
13
14
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
111
113
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
112
114
#define all_bits_set(A,B) ((A) & (B) != (B))
116
/* Version numbers for deprecation messages */
117
#define VER_BETONY "5.5"
118
#define VER_CELOSIA "5.6"
114
120
#define WARN_DEPRECATED(Thd,Ver,Old,New) \
116
122
DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) > 0); \
117
if (((uchar*)Thd) != NULL) \
123
if (((uchar*)Thd) != NULL) \
118
124
push_warning_printf(((THD *)Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \
119
ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX_WITH_VER), \
120
(Old), (Ver), (New)); \
125
ER_WARN_DEPRECATED_SYNTAX, \
126
ER(ER_WARN_DEPRECATED_SYNTAX), \
122
sql_print_warning("The syntax '%s' is deprecated and will be removed " \
123
"in MySQL %s. Please use %s instead.", (Old), (Ver), (New)); \
129
sql_print_warning("'%s' is deprecated and will be removed " \
130
"in a future release. Please use '%s' instead.", \
126
134
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
561
569
#define MY_CHARSET_BIN_MB_MAXLEN 1
572
Flags below are set when we perform
573
context analysis of the statement and make
574
subqueries non-const. It prevents subquery
575
evaluation at context analysis stage.
579
Don't evaluate this subquery during statement prepare even if
580
it's a constant one. The flag is switched off in the end of
583
#define CONTEXT_ANALYSIS_ONLY_PREPARE 1
585
Special JOIN::prepare mode: changing of query is prohibited.
586
When creating a view, we need to just check its syntax omitting
587
any optimizations: afterwards definition of the view will be
588
reconstructed by means of ::print() methods and written to
589
to an .frm file. We need this definition to stay untouched.
591
#define CONTEXT_ANALYSIS_ONLY_VIEW 2
593
Don't evaluate this subquery during derived table prepare even if
596
#define CONTEXT_ANALYSIS_ONLY_DERIVED 4
563
598
// uncachable cause
564
599
#define UNCACHEABLE_DEPENDENT 1
565
600
#define UNCACHEABLE_RAND 2
566
601
#define UNCACHEABLE_SIDEEFFECT 4
567
602
/// forcing to save JOIN for explain
568
603
#define UNCACHEABLE_EXPLAIN 8
569
/** Don't evaluate subqueries in prepare even if they're not correlated */
570
#define UNCACHEABLE_PREPARE 16
571
604
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */
572
#define UNCACHEABLE_UNITED 32
573
#define UNCACHEABLE_CHECKOPTION 64
605
#define UNCACHEABLE_UNITED 16
606
#define UNCACHEABLE_CHECKOPTION 32
575
608
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
576
609
#define UNDEF_POS (-1)
579
Sync points allow us to force the server to reach a certain line of code
580
and block there until the client tells the server it is ok to go on.
581
The client tells the server to block with SELECT GET_LOCK()
582
and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult
585
#define DBUG_SYNC_POINT(lock_name,lock_timeout) \
586
debug_sync_point(lock_name,lock_timeout)
587
void debug_sync_point(const char* lock_name, uint lock_timeout);
589
#define DBUG_SYNC_POINT(lock_name,lock_timeout)
590
#endif /* EXTRA_DEBUG */
592
611
/* BINLOG_DUMP options */
649
668
CHECK_FIELD_ERROR_FOR_NULL
653
/** Struct to handle simple linked lists. */
654
typedef struct st_sql_list {
659
st_sql_list() {} /* Remove gcc warning */
666
inline void link_in_list(uchar *element,uchar **next_ptr)
673
inline void save_and_clear(struct st_sql_list *save)
678
inline void push_front(struct st_sql_list *save)
680
*save->next= first; /* link current list last */
682
elements+= save->elements;
684
inline void push_back(struct st_sql_list *save)
690
elements+= save->elements;
695
671
#if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
696
672
extern "C" THD *_current_thd_noinline();
697
673
#define _current_thd() _current_thd_noinline()
676
THR_THD is a key which will be used to set/get THD* for a thread,
677
using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
699
679
extern pthread_key(THD*, THR_THD);
700
680
inline THD *_current_thd(void)
855
835
void sql_print_information(const char *format, ...)
856
836
ATTRIBUTE_FORMAT(printf, 1, 2);
857
837
typedef void (*sql_print_message_func)(const char *format, ...)
858
ATTRIBUTE_FORMAT(printf, 1, 2);
838
ATTRIBUTE_FORMAT_FPTR(printf, 1, 2);
859
839
extern sql_print_message_func sql_print_message_handlers[];
861
841
int error_log_print(enum loglevel level, const char *format,
1035
void write_bin_log(THD *thd, bool clear_error,
1036
char const *query, ulong query_length);
1015
int write_bin_log(THD *thd, bool clear_error,
1016
char const *query, ulong query_length);
1038
1018
/* sql_connect.cc */
1039
1019
int check_user(THD *thd, enum enum_server_command command,
1045
1025
bool check_mqh(THD *thd, uint check_command);
1046
1026
void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
1047
1027
void decrease_user_connections(USER_CONN *uc);
1048
void thd_init_client_charset(THD *thd, uint cs_number);
1028
bool thd_init_client_charset(THD *thd, uint cs_number);
1029
inline bool is_supported_parser_charset(CHARSET_INFO *cs)
1031
return test(cs->mbminlen == 1);
1049
1033
bool setup_connection_thread_globals(THD *thd);
1051
1035
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
1075
1059
bool force_switch,
1076
1060
bool *cur_db_changed);
1078
void mysql_parse(THD *thd, const char *inBuf, uint length,
1062
void mysql_parse(THD *thd, char *rawbuf, uint length,
1079
1063
const char ** semicolon);
1081
1065
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
1098
1082
char* packet, uint packet_length);
1099
1083
void log_slow_statement(THD *thd);
1100
1084
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
1101
bool compare_record(TABLE *table);
1085
bool records_are_comparable(const TABLE *table);
1086
bool compare_records(const TABLE *table);
1102
1087
bool append_file_to_dir(THD *thd, const char **filename_ptr,
1103
1088
const char *table_name);
1104
1089
void wait_while_table_is_used(THD *thd, TABLE *table,
1113
1098
void kill_mysql(void);
1114
1099
void close_connection(THD *thd, uint errcode, bool lock);
1115
1100
bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
1116
bool *write_to_binlog);
1101
int *write_to_binlog);
1117
1102
#ifndef NO_EMBEDDED_ACCESS_CHECKS
1118
1103
bool check_access(THD *thd, ulong access, const char *db, ulong *save_priv,
1119
1104
bool no_grant, bool no_errors, bool schema_db);
1188
1173
List<Item> &fields, List<Item> &all_fields, ORDER *order,
1189
1174
bool *hidden_group_fields);
1190
1175
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
1191
Item **ref_pointer_array);
1176
Item **ref_pointer_array, ORDER *group_list= NULL);
1193
1178
bool handle_select(THD *thd, LEX *lex, select_result *result,
1194
1179
ulong setup_tables_done_option);
1270
1255
void prepare_triggers_for_insert_stmt(TABLE *table);
1271
1256
int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
1272
1257
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
1273
SQL_LIST *order, ha_rows rows, ulonglong options,
1258
SQL_I_List<ORDER> *order, ha_rows rows, ulonglong options,
1274
1259
bool reset_auto_increment);
1275
1260
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
1276
1261
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
1296
1281
TABLE_LIST *new_child_list, TABLE_LIST **new_last);
1297
1282
bool reopen_table(TABLE *table);
1298
1283
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
1299
thr_lock_type read_lock_type_for_table(THD *thd, TABLE *table);
1284
thr_lock_type read_lock_type_for_table(THD *thd, LEX *lex,
1285
TABLE_LIST *table_list);
1300
1286
void close_data_files_and_morph_locks(THD *thd, const char *db,
1301
1287
const char *table_name);
1302
1288
void close_handle_and_leave_table_as_lock(TABLE *table);
1415
1401
enum enum_schema_table_state executed_place);
1416
1402
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
1418
#define is_schema_db(X) \
1419
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
1404
inline bool is_schema_db(const char *name, size_t len)
1406
return (INFORMATION_SCHEMA_NAME.length == len &&
1407
!my_strcasecmp(system_charset_info,
1408
INFORMATION_SCHEMA_NAME.str, name));
1411
inline bool is_schema_db(const char *name)
1413
return !my_strcasecmp(system_charset_info,
1414
INFORMATION_SCHEMA_NAME.str, name);
1421
1417
/* sql_prepare.cc */
1459
1455
List<String> *interval_list, CHARSET_INFO *cs,
1460
1456
uint uint_geom_type);
1461
1457
void store_position_for_column(const char *name);
1462
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
1458
bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *group,bool asc);
1463
1459
bool push_new_name_resolution_context(THD *thd,
1464
1460
TABLE_LIST *left_op,
1465
1461
TABLE_LIST *right_op);
1480
1476
extern Item **not_found_item;
1483
A set of constants used for checking non aggregated fields and sum
1484
functions mixture in the ONLY_FULL_GROUP_BY_MODE.
1486
#define NON_AGG_FIELD_USED 1
1487
#define SUM_FUNC_USED 2
1490
1479
This enumeration type is used only by the function find_item_in_list
1491
1480
to return the info on how an item has been resolved against a list
1492
1481
of possibly aliased items.
1734
1723
#define WFRM_PACK_FRM 4
1735
1724
#define WFRM_KEEP_SHARE 8
1736
1725
bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
1737
int abort_and_upgrade_lock(ALTER_PARTITION_PARAM_TYPE *lpt);
1726
int abort_and_upgrade_lock_and_close_table(ALTER_PARTITION_PARAM_TYPE *lpt);
1738
1727
void close_open_tables_and_downgrade(ALTER_PARTITION_PARAM_TYPE *lpt);
1739
1728
void mysql_wait_completed_table(ALTER_PARTITION_PARAM_TYPE *lpt, TABLE *my_table);
1831
1820
bool fn_format_relative_to_data_home(char * to, const char *name,
1832
1821
const char *dir, const char *extension);
1823
Test a file path to determine if the path is compatible with the secure file
1826
bool is_secure_file_path(char *path);
1833
1828
#ifdef MYSQL_SERVER
1834
1829
File open_binlog(IO_CACHE *log, const char *log_file_name,
1835
1830
const char **errmsg);
1969
1964
extern uint test_flags,select_errors,ha_open_options;
1970
1965
extern uint protocol_version, mysqld_port, dropping_tables;
1971
1966
extern uint delay_key_write_options;
1967
extern ulong max_long_data_size;
1972
1968
#endif /* MYSQL_SERVER */
1973
1969
#if defined MYSQL_SERVER || defined INNODB_COMPATIBILITY_HOOKS
1974
1970
extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names;
1988
1984
extern ulong log_output_options;
1989
1985
extern my_bool opt_log_queries_not_using_indexes;
1990
1986
extern bool opt_disable_networking, opt_skip_show_db;
1987
extern bool opt_skip_name_resolve;
1991
1988
extern bool opt_ignore_builtin_innodb;
1992
1989
extern my_bool opt_character_set_client_handshake;
1993
1990
extern bool volatile abort_loop, shutdown_in_progress;
2024
2021
extern FILE *bootstrap_file;
2025
2022
extern int bootstrap_error;
2026
2023
extern FILE *stderror_file;
2025
THR_MALLOC is a key which will be used to set/get MEM_ROOT** for a thread,
2026
using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
2027
2028
extern pthread_key(MEM_ROOT**,THR_MALLOC);
2028
2029
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
2029
2030
LOCK_mapped_file,LOCK_user_locks, LOCK_status,
2260
2261
int rename_file_ext(const char * from,const char * to,const char * ext);
2261
2262
bool check_db_name(LEX_STRING *db);
2262
2263
bool check_column_name(const char *name);
2263
bool check_table_name(const char *name, uint length);
2264
bool check_table_name(const char *name, uint length, bool check_for_path_chars);
2264
2265
char *get_field(MEM_ROOT *mem, Field *field);
2265
2266
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
2266
2267
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr);
2284
2285
uint filename_to_tablename(const char *from, char *to, uint to_length);
2285
2286
uint tablename_to_filename(const char *from, char *to, uint to_length);
2286
2287
uint check_n_cut_mysql50_prefix(const char *from, char *to, uint to_length);
2288
bool check_mysql50_prefix(const char *name);
2287
2289
#endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
2288
2290
#ifdef MYSQL_SERVER
2289
2291
uint build_table_filename(char *buff, size_t bufflen, const char *db,