~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/ha_heap.cc

  • Committer: Brian Aker
  • Date: 2010-08-09 18:04:12 UTC
  • mfrom: (1689.3.7 staging)
  • Revision ID: brian@gaz-20100809180412-olurwh51ojllev6p
Merge in heap conversion, and case insensitive patch, and remove need for
M_HASH in session.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "heap_priv.h"
17
17
#include <drizzled/error.h>
18
18
#include <drizzled/table.h>
19
19
#include <drizzled/session.h>
 
20
#include <drizzled/field/timestamp.h>
20
21
#include <drizzled/field/varstring.h>
21
 
#include <drizzled/plugin/daemon.h>
22
 
#include <drizzled/plugin/storage_engine.h>
 
22
#include "drizzled/plugin/daemon.h"
23
23
 
24
24
#include <boost/thread/mutex.hpp>
25
25
 
60
60
    hp_panic(HA_PANIC_CLOSE);
61
61
  }
62
62
 
63
 
  virtual Cursor *create(Table &table)
 
63
  virtual Cursor *create(TableShare &table)
64
64
  {
65
65
    return new ha_heap(*this, table);
66
66
  }
71
71
 
72
72
  int doCreateTable(Session &session,
73
73
                    Table &table_arg,
74
 
                    const identifier::Table &identifier,
 
74
                    const TableIdentifier &identifier,
75
75
                    message::Table &create_proto);
76
76
 
77
77
  /* For whatever reason, internal tables can be created by Cursor::open()
85
85
                        message::Table &create_proto,
86
86
                        HP_SHARE **internal_share);
87
87
 
88
 
  int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
 
88
  int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
89
89
 
90
 
  int doDropTable(Session&, const identifier::Table &identifier);
 
90
  int doDropTable(Session&, const TableIdentifier &identifier);
91
91
 
92
92
  int doGetTableDefinition(Session& session,
93
 
                           const identifier::Table &identifier,
 
93
                           const TableIdentifier &identifier,
94
94
                           message::Table &table_message);
95
95
 
 
96
  /* Temp only engine, so do not return values. */
 
97
  void doGetTableNames(CachedDirectory &, const SchemaIdentifier& , set<string>&) { };
 
98
 
96
99
  uint32_t max_supported_keys()          const { return MAX_KEY; }
97
100
  uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
98
101
 
99
 
  uint32_t index_flags(enum  ha_key_alg ) const
 
102
  uint32_t index_flags(enum  ha_key_alg algorithm) const
100
103
  {
101
 
    return ( HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR);
 
104
    return ((algorithm == HA_KEY_ALG_BTREE) ?
 
105
            HA_READ_NEXT |
 
106
            HA_READ_PREV |
 
107
            HA_READ_ORDER |
 
108
            HA_READ_RANGE :
 
109
            HA_ONLY_WHOLE_INDEX |
 
110
            HA_KEY_SCAN_NOT_ROR);
102
111
  }
103
112
 
104
 
  bool doDoesTableExist(Session& session, const identifier::Table &identifier);
 
113
  bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
105
114
  void doGetTableIdentifiers(CachedDirectory &directory,
106
 
                             const identifier::Schema &schema_identifier,
107
 
                             identifier::Table::vector &set_of_identifiers);
 
115
                             const SchemaIdentifier &schema_identifier,
 
116
                             TableIdentifiers &set_of_identifiers);
108
117
};
109
118
 
110
119
void HeapEngine::doGetTableIdentifiers(CachedDirectory&,
111
 
                                       const identifier::Schema&,
112
 
                                       identifier::Table::vector&)
 
120
                                       const SchemaIdentifier&,
 
121
                                       TableIdentifiers&)
113
122
{
114
123
}
115
124
 
116
 
bool HeapEngine::doDoesTableExist(Session& session, const identifier::Table &identifier)
 
125
bool HeapEngine::doDoesTableExist(Session& session, const TableIdentifier &identifier)
117
126
{
118
 
  return session.getMessageCache().doesTableMessageExist(identifier);
 
127
  return session.doesTableMessageExist(identifier);
119
128
}
120
129
 
