~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/ha_heap.cc

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include <drizzled/server_includes.h>
18
18
#include "ha_heap.h"
19
19
#include "heapdef.h"
20
 
#include <drizzled/error.h>
21
20
 
22
21
static handler *heap_create_handler(handlerton *hton,
23
22
                                    TABLE_SHARE *table, 
36
35
 
37
36
  heap_hton= (handlerton *)p;
38
37
  heap_hton->state=      SHOW_OPTION_YES;
 
38
  heap_hton->db_type=    DB_TYPE_HEAP;
39
39
  heap_hton->create=     heap_create_handler;
40
40
  heap_hton->flags=      HTON_CAN_RECREATE;
41
41
 
61
61
 
62
62
 
63
63
static const char *ha_heap_exts[] = {
64
 
  NULL
 
64
  NullS
65
65
};
66
66
 
67
67
const char **ha_heap::bas_ext() const
82
82
*/
83
83
#define HEAP_STATS_UPDATE_THRESHOLD 10
84
84
 
85
 
int ha_heap::open(const char *name, int mode, uint32_t test_if_locked)
 
85
int ha_heap::open(const char *name, int mode, uint test_if_locked)
86
86
{
87
87
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && my_errno == ENOENT))
88
88
  {
168
168
void ha_heap::set_keys_for_scanning(void)
169
169
{
170
170
  btree_keys.clear_all();
171
 
  for (uint32_t i= 0 ; i < table->s->keys ; i++)
 
171
  for (uint i= 0 ; i < table->s->keys ; i++)
172
172
  {
173
173
    if (table->key_info[i].algorithm == HA_KEY_ALG_BTREE)
174
174
      btree_keys.set_bit(i);
178
178
 
179
179
void ha_heap::update_key_stats()
180
180
{
181
 
  for (uint32_t i= 0; i < table->s->keys; i++)
 
181
  for (uint i= 0; i < table->s->keys; i++)
182
182
  {
183
183
    KEY *key=table->key_info+i;
184
184
    if (!key->rec_per_key)
190
190
      else
191
191
      {
192
192
        ha_rows hash_buckets= file->s->keydef[i].hash_buckets;
193
 
        uint32_t no_records= hash_buckets ? (uint) (file->s->records/hash_buckets) : 2;
 
193
        uint no_records= hash_buckets ? (uint) (file->s->records/hash_buckets) : 2;
194
194
        if (no_records < 2)
195
195
          no_records= 2;
196
196
        key->rec_per_key[key->key_parts-1]= no_records;
203
203
}
204
204
 
205
205
 
206
 
int ha_heap::write_row(unsigned char * buf)
 
206
int ha_heap::write_row(uchar * buf)
207
207
{
208
208
  int res;
209
209
  ha_statistic_increment(&SSV::ha_write_count);
227
227
  return res;
228
228
}
229
229
 
230
 
int ha_heap::update_row(const unsigned char * old_data, unsigned char * new_data)
 
230
int ha_heap::update_row(const uchar * old_data, uchar * new_data)
231
231
{
232
232
  int res;
233
233
  ha_statistic_increment(&SSV::ha_update_count);
246
246
  return res;
247
247
}
248
248
 
249
 
int ha_heap::delete_row(const unsigned char * buf)
 
249
int ha_heap::delete_row(const uchar * buf)
250
250
{
251
251
  int res;
252
252
  ha_statistic_increment(&SSV::ha_delete_count);
263
263
  return res;
264
264
}
265
265
 
266
 
int ha_heap::index_read_map(unsigned char *buf, const unsigned char *key,
 
266
int ha_heap::index_read_map(uchar *buf, const uchar *key,
267
267
                            key_part_map keypart_map,
268
268
                            enum ha_rkey_function find_flag)
269
269
{
274
274
  return error;
275
275
}
276
276
 
277
 
int ha_heap::index_read_last_map(unsigned char *buf, const unsigned char *key,
 
277
int ha_heap::index_read_last_map(uchar *buf, const uchar *key,
278
278
                                 key_part_map keypart_map)
279
279
{
280
280
  assert(inited==INDEX);
285
285
  return error;
286
286
}
287
287
 
288
 
int ha_heap::index_read_idx_map(unsigned char *buf, uint32_t index, const unsigned char *key,
 
288
int ha_heap::index_read_idx_map(uchar *buf, uint index, const uchar *key,
289
289
                                key_part_map keypart_map,
290
290
                                enum ha_rkey_function find_flag)
291
291
{
295
295
  return error;
296
296
}
297
297
 
298
 
int ha_heap::index_next(unsigned char * buf)
 
298
int ha_heap::index_next(uchar * buf)
299
299
{
300
300
  assert(inited==INDEX);
301
301
  ha_statistic_increment(&SSV::ha_read_next_count);
304
304
  return error;
305
305
}
306
306
 
307
 
int ha_heap::index_prev(unsigned char * buf)
 
307
int ha_heap::index_prev(uchar * buf)
308
308
{
309
309
  assert(inited==INDEX);
310
310
  ha_statistic_increment(&SSV::ha_read_prev_count);
313
313
  return error;
314
314
}
315
315
 
316
 
int ha_heap::index_first(unsigned char * buf)
 
316
int ha_heap::index_first(uchar * buf)
317
317
{
318
318
  assert(inited==INDEX);
319
319
  ha_statistic_increment(&SSV::ha_read_first_count);
322
322
  return error;
323
323
}
324
324
 
325
 
int ha_heap::index_last(unsigned char * buf)
 
325
int ha_heap::index_last(uchar * buf)
326
326
{
327
327
  assert(inited==INDEX);
328
328
  ha_statistic_increment(&SSV::ha_read_last_count);
336
336
  return scan ? heap_scan_init(file) : 0;
337
337
}
338
338
 
339
 
int ha_heap::rnd_next(unsigned char *buf)
 
339
int ha_heap::rnd_next(uchar *buf)
340
340
{
341
341
  ha_statistic_increment(&SSV::ha_read_rnd_next_count);
342
342
  int error=heap_scan(file, buf);
344
344
  return error;
345
345
}
346
346
 
347
 
int ha_heap::rnd_pos(unsigned char * buf, unsigned char *pos)
 
347
int ha_heap::rnd_pos(uchar * buf, uchar *pos)
348
348
{
349
349
  int error;
350
350
  HEAP_PTR heap_position;
355
355
  return error;
356
356
}
357
357
 
358
 
void ha_heap::position(const unsigned char *record __attribute__((unused)))
 
358
void ha_heap::position(const uchar *record __attribute__((unused)))
359
359
{
360
360
  *(HEAP_PTR*) ref= heap_position(file);        // Ref is aligned
361
361
}
362
362
 
363
 
int ha_heap::info(uint32_t flag)
 
363
int ha_heap::info(uint flag)
364
364
{
365
365
  HEAPINFO hp_info;
366
366
  (void) heap_info(file,&hp_info,flag);
420
420
  return 0;
421
421
}
422
422
 
423
 
int ha_heap::external_lock(Session *session __attribute__((unused)),
 
423
int ha_heap::external_lock(THD *thd __attribute__((unused)),
424
424
                           int lock_type __attribute__((unused)))
425
425
{
426
426
  return 0;                                     // No external locking
451
451
    HA_ERR_WRONG_COMMAND  mode not implemented.
452
452
*/
453
453
 
454
 
int ha_heap::disable_indexes(uint32_t mode)
 
454
int ha_heap::disable_indexes(uint mode)
455
455
{
456
456
  int error;
457
457
 
498
498
    HA_ERR_WRONG_COMMAND  mode not implemented.
499
499
*/
500
500
 
501
 
int ha_heap::enable_indexes(uint32_t mode)
 
501
int ha_heap::enable_indexes(uint mode)
502
502
{
503
503
  int error;
504
504
 
534
534
  return heap_indexes_are_disabled(file);
535
535
}
536
536
 
537
 
THR_LOCK_DATA **ha_heap::store_lock(Session *session __attribute__((unused)),
 
537
THR_LOCK_DATA **ha_heap::store_lock(THD *thd __attribute__((unused)),
538
538
                                    THR_LOCK_DATA **to,
539
539
                                    enum thr_lock_type lock_type)
540
540
{
569
569
}
570
570
 
571
571
 
572
 
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
 
572
ha_rows ha_heap::records_in_range(uint inx, key_range *min_key,
573
573
                                  key_range *max_key)
574
574
{
575
575
  KEY *key=table->key_info+inx;
595
595
int ha_heap::create(const char *name, Table *table_arg,
596
596
                    HA_CREATE_INFO *create_info)
597
597
{
598
 
  uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
599
 
  uint32_t auto_key= 0, auto_key_type= 0;
600
 
  uint32_t max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
601
 
  uint32_t column_idx, column_count= table_arg->s->fields;
 
598
  uint key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
 
599
  uint auto_key= 0, auto_key_type= 0;
 
600
  uint max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
 
601
  uint column_idx, column_count= table_arg->s->fields;
602
602
  HP_COLUMNDEF *columndef;
603
603
  HP_KEYDEF *keydef;
604
604
  HA_KEYSEG *seg;
621
621
    if (field->null_bit)
622
622
    {
623
623
      column->null_bit= field->null_bit;
624
 
      column->null_pos= (uint) (field->null_ptr - (unsigned char*) table_arg->record[0]);
 
624
      column->null_pos= (uint) (field->null_ptr - (uchar*) table_arg->record[0]);
625
625
    }
626
626
    else
627
627
    {
646
646
                                       parts * sizeof(HA_KEYSEG),
647
647
                                       MYF(MY_WME))))
648
648
  {
649
 
    free((void *) columndef);
 
649
    my_free((void *) columndef, MYF(0));
650
650
    return my_errno;
651
651
  }
652
652
 
653
 
  seg= reinterpret_cast<HA_KEYSEG*> (keydef + keys);
 
653
  seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + keys);
654
654
  for (key= 0; key < keys; key++)
655
655
  {
656
656
    KEY *pos= table_arg->key_info+key;
711
711
      if (field->null_ptr)
712
712
      {
713
713
        seg->null_bit= field->null_bit;
714
 
        seg->null_pos= (uint) (field->null_ptr - (unsigned char*) table_arg->record[0]);
 
714
        seg->null_pos= (uint) (field->null_ptr - (uchar*) table_arg->record[0]);
715
715
      }
716
716
      else
717
717
      {
755
755
  hp_create_info.auto_key_type= auto_key_type;
756
756
  hp_create_info.auto_increment= (create_info->auto_increment_value ?
757
757
                                  create_info->auto_increment_value - 1 : 0);
758
 
  hp_create_info.max_table_size=current_session->variables.max_heap_table_size;
 
758
  hp_create_info.max_table_size=current_thd->variables.max_heap_table_size;
759
759
  hp_create_info.with_auto_increment= found_real_auto_increment;
760
760
  hp_create_info.internal_table= internal_table;
761
761
  hp_create_info.max_chunk_size= share->block_size;
769
769
         (uint32_t) share->max_rows, (uint32_t) share->min_rows,
770
770
         &hp_create_info, &internal_share);
771
771
  
772
 
  free((unsigned char*) keydef);
773
 
  free((void *) columndef);
 
772
  my_free((uchar*) keydef, MYF(0));
 
773
  my_free((void *) columndef, MYF(0));
774
774
  assert(file == 0);
775
775
  return (error);
776
776
}
804
804
 
805
805
 
806
806
bool ha_heap::check_if_incompatible_data(HA_CREATE_INFO *info,
807
 
                                         uint32_t table_changes)
 
807
                                         uint table_changes)
808
808
{
809
809
  /* Check that auto_increment value was not changed */
810
810
  if ((info->used_fields & HA_CREATE_USED_AUTO &&