~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/ha_heap.cc

  • Committer: Andy Lester
  • Date: 2008-08-09 05:13:22 UTC
  • mto: (266.1.29 use-replace-funcs)
  • mto: This revision was merged to the branch mainline in revision 287.
  • Revision ID: andy@petdance.com-20080809051322-dzas70no2mv6c9i5
removed incorrect comment

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
15
15
 
16
 
#define DRIZZLE_SERVER 1
 
16
#define MYSQL_SERVER 1
17
17
#include <drizzled/server_includes.h>
18
18
#include "ha_heap.h"
19
19
#include "heapdef.h"
35
35
 
36
36
  heap_hton= (handlerton *)p;
37
37
  heap_hton->state=      SHOW_OPTION_YES;
 
38
  heap_hton->db_type=    DB_TYPE_HEAP;
38
39
  heap_hton->create=     heap_create_handler;
39
40
  heap_hton->flags=      HTON_CAN_RECREATE;
40
41
 
60
61
 
61
62
 
62
63
static const char *ha_heap_exts[] = {
63
 
  NULL
 
64
  NullS
64
65
};
65
66
 
66
67
const char **ha_heap::bas_ext() const
81
82
*/
82
83
#define HEAP_STATS_UPDATE_THRESHOLD 10
83
84
 
84
 
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)
85
86
{
86
87
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && my_errno == ENOENT))
87
88
  {
167
168
void ha_heap::set_keys_for_scanning(void)
168
169
{
169
170
  btree_keys.clear_all();
170
 
  for (uint32_t i= 0 ; i < table->s->keys ; i++)
 
171
  for (uint i= 0 ; i < table->s->keys ; i++)
171
172
  {
172
173
    if (table->key_info[i].algorithm == HA_KEY_ALG_BTREE)
173
174
      btree_keys.set_bit(i);
177
178
 
178
179
void ha_heap::update_key_stats()
179
180
{
180
 
  for (uint32_t i= 0; i < table->s->keys; i++)
 
181
  for (uint i= 0; i < table->s->keys; i++)
181
182
  {
182
183
    KEY *key=table->key_info+i;
183
184
    if (!key->rec_per_key)
189
190
      else
190
191
      {
191
192
        ha_rows hash_buckets= file->s->keydef[i].hash_buckets;
192
 
        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;
193
194
        if (no_records < 2)
194
195
          no_records= 2;
195
196
        key->rec_per_key[key->key_parts-1]= no_records;
202
203
}
203
204
 
204
205
 
205
 
int ha_heap::write_row(unsigned char * buf)
 
206
int ha_heap::write_row(uchar * buf)
206
207
{
207
208
  int res;
208
209
  ha_statistic_increment(&SSV::ha_write_count);
226
227
  return res;
227
228
}
228
229
 
229
 
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)
230
231
{
231
232
  int res;
232
233
  ha_statistic_increment(&SSV::ha_update_count);
245
246
  return res;
246
247
}
247
248
 
248
 
int ha_heap::delete_row(const unsigned char * buf)
 
249
int ha_heap::delete_row(const uchar * buf)
249
250
{
250
251
  int res;
251
252
  ha_statistic_increment(&SSV::ha_delete_count);
262
263
  return res;
263
264
}
264
265
 
265
 
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,
266
267
                            key_part_map keypart_map,
267
268
                            enum ha_rkey_function find_flag)
268
269
{
273
274
  return error;
274
275
}
275
276
 
276
 
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,
277
278
                                 key_part_map keypart_map)
278
279
{
279
280
  assert(inited==INDEX);
284
285
  return error;
285
286
}
286
287
 
287
 
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,
288
289
                                key_part_map keypart_map,
289
290
                                enum ha_rkey_function find_flag)
290
291
{
294
295
  return error;
295
296
}
296
297
 
297
 
int ha_heap::index_next(unsigned char * buf)
 
298
int ha_heap::index_next(uchar * buf)
298
299
{
299
300
  assert(inited==INDEX);
300
301
  ha_statistic_increment(&SSV::ha_read_next_count);
303
304
  return error;
304
305
}
305
306
 
306
 
int ha_heap::index_prev(unsigned char * buf)
 
307
int ha_heap::index_prev(uchar * buf)
307
308
{
308
309
  assert(inited==INDEX);
309
310
  ha_statistic_increment(&SSV::ha_read_prev_count);
312
313
  return error;
313
314
}
314
315
 
315
 
int ha_heap::index_first(unsigned char * buf)
 
316
int ha_heap::index_first(uchar * buf)
316
317
{
317
318
  assert(inited==INDEX);
318
319
  ha_statistic_increment(&SSV::ha_read_first_count);
321
322
  return error;
322
323
}
323
324
 
324
 
int ha_heap::index_last(unsigned char * buf)
 
325
int ha_heap::index_last(uchar * buf)
325
326
{
326
327
  assert(inited==INDEX);
327
328
  ha_statistic_increment(&SSV::ha_read_last_count);
335
336
  return scan ? heap_scan_init(file) : 0;
336
337
}
337
338
 
338
 
int ha_heap::rnd_next(unsigned char *buf)
 
339
int ha_heap::rnd_next(uchar *buf)
339
340
{
340
341
  ha_statistic_increment(&SSV::ha_read_rnd_next_count);
341
342
  int error=heap_scan(file, buf);
343
344
  return error;
344
345
}
345
346
 
346
 
int ha_heap::rnd_pos(unsigned char * buf, unsigned char *pos)
 
347
int ha_heap::rnd_pos(uchar * buf, uchar *pos)
347
348
{
348
349
  int error;
349
350
  HEAP_PTR heap_position;
354
355
  return error;
355
356
}
356
357
 
357
 
void ha_heap::position(const unsigned char *record __attribute__((unused)))
 
358
void ha_heap::position(const uchar *record __attribute__((unused)))
358
359
{
359
360
  *(HEAP_PTR*) ref= heap_position(file);        // Ref is aligned
360
361
}
361
362
 
362
 
int ha_heap::info(uint32_t flag)
 
363
int ha_heap::info(uint flag)
363
364
{
364
365
  HEAPINFO hp_info;
365
366
  (void) heap_info(file,&hp_info,flag);
450
451
    HA_ERR_WRONG_COMMAND  mode not implemented.
451
452
*/
452
453
 
453
 
int ha_heap::disable_indexes(uint32_t mode)
 
454
int ha_heap::disable_indexes(uint mode)
454
455
{
455
456
  int error;
456
457
 
497
498
    HA_ERR_WRONG_COMMAND  mode not implemented.
498
499
*/
499
500
 
500
 
int ha_heap::enable_indexes(uint32_t mode)
 
501
int ha_heap::enable_indexes(uint mode)
501
502
{
502
503
  int error;
503
504
 
568
569
}
569
570
 
570
571
 
571
 
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,
572
573
                                  key_range *max_key)
573
574
{
574
575
  KEY *key=table->key_info+inx;
591
592
}
592
593
 
593
594
 
594
 
int ha_heap::create(const char *name, Table *table_arg,
 
595
int ha_heap::create(const char *name, TABLE *table_arg,
595
596
                    HA_CREATE_INFO *create_info)
596
597
{
597
 
  uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
598
 
  uint32_t auto_key= 0, auto_key_type= 0;
599
 
  uint32_t max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
600
 
  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;
601
602
  HP_COLUMNDEF *columndef;
602
603
  HP_KEYDEF *keydef;
603
604
  HA_KEYSEG *seg;
620
621
    if (field->null_bit)
621
622
    {
622
623
      column->null_bit= field->null_bit;
623
 
      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]);
624
625
    }
625
626
    else
626
627
    {
645
646
                                       parts * sizeof(HA_KEYSEG),
646
647
                                       MYF(MY_WME))))
