~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-03 20:57:39 UTC
  • mfrom: (1680.6.4 rollup)
  • Revision ID: brian@gaz-20100803205739-7betgobkod41363k
Removes LOCK_system_variables_hash, one goto, drops internall new for std
new (so possible performance regression), fixes bug where Session was not
unlocked correctly.

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>
21
21
#include <drizzled/field/varstring.h>
22
22
#include "drizzled/plugin/daemon.h"
23
23
 
24
 
#include <boost/thread/mutex.hpp>
25
 
 
26
24
#include "heap.h"
27
25
#include "ha_heap.h"
28
26
 
34
32
 
35
33
static const string engine_name("MEMORY");
36
34
 
37
 
boost::mutex THR_LOCK_heap;
 
35
pthread_mutex_t THR_LOCK_heap= PTHREAD_MUTEX_INITIALIZER;
38
36
 
39
37
static const char *ha_heap_exts[] = {
40
38
  NULL
53
51
                          HTON_SKIP_STORE_LOCK |
54
52
                          HTON_TEMPORARY_ONLY)
55
53
  {
 
54
    pthread_mutex_init(&THR_LOCK_heap, MY_MUTEX_INIT_FAST);
56
55
  }
57
56
 
58
57
  virtual ~HeapEngine()
59
58
  {
60
59
    hp_panic(HA_PANIC_CLOSE);
 
60
 
 
61
    pthread_mutex_destroy(&THR_LOCK_heap);
61
62
  }
62
63
 
63
 
  virtual Cursor *create(Table &table)
 
64
  virtual Cursor *create(TableShare &table)
64
65
  {
65
66
    return new ha_heap(*this, table);
66
67
  }
93
94
                           const TableIdentifier &identifier,
94
95
                           message::Table &table_message);
95
96
 
 
97
  /* Temp only engine, so do not return values. */
 
98
  void doGetTableNames(CachedDirectory &, const SchemaIdentifier& , set<string>&) { };
 
99
 
96
100
  uint32_t max_supported_keys()          const { return MAX_KEY; }
97
101
  uint32_t max_supported_key_part_length() const { return MAX_KEY_LENGTH; }
98
102
 
99
 
  uint32_t index_flags(enum  ha_key_alg ) const
 
103
  uint32_t index_flags(enum  ha_key_alg algorithm) const
100
104
  {
101
 
    return ( HA_ONLY_WHOLE_INDEX | HA_KEY_SCAN_NOT_ROR);
 
105
    return ((algorithm == HA_KEY_ALG_BTREE) ?
 
106
            HA_READ_NEXT |
 
107
            HA_READ_PREV |
 
108
            HA_READ_ORDER |
 
109
            HA_READ_RANGE :
 
110
            HA_ONLY_WHOLE_INDEX |
 
111
            HA_KEY_SCAN_NOT_ROR);
102
112
  }
103
113
 
104
114
  bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
105
115
  void doGetTableIdentifiers(CachedDirectory &directory,
106
116
                             const SchemaIdentifier &schema_identifier,
107
 
                             TableIdentifier::vector &set_of_identifiers);
 
117
                             TableIdentifiers &set_of_identifiers);
108
118
};
109
119
 
110
120
void HeapEngine::doGetTableIdentifiers(CachedDirectory&,
111
121
                                       const SchemaIdentifier&,
112
 
                                       TableIdentifier::vector&)
 
122
                                       TableIdentifiers&)
113
123
{
114
124
}
115
125
 
116
126
bool HeapEngine::doDoesTableExist(Session& session, const TableIdentifier &identifier)
117
127
{
118
 
  return session.getMessageCache().doesTableMessageExist(identifier);
 
128
  return session.doesTableMessageExist(identifier);
119
129
}
120
130
 
121
131
int HeapEngine::doGetTableDefinition(Session &session,
122
132
                                     const TableIdentifier &identifier,
123
133
                                     message::Table &table_proto)
