17
17
#include <drizzled/error.h>
18
18
#include <drizzled/table.h>
19
19
#include <drizzled/session.h>
20
#include <drizzled/field/timestamp.h>
20
21
#include <drizzled/field/varstring.h>
21
#include <drizzled/plugin/daemon.h>
22
#include <drizzled/plugin/storage_engine.h>
22
#include "drizzled/plugin/daemon.h"
24
24
#include <boost/thread/mutex.hpp>
60
60
hp_panic(HA_PANIC_CLOSE);
63
virtual Cursor *create(Table &table)
63
virtual Cursor *create(TableShare &table)
65
65
return new ha_heap(*this, table);
72
72
int doCreateTable(Session &session,
74
const identifier::Table &identifier,
74
const TableIdentifier &identifier,
75
75
message::Table &create_proto);
77
77
/* For whatever reason, internal tables can be created by Cursor::open()
85
85
message::Table &create_proto,
86
86
HP_SHARE **internal_share);
88
int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
88
int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
90
int doDropTable(Session&, const identifier::Table &identifier);
90
int doDropTable(Session&, const TableIdentifier &identifier);
92
92
int doGetTableDefinition(Session& session,
93
const identifier::Table &identifier,
93
const TableIdentifier &identifier,
94
94
message::Table &table_message);
96
96
uint32_t max_supported_keys() const { return MAX_KEY; }
101
101
return ( HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR);
104
bool doDoesTableExist(Session& session, const identifier::Table &identifier);
104
bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
105
105
void doGetTableIdentifiers(CachedDirectory &directory,
106
const identifier::Schema &schema_identifier,
107
identifier::Table::vector &set_of_identifiers);
106
const SchemaIdentifier &schema_identifier,
107
TableIdentifiers &set_of_identifiers);
110
110
void HeapEngine::doGetTableIdentifiers(CachedDirectory&,
111
const identifier::Schema&,
112
identifier::Table::vector&)
111
const SchemaIdentifier&,
116
bool HeapEngine::doDoesTableExist(Session& session, const identifier::Table &identifier)
116
bool HeapEngine::doDoesTableExist(Session& session, const TableIdentifier &identifier)
118
return session.getMessageCache().doesTableMessageExist(identifier);
118
return session.doesTableMessageExist(identifier);
121
121
int HeapEngine::doGetTableDefinition(Session &session,
122
const identifier::Table &identifier,
122
const TableIdentifier &identifier,
123
123
message::Table &table_proto)
125
if (session.getMessageCache().getTableMessage(identifier, table_proto))
125
if (session.getTableMessage(identifier, table_proto))
131
131
We have to ignore ENOENT entries as the MEMORY table is created on open and
132
132
not when doing a CREATE on the table.
134
int HeapEngine::doDropTable(Session &session, const identifier::Table &identifier)
134
int HeapEngine::doDropTable(Session &session, const TableIdentifier &identifier)
136
session.getMessageCache().removeTableMessage(identifier);
136
session.removeTableMessage(identifier);
138
138
int error= heap_delete_table(identifier.getPath().c_str());
158
158
*****************************************************************************/
160
160
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
161
TableShare &table_arg)
162
162
:Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
163
163
internal_table(0)
177
177
#define MEMORY_STATS_UPDATE_THRESHOLD 10
179
int ha_heap::doOpen(const drizzled::identifier::Table &identifier, int mode, uint32_t test_if_locked)
179
int ha_heap::doOpen(const drizzled::TableIdentifier &identifier, int mode, uint32_t test_if_locked)
181
181
if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(identifier.getPath().c_str(), mode)) && errno == ENOENT))
185
185
HP_SHARE *internal_share= NULL;
186
186
message::Table create_proto;
188
if (not heap_storage_engine->heap_create_table(getTable()->in_use,
188
if (not heap_storage_engine->heap_create_table(table->in_use,
189
189
identifier.getPath().c_str(),
193
193
&internal_share))
241
241
Cursor *ha_heap::clone(memory::Root *)
243
Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
244
identifier::Table identifier(getTable()->getShare()->getSchemaName(),
245
getTable()->getShare()->getTableName(),
246
getTable()->getShare()->getPath());
243
Cursor *new_handler= table->getMutableShare()->db_type()->getCursor(*(table->getMutableShare()));
244
TableIdentifier identifier(table->getShare()->getSchemaName(),
245
table->getShare()->getTableName(),
246
table->getShare()->getPath());
248
if (new_handler && !new_handler->ha_open(identifier, getTable()->db_stat,
248
if (new_handler && !new_handler->ha_open(identifier, table, table->db_stat,
249
249
HA_OPEN_IGNORE_IF_LOCKED))
250
250
return new_handler;
282
282
void ha_heap::update_key_stats()
284
for (uint32_t i= 0; i < getTable()->getShare()->sizeKeys(); i++)
284
for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++)
286
KeyInfo *key= &getTable()->key_info[i];
286
KeyInfo *key= &table->key_info[i];
288
288
if (!key->rec_per_key)
310
310
int ha_heap::doInsertRecord(unsigned char * buf)
313
if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
313
if (table->next_number_field && buf == table->getInsertRecord())
315
315
if ((res= update_auto_increment()))
352
352
res= heap_delete(file,buf);
353
if (!res && getTable()->getShare()->getType() == message::Table::STANDARD &&
353
if (!res && table->getShare()->getType() == message::Table::STANDARD &&
354
354
++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->getShare()->records)
369
369
assert(inited==INDEX);
370
370
ha_statistic_increment(&system_status_var::ha_read_key_count);
371
371
int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
372
getTable()->status = error ? STATUS_NOT_FOUND : 0;
372
table->status = error ? STATUS_NOT_FOUND : 0;
380
380
ha_statistic_increment(&system_status_var::ha_read_key_count);
381
381
int error= heap_rkey(file, buf, active_index, key, keypart_map,
382
382
HA_READ_PREFIX_LAST);
383
getTable()->status= error ? STATUS_NOT_FOUND : 0;
383
table->status= error ? STATUS_NOT_FOUND : 0;
391
391
ha_statistic_increment(&system_status_var::ha_read_key_count);
392
392
int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
393
getTable()->status = error ? STATUS_NOT_FOUND : 0;
393
table->status = error ? STATUS_NOT_FOUND : 0;
399
399
assert(inited==INDEX);
400
400
ha_statistic_increment(&system_status_var::ha_read_next_count);
401
401
int error=heap_rnext(file,buf);
402
getTable()->status=error ? STATUS_NOT_FOUND: 0;
402
table->status=error ? STATUS_NOT_FOUND: 0;
408
408
assert(inited==INDEX);
409
409
ha_statistic_increment(&system_status_var::ha_read_prev_count);
410
410
int error=heap_rprev(file,buf);
411
getTable()->status=error ? STATUS_NOT_FOUND: 0;
411
table->status=error ? STATUS_NOT_FOUND: 0;
417
417
assert(inited==INDEX);
418
418
ha_statistic_increment(&system_status_var::ha_read_first_count);
419
419
int error=heap_rfirst(file, buf, active_index);
420
getTable()->status=error ? STATUS_NOT_FOUND: 0;
420
table->status=error ? STATUS_NOT_FOUND: 0;
426
426
assert(inited==INDEX);
427
427
ha_statistic_increment(&system_status_var::ha_read_last_count);
428
428
int error=heap_rlast(file, buf, active_index);
429
getTable()->status=error ? STATUS_NOT_FOUND: 0;
429
table->status=error ? STATUS_NOT_FOUND: 0;
440
440
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
441
441
int error=heap_scan(file, buf);
442
getTable()->status=error ? STATUS_NOT_FOUND: 0;
442
table->status=error ? STATUS_NOT_FOUND: 0;
450
450
ha_statistic_increment(&system_status_var::ha_read_rnd_count);
451
451
memcpy(&heap_position, pos, sizeof(HEAP_PTR));
452
452
error=heap_rrnd(file, buf, heap_position);
453
getTable()->status=error ? STATUS_NOT_FOUND: 0;
453
table->status=error ? STATUS_NOT_FOUND: 0;
499
499
int ha_heap::delete_all_rows()
501
501
heap_clear(file);
502
if (getTable()->getShare()->getType() == message::Table::STANDARD)
502
if (table->getShare()->getType() == message::Table::STANDARD)
505
505
We can perform this safely since only one writer at the time is
627
int HeapEngine::doRenameTable(Session &session, const identifier::Table &from, const identifier::Table &to)
627
int HeapEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
629
session.getMessageCache().renameTableMessage(from, to);
629
session.renameTableMessage(from, to);
630
630
return heap_rename(from.getPath().c_str(), to.getPath().c_str());
634
634
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
635
635
key_range *max_key)
637
KeyInfo *key= &getTable()->key_info[inx];
637
KeyInfo *key= &table->key_info[inx];
639
639
if (!min_key || !max_key ||
640
640
min_key->length != max_key->length ||
654
654
int HeapEngine::doCreateTable(Session &session,
655
655
Table &table_arg,
656
const identifier::Table &identifier,
656
const TableIdentifier &identifier,
657
657
message::Table& create_proto)
770
770
auto_key= key+ 1;
771
771
auto_key_type= field->key_type();
773
if ((uint)field->position() + 1 > max_key_fieldnr)
773
if ((uint)field->field_index + 1 > max_key_fieldnr)
775
775
/* Do not use seg->fieldnr as it's not reliable in case of temp tables */
776
max_key_fieldnr= field->position() + 1;
776
max_key_fieldnr= field->field_index + 1;
840
840
"Hash based, stored in memory, useful for temporary tables",
841
841
PLUGIN_LICENSE_GPL,
843
NULL, /* system variables */
844
844
NULL /* config options */
846
846
DRIZZLE_DECLARE_PLUGIN_END;