ha_innodb.h
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:9k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2000 MySQL AB && Innobase Oy
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. /*
  14.   This file is based on ha_berkeley.h of MySQL distribution
  15.   This file defines the Innodb handler: the interface between MySQL and
  16.   Innodb
  17. */
  18. #ifdef USE_PRAGMA_INTERFACE
  19. #pragma interface /* gcc class implementation */
  20. #endif
  21. typedef struct st_innobase_share {
  22.   THR_LOCK lock;
  23.   pthread_mutex_t mutex;
  24.   char *table_name;
  25.   uint table_name_length,use_count;
  26. } INNOBASE_SHARE;
  27. /* The class defining a handle to an Innodb table */
  28. class ha_innobase: public handler
  29. {
  30. void* innobase_prebuilt; /* (row_prebuilt_t*) prebuilt
  31. struct in Innodb, used to save
  32. CPU */
  33. THD* user_thd; /* the thread handle of the user
  34. currently using the handle; this is
  35. set in external_lock function */
  36. ulong           last_query_id;  /* the latest query id where the
  37. handle was used */
  38.    THR_LOCK_DATA  lock;
  39. INNOBASE_SHARE  *share;
  40.    gptr  alloc_ptr;
  41.    byte* upd_buff; /* buffer used in updates */
  42.    byte* key_val_buff; /* buffer used in converting
  43.    search key values from MySQL format
  44.    to Innodb format */
  45. ulong upd_and_key_val_buff_len;
  46. /* the length of each of the previous
  47. two buffers */
  48.    ulong  int_table_flags;
  49.    uint  primary_key;
  50. uint last_dup_key;
  51. ulong start_of_scan; /* this is set to 1 when we are
  52. starting a table scan but have not
  53. yet fetched any row, else 0 */
  54. uint last_match_mode;/* match mode of the latest search:
  55. ROW_SEL_EXACT, ROW_SEL_EXACT_PREFIX,
  56. or undefined */
  57. uint num_write_row; /* number of write_row() calls */
  58. longlong auto_inc_counter_for_this_stat;
  59. ulong max_supported_row_length(const byte *buf);
  60. uint store_key_val_for_row(uint keynr, char* buff, uint buff_len,
  61.        const byte* record);
  62. int update_thd(THD* thd);
  63. int change_active_index(uint keynr);
  64. int general_fetch(byte* buf, uint direction, uint match_mode);
  65. int innobase_read_and_init_auto_inc(longlong* ret);
  66. /* Init values for the class: */
  67.  public:
  68.    ha_innobase(TABLE *table): handler(table),
  69.   int_table_flags(HA_REC_NOT_IN_SEQ |
  70.   HA_NULL_IN_KEY | HA_FAST_KEY_READ |
  71.   HA_CAN_INDEX_BLOBS |
  72.   HA_CAN_SQL_HANDLER |
  73.   HA_NOT_EXACT_COUNT |
  74.   HA_PRIMARY_KEY_IN_READ_INDEX |
  75.   HA_TABLE_SCAN_ON_INDEX),
  76.   last_dup_key((uint) -1),
  77.   start_of_scan(0),
  78.   num_write_row(0)
  79.    {
  80.    }
  81.    ~ha_innobase() {}
  82.    const char* table_type() const { return("InnoDB");}
  83. const char *index_type(uint key_number) { return "BTREE"; }
  84.    const char** bas_ext() const;
  85.   ulong table_flags() const { return int_table_flags; }
  86. ulong index_flags(uint idx, uint part, bool all_parts) const
  87. {
  88.   return (HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE |
  89.                   HA_KEYREAD_ONLY);
  90. }
  91.    uint max_supported_keys()          const { return MAX_KEY; }
  92. /* An InnoDB page must store >= 2 keys;
  93. a secondary key record must also contain the
  94. primary key value:
  95. max key length is therefore set to slightly
  96. less than 1 / 4 of page size which is 16 kB;
  97. but currently MySQL does not work with keys
  98. whose size is > MAX_KEY_LENGTH */
  99.    uint max_supported_key_length() const { return 3500; }
  100.    uint max_supported_key_part_length() const { return 3500; }
  101. const key_map *keys_to_use_for_scanning() { return &key_map_full; }
  102.    bool has_transactions()  { return 1;}
  103.    int open(const char *name, int mode, uint test_if_locked);
  104.    int close(void);
  105.    double scan_time();
  106. double read_time(uint index, uint ranges, ha_rows rows);
  107.    int write_row(byte * buf);
  108.    int update_row(const byte * old_data, byte * new_data);
  109.    int delete_row(const byte * buf);
  110.    int index_init(uint index);
  111.    int index_end();
  112.    int index_read(byte * buf, const byte * key,
  113.        uint key_len, enum ha_rkey_function find_flag);
  114.    int index_read_idx(byte * buf, uint index, const byte * key,
  115.    uint key_len, enum ha_rkey_function find_flag);
  116. int index_read_last(byte * buf, const byte * key, uint key_len);
  117.    int index_next(byte * buf);
  118.    int index_next_same(byte * buf, const byte *key, uint keylen);
  119.    int index_prev(byte * buf);
  120.    int index_first(byte * buf);
  121.    int index_last(byte * buf);
  122.    int rnd_init(bool scan);
  123.    int rnd_end();
  124.    int rnd_next(byte *buf);
  125.    int rnd_pos(byte * buf, byte *pos);
  126.    void position(const byte *record);
  127.    void info(uint);
  128.         int analyze(THD* thd,HA_CHECK_OPT* check_opt);
  129.         int optimize(THD* thd,HA_CHECK_OPT* check_opt);
  130. int discard_or_import_tablespace(my_bool discard);
  131.    int extra(enum ha_extra_function operation);
  132.    int external_lock(THD *thd, int lock_type);
  133. int start_stmt(THD *thd);
  134.    void position(byte *record);
  135.    ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
  136. ha_rows estimate_rows_upper_bound();
  137.    int create(const char *name, register TABLE *form,
  138. HA_CREATE_INFO *create_info);
  139.    int delete_table(const char *name);
  140. int rename_table(const char* from, const char* to);
  141. int check(THD* thd, HA_CHECK_OPT* check_opt);
  142.         char* update_table_comment(const char* comment);
  143. char* get_foreign_key_create_info();
  144. bool can_switch_engines();
  145.    uint referenced_by_foreign_key();
  146. void free_foreign_key_create_info(char* str);
  147.    THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
  148.       enum thr_lock_type lock_type);
  149. void init_table_handle_for_HANDLER(); 
  150. longlong get_auto_increment();
  151.         uint8 table_cache_type() { return HA_CACHE_TBL_ASKTRANSACT; }
  152.         static char      *get_mysql_bin_log_name();
  153.         static ulonglong get_mysql_bin_log_pos();
  154. };
  155. extern uint innobase_init_flags, innobase_lock_type;
  156. extern uint innobase_flush_log_at_trx_commit;
  157. extern ulong innobase_cache_size;
  158. extern char *innobase_home, *innobase_tmpdir, *innobase_logdir;
  159. extern long innobase_lock_scan_time;
  160. extern long innobase_mirrored_log_groups, innobase_log_files_in_group;
  161. extern long innobase_log_file_size, innobase_log_buffer_size;
  162. extern long innobase_buffer_pool_size, innobase_additional_mem_pool_size;
  163. extern long innobase_buffer_pool_awe_mem_mb;
  164. extern long innobase_file_io_threads, innobase_lock_wait_timeout;
  165. extern long innobase_force_recovery, innobase_thread_concurrency;
  166. extern long innobase_open_files;
  167. extern char *innobase_data_home_dir, *innobase_data_file_path;
  168. extern char *innobase_log_group_home_dir, *innobase_log_arch_dir;
  169. extern char *innobase_unix_file_flush_method;
  170. /* The following variables have to be my_bool for SHOW VARIABLES to work */
  171. extern my_bool innobase_log_archive,
  172.                innobase_use_native_aio, innobase_fast_shutdown,
  173.        innobase_file_per_table, innobase_locks_unsafe_for_binlog,
  174.                innobase_create_status_file;
  175. extern my_bool innobase_very_fast_shutdown; /* set this to 1 just before
  176.     calling innobase_end() if you want
  177.     InnoDB to shut down without
  178.     flushing the buffer pool: this
  179.     is equivalent to a 'crash' */
  180. extern "C" {
  181. extern ulong srv_max_buf_pool_modified_pct;
  182. extern ulong srv_max_purge_lag;
  183. extern ulong srv_auto_extend_increment;
  184. }
  185. extern TYPELIB innobase_lock_typelib;
  186. bool innobase_init(void);
  187. bool innobase_end(void);
  188. bool innobase_flush_logs(void);
  189. uint innobase_get_free_space(void);
  190. int innobase_commit(THD *thd, void* trx_handle);
  191. int innobase_report_binlog_offset_and_commit(
  192.         THD*    thd,
  193. void* trx_handle,
  194.         char*   log_file_name,
  195.         my_off_t end_offset);
  196. int innobase_commit_complete(
  197.         void*   trx_handle);
  198. int innobase_rollback(THD *thd, void* trx_handle);
  199. int innobase_rollback_to_savepoint(
  200. THD* thd,
  201. char* savepoint_name,
  202. my_off_t* binlog_cache_pos);
  203. int innobase_savepoint(
  204. THD* thd,
  205. char* savepoint_name,
  206. my_off_t binlog_cache_pos);
  207. int innobase_close_connection(THD *thd);
  208. int innobase_drop_database(char *path);
  209. int innodb_show_status(THD* thd);
  210. my_bool innobase_query_caching_of_table_permitted(THD* thd, char* full_name,
  211. uint full_name_len);
  212. void innobase_release_temporary_latches(void* innobase_tid);
  213. void innobase_store_binlog_offset_and_flush_log(char *binlog_name,longlong offset);
  214. int innobase_start_trx_and_assign_read_view(THD* thd);