124
134
{
125
 
  if (session.getMessageCache().getTableMessage(identifier, table_proto))
 
135
  if (session.getTableMessage(identifier, table_proto))
126
136
    return EEXIST;
127
137
 
128
138
  return ENOENT;
133
143
*/
134
144
int HeapEngine::doDropTable(Session &session, const TableIdentifier &identifier)
135
145
{
136
 
  session.getMessageCache().removeTableMessage(identifier);
 
146
  session.removeTableMessage(identifier);
137
147
 
138
148
  int error= heap_delete_table(identifier.getPath().c_str());
139
149
 
158
168
*****************************************************************************/
159
169
 
160
170
ha_heap::ha_heap(plugin::StorageEngine &engine_arg,
161
 
                 Table &table_arg)
 
171
                 TableShare &table_arg)
162
172
  :Cursor(engine_arg, table_arg), file(0), records_changed(0), key_stat_version(0),
163
173
  internal_table(0)
164
174
{}
176
186
*/
177
187
#define MEMORY_STATS_UPDATE_THRESHOLD 10
178
188
 
179
 
int ha_heap::doOpen(const drizzled::TableIdentifier &identifier, int mode, uint32_t test_if_locked)
 
189
int ha_heap::open(const char *name, int mode, uint32_t test_if_locked)
180
190
{
181
 
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(identifier.getPath().c_str(), mode)) && errno == ENOENT))
 
191
  if ((test_if_locked & HA_OPEN_INTERNAL_TABLE) || (!(file= heap_open(name, mode)) && errno == ENOENT))
182
192
  {
 
193
    HA_CREATE_INFO create_info;
183
194
    internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
 
195
    memset(&create_info, 0, sizeof(create_info));
184
196
    file= 0;
185
197
    HP_SHARE *internal_share= NULL;
186
198
    message::Table create_proto;
187
199
 
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))
 
200
    if (!heap_storage_engine->heap_create_table(table->in_use, name, table,
 
201
                                                internal_table,
 
202
                                                create_proto,
 
203
                                                &internal_share))
194
204
    {
195
205
        file= internal_table ?
196
206
          heap_open_from_share(internal_share, mode) :
198
208
      if (!file)
199
209
      {
200
210
         /* Couldn't open table; Remove the newly created table */
201
 
        THR_LOCK_heap.lock();
 
211
        pthread_mutex_lock(&THR_LOCK_heap);
202
212
        hp_free(internal_share);
203
 
        THR_LOCK_heap.unlock();
 
213
        pthread_mutex_unlock(&THR_LOCK_heap);
204
214
      }
205
215
    }
206
216
  }
217
227
      ha_heap::info(), which is always called before key statistics are
218
228
      used.
219
229
    */
220
 
    key_stat_version= file->getShare()->key_stat_version - 1;
 
230
    key_stat_version= file->s->key_stat_version - 1;
221
231
  }
222
232
  return (file ? 0 : 1);
223
233
}
240
250
 
