~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/ha_heap.cc

  • Committer: Jay Pipes
  • Date: 2009-02-21 16:00:06 UTC
  • mto: (907.1.1 trunk-with-temporal)
  • mto: This revision was merged to the branch mainline in revision 908.
  • Revision ID: jpipes@serialcoder-20090221160006-vnk3wt4qbcz62eru
Removes the TIME column type and related time functions.

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
 
#include "heap_priv.h"
 
16
#include <drizzled/server_includes.h>
 
17
#include "heap.h"
 
18
 
 
19
#include <storage/heap/ha_heap.h>
 
20
#include <storage/heap/heapdef.h>
17
21
#include <drizzled/error.h>
18
22
#include <drizzled/table.h>
19
23
#include <drizzled/session.h>
20
24
#include <drizzled/current_session.h>
21
25
#include <drizzled/field/timestamp.h>
22
26
#include <drizzled/field/varstring.h>
23
 
#include "drizzled/plugin/daemon.h"
24
 
 
25
 
#include "heap.h"
26
 
#include "ha_heap.h"
27
 
 
28
 
#include <string>
29
 
 
30
 
 
31
 
using namespace drizzled;
32
 
using namespace std;
33
 
 
34
 
static const string engine_name("MEMORY");
 
27
 
35
28
 
36
29
pthread_mutex_t THR_LOCK_heap= PTHREAD_MUTEX_INITIALIZER;
37
30
 
38
 
static const char *ha_heap_exts[] = {
39
 
  NULL
40
 
};
41
 
 
42
 
class HeapEngine : public plugin::StorageEngine
43
 
{
44
 
public:
45
 
  explicit HeapEngine(string name_arg) :
46
 
    plugin::StorageEngine(name_arg,
47
 
                          HTON_STATS_RECORDS_IS_EXACT |
48
 
                          HTON_NULL_IN_KEY |
49
 
                          HTON_FAST_KEY_READ |
50
 
                          HTON_NO_BLOBS |
51
 
                          HTON_HAS_RECORDS |
52
 
                          HTON_SKIP_STORE_LOCK |
53
 
                          HTON_TEMPORARY_ONLY)
54
 
  {
55
 
    pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
56
 
  }
57
 
 
58
 
  virtual ~HeapEngine()
59
 
  {
60
 
    hp_panic(HA_PANIC_CLOSE);
61
 
 
62
 
    pthread_mutex_destroy(&THR_LOCK_heap);
63
 
  }
64
 
 
65
 
  virtual Cursor *create(TableShare &table,
66
 
                          memory::Root *mem_root)
67
 
  {
68
 
    return new (mem_root) ha_heap(*this, table);
69
 
  }
70
 
 
71
 
  const char **bas_ext() const {
72
 
    return ha_heap_exts;
73
 
  }
74
 
 
75
 
  int doCreateTable(Session &session,
76
 
                    Table &table_arg,
77
 
                    drizzled::TableIdentifier &identifier,
78
 
                    message::Table &create_proto);
79
 
 
80
 
  /* For whatever reason, internal tables can be created by Cursor::open()
81
 
     for MEMORY.
82
 
     Instead of diving down a rat hole, let's just cry ourselves to sleep
83
 
     at night with this odd hackish workaround.
84
 
   */
85
 
  int heap_create_table(Session *session, const char *table_name,
86
 
                        Table *table_arg,
87
 
                        bool internal_table,
88
 
                        message::Table &create_proto,
89
 
                        HP_SHARE **internal_share);
90
 
 
91
 
  int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
92
 
 
93
 
  int doDropTable(Session&, TableIdentifier &identifier);
94
 
 
95
 
  int doGetTableDefinition(Session& session,
96
 
                           TableIdentifier &identifier,
97
 
                           message::Table &table_message);
98
 
 
99
 
  /* Temp only engine, so do not return values. */
100
 
  void doGetTableNames(CachedDirectory &, SchemaIdentifier& , set<string>&) { };
101
 
 
102
 
  uint32_t max_supported_keys()          const { return MAX_KEY; }
103
 
  uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
104
 
 
105
 
  uint32_t index_flags(enum  ha_key_alg algorithm) const
106
 
  {
107
 
    return ((algorithm == HA_KEY_ALG_BTREE) ?
108
 
            HA_READ_NEXT |
109
 
            HA_READ_PREV |
110
 
            HA_READ_ORDER |
111
 
            HA_READ_RANGE :
112
 
            HA_ONLY_WHOLE_INDEX |
113
 
            HA_KEY_SCAN_NOT_ROR);
114
 
  }
115
 
 
116
 
  bool doDoesTableExist(Session& session, TableIdentifier &identifier);
117
 
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
118
 
                             drizzled::SchemaIdentifier &schema_identifier,
119
 
                             drizzled::TableIdentifiers &set_of_identifiers);