121
130
int HeapEngine::doGetTableDefinition(Session &session,
122
 
                                     const identifier::Table &identifier,
 
131
                                     const TableIdentifier &identifier,
123
132
                                     message::Table &table_proto)
124
133
{
125
 
  if (session.getMessageCache().getTableMessage(identifier, table_proto))
 
134
  if (session.getTableMessage(identifier, table_proto))
126
135
    return EEXIST;
127
136
 
128
137
  return ENOENT;
131
140
  We have to ignore ENOENT entries as the MEMORY table is created on open and
132
141
  not when doing a CREATE on the table.
133
142
*/
134
 
int HeapEngine::doDropTable(Session &session, const identifier::Table &identifier)
 
143
int HeapEngine::doDropTable(Session &session, const TableIdentifier &identifier)
135
144
{
136
 
  session.getMessageCache().removeTableMessage(identifier);
 
145
  session.removeTableMessage(identifier);
137
146
 
138
147
  int error= heap_delete_table(identifier.getPath().c_str());
139
148
 
158
167
*****************************************************************************/
159
168
 
160
169
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
161
 
                 Table &table_arg)
 
170
                 TableShare &table_arg)
162
171
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
163
172
  internal_table(0)
164
173
{}
176
185
*/
177
186
#define MEMORY_STATS_UPDATE_THRESHOLD 10
178
187
 
179
 
int ha_heap::doOpen(const drizzled::identifier::Table &identifier, int mode, uint32_t test_if_locked)
 
188
int ha_heap::open(const char *name, int mode, uint32_t test_if_locked)
180
189
{
181
 
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(identifier.getPath().c_str(), mode)) && errno == ENOENT))
 
190
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && errno == ENOENT))
182
191
  {
183
192
    internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
184
193
    file= 0;
185
194
    HP_SHARE *internal_share= NULL;
186
195
    message::Table create_proto;
187
196
 
188
 
    if (not heap_storage_engine->heap_create_table(getTable()->in_use,
189
 
                                                   identifier.getPath().c_str(),
190
 
                                                   getTable(),
191
 
                                                   internal_table,
192
 
                                                   create_proto,
193
 
                                                   &internal_share))
 
197
    if (!heap_storage_engine->heap_create_table(table->in_use, name, table,
 
198
                                                internal_table,
 
199
                                                create_proto,
 
200
                                                &internal_share))
194
201
    {
195
202
        file= internal_table ?
196
203
          heap_open_from_share(internal_share, mode) :
217
224
      ha_heap::info(), which is always called before key statistics are
218
225
      used.
219
226
    */
220
 
    key_stat_version= file->getShare()->key_stat_version - 1;
 
227
    key_stat_version= file->s->key_stat_version - 1;
221
228
  }
222
229
  return (file ? 0 : 1);
223
230
}
240
247
 