241
251
Cursor *ha_heap::clone(memory::Root *)
242
252
{
243
 
  Cursor *new_handler= getTable()->getMutableShare()->db_type()->getCursor(*getTable());
244
 
  TableIdentifier identifier(getTable()->getShare()->getSchemaName(),
245
 
                             getTable()->getShare()->getTableName(),
246
 
                             getTable()->getShare()->getPath());
 
253
  Cursor *new_handler= table->getMutableShare()->db_type()->getCursor(*(table->getMutableShare()));
 
254
  TableIdentifier identifier(table->getShare()->getSchemaName(),
 
255
                             table->getShare()->getTableName(),
 
256
                             table->getShare()->getPath());
247
257
 
248
 
  if (new_handler && !new_handler->ha_open(identifier, getTable()->db_stat,
 
258
  if (new_handler && !new_handler->ha_open(identifier, table, file->s->name, table->db_stat,
249
259
                                           HA_OPEN_IGNORE_IF_LOCKED))
250
260
    return new_handler;
251
261
  return NULL;
252
262
}
253
263
 
254
264
 
255
 
const char *ha_heap::index_type(uint32_t )
 
265
const char *ha_heap::index_type(uint32_t inx)
256
266
{
257
 
  return ("HASH");
 
267
  return ((table_share->getKeyInfo(inx).algorithm == HA_KEY_ALG_BTREE) ?
 
268
          "BTREE" : "HASH");
258
269
}
259
270
 
260
271
 
276
287
 
277
288
void ha_heap::set_keys_for_scanning(void)
278
289
{
 
290
  btree_keys.reset();
 
291
  for (uint32_t i= 0 ; i < table->getShare()->sizeKeys() ; i++)
 
292
  {
 
293
    if (table->key_info[i].algorithm == HA_KEY_ALG_BTREE)
 
294
      btree_keys.set(i);
 
295
  }
279
296
}
280
297
 
281
298
 
282
299
void ha_heap::update_key_stats()
283
300
{
284
 
  for (uint32_t i= 0; i < getTable()->getShare()->sizeKeys(); i++)
 
301
  for (uint32_t i= 0; i < table->getShare()->sizeKeys(); i++)
285
302
  {
286
 
    KeyInfo *key= &getTable()->key_info[i];
287
 
 
 
303
    KeyInfo *key= &table->key_info[i];
288
304
    if (!key->rec_per_key)
289
305
      continue;
290
 
 
 
306
    if (key->algorithm != HA_KEY_ALG_BTREE)
291
307
    {
292
308
      if (key->flags & HA_NOSAME)
293
309
        key->rec_per_key[key->key_parts-1]= 1;
294
310
      else
295
311
      {
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;
 
312
        ha_rows hash_buckets= file->s->keydef[i].hash_buckets;
 
313
        uint32_t no_records= hash_buckets ? (uint) (file->s->records/hash_buckets) : 2;
298
314
        if (no_records < 2)
299
315
          no_records= 2;
300
316
        key->rec_per_key[key->key_parts-1]= no_records;
303
319
  }
304
320
  records_changed= 0;
305
321
  /* At the end of update_key_stats() we can proudly claim they are OK. */
306
 
  key_stat_version= file->getShare()->key_stat_version;
 
322
  key_stat_version= file->s->key_stat_version;
307
323
}
308
324
 
309
325
 
310
326
int ha_heap::doInsertRecord(unsigned char * buf)
311
327
{
312
328
  int res;
313
 
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
 
329
  if (table->next_number_field && buf == table->getInsertRecord())
314
330
  {
315
331
    if ((res= update_auto_increment()))
316
332
      return res;
317
333
  }
318
334
  res= heap_write(file,buf);
319
335
  if (!res && (++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
320
 
               file->getShare()->records))
 
336
               file->s->records))
321
337
  {
322
338
    /*
323
339
       We can perform this safely since only one writer at the time is
324
340
       allowed on the table.
325
341
    */
326
 
    file->getShare()->key_stat_version++;
 
342
    file->s->key_stat_version++;
327
343
  }
328
344
  return res;
329
345
}
334
350
 
335
351
  res= heap_update(file,old_data,new_data);
336
352
  if (!res && ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD >
337
 
              file->getShare()->records)
 
353
              file->s->records)
338
354
  {
339
355
    /*
340
356
       We can perform this safely since only one writer at the time is
341
357
       allowed on the table.
342
358
    */
343
 
    file->getShare()->key_stat_version++;
 
359
    file->s->key_stat_version++;
344
360
  }
345
361
  return res;
346
362
}
350
366
  int res;
351
367
 
352
368
  res= heap_delete(file,buf);
353
 
  if (!res && getTable()->getShare()->getType() == message::Table::STANDARD &&
354
 
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->getShare()->records)
 
369
  if (!res && table->getShare()->getType() == message::Table::STANDARD &&
 
370
      ++records_changed*MEMORY_STATS_UPDATE_THRESHOLD > file->s->records)
355
371
  {
356
372
    /*
357
373
       We can perform this safely since only one writer at the time is
358
374
       allowed on the table.
359
375
    */
360
 
    file->getShare()->key_stat_version++;
 
376
    file->s->key_stat_version++;
361
377
  }