120
 
};
121
 
 
122
 
void HeapEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
123
 
                                       drizzled::SchemaIdentifier&,
124
 
                                       drizzled::TableIdentifiers&)
125
 
{
126
 
}
127
 
 
128
 
bool HeapEngine::doDoesTableExist(Session& session, TableIdentifier &identifier)
129
 
{
130
 
  return session.doesTableMessageExist(identifier);
131
 
}
132
 
 
133
 
int HeapEngine::doGetTableDefinition(Session &session,
134
 
                                     TableIdentifier &identifier,
135
 
                                     message::Table &table_proto)
136
 
{
137
 
  if (session.getTableMessage(identifier, table_proto))
138
 
    return EEXIST;
139
 
 
140
 
  return ENOENT;
141
 
}
142
 
/*
143
 
  We have to ignore ENOENT entries as the MEMORY table is created on open and
144
 
  not when doing a CREATE on the table.
145
 
*/
146
 
int HeapEngine::doDropTable(Session &session, TableIdentifier &identifier)
147
 
{
148
 
  session.removeTableMessage(identifier);
149
 
 
150
 
  int error= heap_delete_table(identifier.getPath().c_str());
151
 
 
152
 
  if (error == ENOENT)
153
 
    error= 0;
154
 
 
155
 
  return error;
156
 
}
157
 
 
158
 
static HeapEngine *heap_storage_engine= NULL;
159
 
 
160
 
static int heap_init(plugin::Context &context)
161
 
{
162
 
  heap_storage_engine= new HeapEngine(engine_name);
163
 
  context.add(heap_storage_engine);
 
31
static handler *heap_create_handler(handlerton *hton,
 
32
                                    TABLE_SHARE *table,
 
33
                                    MEM_ROOT *mem_root);
 
34
 
 
35
int heap_deinit(void *)
 
36
{
 
37
  pthread_mutex_init(&THR_LOCK_heap,MY_MUTEX_INIT_FAST);
 
38
 
 
39
  return hp_panic(HA_PANIC_CLOSE);
 
40
}
 
41
 
 
42
 
 
43
int heap_init(void *p)
 
44
{
 
45
  heap_hton= (handlerton *)p;
 
46
  heap_hton->state=      SHOW_OPTION_YES;
 
47
  heap_hton->create=     heap_create_handler;
 
48
  heap_hton->flags=      HTON_CAN_RECREATE;
 
49
 
164
50
  return 0;
165
51
}
166
52
 
 
53
static handler *heap_create_handler(handlerton *hton,
 
54
                                    TABLE_SHARE *table,
 
55
                                    MEM_ROOT *mem_root)
 
56
{
 
57
  return new (mem_root) ha_heap(hton, table);
 
58
}
 
59
 
167
60
 
168
61
/*****************************************************************************
169
 
** MEMORY tables
 
62
** HEAP tables
170
63
*****************************************************************************/
171
64
 
172
 
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
173
 
                 TableShare &table_arg)
