00001 /* Copyright (C) 2000,2004 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 #ifdef USE_PRAGMA_INTERFACE 00019 #pragma interface /* gcc class implementation */ 00020 #endif 00021 00022 /* class for the the heap handler */ 00023 00024 #include <heap.h> 00025 00026 class ha_heap: public handler 00027 { 00028 HP_INFO *file; 00029 key_map btree_keys; 00030 /* number of records changed since last statistics update */ 00031 uint records_changed; 00032 uint key_stat_version; 00033 public: 00034 ha_heap(TABLE_SHARE *table); 00035 ~ha_heap() {} 00036 const char *table_type() const 00037 { 00038 return (table->in_use->variables.sql_mode & MODE_MYSQL323) ? 00039 "HEAP" : "MEMORY"; 00040 } 00041 const char *index_type(uint inx) 00042 { 00043 return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ? 00044 "BTREE" : "HASH"); 00045 } 00046 /* Rows also use a fixed-size format */ 00047 enum row_type get_row_type() const { return ROW_TYPE_FIXED; } 00048 const char **bas_ext() const; 00049 ulonglong table_flags() const 00050 { 00051 return (HA_FAST_KEY_READ | HA_NO_BLOBS | HA_NULL_IN_KEY | 00052 HA_REC_NOT_IN_SEQ | HA_CAN_INSERT_DELAYED | HA_NO_TRANSACTIONS | 00053 HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT); 00054 } 00055 ulong index_flags(uint inx, uint part, bool all_parts) const 00056 { 00057 return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ? 00058 HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE : 00059 HA_ONLY_WHOLE_INDEX); 00060 } 00061 const key_map *keys_to_use_for_scanning() { return &btree_keys; } 00062 uint max_supported_keys() const { return MAX_KEY; } 00063 uint max_supported_key_part_length() const { return MAX_KEY_LENGTH; } 00064 double scan_time() 00065 { return (double) (stats.records+stats.deleted) / 20.0+10; } 00066 double read_time(uint index, uint ranges, ha_rows rows) 00067 { return (double) rows / 20.0+1; } 00068 00069 int open(const char *name, int mode, uint test_if_locked); 00070 int close(void); 00071 void set_keys_for_scanning(void); 00072 int write_row(byte * buf); 00073 int update_row(const byte * old_data, byte * new_data); 00074 int delete_row(const byte * buf); 00075 virtual void get_auto_increment(ulonglong offset, ulonglong increment, 00076 ulonglong nb_desired_values, 00077 ulonglong *first_value, 00078 ulonglong *nb_reserved_values); 00079 int index_read(byte * buf, const byte * key, 00080 uint key_len, enum ha_rkey_function find_flag); 00081 int index_read_idx(byte * buf, uint idx, const byte * key, 00082 uint key_len, enum ha_rkey_function find_flag); 00083 int index_read_last(byte * buf, const byte * key, uint key_len); 00084 int index_next(byte * buf); 00085 int index_prev(byte * buf); 00086 int index_first(byte * buf); 00087 int index_last(byte * buf); 00088 int rnd_init(bool scan); 00089 int rnd_next(byte *buf); 00090 int rnd_pos(byte * buf, byte *pos); 00091 void position(const byte *record); 00092 void info(uint); 00093 int extra(enum ha_extra_function operation); 00094 int reset(); 00095 int external_lock(THD *thd, int lock_type); 00096 int delete_all_rows(void); 00097 int disable_indexes(uint mode); 00098 int enable_indexes(uint mode); 00099 int indexes_are_disabled(void); 00100 ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); 00101 int delete_table(const char *from); 00102 void drop_table(const char *name); 00103 int rename_table(const char * from, const char * to); 00104 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); 00105 void update_create_info(HA_CREATE_INFO *create_info); 00106 00107 THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, 00108 enum thr_lock_type lock_type); 00109 int cmp_ref(const byte *ref1, const byte *ref2) 00110 { 00111 HEAP_PTR ptr1=*(HEAP_PTR*)ref1; 00112 HEAP_PTR ptr2=*(HEAP_PTR*)ref2; 00113 return ptr1 < ptr2? -1 : (ptr1 > ptr2? 1 : 0); 00114 } 00115 bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes); 00116 private: 00117 void update_key_stats(); 00118 };
1.4.7

