The world's most popular open source database
00001 /* Copyright (C) 2000-2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* 00018 Mostly this file is used in the server. But a little part of it is used in 00019 mysqlbinlog too (definition of SELECT_DISTINCT and others). 00020 The consequence is that 90% of the file is wrapped in #ifndef MYSQL_CLIENT, 00021 except the part which must be in the server and in the client. 00022 */ 00023 00024 #ifndef MYSQL_CLIENT 00025 00026 #include <my_global.h> 00027 #include <mysql_version.h> 00028 #include <mysql_embed.h> 00029 #include <my_sys.h> 00030 #include <my_time.h> 00031 #include <m_string.h> 00032 #include <hash.h> 00033 #include <signal.h> 00034 #include <thr_lock.h> 00035 #include <my_base.h> /* Needed by field.h */ 00036 #include "sql_bitmap.h" 00037 #include "sql_array.h" 00038 00039 /* TODO convert all these three maps to Bitmap classes */ 00040 typedef ulonglong table_map; /* Used for table bits in join */ 00041 #if MAX_INDEXES <= 64 00042 typedef Bitmap<64> key_map; /* Used for finding keys */ 00043 #else 00044 typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */ 00045 #endif 00046 typedef ulong key_part_map; /* Used for finding key parts */ 00047 typedef ulong nesting_map; /* Used for flags of nesting constructs */ 00048 /* 00049 Used to identify NESTED_JOIN structures within a join (applicable only to 00050 structures that have not been simplified away and embed more the one 00051 element) 00052 */ 00053 typedef ulonglong nested_join_map; 00054 00055 /* query_id */ 00056 typedef ulonglong query_id_t; 00057 extern query_id_t query_id; 00058 00059 /* increment query_id and return it. */ 00060 inline query_id_t next_query_id() { return query_id++; } 00061 00062 /* useful constants */ 00063 extern const key_map key_map_empty; 00064 extern key_map key_map_full; /* Should be threaded as const */ 00065 extern const char *primary_key_name; 00066 00067 #include "mysql_com.h" 00068 #include <violite.h> 00069 #include "unireg.h" 00070 00071 void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size); 00072 gptr sql_alloc(unsigned size); 00073 gptr sql_calloc(unsigned size); 00074 char *sql_strdup(const char *str); 00075 char *sql_strmake(const char *str,uint len); 00076 gptr sql_memdup(const void * ptr,unsigned size); 00077 void sql_element_free(void *ptr); 00078 char *sql_strmake_with_convert(const char *str, uint32 arg_length, 00079 CHARSET_INFO *from_cs, 00080 uint32 max_res_length, 00081 CHARSET_INFO *to_cs, uint32 *result_length); 00082 uint kill_one_thread(THD *thd, ulong id, bool only_kill_query); 00083 void sql_kill(THD *thd, ulong id, bool only_kill_query); 00084 bool net_request_file(NET* net, const char* fname); 00085 char* query_table_status(THD *thd,const char *db,const char *table_name); 00086 00087 #define x_free(A) { my_free((gptr) (A),MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR)); } 00088 #define safeFree(x) { if(x) { my_free((gptr) x,MYF(0)); x = NULL; } } 00089 #define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1)) 00090 #define all_bits_set(A,B) ((A) & (B) != (B)) 00091 00092 #define WARN_DEPRECATED(Thd,Ver,Old,New) \ 00093 do { \ 00094 DBUG_ASSERT(strncmp(Ver, MYSQL_SERVER_VERSION, sizeof(Ver)-1) >= 0); \ 00095 push_warning_printf(((THD *)Thd), MYSQL_ERROR::WARN_LEVEL_WARN, \ 00096 ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX), \ 00097 (Old), (Ver), (New)); \ 00098 } while(0) 00099 00100 00101 extern CHARSET_INFO *system_charset_info, *files_charset_info ; 00102 extern CHARSET_INFO *national_charset_info, *table_alias_charset; 00103 00104 00105 typedef struct my_locale_st 00106 { 00107 const char *name; 00108 const char *description; 00109 const bool is_ascii; 00110 TYPELIB *month_names; 00111 TYPELIB *ab_month_names; 00112 TYPELIB *day_names; 00113 TYPELIB *ab_day_names; 00114 } MY_LOCALE; 00115 00116 extern MY_LOCALE my_locale_en_US; 00117 extern MY_LOCALE *my_locales[]; 00118 00119 MY_LOCALE *my_locale_by_name(const char *name); 00120 00121 /*************************************************************************** 00122 Configuration parameters 00123 ****************************************************************************/ 00124 00125 #define ACL_CACHE_SIZE 256 00126 #define MAX_PASSWORD_LENGTH 32 00127 #define HOST_CACHE_SIZE 128 00128 #define MAX_ACCEPT_RETRY 10 // Test accept this many times 00129 #define MAX_FIELDS_BEFORE_HASH 32 00130 #define USER_VARS_HASH_SIZE 16 00131 #define STACK_MIN_SIZE 8192 // Abort if less stack during eval. 00132 #define STACK_MIN_SIZE_FOR_OPEN 1024*80 00133 #define STACK_BUFF_ALLOC 256 // For stack overrun checks 00134 #ifndef MYSQLD_NET_RETRY_COUNT 00135 #define MYSQLD_NET_RETRY_COUNT 10 // Abort read after this many int. 00136 #endif 00137 #define TEMP_POOL_SIZE 128 00138 00139 #define QUERY_ALLOC_BLOCK_SIZE 8192 00140 #define QUERY_ALLOC_PREALLOC_SIZE 8192 00141 #define TRANS_ALLOC_BLOCK_SIZE 4096 00142 #define TRANS_ALLOC_PREALLOC_SIZE 4096 00143 #define RANGE_ALLOC_BLOCK_SIZE 2048 00144 #define ACL_ALLOC_BLOCK_SIZE 1024 00145 #define UDF_ALLOC_BLOCK_SIZE 1024 00146 #define TABLE_ALLOC_BLOCK_SIZE 1024 00147 #define BDB_LOG_ALLOC_BLOCK_SIZE 1024 00148 #define WARN_ALLOC_BLOCK_SIZE 2048 00149 #define WARN_ALLOC_PREALLOC_SIZE 1024 00150 00151 /* 00152 The following parameters is to decide when to use an extra cache to 00153 optimise seeks when reading a big table in sorted order 00154 */ 00155 #define MIN_FILE_LENGTH_TO_USE_ROW_CACHE (10L*1024*1024) 00156 #define MIN_ROWS_TO_USE_TABLE_CACHE 100 00157 #define MIN_ROWS_TO_USE_BULK_INSERT 100 00158 00159 /* 00160 The following is used to decide if MySQL should use table scanning 00161 instead of reading with keys. The number says how many evaluation of the 00162 WHERE clause is comparable to reading one extra row from a table. 00163 */ 00164 #define TIME_FOR_COMPARE 5 // 5 compares == one read 00165 00166 /* 00167 Number of comparisons of table rowids equivalent to reading one row from a 00168 table. 00169 */ 00170 #define TIME_FOR_COMPARE_ROWID (TIME_FOR_COMPARE*2) 00171 00172 /* 00173 For sequential disk seeks the cost formula is: 00174 DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST * #blocks_to_skip 00175 00176 The cost of average seek 00177 DISK_SEEK_BASE_COST + DISK_SEEK_PROP_COST*BLOCKS_IN_AVG_SEEK =1.0. 00178 */ 00179 #define DISK_SEEK_BASE_COST ((double)0.5) 00180 00181 #define BLOCKS_IN_AVG_SEEK 128 00182 00183 #define DISK_SEEK_PROP_COST ((double)0.5/BLOCKS_IN_AVG_SEEK) 00184 00185 00186 /* 00187 Number of rows in a reference table when refereed through a not unique key. 00188 This value is only used when we don't know anything about the key 00189 distribution. 00190 */ 00191 #define MATCHING_ROWS_IN_OTHER_TABLE 10 00192 00193 /* Don't pack string keys shorter than this (if PACK_KEYS=1 isn't used) */ 00194 #define KEY_DEFAULT_PACK_LENGTH 8 00195 00196 /* Characters shown for the command in 'show processlist' */ 00197 #define PROCESS_LIST_WIDTH 100 00198 /* Characters shown for the command in 'information_schema.processlist' */ 00199 #define PROCESS_LIST_INFO_WIDTH 65535 00200 00201 /* Time handling defaults */ 00202 #define TIMESTAMP_MAX_YEAR 2038 00203 #define YY_PART_YEAR 70 00204 #define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1) 00205 #define TIMESTAMP_MAX_VALUE 2145916799 00206 #define TIMESTAMP_MIN_VALUE 1 00207 #define PRECISION_FOR_DOUBLE 53 00208 #define PRECISION_FOR_FLOAT 24 00209 00210 /* The following can also be changed from the command line */ 00211 #define CONNECT_TIMEOUT 5 // Do not wait long for connect 00212 #define DEFAULT_CONCURRENCY 10 00213 #define DELAYED_LIMIT 100 /* pause after xxx inserts */ 00214 #define DELAYED_QUEUE_SIZE 1000 00215 #define DELAYED_WAIT_TIMEOUT 5*60 /* Wait for delayed insert */ 00216 #define FLUSH_TIME 0 /* Don't flush tables */ 00217 #define MAX_CONNECT_ERRORS 10 // errors before disabling host 00218 00219 #ifdef __NETWARE__ 00220 #define IF_NETWARE(A,B) (A) 00221 #else 00222 #define IF_NETWARE(A,B) (B) 00223 #endif 00224 00225 #if defined(__WIN__) 00226 #define IF_WIN(A,B) (A) 00227 #undef FLUSH_TIME 00228 #define FLUSH_TIME 1800 /* Flush every half hour */ 00229 00230 #define INTERRUPT_PRIOR -2 00231 #define CONNECT_PRIOR -1 00232 #define WAIT_PRIOR 0 00233 #define QUERY_PRIOR 2 00234 #else 00235 #define IF_WIN(A,B) (B) 00236 #define INTERRUPT_PRIOR 10 00237 #define CONNECT_PRIOR 9 00238 #define WAIT_PRIOR 8 00239 #define QUERY_PRIOR 6 00240 #endif /* __WIN92__ */ 00241 00242 /* Bits from testflag */ 00243 #define TEST_PRINT_CACHED_TABLES 1 00244 #define TEST_NO_KEY_GROUP 2 00245 #define TEST_MIT_THREAD 4 00246 #define TEST_BLOCKING 8 00247 #define TEST_KEEP_TMP_TABLES 16 00248 #define TEST_NO_THREADS 32 /* For debugging under Linux */ 00249 #define TEST_READCHECK 64 /* Force use of readcheck */ 00250 #define TEST_NO_EXTRA 128 00251 #define TEST_CORE_ON_SIGNAL 256 /* Give core if signal */ 00252 #define TEST_NO_STACKTRACE 512 00253 #define TEST_SIGINT 1024 /* Allow sigint on threads */ 00254 #define TEST_SYNCHRONIZATION 2048 /* get server to do sleep in 00255 some places */ 00256 #endif 00257 00258 /* 00259 This is included in the server and in the client. 00260 Options for select set by the yacc parser (stored in lex->options). 00261 00262 XXX: 00263 log_event.h defines OPTIONS_WRITTEN_TO_BIN_LOG to specify what THD 00264 options list are written into binlog. These options can NOT change their 00265 values, or it will break replication between version. 00266 00267 context is encoded as following: 00268 SELECT - SELECT_LEX_NODE::options 00269 THD - THD::options 00270 intern - neither. used only as 00271 func(..., select_node->options | thd->options | OPTION_XXX, ...) 00272 00273 TODO: separate three contexts above, move them to separate bitfields. 00274 */ 00275 00276 #define SELECT_DISTINCT (LL(1) << 0) // SELECT, user 00277 #define SELECT_STRAIGHT_JOIN (LL(1) << 1) // SELECT, user 00278 #define SELECT_DESCRIBE (LL(1) << 2) // SELECT, user 00279 #define SELECT_SMALL_RESULT (LL(1) << 3) // SELECT, user 00280 #define SELECT_BIG_RESULT (LL(1) << 4) // SELECT, user 00281 #define OPTION_FOUND_ROWS (LL(1) << 5) // SELECT, user 00282 #define OPTION_TO_QUERY_CACHE (LL(1) << 6) // SELECT, user 00283 #define SELECT_NO_JOIN_CACHE (LL(1) << 7) // intern 00284 #define OPTION_BIG_TABLES (LL(1) << 8) // THD, user 00285 #define OPTION_BIG_SELECTS (LL(1) << 9) // THD, user 00286 #define OPTION_LOG_OFF (LL(1) << 10) // THD, user 00287 #define OPTION_QUOTE_SHOW_CREATE (LL(1) << 11) // THD, user 00288 #define TMP_TABLE_ALL_COLUMNS (LL(1) << 12) // SELECT, intern 00289 #define OPTION_WARNINGS (LL(1) << 13) // THD, user 00290 #define OPTION_AUTO_IS_NULL (LL(1) << 14) // THD, user, binlog 00291 #define OPTION_FOUND_COMMENT (LL(1) << 15) // SELECT, intern, parser 00292 #define OPTION_SAFE_UPDATES (LL(1) << 16) // THD, user 00293 #define OPTION_BUFFER_RESULT (LL(1) << 17) // SELECT, user 00294 #define OPTION_BIN_LOG (LL(1) << 18) // THD, user 00295 #define OPTION_NOT_AUTOCOMMIT (LL(1) << 19) // THD, user 00296 #define OPTION_BEGIN (LL(1) << 20) // THD, intern 00297 #define OPTION_TABLE_LOCK (LL(1) << 21) // THD, intern 00298 #define OPTION_QUICK (LL(1) << 22) // SELECT (for DELETE) 00299 #define OPTION_KEEP_LOG (LL(1) << 23) // Keep binlog on rollback 00300 00301 /* The following is used to detect a conflict with DISTINCT */ 00302 #define SELECT_ALL (LL(1) << 24) // SELECT, user, parser 00303 00304 /* Set if we are updating a non-transaction safe table */ 00305 #define OPTION_STATUS_NO_TRANS_UPDATE (LL(1) << 25) // THD, intern 00306 00307 /* The following can be set when importing tables in a 'wrong order' 00308 to suppress foreign key checks */ 00309 #define OPTION_NO_FOREIGN_KEY_CHECKS (LL(1) << 26) // THD, user, binlog 00310 /* The following speeds up inserts to InnoDB tables by suppressing unique 00311 key checks in some cases */ 00312 #define OPTION_RELAXED_UNIQUE_CHECKS (LL(1) << 27) // THD, user, binlog 00313 #define SELECT_NO_UNLOCK (LL(1) << 28) // SELECT, intern 00314 #define OPTION_SCHEMA_TABLE (LL(1) << 29) // SELECT, intern 00315 /* Flag set if setup_tables already done */ 00316 #define OPTION_SETUP_TABLES_DONE (LL(1) << 30) // intern 00317 /* If not set then the thread will ignore all warnings with level notes. */ 00318 #define OPTION_SQL_NOTES (LL(1) << 31) // THD, user 00319 /* 00320 Force the used temporary table to be a MyISAM table (because we will use 00321 fulltext functions when reading from it. 00322 */ 00323 #define TMP_TABLE_FORCE_MYISAM (LL(1) << 32) 00324 00325 /* 00326 Maximum length of time zone name that we support 00327 (Time zone name is char(64) in db). mysqlbinlog needs it. 00328 */ 00329 #define MAX_TIME_ZONE_NAME_LENGTH 72 00330 00331 /* The rest of the file is included in the server only */ 00332 #ifndef MYSQL_CLIENT 00333 00334 /* Bits for different SQL modes modes (including ANSI mode) */ 00335 #define MODE_REAL_AS_FLOAT 1 00336 #define MODE_PIPES_AS_CONCAT 2 00337 #define MODE_ANSI_QUOTES 4 00338 #define MODE_IGNORE_SPACE 8 00339 #define MODE_NOT_USED 16 00340 #define MODE_ONLY_FULL_GROUP_BY 32 00341 #define MODE_NO_UNSIGNED_SUBTRACTION 64 00342 #define MODE_NO_DIR_IN_CREATE 128 00343 #define MODE_POSTGRESQL 256 00344 #define MODE_ORACLE 512 00345 #define MODE_MSSQL 1024 00346 #define MODE_DB2 2048 00347 #define MODE_MAXDB 4096 00348 #define MODE_NO_KEY_OPTIONS 8192 00349 #define MODE_NO_TABLE_OPTIONS 16384 00350 #define MODE_NO_FIELD_OPTIONS 32768 00351 #define MODE_MYSQL323 65536 00352 #define MODE_MYSQL40 (MODE_MYSQL323*2) 00353 #define MODE_ANSI (MODE_MYSQL40*2) 00354 #define MODE_NO_AUTO_VALUE_ON_ZERO (MODE_ANSI*2) 00355 #define MODE_NO_BACKSLASH_ESCAPES (MODE_NO_AUTO_VALUE_ON_ZERO*2) 00356 #define MODE_STRICT_TRANS_TABLES (MODE_NO_BACKSLASH_ESCAPES*2) 00357 #define MODE_STRICT_ALL_TABLES (MODE_STRICT_TRANS_TABLES*2) 00358 #define MODE_NO_ZERO_IN_DATE (MODE_STRICT_ALL_TABLES*2) 00359 #define MODE_NO_ZERO_DATE (MODE_NO_ZERO_IN_DATE*2) 00360 #define MODE_INVALID_DATES (MODE_NO_ZERO_DATE*2) 00361 #define MODE_ERROR_FOR_DIVISION_BY_ZERO (MODE_INVALID_DATES*2) 00362 #define MODE_TRADITIONAL (MODE_ERROR_FOR_DIVISION_BY_ZERO*2) 00363 #define MODE_NO_AUTO_CREATE_USER (MODE_TRADITIONAL*2) 00364 #define MODE_HIGH_NOT_PRECEDENCE (MODE_NO_AUTO_CREATE_USER*2) 00365 #define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2) 00366 /* 00367 Replication uses 8 bytes to store SQL_MODE in the binary log. The day you 00368 use strictly more than 64 bits by adding one more define above, you should 00369 contact the replication team because the replication code should then be 00370 updated (to store more bytes on disk). 00371 00372 NOTE: When adding new SQL_MODE types, make sure to also add them to 00373 ../scripts/mysql_create_system_tables.sh and 00374 ../scripts/mysql_fix_privilege_tables.sql 00375 */ 00376 00377 #define RAID_BLOCK_SIZE 1024 00378 00379 #define MY_CHARSET_BIN_MB_MAXLEN 1 00380 00381 // uncachable cause 00382 #define UNCACHEABLE_DEPENDENT 1 00383 #define UNCACHEABLE_RAND 2 00384 #define UNCACHEABLE_SIDEEFFECT 4 00385 // forcing to save JOIN for explain 00386 #define UNCACHEABLE_EXPLAIN 8 00387 /* Don't evaluate subqueries in prepare even if they're not correlated */ 00388 #define UNCACHEABLE_PREPARE 16 00389 00390 #ifdef EXTRA_DEBUG 00391 /* 00392 Sync points allow us to force the server to reach a certain line of code 00393 and block there until the client tells the server it is ok to go on. 00394 The client tells the server to block with SELECT GET_LOCK() 00395 and unblocks it with SELECT RELEASE_LOCK(). Used for debugging difficult 00396 concurrency problems 00397 */ 00398 #define DBUG_SYNC_POINT(lock_name,lock_timeout) \ 00399 debug_sync_point(lock_name,lock_timeout) 00400 void debug_sync_point(const char* lock_name, uint lock_timeout); 00401 #else 00402 #define DBUG_SYNC_POINT(lock_name,lock_timeout) 00403 #endif /* EXTRA_DEBUG */ 00404 00405 /* BINLOG_DUMP options */ 00406 00407 #define BINLOG_DUMP_NON_BLOCK 1 00408 00409 /* sql_show.cc:show_log_files() */ 00410 #define SHOW_LOG_STATUS_FREE "FREE" 00411 #define SHOW_LOG_STATUS_INUSE "IN USE" 00412 00413 struct st_table_list; 00414 class String; 00415 void view_store_options(THD *thd, st_table_list *table, String *buff); 00416 00417 /* Options to add_table_to_list() */ 00418 #define TL_OPTION_UPDATING 1 00419 #define TL_OPTION_FORCE_INDEX 2 00420 #define TL_OPTION_IGNORE_LEAVES 4 00421 00422 /* Some portable defines */ 00423 00424 #define portable_sizeof_char_ptr 8 00425 00426 #define tmp_file_prefix "#sql" /* Prefix for tmp tables */ 00427 #define tmp_file_prefix_length 4 00428 00429 /* Flags for calc_week() function. */ 00430 #define WEEK_MONDAY_FIRST 1 00431 #define WEEK_YEAR 2 00432 #define WEEK_FIRST_WEEKDAY 4 00433 00434 #define STRING_BUFFER_USUAL_SIZE 80 00435 00436 /* 00437 Some defines for exit codes for ::is_equal class functions. 00438 */ 00439 #define IS_EQUAL_NO 0 00440 #define IS_EQUAL_YES 1 00441 #define IS_EQUAL_PACK_LENGTH 2 00442 00443 enum enum_parsing_place 00444 { 00445 NO_MATTER, 00446 IN_HAVING, 00447 SELECT_LIST, 00448 IN_WHERE 00449 }; 00450 00451 struct st_table; 00452 class THD; 00453 00454 /* Struct to handle simple linked lists */ 00455 00456 typedef struct st_sql_list { 00457 uint elements; 00458 byte *first; 00459 byte **next; 00460 00461 st_sql_list() {} /* Remove gcc warning */ 00462 inline void empty() 00463 { 00464 elements=0; 00465 first=0; 00466 next= &first; 00467 } 00468 inline void link_in_list(byte *element,byte **next_ptr) 00469 { 00470 elements++; 00471 (*next)=element; 00472 next= next_ptr; 00473 *next=0; 00474 } 00475 inline void save_and_clear(struct st_sql_list *save) 00476 { 00477 *save= *this; 00478 empty(); 00479 } 00480 inline void push_front(struct st_sql_list *save) 00481 { 00482 *save->next= first; /* link current list last */ 00483 first= save->first; 00484 elements+= save->elements; 00485 } 00486 inline void push_back(struct st_sql_list *save) 00487 { 00488 if (save->first) 00489 { 00490 *next= save->first; 00491 next= save->next; 00492 elements+= save->elements; 00493 } 00494 } 00495 } SQL_LIST; 00496 00497 00498 extern pthread_key(THD*, THR_THD); 00499 inline THD *_current_thd(void) 00500 { 00501 return my_pthread_getspecific_ptr(THD*,THR_THD); 00502 } 00503 #define current_thd _current_thd() 00504 00505 /* below functions are required for plugins as THD class is opaque */ 00506 my_bool thd_in_lock_tables(const THD *thd); 00507 my_bool thd_tablespace_op(const THD *thd); 00508 const char *thd_proc_info(THD *thd, const char *info); 00509 void **thd_ha_data(const THD *thd, const struct handlerton *hton); 00510 00511 /* 00512 External variables 00513 */ 00514 extern ulong server_id, concurrency; 00515 00516 00517 typedef my_bool (*qc_engine_callback)(THD *thd, char *table_key, 00518 uint key_length, 00519 ulonglong *engine_data); 00520 #include "sql_string.h" 00521 #include "sql_list.h" 00522 #include "sql_map.h" 00523 #include "my_decimal.h" 00524 #include "sql_plugin.h" 00525 #include "handler.h" 00526 #include "parse_file.h" 00527 #include "table.h" 00528 #include "sql_error.h" 00529 #include "field.h" /* Field definitions */ 00530 #include "protocol.h" 00531 #include "sql_udf.h" 00532 #include "sql_partition.h" 00533 00534 class user_var_entry; 00535 class Security_context; 00536 enum enum_var_type 00537 { 00538 OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL 00539 }; 00540 class sys_var; 00541 #ifdef MYSQL_SERVER 00542 class Comp_creator; 00543 typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); 00544 #endif 00545 #include "item.h" 00546 extern my_decimal decimal_zero; 00547 00548 /* sql_parse.cc */ 00549 void free_items(Item *item); 00550 void cleanup_items(Item *item); 00551 class THD; 00552 void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0); 00553 bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables); 00554 bool check_single_table_access(THD *thd, ulong privilege, 00555 TABLE_LIST *tables); 00556 bool check_routine_access(THD *thd,ulong want_access,char *db,char *name, 00557 bool is_proc, bool no_errors); 00558 bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table); 00559 bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list); 00560 bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc); 00561 bool multi_update_precheck(THD *thd, TABLE_LIST *tables); 00562 bool multi_delete_precheck(THD *thd, TABLE_LIST *tables); 00563 bool mysql_multi_update_prepare(THD *thd); 00564 bool mysql_multi_delete_prepare(THD *thd); 00565 bool mysql_insert_select_prepare(THD *thd); 00566 bool update_precheck(THD *thd, TABLE_LIST *tables); 00567 bool delete_precheck(THD *thd, TABLE_LIST *tables); 00568 bool insert_precheck(THD *thd, TABLE_LIST *tables); 00569 bool create_table_precheck(THD *thd, TABLE_LIST *tables, 00570 TABLE_LIST *create_table); 00571 int append_query_string(CHARSET_INFO *csinfo, 00572 String const *from, String *to); 00573 00574 void get_default_definer(THD *thd, LEX_USER *definer); 00575 LEX_USER *create_default_definer(THD *thd); 00576 LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name); 00577 LEX_USER *get_current_user(THD *thd, LEX_USER *user); 00578 00579 enum enum_mysql_completiontype { 00580 ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7, 00581 COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6 00582 }; 00583 00584 bool begin_trans(THD *thd); 00585 bool end_active_trans(THD *thd); 00586 int end_trans(THD *thd, enum enum_mysql_completiontype completion); 00587 00588 Item *negate_expression(THD *thd, Item *expr); 00589 #include "sql_class.h" 00590 #include "sql_acl.h" 00591 #include "tztime.h" 00592 #ifdef MYSQL_SERVER 00593 #include "opt_range.h" 00594 00595 #ifdef HAVE_QUERY_CACHE 00596 struct Query_cache_query_flags 00597 { 00598 unsigned int client_long_flag:1; 00599 unsigned int client_protocol_41:1; 00600 unsigned int more_results_exists:1; 00601 unsigned int pkt_nr; 00602 uint character_set_client_num; 00603 uint character_set_results_num; 00604 uint collation_connection_num; 00605 ha_rows limit; 00606 Time_zone *time_zone; 00607 ulong sql_mode; 00608 ulong max_sort_length; 00609 ulong group_concat_max_len; 00610 MY_LOCALE *lc_time_names; 00611 }; 00612 #define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags) 00613 #include "sql_cache.h" 00614 #define query_cache_store_query(A, B) query_cache.store_query(A, B) 00615 #define query_cache_destroy() query_cache.destroy() 00616 #define query_cache_result_size_limit(A) query_cache.result_size_limit(A) 00617 #define query_cache_init() query_cache.init() 00618 #define query_cache_resize(A) query_cache.resize(A) 00619 #define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A) 00620 #define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C) 00621 #define query_cache_invalidate1(A) query_cache.invalidate(A) 00622 #define query_cache_send_result_to_client(A, B, C) \ 00623 query_cache.send_result_to_client(A, B, C) 00624 #define query_cache_invalidate_by_MyISAM_filename_ref \ 00625 &query_cache_invalidate_by_MyISAM_filename 00626 #else 00627 #define QUERY_CACHE_FLAGS_SIZE 0 00628 #define query_cache_store_query(A, B) 00629 #define query_cache_destroy() 00630 #define query_cache_result_size_limit(A) 00631 #define query_cache_init() 00632 #define query_cache_resize(A) 00633 #define query_cache_set_min_res_unit(A) 00634 #define query_cache_invalidate3(A, B, C) 00635 #define query_cache_invalidate1(A) 00636 #define query_cache_send_result_to_client(A, B, C) 0 00637 #define query_cache_invalidate_by_MyISAM_filename_ref NULL 00638 00639 #define query_cache_abort(A) 00640 #define query_cache_end_of_result(A) 00641 #define query_cache_invalidate_by_MyISAM_filename_ref NULL 00642 #endif /*HAVE_QUERY_CACHE*/ 00643 00644 /* 00645 Error injector Macros to enable easy testing of recovery after failures 00646 in various error cases. 00647 */ 00648 #ifndef ERROR_INJECT_SUPPORT 00649 00650 #define ERROR_INJECT(x) 0 00651 #define ERROR_INJECT_ACTION(x,action) 0 00652 #define ERROR_INJECT_CRASH(x) 0 00653 #define ERROR_INJECT_VALUE(x) 0 00654 #define ERROR_INJECT_VALUE_ACTION(x,action) 0 00655 #define ERROR_INJECT_VALUE_CRASH(x) 0 00656 #define SET_ERROR_INJECT_VALUE(x) 00657 00658 #else 00659 00660 inline bool check_and_unset_keyword(const char *dbug_str) 00661 { 00662 const char *extra_str= "-d,"; 00663 char total_str[200]; 00664 if (_db_strict_keyword_ (dbug_str)) 00665 { 00666 strxmov(total_str, extra_str, dbug_str, NullS); 00667 DBUG_SET(total_str); 00668 return 1; 00669 } 00670 return 0; 00671 } 00672 00673 00674 inline bool 00675 check_and_unset_inject_value(int value) 00676 { 00677 THD *thd= current_thd; 00678 if (thd->error_inject_value == (uint)value) 00679 { 00680 thd->error_inject_value= 0; 00681 return 1; 00682 } 00683 return 0; 00684 } 00685 00686 /* 00687 ERROR INJECT MODULE: 00688 -------------------- 00689 These macros are used to insert macros from the application code. 00690 The event that activates those error injections can be activated 00691 from SQL by using: 00692 SET SESSION dbug=+d,code; 00693 00694 After the error has been injected, the macros will automatically 00695 remove the debug code, thus similar to using: 00696 SET SESSION dbug=-d,code 00697 from SQL. 00698 00699 ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code 00700 is set when macro is called. ERROR_INJECT_CRASH can be used in 00701 if-statements, it will always return FALSE unless of course it 00702 crashes in which case it doesn't return at all. 00703 00704 ERROR_INJECT_ACTION will inject the action specified in the action 00705 parameter of the macro, before performing the action the code will 00706 be removed such that no more events occur. ERROR_INJECT_ACTION 00707 can also be used in if-statements and always returns FALSE. 00708 ERROR_INJECT can be used in a normal if-statement, where the action 00709 part is performed in the if-block. The macro returns TRUE if the 00710 error was activated and otherwise returns FALSE. If activated the 00711 code is removed. 00712 00713 Sometimes it is necessary to perform error inject actions as a serie 00714 of events. In this case one can use one variable on the THD object. 00715 Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100). 00716 Then one can later test for it by using ERROR_INJECT_CRASH_VALUE, 00717 ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same 00718 behaviour as the above described macros except that they use the 00719 error inject value instead of a code used by DBUG macros. 00720 */ 00721 #define SET_ERROR_INJECT_VALUE(x) \ 00722 current_thd->error_inject_value= (x) 00723 #define ERROR_INJECT_CRASH(code) \ 00724 DBUG_EVALUATE_IF(code, (abort(), 0), 0) 00725 #define ERROR_INJECT_ACTION(code, action) \ 00726 (check_and_unset_keyword(code) ? ((action), 0) : 0) 00727 #define ERROR_INJECT(code) \ 00728 check_and_unset_keyword(code) 00729 #define ERROR_INJECT_VALUE(value) \ 00730 check_and_unset_inject_value(value) 00731 #define ERROR_INJECT_VALUE_ACTION(value,action) \ 00732 (check_and_unset_inject_value(value) ? (action) : 0) 00733 #define ERROR_INJECT_VALUE_CRASH(value) \ 00734 ERROR_INJECT_VALUE_ACTION(value, (abort(), 0)) 00735 00736 #endif 00737 00738 uint build_table_path(char *buff, size_t bufflen, const char *db, 00739 const char *table, const char *ext); 00740 void write_bin_log(THD *thd, bool clear_error, 00741 char const *query, ulong query_length); 00742 00743 bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); 00744 bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); 00745 bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent); 00746 bool mysql_rename_db(THD *thd, LEX_STRING *old_db, LEX_STRING *new_db); 00747 void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags); 00748 void mysql_client_binlog_statement(THD *thd); 00749 bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists, 00750 my_bool drop_temporary); 00751 int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, 00752 bool drop_temporary, bool drop_view, bool log_query); 00753 int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables, 00754 bool if_exists, bool drop_temporary, 00755 bool log_query); 00756 bool quick_rm_table(handlerton *base,const char *db, 00757 const char *table_name, uint flags); 00758 void close_cached_table(THD *thd, TABLE *table); 00759 bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent); 00760 bool mysql_change_db(THD *thd,const char *name,bool no_access_check); 00761 void mysql_parse(THD *thd,char *inBuf,uint length); 00762 bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length); 00763 bool is_update_query(enum enum_sql_command command); 00764 bool alloc_query(THD *thd, const char *packet, uint packet_length); 00765 void mysql_init_select(LEX *lex); 00766 void mysql_reset_thd_for_next_command(THD *thd); 00767 void mysql_init_query(THD *thd, uchar *buf, uint length); 00768 bool mysql_new_select(LEX *lex, bool move_down); 00769 void create_select_for_variable(const char *var_name); 00770 void mysql_init_multi_delete(LEX *lex); 00771 bool multi_delete_set_locks_and_link_aux_tables(LEX *lex); 00772 void init_max_user_conn(void); 00773 void init_update_queries(void); 00774 void free_max_user_conn(void); 00775 pthread_handler_t handle_one_connection(void *arg); 00776 pthread_handler_t handle_bootstrap(void *arg); 00777 void end_thread(THD *thd,bool put_in_cache); 00778 void flush_thread_cache(); 00779 bool mysql_execute_command(THD *thd); 00780 bool do_command(THD *thd); 00781 bool dispatch_command(enum enum_server_command command, THD *thd, 00782 char* packet, uint packet_length); 00783 void log_slow_statement(THD *thd); 00784 bool check_dup(const char *db, const char *name