174
 
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
 
65
ha_heap::ha_heap(handlerton *hton, TABLE_SHARE *table_arg)
 
66
  :handler(hton, table_arg), file(0), records_changed(0), key_stat_version(0),
175
67
  internal_table(0)
176
68
{}
177
69
 
 
70
 
 
71
static const char *ha_heap_exts[] = {
 
72
  NULL
 
73
};
 
74
 
 
75
const char **ha_heap::bas_ext() const
 
76
{
 
77
  return ha_heap_exts;
 
78
}
 
79
 
178
80
/*
179
81
  Hash index statistics is updated (copied from HP_KEYDEF::hash_buckets to
180
 
  rec_per_key) after 1/MEMORY_STATS_UPDATE_THRESHOLD fraction of table records
 
82
  rec_per_key) after 1/HEAP_STATS_UPDATE_THRESHOLD fraction of table records
181
83
  have been inserted/updated/deleted. delete_all_rows() and table flush cause
182
84
  immediate update.
183
85
 
186
88
   from 0 to non-zero value and vice versa. Otherwise records_in_range may
187
89
   erroneously return 0 and 'range' may miss records.
188
90
*/
189
 
#define MEMORY_STATS_UPDATE_THRESHOLD 10
 
91
#define HEAP_STATS_UPDATE_THRESHOLD 10
190
92
 
191
93
int ha_heap::open(const char *name, int mode, uint32_t test_if_locked)
192
94
{
193
 
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && errno == ENOENT))
 
95
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && my_errno == ENOENT))
194
96
  {
195
97
    HA_CREATE_INFO create_info;
196
98
    internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
197
99
    memset(&create_info, 0, sizeof(create_info));
198
100
    file= 0;
199
 
    HP_SHARE *internal_share= NULL;
200
 
    message::Table create_proto;
201
 
 
202
 
    if (!heap_storage_engine->heap_create_table(ha_session(), name, table,
203
 
                                                internal_table,
204
 
                                                create_proto,
205
 
                                                &internal_share))
 
101
    if (!create(name, table, &create_info))
206
102
    {
207
103
        file= internal_table ?
208
104
          heap_open_from_share(internal_share, mode) :
251
147
    with '\'-delimited path.
252
148
*/
253
149
 
254
 
Cursor *ha_heap::clone(memory::Root *mem_root)
 
150
handler *ha_heap::clone(MEM_ROOT *mem_root)
255
151
{
256
 
  Cursor *new_handler= table->s->db_type()->getCursor(*table->s, mem_root);
257
 
 
 
152
  handler *new_handler= get_new_handler(table->s, mem_root, table->s->db_type());
258
153
  if (new_handler && !new_handler->ha_open(table, file->s->name, table->db_stat,
259
154
                                           HA_OPEN_IGNORE_IF_LOCKED))
260
155
    return new_handler;
261
 
  return NULL;
 
156
  return NULL;  /* purecov: inspected */
262
157
}
263
158
 
264
159
 
269
164
}
270
165
 
271
166
 
 
167
uint32_t ha_heap::index_flags(uint32_t inx, uint32_t, bool) const
 
168
{
 
169
  return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_BTREE) ?
 
170
          HA_READ_NEXT | HA_READ_PREV | HA_READ_ORDER | HA_READ_RANGE :
 
171
          HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR);
 
172
}
 
173
 
 
174
 
