42
class HeapEngine : public plugin::StorageEngine
40
class HeapEngine : public StorageEngine
45
explicit HeapEngine(string name_arg) :
46
plugin::StorageEngine(name_arg,
47
HTON_STATS_RECORDS_IS_EXACT |
52
HTON_SKIP_STORE_LOCK |
55
pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
60
hp_panic(HA_PANIC_CLOSE);
62
pthread_mutex_destroy(&THR_LOCK_heap);
65
virtual Cursor *create(TableShare &table,
66
memory::Root *mem_root)
68
return new (mem_root) ha_heap(*this, table);
43
HeapEngine(string name_arg) : StorageEngine(name_arg, HTON_CAN_RECREATE|HTON_TEMPORARY_ONLY)
48
virtual handler *create(TableShare *table,
51
return new (mem_root) ha_heap(this, table);
71
54
const char **bas_ext() const {
72
55
return ha_heap_exts;
75
int doCreateTable(Session &session,
77
drizzled::TableIdentifier &identifier,
78
message::Table &create_proto);
58
int createTableImplementation(Session *session, const char *table_name,
59
Table *table_arg, HA_CREATE_INFO *create_info,
60
drizzled::message::Table*);
80
/* For whatever reason, internal tables can be created by Cursor::open()
62
/* For whatever reason, internal tables can be created by handler::open()
82
64
Instead of diving down a rat hole, let's just cry ourselves to sleep
83
65
at night with this odd hackish workaround.
85
67
int heap_create_table(Session *session, const char *table_name,
68
Table *table_arg, HA_CREATE_INFO *create_info,
87
69
bool internal_table,
88
message::Table &create_proto,
89
70
HP_SHARE **internal_share);
91
int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
93
int doDropTable(Session&, TableIdentifier &identifier);
95
int doGetTableDefinition(Session& session,
96
TableIdentifier &identifier,
97
message::Table &table_message);
99
/* Temp only engine, so do not return values. */
100
void doGetTableNames(CachedDirectory &, SchemaIdentifier& , set<string>&) { };
102
uint32_t max_supported_keys() const { return MAX_KEY; }
103
uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
105
uint32_t index_flags(enum ha_key_alg algorithm) const
107
return ((algorithm == HA_KEY_ALG_BTREE) ?
112
HA_ONLY_WHOLE_INDEX |
113
HA_KEY_SCAN_NOT_ROR);
116
bool doDoesTableExist(Session& session, TableIdentifier &identifier);
117
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
118
drizzled::SchemaIdentifier &schema_identifier,
119
drizzled::TableIdentifiers &set_of_identifiers);
72
int renameTableImplementation(Session*, const char * from, const char * to);
74
int deleteTableImplementation(Session *, const string table_path);
122
void HeapEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
123
drizzled::SchemaIdentifier&,
124
drizzled::TableIdentifiers&)
128
bool HeapEngine::doDoesTableExist(Session& session, TableIdentifier &identifier)
130
return session.doesTableMessageExist(identifier);
133
int HeapEngine::doGetTableDefinition(Session &session,
134
TableIdentifier &identifier,
135
message::Table &table_proto)
137
if (session.getTableMessage(identifier, table_proto))
143
We have to ignore ENOENT entries as the MEMORY table is created on open and
78
We have to ignore ENOENT entries as the HEAP table is created on open and
144
79
not when doing a CREATE on the table.
146
int HeapEngine::doDropTable(Session &session, TableIdentifier &identifier)
81
int HeapEngine::deleteTableImplementation(Session*, const string table_path)
148
session.removeTableMessage(identifier);
150
int error= heap_delete_table(identifier.getPath().c_str());
83
return heap_delete_table(table_path.c_str());
158
86
static HeapEngine *heap_storage_engine= NULL;
160
static int heap_init(plugin::Context &context)
88
static int heap_init(drizzled::plugin::Registry ®istry)
162
90
heap_storage_engine= new HeapEngine(engine_name);
163
context.add(heap_storage_engine);
91
registry.add(heap_storage_engine);
92
pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
96
static int heap_deinit(drizzled::plugin::Registry ®istry)
98
registry.remove(heap_storage_engine);
99
delete heap_storage_engine;
101
pthread_mutex_destroy(&THR_LOCK_heap);
103
return hp_panic(HA_PANIC_CLOSE);
168
108
/*****************************************************************************
170
110
*****************************************************************************/
172
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
173
TableShare &table_arg)
174
:Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
112
ha_heap::ha_heap(StorageEngine *engine_arg, TableShare *table_arg)
113
:handler(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
175
114
internal_table(0)
179
118
Hash index statistics is updated (copied from HP_KEYDEF::hash_buckets to
180
rec_per_key) after 1/MEMORY_STATS_UPDATE_THRESHOLD fraction of table records
119
rec_per_key) after 1/HEAP_STATS_UPDATE_THRESHOLD fraction of table records
181
120
have been inserted/updated/deleted. delete_all_rows() and table flush cause
182
121
immediate update.
186
125
from 0 to non-zero value and vice versa. Otherwise records_in_range may
187
126
erroneously return 0 and 'range' may miss records.
189
#define MEMORY_STATS_UPDATE_THRESHOLD 10
128
#define HEAP_STATS_UPDATE_THRESHOLD 10
191
130
int ha_heap::open(const char *name, int mode, uint32_t test_if_locked)
193
if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && errno == ENOENT))
132
if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && my_errno == ENOENT))
195
134
HA_CREATE_INFO create_info;
196
135
internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
197
136
memset(&create_info, 0, sizeof(create_info));
199
138
HP_SHARE *internal_share= NULL;
200
message::Table create_proto;
202
139
if (!heap_storage_engine->heap_create_table(ha_session(), name, table,
141
internal_table,&internal_share))
207
143
file= internal_table ?
208
144
heap_open_from_share(internal_share, mode) :
681
640
return key->rec_per_key[key->key_parts-1];
684
int HeapEngine::doCreateTable(Session &session,
686
drizzled::TableIdentifier &identifier,
687
message::Table& create_proto)
643
int HeapEngine::createTableImplementation(Session *session,
644
const char *table_name,
646
HA_CREATE_INFO *create_info,
647
drizzled::message::Table*)
690
649
HP_SHARE *internal_share;
691
const char *table_name= identifier.getPath().c_str();
693
error= heap_create_table(&session, table_name, &table_arg,
700
session.storeTableMessage(identifier, create_proto);
650
return heap_create_table(session, table_name, table_arg, create_info,
651
false, &internal_share);
707
655
int HeapEngine::heap_create_table(Session *session, const char *table_name,
710
message::Table &create_proto,
711
HP_SHARE **internal_share)
656
Table *table_arg, HA_CREATE_INFO *create_info,
657
bool internal_table, HP_SHARE **internal_share)
713
659
uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
714
660
uint32_t auto_key= 0, auto_key_type= 0;
877
813
HP_CREATE_INFO hp_create_info;
878
814
hp_create_info.auto_key= auto_key;
879
815
hp_create_info.auto_key_type= auto_key_type;
880
hp_create_info.auto_increment= (create_proto.options().has_auto_increment_value() ?
881
create_proto.options().auto_increment_value() - 1 : 0);
816
hp_create_info.auto_increment= (create_info->auto_increment_value ?
817
create_info->auto_increment_value - 1 : 0);
882
818
hp_create_info.max_table_size=session->variables.max_heap_table_size;
883
819
hp_create_info.with_auto_increment= found_real_auto_increment;
884
820
hp_create_info.internal_table= internal_table;
885
821
hp_create_info.max_chunk_size= share->block_size;
886
822
hp_create_info.is_dynamic= (share->row_type == ROW_TYPE_DYNAMIC);
888
error= heap_create(internal::fn_format(buff,table_name,"","",
889
MY_REPLACE_EXT|MY_UNPACK_FILENAME),
891
column_count, columndef,
892
max_key_fieldnr, key_part_size,
893
share->reclength, mem_per_row_keys,
894
static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
896
&hp_create_info, internal_share);
823
error= heap_create(fn_format(buff,table_name,"","",
824
MY_REPLACE_EXT|MY_UNPACK_FILENAME),
826
column_count, columndef,
827
max_key_fieldnr, key_part_size,
828
share->reclength, mem_per_row_keys,
829
(uint32_t) share->max_rows, (uint32_t) share->min_rows,
830
&hp_create_info, internal_share);
898
832
free((unsigned char*) keydef);
899
833
free((void *) columndef);