| 1 | /* | 
|---|
| 2 | Copyright (c) 2000, 2011, Oracle and/or its affiliates | 
|---|
| 3 | Copyright (c) 2009, 2011, Monty Program Ab | 
|---|
| 4 |  | 
|---|
| 5 | This program is free software; you can redistribute it and/or modify | 
|---|
| 6 | it under the terms of the GNU General Public License as published by | 
|---|
| 7 | the Free Software Foundation; version 2 of the License. | 
|---|
| 8 |  | 
|---|
| 9 | This program is distributed in the hope that it will be useful, | 
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 12 | GNU General Public License for more details. | 
|---|
| 13 |  | 
|---|
| 14 | You should have received a copy of the GNU General Public License | 
|---|
| 15 | along with this program; if not, write to the Free Software | 
|---|
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */ | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | #ifdef USE_PRAGMA_INTERFACE | 
|---|
| 20 | #pragma interface			/* gcc class implementation */ | 
|---|
| 21 | #endif | 
|---|
| 22 |  | 
|---|
| 23 | /* class for the the heap handler */ | 
|---|
| 24 |  | 
|---|
| 25 | #include <heap.h> | 
|---|
| 26 | #include "sql_class.h"                          /* THD */ | 
|---|
| 27 |  | 
|---|
| 28 | class ha_heap: public handler | 
|---|
| 29 | { | 
|---|
| 30 | HP_INFO *file; | 
|---|
| 31 | HP_SHARE *internal_share; | 
|---|
| 32 | key_map btree_keys; | 
|---|
| 33 | /* number of records changed since last statistics update */ | 
|---|
| 34 | ulong   records_changed; | 
|---|
| 35 | uint    key_stat_version; | 
|---|
| 36 | my_bool internal_table; | 
|---|
| 37 | public: | 
|---|
| 38 | ha_heap(handlerton *hton, TABLE_SHARE *table); | 
|---|
| 39 | ~ha_heap() {} | 
|---|
| 40 | handler *clone(const char *name, MEM_ROOT *mem_root); | 
|---|
| 41 | const char *index_type(uint inx) | 
|---|
| 42 | { | 
|---|
| 43 | return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ? | 
|---|
| 44 | "BTREE": "HASH"); | 
|---|
| 45 | } | 
|---|
| 46 | /* Rows also use a fixed-size format */ | 
|---|
| 47 | enum row_type get_row_type() const { return ROW_TYPE_FIXED; } | 
|---|
| 48 | ulonglong table_flags() const | 
|---|
| 49 | { | 
|---|
| 50 | return (HA_FAST_KEY_READ | HA_NO_BLOBS | HA_NULL_IN_KEY | | 
|---|
| 51 | HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE | | 
|---|
| 52 | HA_CAN_SQL_HANDLER | | 
|---|
| 53 | HA_REC_NOT_IN_SEQ | HA_CAN_INSERT_DELAYED | HA_NO_TRANSACTIONS | | 
|---|
| 54 | HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT); | 
|---|
| 55 | } | 
|---|
| 56 | ulong index_flags(uint inx, uint part, bool all_parts) const | 
|---|
| 57 | { | 
|---|
| 58 | return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ? | 
|---|
| 59 | HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE : | 
|---|
| 60 | HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR); | 
|---|
| 61 | } | 
|---|
| 62 | const key_map *keys_to_use_for_scanning() { return &btree_keys; } | 
|---|
| 63 | uint max_supported_keys()          const { return MAX_KEY; } | 
|---|
| 64 | uint max_supported_key_part_length() const { return MAX_KEY_LENGTH; } | 
|---|
| 65 | double scan_time() | 
|---|
| 66 | { return (double) (stats.records+stats.deleted) / 20.0+10; } | 
|---|
| 67 | double read_time(uint index, uint ranges, ha_rows rows) | 
|---|
| 68 | { return (double) rows /  20.0+1; } | 
|---|
| 69 |  | 
|---|
| 70 | int open(const char *name, int mode, uint test_if_locked); | 
|---|
| 71 | int close(void); | 
|---|
| 72 | void set_keys_for_scanning(void); | 
|---|
| 73 | int write_row(uchar * buf); | 
|---|
| 74 | int update_row(const uchar * old_data, const uchar * new_data); | 
|---|
| 75 | int delete_row(const uchar * buf); | 
|---|
| 76 | virtual void get_auto_increment(ulonglong offset, ulonglong increment, | 
|---|
| 77 | ulonglong nb_desired_values, | 
|---|
| 78 | ulonglong *first_value, | 
|---|
| 79 | ulonglong *nb_reserved_values); | 
|---|
| 80 | int index_read_map(uchar * buf, const uchar * key, key_part_map keypart_map, | 
|---|
| 81 | enum ha_rkey_function find_flag); | 
|---|
| 82 | int index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map); | 
|---|
| 83 | int index_read_idx_map(uchar * buf, uint index, const uchar * key, | 
|---|
| 84 | key_part_map keypart_map, | 
|---|
| 85 | enum ha_rkey_function find_flag); | 
|---|
| 86 | int index_next(uchar * buf); | 
|---|
| 87 | int index_prev(uchar * buf); | 
|---|
| 88 | int index_first(uchar * buf); | 
|---|
| 89 | int index_last(uchar * buf); | 
|---|
| 90 | int rnd_init(bool scan); | 
|---|
| 91 | int rnd_next(uchar *buf); | 
|---|
| 92 | int rnd_pos(uchar * buf, uchar *pos); | 
|---|
| 93 | void position(const uchar *record); | 
|---|
| 94 | int can_continue_handler_scan(); | 
|---|
| 95 | int info(uint); | 
|---|
| 96 | int (enum ha_extra_function operation); | 
|---|
| 97 | int reset(); | 
|---|
| 98 | int external_lock(THD *thd, int lock_type); | 
|---|
| 99 | int delete_all_rows(void); | 
|---|
| 100 | int reset_auto_increment(ulonglong value); | 
|---|
| 101 | int disable_indexes(uint mode); | 
|---|
| 102 | int enable_indexes(uint mode); | 
|---|
| 103 | int indexes_are_disabled(void); | 
|---|
| 104 | ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); | 
|---|
| 105 | int delete_table(const char *from); | 
|---|
| 106 | void drop_table(const char *name); | 
|---|
| 107 | int rename_table(const char * from, const char * to); | 
|---|
| 108 | int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); | 
|---|
| 109 | void update_create_info(HA_CREATE_INFO *create_info); | 
|---|
| 110 |  | 
|---|
| 111 | THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, | 
|---|
| 112 | enum thr_lock_type lock_type); | 
|---|
| 113 | int cmp_ref(const uchar *ref1, const uchar *ref2) | 
|---|
| 114 | { | 
|---|
| 115 | return memcmp(ref1, ref2, sizeof(HEAP_PTR)); | 
|---|
| 116 | } | 
|---|
| 117 | bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes); | 
|---|
| 118 | int find_unique_row(uchar *record, uint unique_idx); | 
|---|
| 119 | private: | 
|---|
| 120 | void update_key_stats(); | 
|---|
| 121 | }; | 
|---|
| 122 |  | 
|---|