647
648
  {
648
 
    free((void *) columndef);
 
649
    my_free((void *) columndef, MYF(0));
649
650
    return my_errno;
650
651
  }
651
652
 
652
 
  seg= reinterpret_cast<HA_KEYSEG*> (keydef + keys);
 
653
  seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + keys);
653
654
  for (key= 0; key < keys; key++)
654
655
  {
655
656
    KEY *pos= table_arg->key_info+key;
710
711
      if (field->null_ptr)
711
712
      {
712
713
        seg->null_bit= field->null_bit;
713
 
        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]);
714
715
      }
715
716
      else
716
717
      {
765
766
         column_count, columndef,
766
767
         max_key_fieldnr, key_part_size,
767
768
         share->reclength, mem_per_row_keys,
768
 
         (uint32_t) share->max_rows, (uint32_t) share->min_rows,
 
769
         (ulong) share->max_rows, (ulong) share->min_rows,
769
770
         &hp_create_info, &internal_share);
770
771
  
771
 
  free((unsigned char*) keydef);
772
 
  free((void *) columndef);
 
772
  my_free((uchar*) keydef, MYF(0));
 
773
  my_free((void *) columndef, MYF(0));
773
774
  assert(file == 0);
774
775
  return (error);
775
776
}
803
804
 
804
805
 
805
806
bool ha_heap::check_if_incompatible_data(HA_CREATE_INFO *info,
806
 
                                         uint32_t table_changes)
 
807
                                         uint table_changes)
807
808
{
808
809
  /* Check that auto_increment value was not changed */
809
810
  if ((info->used_fields & HA_CREATE_USED_AUTO &&
816
817
 
817
818
mysql_declare_plugin(heap)
818
819
{
819
 
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
 
820
  MYSQL_STORAGE_ENGINE_PLUGIN,
820
821
  "MEMORY",
821
822
  "1.0",
822
823
  "MySQL AB",