The world's most popular open source database
00001 /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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 /* Classes in mysql */ 00019 00020 #ifdef USE_PRAGMA_INTERFACE 00021 #pragma interface /* gcc class implementation */ 00022 #endif 00023 00024 #include "log.h" 00025 #include "rpl_rli.h" 00026 #include "rpl_tblmap.h" 00027 00028 class Query_log_event; 00029 class Load_log_event; 00030 class Slave_log_event; 00031 class sp_rcontext; 00032 class sp_cache; 00033 class Rows_log_event; 00034 00035 enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE }; 00036 enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME }; 00037 enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE }; 00038 enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON, 00039 DELAY_KEY_WRITE_ALL }; 00040 enum enum_check_fields 00041 { CHECK_FIELD_IGNORE, CHECK_FIELD_WARN, CHECK_FIELD_ERROR_FOR_NULL }; 00042 enum enum_mark_columns 00043 { MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE}; 00044 00045 extern char internal_table_name[2]; 00046 extern char empty_c_string[1]; 00047 extern const char **errmesg; 00048 00049 #define TC_LOG_PAGE_SIZE 8192 00050 #define TC_LOG_MIN_SIZE (3*TC_LOG_PAGE_SIZE) 00051 00052 #define TC_HEURISTIC_RECOVER_COMMIT 1 00053 #define TC_HEURISTIC_RECOVER_ROLLBACK 2 00054 extern uint tc_heuristic_recover; 00055 00056 typedef struct st_user_var_events 00057 { 00058 user_var_entry *user_var_event; 00059 char *value; 00060 ulong length; 00061 Item_result type; 00062 uint charset_number; 00063 } BINLOG_USER_VAR_EVENT; 00064 00065 #define RP_LOCK_LOG_IS_ALREADY_LOCKED 1 00066 #define RP_FORCE_ROTATE 2 00067 00068 typedef struct st_copy_info { 00069 ha_rows records; 00070 ha_rows deleted; 00071 ha_rows updated; 00072 ha_rows copied; 00073 ha_rows error_count; 00074 enum enum_duplicates handle_duplicates; 00075 int escape_char, last_errno; 00076 bool ignore; 00077 /* for INSERT ... UPDATE */ 00078 List<Item> *update_fields; 00079 List<Item> *update_values; 00080 /* for VIEW ... WITH CHECK OPTION */ 00081 TABLE_LIST *view; 00082 } COPY_INFO; 00083 00084 00085 class key_part_spec :public Sql_alloc { 00086 public: 00087 const char *field_name; 00088 uint length; 00089 key_part_spec(const char *name,uint len=0) :field_name(name), length(len) {} 00090 bool operator==(const key_part_spec& other) const; 00091 }; 00092 00093 00094 class Alter_drop :public Sql_alloc { 00095 public: 00096 enum drop_type {KEY, COLUMN }; 00097 const char *name; 00098 enum drop_type type; 00099 Alter_drop(enum drop_type par_type,const char *par_name) 00100 :name(par_name), type(par_type) {} 00101 }; 00102 00103 00104 class Alter_column :public Sql_alloc { 00105 public: 00106 const char *name; 00107 Item *def; 00108 Alter_column(const char *par_name,Item *literal) 00109 :name(par_name), def(literal) {} 00110 }; 00111 00112 00113 class Key :public Sql_alloc { 00114 public: 00115 enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FULLTEXT, SPATIAL, FOREIGN_KEY}; 00116 enum Keytype type; 00117 KEY_CREATE_INFO key_create_info; 00118 List<key_part_spec> columns; 00119 const char *name; 00120 bool generated; 00121 00122 Key(enum Keytype type_par, const char *name_arg, 00123 KEY_CREATE_INFO *key_info_arg, 00124 bool generated_arg, List<key_part_spec> &cols) 00125 :type(type_par), key_create_info(*key_info_arg), columns(cols), 00126 name(name_arg), generated(generated_arg) 00127 {} 00128 ~Key() {} 00129 /* Equality comparison of keys (ignoring name) */ 00130 friend bool foreign_key_prefix(Key *a, Key *b); 00131 }; 00132 00133 class Table_ident; 00134 00135 class foreign_key: public Key { 00136 public: 00137 enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL, 00138 FK_MATCH_PARTIAL, FK_MATCH_SIMPLE}; 00139 enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE, 00140 FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT}; 00141 00142 Table_ident *ref_table; 00143 List<key_part_spec> ref_columns; 00144 uint delete_opt, update_opt, match_opt; 00145 foreign_key(const char *name_arg, List<key_part_spec> &cols, 00146 Table_ident *table, List<key_part_spec> &ref_cols, 00147 uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg) 00148 :Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols), 00149 ref_table(table), ref_columns(cols), 00150 delete_opt(delete_opt_arg), update_opt(update_opt_arg), 00151 match_opt(match_opt_arg) 00152 {} 00153 }; 00154 00155 typedef struct st_mysql_lock 00156 { 00157 TABLE **table; 00158 uint table_count,lock_count; 00159 THR_LOCK_DATA **locks; 00160 } MYSQL_LOCK; 00161 00162 00163 class LEX_COLUMN : public Sql_alloc 00164 { 00165 public: 00166 String column; 00167 uint rights; 00168 LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {} 00169 }; 00170 00171 #include "sql_lex.h" /* Must be here */ 00172 00173 class delayed_insert; 00174 class select_result; 00175 class Time_zone; 00176 00177 #define THD_SENTRY_MAGIC 0xfeedd1ff 00178 #define THD_SENTRY_GONE 0xdeadbeef 00179 00180 #define THD_CHECK_SENTRY(thd) DBUG_ASSERT(thd->dbug_sentry == THD_SENTRY_MAGIC) 00181 00182 struct system_variables 00183 { 00184 ulonglong myisam_max_extra_sort_file_size; 00185 ulonglong myisam_max_sort_file_size; 00186 ha_rows select_limit; 00187 ha_rows max_join_size; 00188 ulong auto_increment_increment, auto_increment_offset; 00189 ulong bulk_insert_buff_size; 00190 ulong join_buff_size; 00191 ulong long_query_time; 00192 ulong max_allowed_packet; 00193 ulong max_error_count; 00194 ulong max_heap_table_size; 00195 ulong max_length_for_sort_data; 00196 ulong max_sort_length; 00197 ulong max_tmp_tables; 00198 ulong max_insert_delayed_threads; 00199 ulong multi_range_count; 00200 ulong myisam_repair_threads; 00201 ulong myisam_sort_buff_size; 00202 ulong myisam_stats_method; 00203 ulong net_buffer_length; 00204 ulong net_interactive_timeout; 00205 ulong net_read_timeout; 00206 ulong net_retry_count; 00207 ulong net_wait_timeout; 00208 ulong net_write_timeout; 00209 ulong optimizer_prune_level; 00210 ulong optimizer_search_depth; 00211 ulong preload_buff_size; 00212 ulong query_cache_type; 00213 ulong read_buff_size; 00214 ulong read_rnd_buff_size; 00215 ulong div_precincrement; 00216 ulong sortbuff_size; 00217 handlerton *table_type; 00218 ulong tmp_table_size; 00219 ulong tx_isolation; 00220 ulong completion_type; 00221 /* Determines which non-standard SQL behaviour should be enabled */ 00222 ulong sql_mode; 00223 ulong max_sp_recursion_depth; 00224 /* check of key presence in updatable view */ 00225 ulong updatable_views_with_limit; 00226 ulong default_week_format; 00227 ulong max_seeks_for_key; 00228 ulong range_alloc_block_size; 00229 ulong query_alloc_block_size; 00230 ulong query_prealloc_size; 00231 ulong trans_alloc_block_size; 00232 ulong trans_prealloc_size; 00233 ulong log_warnings; 00234 ulong group_concat_max_len; 00235 /* 00236 In slave thread we need to know in behalf of which 00237 thread the query is being run to replicate temp tables properly 00238 */ 00239 ulong pseudo_thread_id; 00240 00241 my_bool low_priority_updates; 00242 my_bool new_mode; 00243 my_bool query_cache_wlock_invalidate; 00244 my_bool engine_condition_pushdown; 00245 my_bool innodb_table_locks; 00246 my_bool innodb_support_xa; 00247 my_bool ndb_force_send; 00248 my_bool ndb_use_copying_alter_table; 00249 my_bool ndb_use_exact_count; 00250 my_bool ndb_use_transactions; 00251 my_bool ndb_index_stat_enable; 00252 ulong ndb_autoincrement_prefetch_sz; 00253 ulong ndb_index_stat_cache_entries; 00254 ulong ndb_index_stat_update_freq; 00255 ulong binlog_format; // binlog format for this thd (see enum_binlog_format) 00256 00257 my_bool old_alter_table; 00258 my_bool old_passwords; 00259 00260 /* Only charset part of these variables is sensible */ 00261 CHARSET_INFO *character_set_filesystem; 00262 CHARSET_INFO *character_set_client; 00263 CHARSET_INFO *character_set_results; 00264 00265 /* Both charset and collation parts of these variables are important */ 00266 CHARSET_INFO *collation_server; 00267 CHARSET_INFO *collation_database; 00268 CHARSET_INFO *collation_connection; 00269 00270 /* Locale Support */ 00271 MY_LOCALE *lc_time_names; 00272 00273 Time_zone *time_zone; 00274 00275 /* DATE, DATETIME and TIME formats */ 00276 DATE_TIME_FORMAT *date_format; 00277 DATE_TIME_FORMAT *datetime_format; 00278 DATE_TIME_FORMAT *time_format; 00279 my_bool sysdate_is_now; 00280 }; 00281 00282 00283 /* per thread status variables */ 00284 00285 typedef struct system_status_var 00286 { 00287 ulong bytes_received; 00288 ulong bytes_sent; 00289 ulong com_other; 00290 ulong com_stat[(uint) SQLCOM_END]; 00291 ulong created_tmp_disk_tables; 00292 ulong created_tmp_tables; 00293 ulong ha_commit_count; 00294 ulong ha_delete_count; 00295 ulong ha_read_first_count; 00296 ulong ha_read_last_count; 00297 ulong ha_read_key_count; 00298 ulong ha_read_next_count; 00299 ulong ha_read_prev_count; 00300 ulong ha_read_rnd_count; 00301 ulong ha_read_rnd_next_count; 00302 ulong ha_rollback_count; 00303 ulong ha_update_count; 00304 ulong ha_write_count; 00305 ulong ha_prepare_count; 00306 ulong ha_discover_count; 00307 ulong ha_savepoint_count; 00308 ulong ha_savepoint_rollback_count; 00309 00310 /* KEY_CACHE parts. These are copies of the original */ 00311 ulong key_blocks_changed; 00312 ulong key_blocks_used; 00313 ulong key_cache_r_requests; 00314 ulong key_cache_read; 00315 ulong key_cache_w_requests; 00316 ulong key_cache_write; 00317 /* END OF KEY_CACHE parts */ 00318 00319 ulong net_big_packet_count; 00320 ulong opened_tables; 00321 ulong opened_shares; 00322 ulong select_full_join_count; 00323 ulong select_full_range_join_count; 00324 ulong select_range_count; 00325 ulong select_range_check_count; 00326 ulong select_scan_count; 00327 ulong long_query_count; 00328 ulong filesort_merge_passes; 00329 ulong filesort_range_count; 00330 ulong filesort_rows; 00331 ulong filesort_scan_count; 00332 /* Prepared statements and binary protocol */ 00333 ulong com_stmt_prepare; 00334 ulong com_stmt_execute; 00335 ulong com_stmt_send_long_data; 00336 ulong com_stmt_fetch; 00337 ulong com_stmt_reset; 00338 ulong com_stmt_close; 00339 00340 double last_query_cost; 00341 } STATUS_VAR; 00342 00343 /* 00344 This is used for 'show status'. It must be updated to the last ulong 00345 variable in system_status_var 00346 */ 00347 00348 #define last_system_status_var com_stmt_close 00349 00350 #ifdef MYSQL_SERVER 00351 00352 void free_tmp_table(THD *thd, TABLE *entry); 00353 00354 00355 /* The following macro is to make init of Query_arena simpler */ 00356 #ifndef DBUG_OFF 00357 #define INIT_ARENA_DBUG_INFO is_backup_arena= 0 00358 #else 00359 #define INIT_ARENA_DBUG_INFO 00360 #endif 00361 00362 class Query_arena 00363 { 00364 public: 00365 /* 00366 List of items created in the parser for this query. Every item puts 00367 itself to the list on creation (see Item::Item() for details)) 00368 */ 00369 Item *free_list; 00370 MEM_ROOT *mem_root; // Pointer to current memroot 00371 #ifndef DBUG_OFF 00372 bool is_backup_arena; /* True if this arena is used for backup. */ 00373 #endif 00374 enum enum_state 00375 { 00376 INITIALIZED= 0, INITIALIZED_FOR_SP= 1, PREPARED= 2, 00377 CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1 00378 }; 00379 00380 enum_state state; 00381 00382 /* We build without RTTI, so dynamic_cast can't be used. */ 00383 enum Type 00384 { 00385 STATEMENT, PREPARED_STATEMENT, STORED_PROCEDURE 00386 }; 00387 00388 Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) : 00389 free_list(0), mem_root(mem_root_arg), state(state_arg) 00390 { INIT_ARENA_DBUG_INFO; } 00391 /* 00392 This constructor is used only when Query_arena is created as 00393 backup storage for another instance of Query_arena. 00394 */ 00395 Query_arena() { INIT_ARENA_DBUG_INFO; } 00396 00397 virtual Type type() const; 00398 virtual ~Query_arena() {}; 00399 00400 inline bool is_stmt_prepare() const { return state == INITIALIZED; } 00401 inline bool is_first_sp_execute() const 00402 { return state == INITIALIZED_FOR_SP; } 00403 inline bool is_stmt_prepare_or_first_sp_execute() const 00404 { return (int)state < (int)PREPARED; } 00405 inline bool is_first_stmt_execute() const { return state == PREPARED; } 00406 inline bool is_stmt_execute() const 00407 { return state == PREPARED || state == EXECUTED; } 00408 inline bool is_conventional() const 00409 { return state == CONVENTIONAL_EXECUTION; } 00410 00411 inline gptr alloc(unsigned int size) { return alloc_root(mem_root,size); } 00412 inline gptr calloc(unsigned int size) 00413 { 00414 gptr ptr; 00415 if ((ptr=alloc_root(mem_root,size))) 00416 bzero((char*) ptr,size); 00417 return ptr; 00418 } 00419 inline char *strdup(const char *str) 00420 { return strdup_root(mem_root,str); } 00421 inline char *strmake(const char *str, uint size) 00422 { return strmake_root(mem_root,str,size); } 00423 inline char *memdup(const char *str, uint size) 00424 { return memdup_root(mem_root,str,size); } 00425 inline char *memdup_w_gap(const char *str, uint size, uint gap) 00426 { 00427 gptr ptr; 00428 if ((ptr=alloc_root(mem_root,size+gap))) 00429 memcpy(ptr,str,size); 00430 return ptr; 00431 } 00432 00433 void set_query_arena(Query_arena *set); 00434 00435 void free_items(); 00436 /* Close the active state associated with execution of this statement */ 00437 virtual void cleanup_stmt(); 00438 }; 00439 00440 00441 class Server_side_cursor; 00442 00443 /* 00444 State of a single command executed against this connection. 00445 One connection can contain a lot of simultaneously running statements, 00446 some of which could be: 00447 - prepared, that is, contain placeholders, 00448 - opened as cursors. We maintain 1 to 1 relationship between 00449 statement and cursor - if user wants to create another cursor for his 00450 query, we create another statement for it. 00451 To perform some action with statement we reset THD part to the state of 00452 that statement, do the action, and then save back modified state from THD 00453 to the statement. It will be changed in near future, and Statement will 00454 be used explicitly. 00455 */ 00456 00457 class Statement: public ilink, public Query_arena 00458 { 00459 Statement(const Statement &rhs); /* not implemented: */ 00460 Statement &operator=(const Statement &rhs); /* non-copyable */ 00461 public: 00462 /* FIXME: these must be protected */ 00463 MEM_ROOT main_mem_root; 00464 LEX main_lex; 00465 00466 /* 00467 Uniquely identifies each statement object in thread scope; change during 00468 statement lifetime. FIXME: must be const 00469 */ 00470 ulong id; 00471 00472 /* 00473 MARK_COLUMNS_NONE: Means mark_used_colums is not set and no indicator to 00474 handler of fields used is set 00475 MARK_COLUMNS_READ: Means a bit in read set is set to inform handler 00476 that the field is to be read. If field list contains 00477 duplicates, then thd->dup_field is set to point 00478 to the last found duplicate. 00479 MARK_COLUMNS_WRITE: Means a bit is set in write set to inform handler 00480 that it needs to update this field in write_row 00481 and update_row. 00482 */ 00483 enum enum_mark_columns mark_used_columns; 00484 00485 LEX_STRING name; /* name for named prepared statements */ 00486 LEX *lex; // parse tree descriptor 00487 /* 00488 Points to the query associated with this statement. It's const, but 00489 we need to declare it char * because all table handlers are written 00490 in C and need to point to it. 00491 00492 Note that (A) if we set query = NULL, we must at the same time set 00493 query_length = 0, and protect the whole operation with the 00494 LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a 00495 non-NULL value if its previous value is NULL. We do not need to protect 00496 operation (B) with any mutex. To avoid crashes in races, if we do not 00497 know that thd->query cannot change at the moment, one should print 00498 thd->query like this: 00499 (1) reserve the LOCK_thread_count mutex; 00500 (2) check if thd->query is NULL; 00501 (3) if not NULL, then print at most thd->query_length characters from 00502 it. We will see the query_length field as either 0, or the right value 00503 for it. 00504 Assuming that the write and read of an n-bit memory field in an n-bit 00505 computer is atomic, we can avoid races in the above way. 00506 This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB 00507 STATUS. 00508 */ 00509 char *query; 00510 uint32 query_length; // current query length 00511 Server_side_cursor *cursor; 00512 00513 public: 00514 00515 /* This constructor is called for backup statements */ 00516 Statement() { clear_alloc_root(&main_mem_root); } 00517 00518 Statement(enum enum_state state_arg, ulong id_arg, 00519 ulong alloc_block_size, ulong prealloc_size); 00520 virtual ~Statement(); 00521 00522 /* Assign execution context (note: not all members) of given stmt to self */ 00523 void set_statement(Statement *stmt); 00524 void set_n_backup_statement(Statement *stmt, Statement *backup); 00525 void restore_backup_statement(Statement *stmt, Statement *backup); 00526 /* return class type */ 00527 virtual Type type() const; 00528 }; 00529 00530 00531 /* 00532 Container for all statements created/used in a connection. 00533 Statements in Statement_map have unique Statement::id (guaranteed by id 00534 assignment in Statement::Statement) 00535 Non-empty statement names are unique too: attempt to insert a new statement 00536 with duplicate name causes older statement to be deleted 00537 00538 Statements are auto-deleted when they are removed from the map and when the 00539 map is deleted. 00540 */ 00541 00542 class Statement_map 00543 { 00544 public: 00545 Statement_map(); 00546 00547 int insert(THD *thd, Statement *statement); 00548 00549 Statement *find_by_name(LEX_STRING *name) 00550 { 00551 Statement *stmt; 00552 stmt= (Statement*)hash_search(&names_hash, (byte*)name->str, 00553 name->length); 00554 return stmt; 00555 } 00556 00557 Statement *find(ulong id) 00558 { 00559 if (last_found_statement == 0 || id != last_found_statement->id) 00560 { 00561 Statement *stmt; 00562 stmt= (Statement *) hash_search(&st_hash, (byte *) &id, sizeof(id)); 00563 if (stmt && stmt->name.str) 00564 return NULL; 00565 last_found_statement= stmt; 00566 } 00567 return last_found_statement; 00568 } 00569 /* 00570 Close all cursors of this connection that use tables of a storage 00571 engine that has transaction-specific state and therefore can not 00572 survive COMMIT or ROLLBACK. Currently all but MyISAM cursors are closed. 00573 */ 00574 void close_transient_cursors(); 00575 void erase(Statement *statement); 00576 /* Erase all statements (calls Statement destructor) */ 00577 void reset(); 00578 ~Statement_map(); 00579 private: 00580 HASH st_hash; 00581 HASH names_hash; 00582 I_List<Statement> transient_cursor_list; 00583 Statement *last_found_statement; 00584 }; 00585 00586 struct st_savepoint { 00587 struct st_savepoint *prev; 00588 char *name; 00589 uint length, nht; 00590 }; 00591 00592 enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED}; 00593 extern const char *xa_state_names[]; 00594 00595 typedef struct st_xid_state { 00596 /* For now, this is only used to catch duplicated external xids */ 00597 XID xid; // transaction identifier 00598 enum xa_states xa_state; // used by external XA only 00599 bool in_thd; 00600 } XID_STATE; 00601 00602 extern pthread_mutex_t LOCK_xid_cache; 00603 extern HASH xid_cache; 00604 bool xid_cache_init(void); 00605 void xid_cache_free(void); 00606 XID_STATE *xid_cache_search(XID *xid); 00607 bool xid_cache_insert(XID *xid, enum xa_states xa_state); 00608 bool xid_cache_insert(XID_STATE *xid_state); 00609 void xid_cache_delete(XID_STATE *xid_state); 00610 00611 00612 class Security_context { 00613 public: 00614 Security_context() {} /* Remove gcc warning */ 00615 /* 00616 host - host of the client 00617 user - user of the client, set to NULL until the user has been read from 00618 the connection 00619 priv_user - The user privilege we are using. May be "" for anonymous user. 00620 ip - client IP 00621 */ 00622 char *host, *user, *priv_user, *ip; 00623 /* The host privilege we are using */ 00624 char priv_host[MAX_HOSTNAME]; 00625 /* points to host if host is available, otherwise points to ip */ 00626 const char *host_or_ip; 00627 ulong master_access; /* Global privileges from mysql.user */ 00628 ulong db_access; /* Privileges for current db */ 00629 00630 void init(); 00631 void destroy(); 00632 void skip_grants(); 00633 inline char *priv_host_name() 00634 { 00635 return (*priv_host ? priv_host : (char *)"%"); 00636 } 00637 00638 bool set_user(char *user_arg); 00639 }; 00640 00641 00642 /* 00643 A registry for item tree transformations performed during 00644 query optimization. We register only those changes which require 00645 a rollback to re-execute a prepared statement or stored procedure 00646 yet another time. 00647 */ 00648 00649 struct Item_change_record; 00650 typedef I_List<Item_change_record> Item_change_list; 00651 00652 00653 /* 00654 Type of prelocked mode. 00655 See comment for THD::prelocked_mode for complete description. 00656 */ 00657 00658 enum prelocked_mode_type {NON_PRELOCKED= 0, PRELOCKED= 1, 00659 PRELOCKED_UNDER_LOCK_TABLES= 2}; 00660 00661 00662 /* 00663 Class that holds information about tables which were opened and locked 00664 by the thread. It is also used to save/restore this information in 00665 push_open_tables_state()/pop_open_tables_state(). 00666 */ 00667 00668 class Open_tables_state 00669 { 00670 public: 00671 /* 00672 open_tables - list of regular tables in use by this thread 00673 temporary_tables - list of temp tables in use by this thread 00674 handler_tables - list of tables that were opened with HANDLER OPEN 00675 and are still in use by this thread 00676 */ 00677 TABLE *open_tables, *temporary_tables, *handler_tables, *derived_tables; 00678 /* 00679 During a MySQL session, one can lock tables in two modes: automatic 00680 or manual. In automatic mode all necessary tables are locked just before 00681 statement execution, and all acquired locks are stored in 'lock' 00682 member. Unlocking takes place automatically as well, when the 00683 statement ends. 00684 Manual mode comes into play when a user issues a 'LOCK TABLES' 00685 statement. In this mode the user can only use the locked tables. 00686 Trying to use any other tables will give an error. The locked tables are 00687 stored in 'locked_tables' member. Manual locking is described in 00688 the 'LOCK_TABLES' chapter of the MySQL manual. 00689 See also lock_tables() for details. 00690 */ 00691 MYSQL_LOCK *lock; 00692 /* 00693 Tables that were locked with explicit or implicit LOCK TABLES. 00694 (Implicit LOCK TABLES happens when we are prelocking tables for 00695 execution of statement which uses stored routines. See description 00696 THD::prelocked_mode for more info.) 00697 */ 00698 MYSQL_LOCK *locked_tables; 00699 00700 /* 00701 CREATE-SELECT keeps an extra lock for the table being 00702 created. This field is used to keep the extra lock available for 00703 lower level routines, which would otherwise miss that lock. 00704 */ 00705 MYSQL_LOCK *extra_lock; 00706 00707 /* 00708 prelocked_mode_type enum and prelocked_mode member are used for 00709 indicating whenever "prelocked mode" is on, and what type of 00710 "prelocked mode" is it. 00711 00712 Prelocked mode is used for execution of queries which explicitly 00713 or implicitly (via views or triggers) use functions, thus may need 00714 some additional tables (mentioned in query table list) for their 00715 execution. 00716 00717 First open_tables() call for such query will analyse all functions 00718 used by it and add all additional tables to table its list. It will 00719 also mark this query as requiring prelocking. After that lock_tables() 00720 will issue implicit LOCK TABLES for the whole table list and change 00721 thd::prelocked_mode to non-0. All queries called in functions invoked 00722 by the main query will use prelocked tables. Non-0 prelocked_mode 00723 will also surpress mentioned analysys in those queries thus saving 00724 cycles. Prelocked mode will be turned off once close_thread_tables() 00725 for the main query will be called. 00726 00727 Note: Since not all "tables" present in table list are really locked 00728 thd::prelocked_mode does not imply thd::locked_tables. 00729 */ 00730 prelocked_mode_type prelocked_mode; 00731 ulong version; 00732 uint current_tablenr; 00733 00734 enum enum_flags { 00735 BACKUPS_AVAIL = (1U << 0) /* There are backups available */ 00736 }; 00737 00738 /* 00739 Flags with information about the open tables state. 00740 */ 00741 uint state_flags; 00742 00743 /* 00744 This constructor serves for creation of Open_tables_state instances 00745 which are used as backup storage. 00746 */ 00747 Open_tables_state() : state_flags(0U) { } 00748 00749 Open_tables_state(ulong version_arg); 00750 00751 void set_open_tables_state(Open_tables_state *state) 00752 { 00753 *this= *state; 00754 } 00755 00756 void reset_open_tables_state() 00757 { 00758 open_tables= temporary_tables= handler_tables= derived_tables= 0; 00759 extra_lock= lock= locked_tables= 0; 00760 prelocked_mode= NON_PRELOCKED; 00761 state_flags= 0U; 00762 } 00763 }; 00764 00765 00766 /* class to save context when executing a function or trigger */ 00767 00768 /* Defines used for Sub_statement_state::in_sub_stmt */ 00769 00770 #define SUB_STMT_TRIGGER 1 00771 #define SUB_STMT_FUNCTION 2 00772 00773 class Sub_statement_state 00774 { 00775 public: 00776 ulonglong options; 00777 ulonglong first_successful_insert_id_in_prev_stmt; 00778 ulonglong first_successful_insert_id_in_cur_stmt, insert_id_for_cur_row; 00779 Discrete_interval auto_inc_interval_for_cur_row; 00780 ulonglong limit_found_rows; 00781 ha_rows cuted_fields, sent_row_count, examined_row_count; 00782 ulong client_capabilities; 00783 uint in_sub_stmt; 00784 bool enable_slow_log; 00785 bool last_insert_id_used; 00786 my_bool no_send_ok; 00787 SAVEPOINT *savepoints; 00788 }; 00789 00790 00791 /* Flags for the THD::system_thread variable */ 00792 enum enum_thread_type 00793 { 00794 NON_SYSTEM_THREAD= 0, 00795 SYSTEM_THREAD_DELAYED_INSERT= 1, 00796 SYSTEM_THREAD_SLAVE_IO= 2, 00797 S