241
248
Cursor *ha_heap::clone(memory::Root *)
242
249
{
243
 
  Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
244
 
  identifier::Table identifier(getTable()->getShare()->getSchemaName(),
245
 
                             getTable()->getShare()->getTableName(),
246
 
                             getTable()->getShare()->getPath());
 
250
  Cursor *new_handler= table->getMutableShare()->db_type()->getCursor(*(table->getMutableShare()));
 
251
  TableIdentifier identifier(table->getShare()->getSchemaName(),
 
252
                             table->getShare()->getTableName(),
 
253
                             table->getShare()->getPath());
247
254
 
248
 
  if (new_handler && !new_handler->ha_open(identifier, getTable()->db_stat,
 
255
  if (new_handler && !new_handler->ha_open(identifier, table, file->s->name, table->db_stat,
249
256
                                           HA_OPEN_IGNORE_IF_LOCKED))
250
257
    return new_handler;
251
258
  return NULL;
252
259
}
253
260
 
254
261
 
255
 
const char *ha_heap::index_type(uint32_t )
 
262
const char *ha_heap::index_type(uint32_t inx)
256
263
{
257
 
  return ("HASH");
 
264
  return ((table_share->getKeyInfo(inx).algorithm == HA_KEY_ALG_BTREE) ?
 
265
          "BTREE" : "HASH");
258
266
}
259
267
 
260
268
 
276
284
 
277
285
void ha_heap::set_keys_for_scanning(void)
278
286
{
 
287
  btree_keys.reset();
 
288
  for (uint32_t i= 0 ; i < table->getShare()->sizeKeys() ; i++)
 
289
  {
 
290
    if (table->key_info[i].algorithm == HA_KEY_ALG_BTREE)
 
291
      btree_keys.set(i);
 
292
  }
279
293
}
280
294
 
281
295
 
282
296
void ha_heap::update_key_stats()
283
297
{
284
 
  for (uint32_t i= 0; i < getTable()->getShare()->sizeKeys(); i++)
 
298
  for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++)
285
299
  {
286
 
    KeyInfo *key= &getTable()->key_info[i];
287
 
 
 
300
    KeyInfo *key= &table->key_info[i];
288
301
    if (!key->rec_per_key)
289
302
      continue;
290
 
 
 
303
    if (key->algorithm != HA_KEY_ALG_BTREE)
291
304
    {
292
305
      if (key->flags & HA_NOSAME)
293
306
        key->rec_per_key[key->key_parts-1]= 1;
294
307
      else
295
308
      {
296
 
        ha_rows hash_buckets= file->getShare()->keydef[i].hash_buckets;
297
 
        uint32_t no_records= hash_buckets ? (uint) (file->getShare()->records/hash_buckets) : 2;
 
309
        ha_rows hash_buckets= file->s->keydef[i].hash_buckets;
 
310
        uint32_t no_records= hash_buckets ? (uint) (file->s->records/hash_buckets) : 2;
298
311
        if (no_records < 2)
299
312
          no_records= 2;
300
313
        key->rec_per_key[key->key_parts-1]= no_records;
303
316
  }
304
317
  records_changed= 0;
305
318
  /* At the end of update_key_stats() we can proudly claim they are OK. */
306
 
  key_stat_version= file->getShare()->key_stat_version;
 
319
  key_stat_version= file->s->key_stat_version;
307
320
}
308
321
 
309
322
 
310
323
int ha_heap::doInsertRecord(unsigned char * buf)
311
324
{
312
325
  int res;
313
 
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
 
326
  if (table->next_number_field && buf == table->getInsertRecord())
314
327
  {
315
328
    if ((res= update_auto_increment()))
316
329
      return res;
317
330
  }
318
331
  res= heap_write(file,buf);
319
332
  if (!res && (++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
320
 
               file->getShare()->records))
 
333
               file->s->records))
321
334
  {
322
335
    /*
323
336
       We can perform this safely since only one writer at the time is
324
337
       allowed on the table.
325
338
    */
326
 
    file->getShare()->key_stat_version++;
 
339
    file->s->key_stat_version++;
327
340
  }
328
341
  return res;
329
342
}
334
347
 
335
348
  res= heap_update(file,old_data,new_data);
336
349
  if (!res && ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
337
 
              file->getShare()->records)
 
350
              file->s->records)
338
351
  {
339
352
    /*
340
353
       We can perform this safely since only one writer at the time is
341
354
       allowed on the table.
342
355
    */
343
 
    file->getShare()->key_stat_version++;
 
356
    file->s->key_stat_version++;
344
357
  }
345
358
  return res;
346
359
}
350
363
  int res;
351
364
 
352
365
  res= heap_delete(file,buf);
353
 
  if (!res && getTable()->getShare()->getType() == message::Table::STANDARD &&
354
 
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->getShare()->records)
 
366
  if (!res && table->getShare()->getType() == message::Table::STANDARD &&
 
367
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->s->records)
355
368
  {
356
369
    /*
357
370
       We can perform this safely since only one writer at the time is
358
371
       allowed on the table.
359
372
    */
360
 
    file->getShare()->key_stat_version++;
 
373
    file->s->key_stat_version++;
361
374
  }
362
375
  return res;
363
376
}
369
382
  assert(inited==INDEX);
370
383
  ha_statistic_increment(&system_status_var::ha_read_key_count);
371
384
  int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
372
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
385
  table->status = error ? STATUS_NOT_FOUND : 0;
373
386
  return error;
374
387
}
375
388
 