272
175
/*
273
176
  Compute which keys to use for scanning
274
177
 
287
190
 
288
191
void ha_heap::set_keys_for_scanning(void)
289
192
{
290
 
  btree_keys.reset();
 
193
  btree_keys.clear_all();
291
194
  for (uint32_t i= 0 ; i < table->s->keys ; i++)
292
195
  {
293
196
    if (table->key_info[i].algorithm == HA_KEY_ALG_BTREE)
294
 
      btree_keys.set(i);
 
197
      btree_keys.set_bit(i);
295
198
  }
296
199
}
297
200
 
326
229
int ha_heap::write_row(unsigned char * buf)
327
230
{
328
231
  int res;
329
 
  ha_statistic_increment(&system_status_var::ha_write_count);
 
232
  ha_statistic_increment(&SSV::ha_write_count);
330
233
  if (table->next_number_field && buf == table->record[0])
331
234
  {
332
235
    if ((res= update_auto_increment()))
333
236
      return res;
334
237
  }
335
238
  res= heap_write(file,buf);
336
 
  if (!res && (++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
 
239
  if (!res && (++records_changed*HEAP_STATS_UPDATE_THRESHOLD >
337
240
               file->s->records))
338
241
  {
339
242
    /*
348
251
int ha_heap::update_row(const unsigned char * old_data, unsigned char * new_data)
349
252
{
350
253
  int res;
351
 
  ha_statistic_increment(&system_status_var::ha_update_count);
 
254
  ha_statistic_increment(&SSV::ha_update_count);
352
255
  if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
353
256
    table->timestamp_field->set_time();
354
257
  res= heap_update(file,old_data,new_data);
355
 
  if (!res && ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
 
258
  if (!res && ++records_changed*HEAP_STATS_UPDATE_THRESHOLD >
356
259
              file->s->records)
357
260
  {
358
261
    /*
367
270
int ha_heap::delete_row(const unsigned char * buf)
368
271
{
369
272
  int res;
370
 
  ha_statistic_increment(&system_status_var::ha_delete_count);
 
273
  ha_statistic_increment(&SSV::ha_delete_count);
371
274
  res= heap_delete(file,buf);
372
 
  if (!res && table->s->tmp_table == message::Table::STANDARD &&
373
 
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->s->records)
 
275
  if (!res && table->s->tmp_table == NO_TMP_TABLE &&
 
276
      ++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records)
374
277
  {
375
278
    /*
376
279
       We can perform this safely since only one writer at the time is
386
289
                            enum ha_rkey_function find_flag)
387
290
{
388
291
  assert(inited==INDEX);
389
 
  ha_statistic_increment(&system_status_var::ha_read_key_count);
 
292
  ha_statistic_increment(&SSV::ha_read_key_count);
390
293
  int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
391
294
  table->status = error ? STATUS_NOT_FOUND : 0;
392
295
  return error;
396
299
                                 key_part_map keypart_map)
397
300
{
398
301
  assert(inited==INDEX);
399
 
  ha_statistic_increment(&system_status_var::ha_read_key_count);
 
302
  ha_statistic_increment(&SSV::ha_read_key_count);
400
303
  int error= heap_rkey(file, buf, active_index, key, keypart_map,
401
304
                       HA_READ_PREFIX_LAST);
402
305
  table->status= error ? STATUS_NOT_FOUND : 0;
407
310
                                key_part_map keypart_map,
408
311
                                enum ha_rkey_function find_flag)
409
312
{
410
 
  ha_statistic_increment(&system_status_var::ha_read_key_count);
 
313
  ha_statistic_increment(&SSV::ha_read_key_count);
411
314
  int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
412
315
  table->status = error ? STATUS_NOT_FOUND : 0;
413
316
  return error;
416
319
int ha_heap::index_next(unsigned char * buf)
417
320
{
418
321
  assert(inited==INDEX);
419
 
  ha_statistic_increment(&system_status_var::ha_read_next_count);
 
322
  ha_statistic_increment(&SSV::ha_read_next_count);
420
323
  int error=heap_rnext(file,buf);
421
324
  table->status=error ? STATUS_NOT_FOUND: 0;
422
325
  return error;
425
328
int ha_heap::index_prev(unsigned char * buf)
426
329
{
427
330
  assert(inited==INDEX);
428
 
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
 
331
  ha_statistic_increment(&SSV::ha_read_prev_count);
429
332
  int error=heap_rprev(file,buf);
430
333
  table->status=error ? STATUS_NOT_FOUND: 0;
431
334
  return error;
434
337
int ha_heap::index_first(unsigned char * buf)
435
338
{
436
339
  assert(inited==INDEX);
437
 
  ha_statistic_increment(&system_status_var::ha_read_first_count);
 
340
  ha_statistic_increment(&SSV::ha_read_first_count);
438
341
  int error=heap_rfirst(file, buf, active_index);
439
342
  table->status=error ? STATUS_NOT_FOUND: 0;
440
343
  return error;
443
346
int ha_heap::index_last(unsigned char * buf)
444
347
{
445
348
  assert(inited==INDEX);
446
 
  ha_statistic_increment(&system_status_var::ha_read_last_count);
 
349
  ha_statistic_increment(&SSV::ha_read_last_count);
447
350
  int error=heap_rlast(file, buf, active_index);
448
351
  table->status=error ? STATUS_NOT_FOUND: 0;
449
352
  return error;
456
359
 
457
360
int ha_heap::rnd_next(unsigned char *buf)
458
361
{
459
 
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
 
362
  ha_statistic_increment(&SSV::ha_read_rnd_next_count);
460
363
  int error=heap_scan(file, buf);
461
364
  table->status=error ? STATUS_NOT_FOUND: 0;
462
365
  return error;
466
369
{
467
370
  int error;
468
371
  HEAP_PTR heap_position;
469
 
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
 
372
  ha_statistic_increment(&SSV::ha_read_rnd_count);
470
373
  memcpy(&heap_position, pos, sizeof(HEAP_PTR));
471
374
  error=heap_rrnd(file, buf, heap_position);
472
375
  table->status=error ? STATUS_NOT_FOUND: 0;
527
430
int ha_heap::delete_all_rows()
528
431
{
529
432
  heap_clear(file);
530
 
  if (table->s->tmp_table == message::Table::STANDARD)
 
433
  if (table->s->tmp_table == NO_TMP_TABLE)
531
434
  {
532
435
    /*
533
436
       We can perform this safely since only one writer at the time is
538
441
  return 0;
539
442
}
540
443
 
 
444
int ha_heap::external_lock(Session *, int)
 
445
{
 
446
  return 0;                                     // No external locking
 
447
}
 
448
 
 
449
 
541
450
/*
542
451
  Disable indexes.
543
452
 
596
505
    The indexes might have been disabled by disable_index() before.
597
506
    The function works only if both data and indexes are empty,
598
507
    since the heap storage engine cannot repair the indexes.
599
 
    To be sure, call Cursor::delete_all_rows() before.
 
508
    To be sure, call handler::delete_all_rows() before.
600
509
 
601
510
  IMPLEMENTATION
602
511
    HA_KEY_SWITCH_NONUNIQ       is not implemented.
645
554
  return heap_indexes_are_disabled(file);
646
555
}
647
556
 
 
557
THR_LOCK_DATA **ha_heap::store_lock(Session *,
 
558
                                    THR_LOCK_DATA **to,
 
559
                                    enum thr_lock_type lock_type)
 
560
{
 
561
  if (lock_type != TL_IGNORE && file->lock.type == TL_UNLOCK)
 
562
    file->lock.type=lock_type;
 
563
  *to++= &file->lock;
 
564
  return to;
 
565
}
 
566
 
 
567
/*
 
568
  We have to ignore ENOENT entries as the HEAP table is created on open and
 
569
  not when doing a CREATE on the table.
 
570
*/
 