362
378
  return res;
363
379
}
369
385
  assert(inited==INDEX);
370
386
  ha_statistic_increment(&system_status_var::ha_read_key_count);
371
387
  int error = heap_rkey(file,buf,active_index, key, keypart_map, find_flag);
372
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
388
  table->status = error ? STATUS_NOT_FOUND : 0;
373
389
  return error;
374
390
}
375
391
 
380
396
  ha_statistic_increment(&system_status_var::ha_read_key_count);
381
397
  int error= heap_rkey(file, buf, active_index, key, keypart_map,
382
398
                       HA_READ_PREFIX_LAST);
383
 
  getTable()->status= error ? STATUS_NOT_FOUND : 0;
 
399
  table->status= error ? STATUS_NOT_FOUND : 0;
384
400
  return error;
385
401
}
386
402
 
390
406
{
391
407
  ha_statistic_increment(&system_status_var::ha_read_key_count);
392
408
  int error = heap_rkey(file, buf, index, key, keypart_map, find_flag);
393
 
  getTable()->status = error ? STATUS_NOT_FOUND : 0;
 
409
  table->status = error ? STATUS_NOT_FOUND : 0;
394
410
  return error;
395
411
}
396
412
 
399
415
  assert(inited==INDEX);
400
416
  ha_statistic_increment(&system_status_var::ha_read_next_count);
401
417
  int error=heap_rnext(file,buf);
402
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
418
  table->status=error ? STATUS_NOT_FOUND: 0;
403
419
  return error;
404
420
}
405
421
 
408
424
  assert(inited==INDEX);
409
425
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
410
426
  int error=heap_rprev(file,buf);
411
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
427
  table->status=error ? STATUS_NOT_FOUND: 0;
412
428
  return error;
413
429
}
414
430
 
417
433
  assert(inited==INDEX);
418
434
  ha_statistic_increment(&system_status_var::ha_read_first_count);
419
435
  int error=heap_rfirst(file, buf, active_index);
420
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
436
  table->status=error ? STATUS_NOT_FOUND: 0;
421
437
  return error;
422
438
}
423
439
 
426
442
  assert(inited==INDEX);
427
443
  ha_statistic_increment(&system_status_var::ha_read_last_count);
428
444
  int error=heap_rlast(file, buf, active_index);
429
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
445
  table->status=error ? STATUS_NOT_FOUND: 0;
430
446
  return error;
431
447
}
432
448
 
439
455
{
440
456
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
441
457
  int error=heap_scan(file, buf);
442
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
458
  table->status=error ? STATUS_NOT_FOUND: 0;
443
459
  return error;
444
460
}
445
461
 
450
466
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
451
467
  memcpy(&heap_position, pos, sizeof(HEAP_PTR));
452
468
  error=heap_rrnd(file, buf, heap_position);
453
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
469
  table->status=error ? STATUS_NOT_FOUND: 0;
454
470
  return error;
455
471
}
456
472
 
479
495
    have to update the key statistics. Hoping that a table lock is now
480
496
    in place.
481
497
  */
482
 
  if (key_stat_version != file->getShare()->key_stat_version)
 
498
  if (key_stat_version != file->s->key_stat_version)
483
499
    update_key_stats();
484
500
  return 0;
485
501
}
499
515
int ha_heap::delete_all_rows()
500
516
{
501
517
  heap_clear(file);
502
 
  if (getTable()->getShare()->getType() == message::Table::STANDARD)
 
518
  if (table->getShare()->getType() == message::Table::STANDARD)
503
519
  {
504
520
    /*
505
521
       We can perform this safely since only one writer at the time is
506
522
       allowed on the table.
507
523
    */
508
 
    file->getShare()->key_stat_version++;
 
524
    file->s->key_stat_version++;
509
525
  }
510
526
  return 0;
511
527
}
619
635
 
620
636
void ha_heap::drop_table(const char *)
621
637
{
622
 
  file->getShare()->delete_on_close= 1;
 
638
  file->s->delete_on_close= 1;
623
639
  close();
624
640
}
625
641
 
