34
34
int ha_heap::open(const char *name, int mode, uint test_if_locked)
36
uint key,parts,mem_per_row=0;
40
THD *thd= current_thd;
42
for (key=parts=0 ; key < table->keys ; key++)
43
parts+=table->key_info[key].key_parts;
45
if (!(keydef=(HP_KEYDEF*) my_malloc(table->keys*sizeof(HP_KEYDEF)+
46
parts*sizeof(HP_KEYSEG),MYF(MY_WME))))
48
seg=my_reinterpret_cast(HP_KEYSEG*) (keydef+table->keys);
49
for (key=0 ; key < table->keys ; key++)
36
if (!(file= heap_open(name, mode)) && my_errno == ENOENT)
51
KEY *pos=table->key_info+key;
52
KEY_PART_INFO *key_part= pos->key_part;
53
KEY_PART_INFO *key_part_end= key_part+pos->key_parts;
55
mem_per_row += (pos->key_length + (sizeof(char*) * 2));
57
keydef[key].keysegs=(uint) pos->key_parts;
58
keydef[key].flag = (pos->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL));
61
for (; key_part != key_part_end ; key_part++, seg++)
63
uint flag=key_part->key_type;
64
Field *field=key_part->field;
65
if (!f_is_packed(flag) &&
66
f_packtype(flag) == (int) FIELD_TYPE_DECIMAL &&
67
!(flag & FIELDFLAG_BINARY))
68
seg->type= (int) HA_KEYTYPE_TEXT;
70
seg->type= (int) HA_KEYTYPE_BINARY;
71
seg->start=(uint) key_part->offset;
72
seg->length=(uint) key_part->length;
75
seg->null_bit=field->null_bit;
76
seg->null_pos= (uint) (field->null_ptr-
77
(uchar*) table->record[0]);
38
if (!create(name, table, NULL))
39
file= heap_open(name, mode);
86
mem_per_row += MY_ALIGN(table->reclength+1, sizeof(char*));
87
max_rows = (ulong) (thd->variables.max_heap_table_size / mem_per_row);
88
file=heap_open(name,mode,
91
((table->max_rows < max_rows && table->max_rows) ?
92
table->max_rows : max_rows),
94
my_free((gptr) keydef,MYF(0));
96
info(HA_STATUS_NO_LOCK | HA_STATUS_CONST | HA_STATUS_VARIABLE);
97
ref_length=sizeof(HEAP_PTR);
98
return (!file ? errno : 0);
41
return (file ? 0 : 1);
101
44
int ha_heap::close(void)
125
68
return heap_delete(file,buf);
128
int ha_heap::index_read(byte * buf, const byte * key,
129
uint key_len __attribute__((unused)),
130
enum ha_rkey_function find_flag
131
__attribute__((unused)))
71
int ha_heap::index_read(byte * buf, const byte * key, uint key_len,
72
enum ha_rkey_function find_flag)
133
statistic_increment(ha_read_key_count,&LOCK_status);
134
int error=heap_rkey(file,buf,active_index, key);
135
table->status=error ? STATUS_NOT_FOUND: 0;
74
statistic_increment(ha_read_key_count, &LOCK_status);
75
int error = heap_rkey(file,buf,active_index, key, key_len, find_flag);
76
table->status = error ? STATUS_NOT_FOUND : 0;
139
80
int ha_heap::index_read_idx(byte * buf, uint index, const byte * key,
140
uint key_len __attribute__((unused)),
141
enum ha_rkey_function find_flag
142
__attribute__((unused)))
81
uint key_len, enum ha_rkey_function find_flag)
144
statistic_increment(ha_read_key_count,&LOCK_status);
145
int error=heap_rkey(file, buf, index, key);
146
table->status=error ? STATUS_NOT_FOUND: 0;
83
statistic_increment(ha_read_key_count, &LOCK_status);
84
int error = heap_rkey(file, buf, index, key, key_len, find_flag);
85
table->status = error ? STATUS_NOT_FOUND : 0;
280
217
enum ha_rkey_function end_search_flag)
282
219
KEY *pos=table->key_info+inx;
283
if (start_key_len != end_key_len ||
284
start_key_len != pos->key_length ||
285
start_search_flag != HA_READ_KEY_EXACT ||
286
end_search_flag != HA_READ_AFTER_KEY)
287
return HA_POS_ERROR; // Can't only use exact keys
288
return 10; // Good guess
220
if (pos->algorithm == HA_KEY_ALG_BTREE)
222
return hp_rb_records_in_range(file, inx, start_key, start_key_len,
223
start_search_flag, end_key, end_key_len,
228
if (start_key_len != end_key_len ||
229
start_key_len != pos->key_length ||
230
start_search_flag != HA_READ_KEY_EXACT ||
231
end_search_flag != HA_READ_AFTER_KEY)
232
return HA_POS_ERROR; // Can't only use exact keys
233
return 10; // Good guess
292
int ha_heap::create(const char *name, TABLE *form, HA_CREATE_INFO *create_info)
238
int ha_heap::create(const char *name, TABLE *table,
239
HA_CREATE_INFO *create_info)
241
uint key, parts, mem_per_row= 0;
295
245
char buff[FN_REFLEN];
296
return heap_create(fn_format(buff,name,"","",4+2));
248
for (key= parts= 0; key < table->keys; key++)
250
parts+= table->key_info[key].key_parts;
251
if (table->key_info[key].algorithm == HA_KEY_ALG_BTREE)
252
parts++; /* additional HA_KEYTYPE_END keyseg */
255
if (!(keydef= (HP_KEYDEF*) my_malloc(table->keys * sizeof(HP_KEYDEF) +
256
parts * sizeof(HA_KEYSEG),
259
seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + table->keys);
260
for (key= 0; key < table->keys; key++)
262
KEY *pos= table->key_info+key;
263
KEY_PART_INFO *key_part= pos->key_part;
264
KEY_PART_INFO *key_part_end= key_part + pos->key_parts;
266
mem_per_row+= (pos->key_length + (sizeof(char*) * 2));
268
keydef[key].keysegs= (uint) pos->key_parts;
269
keydef[key].flag= (pos->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL));
270
keydef[key].seg= seg;
271
keydef[key].algorithm= ((pos->algorithm == HA_KEY_ALG_UNDEF) ?
272
HA_KEY_ALG_HASH : pos->algorithm);
274
for (; key_part != key_part_end; key_part++, seg++)
276
uint flag= key_part->key_type;
277
Field *field= key_part->field;
278
if (pos->algorithm == HA_KEY_ALG_BTREE)
279
seg->type= field->key_type();
282
if (!f_is_packed(flag) &&
283
f_packtype(flag) == (int) FIELD_TYPE_DECIMAL &&
284
!(flag & FIELDFLAG_BINARY))
285
seg->type= (int) HA_KEYTYPE_TEXT;
287
seg->type= (int) HA_KEYTYPE_BINARY;
289
seg->start= (uint) key_part->offset;
290
seg->length= (uint) key_part->length;
292
seg->charset= field->binary() ? NULL : ((Field_str*)field)->charset();
295
seg->null_bit= field->null_bit;
296
seg->null_pos= (uint) (field->null_ptr - (uchar*) table->record[0]);
304
if (pos->algorithm == HA_KEY_ALG_BTREE)
306
/* additional HA_KEYTYPE_END keyseg */
307
seg->type= HA_KEYTYPE_END;
308
seg->length= sizeof(byte*);
314
mem_per_row+= MY_ALIGN(table->reclength + 1, sizeof(char*));
315
max_rows = (ulong) (current_thd->variables.max_heap_table_size /
317
error= heap_create(fn_format(buff,name,"","",4+2),
318
table->keys,keydef, table->reclength,
319
((table->max_rows < max_rows && table->max_rows) ?
320
table->max_rows : max_rows),
322
my_free((gptr) keydef, MYF(0));
324
info(HA_STATUS_NO_LOCK | HA_STATUS_CONST | HA_STATUS_VARIABLE);
325
ref_length= sizeof(HEAP_PTR);