571
 
 
572
int ha_heap::delete_table(const char *name)
 
573
{
 
574
  return heap_delete_table(name);
 
575
}
 
576
 
 
577
 
648
578
void ha_heap::drop_table(const char *)
649
579
{
650
580
  file->s->delete_on_close= 1;
652
582
}
653
583
 
654
584
 
655
 
int HeapEngine::doRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
 
585
int ha_heap::rename_table(const char * from, const char * to)
656
586
{
657
 
  session.renameTableMessage(from, to);
658
 
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
 
587
  return heap_rename(from,to);
659
588
}
660
589
 
661
590
 
681
610
  return key->rec_per_key[key->key_parts-1];
682
611
}
683
612
 
684
 
int HeapEngine::doCreateTable(Session &session,
685
 
                              Table &table_arg,
686
 
                              drizzled::TableIdentifier &identifier,
687
 
                              message::Table& create_proto)
688
 
{
689
 
  int error;
690
 
  HP_SHARE *internal_share;
691
 
  const char *table_name= identifier.getPath().c_str();
692
 
 
693
 
  error= heap_create_table(&session, table_name, &table_arg,
694
 
                           false, 
695
 
                           create_proto,
696
 
                           &internal_share);
697
 
 
698
 
  if (error == 0)
699
 
  {
700
 
    session.storeTableMessage(identifier, create_proto);
701
 
  }
702
 
 
703
 
  return error;
704
 
}
705
 
 
706
 
 
707
 