626
642
 
627
643
int HeapEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
628
644
{
629
 
  session.getMessageCache().renameTableMessage(from, to);
 
645
  session.renameTableMessage(from, to);
630
646
  return heap_rename(from.getPath().c_str(), to.getPath().c_str());
631
647
}
632
648
 
634
650
ha_rows ha_heap::records_in_range(uint32_t inx, key_range *min_key,
635
651
                                  key_range *max_key)
636
652
{
637
 
  KeyInfo *key= &getTable()->key_info[inx];
 
653
  KeyInfo *key= &table->key_info[inx];
 
654
  if (key->algorithm == HA_KEY_ALG_BTREE)
 
655
    return hp_rb_records_in_range(file, inx, min_key, max_key);
638
656
 
639
657
  if (!min_key || !max_key ||
640
658
      min_key->length != max_key->length ||
647
665
    return stats.records;
648
666
 
649
667
  /* Assert that info() did run. We need current statistics here. */
650
 
  assert(key_stat_version == file->getShare()->key_stat_version);
 
668
  assert(key_stat_version == file->s->key_stat_version);
651
669
  return key->rec_per_key[key->key_parts-1];
652
670
}
653
671
 
667
685
 
668
686
  if (error == 0)
669
687
  {
670
 
    session.getMessageCache().storeTableMessage(identifier, create_proto);
 
688
    session.storeTableMessage(identifier, create_proto);
671
689
  }
672
690
 
673
691
  return error;
680
698
                                  message::Table &create_proto,
681
699
                                  HP_SHARE **internal_share)