380
393
  ha_statistic_increment(&system_status_var::ha_read_key_count);
381
394
  int error= heap_rkey(file, buf, active_index, key, keypart_map,
382
395
                       HA_READ_PREFIX_LAST);
383
 
  getTable()->status= error ? STATUS_NOT_FOUND : 0;
 
396
  table->status= error ? STATUS_NOT_FOUND : 0;
384
397
  return error;
385
398
}
386
399
 
390
403
{
391
404
  ha_statistic_increment(&system_status_var::ha_read_key_count);
392
405
  int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
393
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
406
  table->status = error ? STATUS_NOT_FOUND : 0;
394
407
  return error;
395
408
}
396
409
 
399
412
  assert(inited==INDEX);
400
413
  ha_statistic_increment(&system_status_var::ha_read_next_count);
401
414
  int error=heap_rnext(file,buf);
402
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
415
  table->status=error ? STATUS_NOT_FOUND: 0;
403
416
  return error;
404
417
}
405
418
 
408
421
  assert(inited==INDEX);
409
422
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
410
423
  int error=heap_rprev(file,buf);
411
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
424
  table->status=error ? STATUS_NOT_FOUND: 0;
412
425
  return error;
413
426
}
414
427
 
417
430
  assert(inited==INDEX);
418
431
  ha_statistic_increment(&system_status_var::ha_read_first_count);
419
432
  int error=heap_rfirst(file, buf, active_index);
420
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
433
  table->status=error ? STATUS_NOT_FOUND: 0;
421
434
  return error;
422
435
}
423
436
 
426
439
  assert(inited==INDEX);
427
440
  ha_statistic_increment(&system_status_var::ha_read_last_count);
428
441
  int error=heap_rlast(file, buf, active_index);
429
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
442
  table->status=error ? STATUS_NOT_FOUND: 0;
430
443
  return error;
431
444
}
432
445
 
439
452
{
440
453
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
441
454
  int error=heap_scan(file, buf);
442
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
455
  table->status=error ? STATUS_NOT_FOUND: 0;
443
456
  return error;
444
457
}
445
458
 
450
463
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
451
464
  memcpy(&heap_position, pos, sizeof(HEAP_PTR));
452
465
  error=heap_rrnd(file, buf, heap_position);
453
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
466
  table->status=error ? STATUS_NOT_FOUND: 0;
454
467
  return error;
455
468
}
456
469
 
479
492
    have to update the key statistics. Hoping that a table lock is now
480
493
    in place.
481
494
  */
482
 
  if (key_stat_version != file->getShare()->key_stat_version)
 
495
  if (key_stat_version != file->s->key_stat_version)
483
496
    update_key_stats();
484
497
  return 0;
485
498
}
499
512
int ha_heap::delete_all_rows()
500
513
{
501
514
  heap_clear(file);
502
 
  if (getTable()->getShare()->getType() == message::Table::STANDARD)
 
515
  if (table->getShare()->getType() == message::Table::STANDARD)
503
516
  {
504
517
    /*
505
518
       We can perform this safely since only one writer at the time is
506
519
       allowed on the table.
507
520
    */
508
 
    file->getShare()->key_stat_version++;
 
521
    file->s->key_stat_version++;
509
522
  }
510
523
  return 0;
511
524
}
619
632
 
620
633
void ha_heap::drop_table(const char *)
621
634
{
622
 
  file->getShare()->delete_on_close= 1;
 
635
  file->s->delete_on_close= 1;
623
636
  close();
624
637
}
625
638
 
626
639
 
627
 
int HeapEngine::doRenameTable(Session &session, const identifier::Table &from, const identifier::Table &to)
 
640
int HeapEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
628
641
{
629
 
  session.getMessageCache().renameTableMessage(from, to);
 
642
  session.renameTableMessage(from, to);
630
643
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
631
644
}
632
645
 
634
647
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
635
648
                                  key_range *max_key)