int HeapEngine::heap_create_table(Session *session, const char *table_name,
708
 
                                  Table *table_arg,
709
 
                                  bool internal_table, 
710
 
                                  message::Table &create_proto,
711
 
                                  HP_SHARE **internal_share)
 
613
 
 
614
int ha_heap::create(const char *name, Table *table_arg,
 
615
                    HA_CREATE_INFO *create_info)
712
616
{
713
617
  uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
714
618
  uint32_t auto_key= 0, auto_key_type= 0;
719
623
  HA_KEYSEG *seg;
720
624
  char buff[FN_REFLEN];
721
625
  int error;
722
 
  TableShare *share= table_arg->s;
 
626
  TABLE_SHARE *share= table_arg->s;
723
627
  bool found_real_auto_increment= 0;
724
628
 
725
 
  /* 
726
 
   * We cannot create tables with more rows than UINT32_MAX.  This is a
727
 
   * limitation of the HEAP engine.  Here, since TableShare::getMaxRows()
728
 
   * can return a number more than that, we trap it here instead of casting
729
 
   * to a truncated integer.
730
 
   */
731
 
  uint64_t num_rows= share->getMaxRows();
732
 
  if (num_rows > UINT32_MAX)
733
 
    return -1;
734
 
 
735
629
  if (!(columndef= (HP_COLUMNDEF*) malloc(column_count * sizeof(HP_COLUMNDEF))))
736
 
    return errno;
 
630
    return my_errno;
737
631
 
738
632
  for (column_idx= 0; column_idx < column_count; column_idx++)
739
633
  {
771
665
                                    parts * sizeof(HA_KEYSEG))))
772
666
  {
773
667
    free((void *) columndef);
774
 
    return errno;
 
668
    return my_errno;
775
669
  }
776
670
 
777
671
  seg= reinterpret_cast<HA_KEYSEG*> (keydef + keys);
828
722
        key_part_size= next_field_pos;
829
723
      }
830
724
 
831
 
      if (field->flags & ENUM_FLAG)
 
725
      if (field->flags & (ENUM_FLAG | SET_FLAG))
832
726
        seg->charset= &my_charset_bin;
833
727
      else
834
728
        seg->charset= field->charset();
877
771
  HP_CREATE_INFO hp_create_info;
878
772
  hp_create_info.auto_key= auto_key;
879
773
  hp_create_info.auto_key_type= auto_key_type;
880
 
  hp_create_info.auto_increment= (create_proto.options().has_auto_increment_value() ?
881
 
                                  create_proto.options().auto_increment_value() - 1 : 0);
882
 
  hp_create_info.max_table_size=session->variables.max_heap_table_size;
 
774
  hp_create_info.auto_increment= (create_info->auto_increment_value ?
 
775
                                  create_info->auto_increment_value - 1 : 0);
 
