~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/ha_heap.cc

  • Committer: brian
  • Date: 2008-08-01 17:43:30 UTC
  • mfrom: (261.1.8 drizzle)
  • Revision ID: brian@localhost.localdomain-20080801174330-3y6yxa7pxkzdir6p
Merge from downsource tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
391
391
}
392
392
 
393
393
 
 
394
enum row_type ha_heap::get_row_type() const
 
395
{
 
396
  if (file->s->recordspace.is_variable_size)
 
397
    return ROW_TYPE_DYNAMIC;
 
398
 
 
399
  return ROW_TYPE_FIXED;
 
400
}
 
401
 
394
402
int ha_heap::extra(enum ha_extra_function operation)
395
403
{
396
404
  return heap_extra(file,operation);
592
600
int ha_heap::create(const char *name, TABLE *table_arg,
593
601
                    HA_CREATE_INFO *create_info)
594
602
{
595
 
  uint key, parts, mem_per_row= 0, keys= table_arg->s->keys;
 
603
  uint key, parts, mem_per_row_keys= 0, keys= table_arg->s->keys;
596
604
  uint auto_key= 0, auto_key_type= 0;
597
 
  ha_rows max_rows;
 
605
  uint max_key_fieldnr = 0, key_part_size = 0, next_field_pos = 0;
 
606
  uint column_idx, column_count= table_arg->s->fields;
 
607
  HP_COLUMNDEF *columndef;
598
608
  HP_KEYDEF *keydef;
599
609
  HA_KEYSEG *seg;
 
610
  char buff[FN_REFLEN];
600
611
  int error;
601
612
  TABLE_SHARE *share= table_arg->s;
602
613
  bool found_real_auto_increment= 0;
603
614
 
 
615
  if (!(columndef= (HP_COLUMNDEF*) my_malloc(column_count * sizeof(HP_COLUMNDEF), MYF(MY_WME))))
 
616
    return my_errno;
 
617
 
 
618
  for (column_idx= 0; column_idx < column_count; column_idx++)
 
619
  {
 
620
    Field* field= *(table_arg->field + column_idx);
 
621
    HP_COLUMNDEF* column= columndef + column_idx;
 
622
    column->type= (uint16_t)field->type();
 
623
    column->length= field->pack_length();
 
624
    column->offset= field->offset(field->table->record[0]);
 
625
 
 
626
    if (field->null_bit)
 
627
    {
 
628
      column->null_bit= field->null_bit;
 
629
      column->null_pos= (uint) (field->null_ptr - (uchar*) table_arg->record[0]);
 
630
    }
 
631
    else
 
632
    {
 
633
      column->null_bit= 0;
 
634
      column->null_pos= 0;
 
635
    }
 
636
 
 
637
    if (field->type() == DRIZZLE_TYPE_VARCHAR)
 
638
    {
 
639
      column->length_bytes= (uint8_t)(((Field_varstring*)field)->length_bytes);
 
640
    }
 
641
    else
 
642
    {
 
643
      column->length_bytes= 0;
 
644
    }
 
645
  }
 
646
 
604
647
  for (key= parts= 0; key < keys; key++)
605
648
    parts+= table_arg->key_info[key].key_parts;
606
649
 
607
650
  if (!(keydef= (HP_KEYDEF*) my_malloc(keys * sizeof(HP_KEYDEF) +
608
651
                                       parts * sizeof(HA_KEYSEG),
609
652
                                       MYF(MY_WME))))
 
653
  {
 
654
    my_free((void *) columndef, MYF(0));
610
655
    return my_errno;
 
656
  }
 
657
 
611
658
  seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + keys);
612
659
  for (key= 0; key < keys; key++)
613
660
  {
623
670
    case HA_KEY_ALG_UNDEF:
624
671
    case HA_KEY_ALG_HASH:
625
672
      keydef[key].algorithm= HA_KEY_ALG_HASH;
626
 
      mem_per_row+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
 
673
      mem_per_row_keys+= sizeof(char*) * 2; // = sizeof(HASH_INFO)
627
674
      break;
628
675
    case HA_KEY_ALG_BTREE:
629
676
      keydef[key].algorithm= HA_KEY_ALG_BTREE;
630
 
      mem_per_row+=sizeof(TREE_ELEMENT)+pos->key_length+sizeof(char*);
 
677
      mem_per_row_keys+=sizeof(TREE_ELEMENT)+pos->key_length+sizeof(char*);
631
678
      break;
632
679
    default:
633
680
      assert(0); // cannot happen
652
699
      seg->length=  (uint) key_part->length;
653
700
      seg->flag=    key_part->key_part_flag;
654
701
 
 
702
      next_field_pos= seg->start + seg->length;
 
703
      if (field->type() == DRIZZLE_TYPE_VARCHAR)
 
704
      {
 
705
        next_field_pos+= (uint8_t)(((Field_varstring*)field)->length_bytes);
 
706
      }
 
707
 
 
708
      if (next_field_pos > key_part_size) {
 
709
        key_part_size= next_field_pos;
 
710
      }
 
711
 
655
712
      if (field->flags & (ENUM_FLAG | SET_FLAG))
656
713
        seg->charset= &my_charset_bin;
657
714
      else
677
734
        auto_key= key+ 1;
678
735
        auto_key_type= field->key_type();
679
736
      }
 
737
      if ((uint)field->field_index + 1 > max_key_fieldnr)
 
738
      {
 
739
        /* Do not use seg->fieldnr as it's not reliable in case of temp tables */
 
740
        max_key_fieldnr= field->field_index + 1;
 
741
      }
680
742
    }