636
649
{
637
 
  KeyInfo *key= &getTable()->key_info[inx];
 
650
  KeyInfo *key= &table->key_info[inx];
 
651
  if (key->algorithm == HA_KEY_ALG_BTREE)
 
652
    return hp_rb_records_in_range(file, inx, min_key, max_key);
638
653
 
639
654
  if (!min_key || !max_key ||
640
655
      min_key->length != max_key->length ||
647
662
    return stats.records;
648
663
 
649
664
  /* Assert that info() did run. We need current statistics here. */
650
 
  assert(key_stat_version == file->getShare()->key_stat_version);
 
665
  assert(key_stat_version == file->s->key_stat_version);
651
666
  return key->rec_per_key[key->key_parts-1];
652
667
}
653
668
 
654
669
int HeapEngine::doCreateTable(Session &session,
655
670
                              Table &table_arg,
656
 
                              const identifier::Table &identifier,
 
671
                              const TableIdentifier &identifier,
657
672
                              message::Table& create_proto)
658
673
{
659
674
  int error;
667
682
 
668
683
  if (error == 0)
669
684
  {
670
 
    session.getMessageCache().storeTableMessage(identifier, create_proto);
 
685
    session.storeTableMessage(identifier, create_proto);
671
686
  }
672
687
 
673
688
  return error;
680
695
                                  message::Table &create_proto,
681
696
                                  HP_SHARE **internal_share)
682
697
{
683
 
  uint32_t key, parts, mem_per_row_keys= 0;
684
 
  uint32_t keys= table_arg->getShare()->sizeKeys();
 
698
  uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->getShare()->sizeKeys();
685
699
  uint32_t auto_key= 0, auto_key_type= 0;
686
700
  uint32_t max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
687
 
  uint32_t column_count= table_arg->getShare()->sizeFields();
688
 
  std::vector<HP_KEYDEF> keydef;
 
701
  uint32_t column_idx, column_count= table_arg->getShare()->sizeFields();
 
702
  HP_COLUMNDEF *columndef;
 
703
  HP_KEYDEF *keydef;
 
704
  HA_KEYSEG *seg;
 
705
  char buff[FN_REFLEN];
689
706
  int error;
690
707
  bool found_real_auto_increment= 0;
691
708
 
699
716
  if (num_rows > UINT32_MAX)
700
717
    return -1;
701
718
 
 
719
  if (!(columndef= (HP_COLUMNDEF*) malloc(column_count * sizeof(HP_COLUMNDEF))))
 
720
    return errno;
 
721
 
 
722
  for (column_idx= 0; column_idx < column_count; column_idx++)
 
723
  {
 
724
    Field* field= *(table_arg->getFields() + column_idx);
 
725
    HP_COLUMNDEF* column= columndef + column_idx;
 
726
    column->type= (uint16_t)field->type();
 
727
    column->length= field->pack_length();
 
728
    column->offset= field->offset(field->getTable()->getInsertRecord());
 
729
 
 
730
    if (field->null_bit)
 
731
    {
 
732
      column->null_bit= field->null_bit;
 
733
      column->null_pos= (uint) (field->null_ptr - (unsigned char*) table_arg->getInsertRecord());
 
734
    }
 
735
    else
 
736
    {
 
737
      column->null_bit= 0;
 
738
      column->null_pos= 0;
 
739
    }
 
740
 
 
741
    if (field->type() == DRIZZLE_TYPE_VARCHAR)
 
742
    {
 
743
      column->length_bytes= (uint8_t)(((Field_varstring*)field)->length_bytes);
 
744
    }
 
745
    else
 
746
    {
 
747
      column->length_bytes= 0;
 
748
    }
 
749
  }
 
750
 
702
751
  for (key= parts= 0; key < keys; key++)
703
752
    parts+= table_arg->key_info[key].key_parts;
704
753
 
705
 
  keydef.resize(keys);
706
 
  std::vector<HA_KEYSEG> seg_buffer;
707
 
  seg_buffer.resize(parts);
708
 
  HA_KEYSEG *seg= &seg_buffer[0];
 
754
  if (!(keydef= (HP_KEYDEF*) malloc(keys * sizeof(HP_KEYDEF) +
 
755
                                    parts * sizeof(HA_KEYSEG))))
 
756
  {
 
757
    free((void *) columndef);
 
758
    return errno;
 
759
  }
709
760
 
 
761
  seg= reinterpret_cast<HA_KEYSEG*> (keydef + keys);
710
762
  for (key= 0; key < keys; key++)
711
763
  {
712
764
    KeyInfo *pos= &table_arg->key_info[key];
717
769
    keydef[key].flag=      (pos->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL));
718
770
    keydef[key].seg=       seg;
719
771
 
720
 
    mem_per_row_keys+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
 
772
    switch (pos->algorithm) {
 
773
    case HA_KEY_ALG_UNDEF:
 
774
    case HA_KEY_ALG_HASH:
 
775
      keydef[key].algorithm= HA_KEY_ALG_HASH;
 
776
      mem_per_row_keys+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
 
777
      break;
 
778
    case HA_KEY_ALG_BTREE:
 
779
      keydef[key].algorithm= HA_KEY_ALG_BTREE;
 
780
      mem_per_row_keys+=sizeof(TREE_ELEMENT)+pos->key_length+sizeof(char*);
 
781
      break;
 
782
    default:
 
783
      assert(0); // cannot happen
 
784
    }
721
785
 
722
786
    for (; key_part != key_part_end; key_part++, seg++)
723
787
    {
724
788
      Field *field= key_part->field;
725
789
 
 
790
      if (pos->algorithm == HA_KEY_ALG_BTREE)
 
791
        seg->type= field->key_type();
 
792
      else
726
793
      {
727
794
        if ((seg->type = field->key_type()) != (int) HA_KEYTYPE_TEXT &&
728
795
            seg->type != HA_KEYTYPE_VARTEXT1 &&
738
805
      next_field_pos= seg->start + seg->length;
739
806
      if (field->type() == DRIZZLE_TYPE_VARCHAR)
740
807
      {
741
 
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->pack_length_no_ptr());
 
808
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->length_bytes);
742
809
      }
743
810
 
744
811
      if (next_field_pos > key_part_size) {
770
837
        auto_key= key+ 1;
771
838
        auto_key_type= field->key_type();
772
839
      }
773
 
      if ((uint)field->position() + 1 > max_key_fieldnr)
 
840
      if ((uint)field->field_index + 1 > max_key_fieldnr)
774
841
      {
775
842
        /* Do not use seg->fieldnr as it's not reliable in case of temp tables */
776
 
        max_key_fieldnr= field->position() + 1;
 
843
        max_key_fieldnr= field->field_index + 1;
777
844
      }
778
845
    }
779
846
  }
800
867
  hp_create_info.with_auto_increment= found_real_auto_increment;
801
868
  hp_create_info.internal_table= internal_table;
802
869
  hp_create_info.max_chunk_size= table_arg->getShare()->block_size;
803
 
 
804
 
  error= heap_create(table_name,
805
 
                     keys, &keydef[0],
806
 
                     column_count,
807
 
                     key_part_size,
808
 
                     table_arg->getShare()->getRecordLength(), mem_per_row_keys,
809
 
                     static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
810
 
                     0, // Factor out MIN
811
 
                     &hp_create_info, internal_share);
 
870
  hp_create_info.is_dynamic= false;
 
871
 
 
872
  error= heap_create(internal::fn_format(buff,table_name,"","",
 
873
                              MY_REPLACE_EXT|MY_UNPACK_FILENAME),
 
874
                    keys, keydef,
 
875
                    column_count, columndef,
 
876
                    max_key_fieldnr, key_part_size,
 
877
                    table_arg->getShare()->getRecordLength(), mem_per_row_keys,
 
878
                    static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
 
879
                    0, // Factor out MIN
 
880
                    &hp_create_info, internal_share);
 
881
 
 
882
  free((unsigned char*) keydef);
 
883
  free((void *) columndef);
812
884
 
813
885
  return (error);
814
886
}
840
912
  "Hash based, stored in memory, useful for temporary tables",
841
913
  PLUGIN_LICENSE_GPL,
842
914
  heap_init,
843
 
  NULL,                       /* depends */
 
915
  NULL,                       /* system variables                */
844
916
  NULL                        /* config options                  */
845
917
}
846
918
DRIZZLE_DECLARE_PLUGIN_END;