13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#define DRIZZLE_SERVER 1
17
16
#include <drizzled/server_includes.h>
17
#include <drizzled/error.h>
18
#include <drizzled/table.h>
19
#include <drizzled/session.h>
20
#include <drizzled/current_session.h>
21
#include <drizzled/field/timestamp.h>
22
#include <drizzled/field/varstring.h>
18
25
#include "ha_heap.h"
19
26
#include "heapdef.h"
21
static handler *heap_create_handler(handlerton *hton,
25
int heap_deinit(void *p __attribute__((unused)))
32
static const string engine_name("MEMORY");
34
pthread_mutex_t THR_LOCK_heap= PTHREAD_MUTEX_INITIALIZER;
37
class HeapEngine : public StorageEngine
40
HeapEngine(string name_arg) : StorageEngine(name_arg, HTON_CAN_RECREATE)
45
virtual handler *create(TableShare *table,
48
return new (mem_root) ha_heap(this, table);
52
static HeapEngine *engine= NULL;
53
int heap_init(PluginRegistry ®istry)
55
engine= new HeapEngine(engine_name);
57
pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
61
int heap_deinit(PluginRegistry ®istry)
63
registry.remove(engine);
66
pthread_mutex_destroy(&THR_LOCK_heap);
28
68
return hp_panic(HA_PANIC_CLOSE);
32
int heap_init(void *p)
34
handlerton *heap_hton;
36
heap_hton= (handlerton *)p;
37
heap_hton->state= SHOW_OPTION_YES;
38
heap_hton->create= heap_create_handler;
39
heap_hton->flags= HTON_CAN_RECREATE;
44
static handler *heap_create_handler(handlerton *hton,
48
return new (mem_root) ha_heap(hton, table);
52
73
/*****************************************************************************
54
75
*****************************************************************************/
56
ha_heap::ha_heap(handlerton *hton, TABLE_SHARE *table_arg)
57
:handler(hton, table_arg), file(0), records_changed(0), key_stat_version(0),
77
ha_heap::ha_heap(StorageEngine *engine_arg, TableShare *table_arg)
78
:handler(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
72
Hash index statistics is updated (copied from HP_KEYDEF::hash_buckets to
73
rec_per_key) after 1/HEAP_STATS_UPDATE_THRESHOLD fraction of table records
74
have been inserted/updated/deleted. delete_all_rows() and table flush cause
93
Hash index statistics is updated (copied from HP_KEYDEF::hash_buckets to
94
rec_per_key) after 1/HEAP_STATS_UPDATE_THRESHOLD fraction of table records
95
have been inserted/updated/deleted. delete_all_rows() and table flush cause
78
99
hash index statistics must be updated when number of table records changes
79
from 0 to non-zero value and vice versa. Otherwise records_in_range may
100
from 0 to non-zero value and vice versa. Otherwise records_in_range may
80
101
erroneously return 0 and 'range' may miss records.
82
103
#define HEAP_STATS_UPDATE_THRESHOLD 10
132
153
Create a copy of this table
135
Do same as default implementation but use file->s->name instead of
156
Do same as default implementation but use file->s->name instead of
136
157
table->s->path. This is needed by Windows where the clone() call sees
137
'/'-delimited path in table->s->path, while ha_peap::open() was called
158
'/'-delimited path in table->s->path, while ha_peap::open() was called
138
159
with '\'-delimited path.
172
const char *ha_heap::index_type(uint32_t inx)
174
return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ?
179
uint32_t ha_heap::index_flags(uint32_t inx, uint32_t, bool) const
181
return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ?
182
HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE :
183
HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR);
152
188
Compute which keys to use for scanning
208
244
ha_statistic_increment(&SSV::ha_write_count);
209
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
210
table->timestamp_field->set_time();
211
245
if (table->next_number_field && buf == table->record[0])
213
247
if ((res= update_auto_increment()))
216
250
res= heap_write(file,buf);
217
if (!res && (++records_changed*HEAP_STATS_UPDATE_THRESHOLD >
251
if (!res && (++records_changed*HEAP_STATS_UPDATE_THRESHOLD >
218
252
file->s->records))
551
584
int ha_heap::delete_table(const char *name)
553
int error= heap_delete_table(name);
554
return error == ENOENT ? 0 : error;
586
return heap_delete_table(name);
558
void ha_heap::drop_table(const char *name __attribute__((unused)))
590
void ha_heap::drop_table(const char *)
560
592
file->s->delete_on_close= 1;
604
636
char buff[FN_REFLEN];
606
TABLE_SHARE *share= table_arg->s;
638
TableShare *share= table_arg->s;
607
639
bool found_real_auto_increment= 0;
609
if (!(columndef= (HP_COLUMNDEF*) my_malloc(column_count * sizeof(HP_COLUMNDEF), MYF(MY_WME))))
641
if (!(columndef= (HP_COLUMNDEF*) malloc(column_count * sizeof(HP_COLUMNDEF))))
612
644
for (column_idx= 0; column_idx < column_count; column_idx++)
641
673
for (key= parts= 0; key < keys; key++)
642
674
parts+= table_arg->key_info[key].key_parts;
644
if (!(keydef= (HP_KEYDEF*) my_malloc(keys * sizeof(HP_KEYDEF) +
645
parts * sizeof(HA_KEYSEG),
676
if (!(keydef= (HP_KEYDEF*) malloc(keys * sizeof(HP_KEYDEF) +
677
parts * sizeof(HA_KEYSEG))))
648
679
free((void *) columndef);
754
785
hp_create_info.auto_key_type= auto_key_type;
755
786
hp_create_info.auto_increment= (create_info->auto_increment_value ?
756
787
create_info->auto_increment_value - 1 : 0);
757
hp_create_info.max_table_size=current_thd->variables.max_heap_table_size;
788
hp_create_info.max_table_size=current_session->variables.max_heap_table_size;
758
789
hp_create_info.with_auto_increment= found_real_auto_increment;
759
790
hp_create_info.internal_table= internal_table;
760
791
hp_create_info.max_chunk_size= share->block_size;
767
798
share->reclength, mem_per_row_keys,
768
799
(uint32_t) share->max_rows, (uint32_t) share->min_rows,
769
800
&hp_create_info, &internal_share);
771
802
free((unsigned char*) keydef);
772
803
free((void *) columndef);
773
804
assert(file == 0);
792
void ha_heap::get_auto_increment(uint64_t offset __attribute__((unused)),
793
uint64_t increment __attribute__((unused)),
794
uint64_t nb_desired_values __attribute__((unused)),
823
void ha_heap::get_auto_increment(uint64_t, uint64_t, uint64_t,
795
824
uint64_t *first_value,
796
825
uint64_t *nb_reserved_values)
805
bool ha_heap::check_if_incompatible_data(HA_CREATE_INFO *info,
806
uint32_t table_changes)
834
int ha_heap::cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
808
/* Check that auto_increment value was not changed */
809
if ((info->used_fields & HA_CREATE_USED_AUTO &&
810
info->auto_increment_value != 0) ||
811
table_changes == IS_EQUAL_NO ||
812
table_changes & IS_EQUAL_PACK_LENGTH) // Not implemented yet
813
return COMPATIBLE_DATA_NO;
814
return COMPATIBLE_DATA_YES;
836
return memcmp(ref1, ref2, sizeof(HEAP_PTR));
817
mysql_declare_plugin(heap)
840
drizzle_declare_plugin(heap)
819
DRIZZLE_STORAGE_ENGINE_PLUGIN,