682
700
{
683
 
  uint32_t key, parts, mem_per_row_keys= 0;
684
 
  uint32_t keys= table_arg->getShare()->sizeKeys();
 
701
  uint32_t key, parts, mem_per_row_keys= 0, keys= table_arg->getShare()->sizeKeys();
685
702
  uint32_t auto_key= 0, auto_key_type= 0;
686
703
  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;
 
704
  uint32_t column_idx, column_count= table_arg->getShare()->sizeFields();
 
705
  HP_COLUMNDEF *columndef;
 
706
  HP_KEYDEF *keydef;
 
707
  HA_KEYSEG *seg;
 
708
  char buff[FN_REFLEN];
689
709
  int error;
690
710
  bool found_real_auto_increment= 0;
691
711
 
699
719
  if (num_rows > UINT32_MAX)
700
720
    return -1;
701
721
 
 
722
  if (!(columndef= (HP_COLUMNDEF*) malloc(column_count * sizeof(HP_COLUMNDEF))))
 
723
    return errno;
 
724
 
 
725
  for (column_idx= 0; column_idx < column_count; column_idx++)
 
726
  {
 
727
    Field* field= *(table_arg->getFields() + column_idx);
 
728
    HP_COLUMNDEF* column= columndef + column_idx;
 
729
    column->type= (uint16_t)field->type();
 
730
    column->length= field->pack_length();
 
731
    column->offset= field->offset(field->getTable()->getInsertRecord());
 
732
 
 
733
    if (field->null_bit)
 
734
    {
 
735
      column->null_bit= field->null_bit;
 
736
      column->null_pos= (uint) (field->null_ptr - (unsigned char*) table_arg->getInsertRecord());
 
737
    }
 
738
    else
 
739
    {
 
740
      column->null_bit= 0;
 
741
      column->null_pos= 0;
 
742
    }
 
743
 
 
744
    if (field->type() == DRIZZLE_TYPE_VARCHAR)
 
745
    {
 
746
      column->length_bytes= (uint8_t)(((Field_varstring*)field)->length_bytes);
 
747
    }
 
748
    else
 
749
    {
 
750
      column->length_bytes= 0;
 
751
    }
 
752
  }
 
753
 
702
754
  for (key= parts= 0; key < keys; key++)
703
755
    parts+= table_arg->key_info[key].key_parts;
704
756
 
705
 
  keydef.resize(keys);
706
 
  std::vector<HA_KEYSEG> seg_buffer;
707
 
  seg_buffer.resize(parts);
708
 
  HA_KEYSEG *seg= &seg_buffer[0];
 
757
  if (!(keydef= (HP_KEYDEF*) malloc(keys * sizeof(HP_KEYDEF) +
 
758
                                    parts * sizeof(HA_KEYSEG))))
 
759
  {
 
760
    free((void *) columndef);
 
761
    return errno;
 
762
  }
709
763
 
 
764
  seg= reinterpret_cast<HA_KEYSEG*> (keydef + keys);
710
765
  for (key= 0; key < keys; key++)
711
766
  {
712
767
    KeyInfo *pos= &table_arg->key_info[key];
717
772
    keydef[key].flag=      (pos->flags & (HA_NOSAME | HA_NULL_ARE_EQUAL));
718
773
    keydef[key].seg=       seg;
719
774
 
720
 
    mem_per_row_keys+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
 
775
    switch (pos->algorithm) {
 
776
    case HA_KEY_ALG_UNDEF:
 
777
    case HA_KEY_ALG_HASH:
 
778
      keydef[key].algorithm= HA_KEY_ALG_HASH;
 
779
      mem_per_row_keys+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
 
780
      break;
 
781
    case HA_KEY_ALG_BTREE:
 
782
      keydef[key].algorithm= HA_KEY_ALG_BTREE;
 
783
      mem_per_row_keys+=sizeof(TREE_ELEMENT)+pos->key_length+sizeof(char*);
 
784
      break;
 
785
    default:
 
786
      assert(0); // cannot happen
 
787
    }
721
788
 
722
789
    for (; key_part != key_part_end; key_part++, seg++)
723
790
    {
724
791
      Field *field= key_part->field;
725
792
 
 
793
      if (pos->algorithm == HA_KEY_ALG_BTREE)
 
794
        seg->type= field->key_type();
 
795
      else
726
796
      {
727
797
        if ((seg->type = field->key_type()) != (int) HA_KEYTYPE_TEXT &&
728
798
            seg->type != HA_KEYTYPE_VARTEXT1 &&
738
808
      next_field_pos= seg->start + seg->length;
739
809
      if (field->type() == DRIZZLE_TYPE_VARCHAR)
740
810
      {
741
 
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->pack_length_no_ptr());
 
811
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->length_bytes);
742
812
      }
743
813
 
744
814
      if (next_field_pos > key_part_size) {
770
840
        auto_key= key+ 1;
771
841
        auto_key_type= field->key_type();
772
842
      }
773
 
      if ((uint)field->position() + 1 > max_key_fieldnr)
 
843
      if ((uint)field->field_index + 1 > max_key_fieldnr)
774
844
      {
775
845
        /* Do not use seg->fieldnr as it's not reliable in case of temp tables */
776
 
        max_key_fieldnr= field->position() + 1;
 
846
        max_key_fieldnr= field->field_index + 1;
777
847
      }
778
848
    }
779
849
  }
800
870
  hp_create_info.with_auto_increment= found_real_auto_increment;
801
871
  hp_create_info.internal_table= internal_table;
802
872
  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);
 
873
  hp_create_info.is_dynamic= false;
 
874
 
 
875
  error= heap_create(internal::fn_format(buff,table_name,"","",
 
876
                              MY_REPLACE_EXT|MY_UNPACK_FILENAME),
 
877
                    keys, keydef,
 
878
                    column_count, columndef,
 
879
                    max_key_fieldnr, key_part_size,
 
880
                    table_arg->getShare()->getRecordLength(), mem_per_row_keys,
 
881
                    static_cast<uint32_t>(num_rows), /* We check for overflow above, so cast is fine here. */
 
882
                    0, // Factor out MIN
 
883
                    &hp_create_info, internal_share);
 
884
 
 
885
  free((unsigned char*) keydef);
 
886
  free((void *) columndef);
812
887
 
813
888
  return (error);
814
889
}