681
743
  }
682
 
  mem_per_row+= MY_ALIGN(share->reclength + 1, sizeof(char*));
683
 
  max_rows = (ha_rows) (table_arg->in_use->variables.max_heap_table_size /
684
 
                        (uint64_t) mem_per_row);
 
744
  
 
745
  if (key_part_size < share->null_bytes + ((share->last_null_bit_pos+7) >> 3))
 
746
  {
 
747
    /* Make sure to include null fields regardless of the presense of keys */
 
748
    key_part_size = share->null_bytes + ((share->last_null_bit_pos+7) >> 3);
 
749
  }
 
750
 
 
751
  
 
752
  
685
753
  if (table_arg->found_next_number_field)
686
754
  {
687
755
    keydef[share->next_number_index].flag|= HA_AUTO_KEY;
695
763
  hp_create_info.max_table_size=current_thd->variables.max_heap_table_size;
696
764
  hp_create_info.with_auto_increment= found_real_auto_increment;
697
765
  hp_create_info.internal_table= internal_table;
698
 
  max_rows = (ha_rows) (hp_create_info.max_table_size / mem_per_row);
699
 
  error= heap_create(name,
700
 
                     keys, keydef, share->reclength,
701
 
                     (ulong) ((share->max_rows < max_rows &&
702
 
                               share->max_rows) ? 
703
 
                              share->max_rows : max_rows),
704
 
                     (ulong) share->min_rows, &hp_create_info, &internal_share);
 
766
  hp_create_info.max_chunk_size= share->block_size;
 
767
  hp_create_info.is_dynamic= (share->row_type == ROW_TYPE_DYNAMIC);
 
768
  error= heap_create(fn_format(buff,name,"","",
 
769
                               MY_REPLACE_EXT|MY_UNPACK_FILENAME),
 
770
                   keys, keydef,
 
771
         column_count, columndef,
 
772
         max_key_fieldnr, key_part_size,
 
773
         share->reclength, mem_per_row_keys,
 
774
         (ulong) share->max_rows, (ulong) share->min_rows,
 
775
         &hp_create_info, &internal_share);
 
776
  
705
777
  my_free((uchar*) keydef, MYF(0));
 
778
  my_free((void *) columndef, MYF(0));
706
779
  assert(file == 0);
707
780
  return (error);
708
781
}
713
786
  table->file->info(HA_STATUS_AUTO);
714
787
  if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
715
788
    create_info->auto_increment_value= stats.auto_increment_value;
 
789
  if (!(create_info->used_fields & HA_CREATE_USED_BLOCK_SIZE))
 
790
  {
 
791
    if (file->s->recordspace.is_variable_size)
 
792
      create_info->block_size= file->s->recordspace.chunk_length;
 
793
    else
 
794
      create_info->block_size= 0;
 
795
  }
716
796
}
717
797
 
718
798
void ha_heap::get_auto_increment(uint64_t offset __attribute__((unused)),