776
  hp_create_info.max_table_size=current_session->variables.max_heap_table_size;
883
777
  hp_create_info.with_auto_increment= found_real_auto_increment;
884
778
  hp_create_info.internal_table= internal_table;
885
779
  hp_create_info.max_chunk_size= share->block_size;
886
780
  hp_create_info.is_dynamic= (share->row_type == ROW_TYPE_DYNAMIC);
887
 
 
888
 
  error= heap_create(internal::fn_format(buff,table_name,"","",
889
 
                              MY_REPLACE_EXT|MY_UNPACK_FILENAME),
890
 
                    keys, keydef,
891
 
                    column_count, columndef,
892
 
                    max_key_fieldnr, key_part_size,
893
 
                    share->reclength, mem_per_row_keys,
894
 
                    static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
895
 
                    0, // Factor out MIN
896
 
                    &hp_create_info, internal_share);
 
781
  error= heap_create(fn_format(buff,name,"","",
 
782
                               MY_REPLACE_EXT|MY_UNPACK_FILENAME),
 
783
                   keys, keydef,
 
784
         column_count, columndef,
 
785
         max_key_fieldnr, key_part_size,
 
786
         share->reclength, mem_per_row_keys,
 
787
         (uint32_t) share->max_rows, (uint32_t) share->min_rows,
 
788
         &hp_create_info, &internal_share);
897
789
 
898
790
  free((unsigned char*) keydef);
899
791
  free((void *) columndef);
900
 
 
 
792
  assert(file == 0);
901
793
  return (error);
902
794
}
903
795
 
904
796
 
 
797
void ha_heap::update_create_info(HA_CREATE_INFO *create_info)
 
798
{
 
799
  table->file->info(HA_STATUS_AUTO);
 
800
  if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
 
801
    create_info->auto_increment_value= stats.auto_increment_value;
 
802
  if (!(create_info->used_fields & HA_CREATE_USED_BLOCK_SIZE))
 
803
  {
 
804
    if (file->s->recordspace.is_variable_size)
 
805
      create_info->block_size= file->s->recordspace.chunk_length;
 
806
    else
 
807
      create_info->block_size= 0;
 
808
  }
 
809
}
 
810
 
905
811
void ha_heap::get_auto_increment(uint64_t, uint64_t, uint64_t,
906
812
                                 uint64_t *first_value,
907
813
                                 uint64_t *nb_reserved_values)
919
825
}
920
826
 
921
827
 
922
 
DRIZZLE_DECLARE_PLUGIN
923
 
{
924
 
  DRIZZLE_VERSION_ID,
 
828
bool ha_heap::check_if_incompatible_data(HA_CREATE_INFO *info_in,
 
829
                                         uint32_t table_changes)
 
830
{
 
831
  /* Check that auto_increment value was not changed */
 
832
  if ((info_in->used_fields & HA_CREATE_USED_AUTO &&
 
833
       info_in->auto_increment_value != 0) ||
 
834
      table_changes == IS_EQUAL_NO ||
 
835
      table_changes & IS_EQUAL_PACK_LENGTH) // Not implemented yet
 
836
    return COMPATIBLE_DATA_NO;
 
837
  return COMPATIBLE_DATA_YES;
 
838
}
 
839
 
 
840
drizzle_declare_plugin(heap)
 
841
{
 
842
  DRIZZLE_STORAGE_ENGINE_PLUGIN,
925
843
  "MEMORY",
926
844
  "1.0",
927
845
  "MySQL AB",
928
846
  "Hash based, stored in memory, useful for temporary tables",
929
847
  PLUGIN_LICENSE_GPL,
930
848
  heap_init,
 
849
  heap_deinit,
 
850
  NULL,                       /* status variables                */
931
851
  NULL,                       /* system variables                */
932
852
  NULL                        /* config options                  */
933
853
}
934
 
DRIZZLE_DECLARE_PLUGIN_END;
 
854
drizzle_declare_plugin_end;