~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Mark Atwood
  • Date: 2011-06-24 02:13:02 UTC
  • mfrom: (2318.6.56 rf)
  • Revision ID: me@mark.atwood.name-20110624021302-y9oiksid220xan9s
mergeĀ lp:~olafvdspek/drizzle/refactor14

Show diffs side-by-side

added added

removed removed

Lines of Context:
206
206
}
207
207
 
208
208
 
209
 
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings)
 
209
TYPELIB *typelib(memory::Root& mem_root, List<String> &strings)
210
210
{
211
 
  TYPELIB *result= (TYPELIB*) mem_root->alloc_root(sizeof(TYPELIB));
212
 
  if (!result)
213
 
    return 0;
 
211
  TYPELIB *result= new (mem_root) TYPELIB;
214
212
  result->count= strings.size();
215
213
  result->name= "";
216
 
  uint32_t nbytes= (sizeof(char*) + sizeof(uint32_t)) * (result->count + 1);
217
 
  
218
 
  if (!(result->type_names= (const char**) mem_root->alloc_root(nbytes)))
219
 
    return 0;
220
 
    
 
214
  result->type_names= (const char**) mem_root.alloc((sizeof(char*) + sizeof(uint32_t)) * (result->count + 1));
221
215
  result->type_lengths= (uint*) (result->type_names + result->count + 1);
222
216
 
223
217
  List<String>::iterator it(strings.begin());
669
663
    Make sure that the blob fits into a Field_varstring which has
670
664
    2-byte lenght.
671
665
  */
672
 
  if (convert_blob_length && convert_blob_length <= Field_varstring::MAX_SIZE &&
673
 
      (org_field->flags & BLOB_FLAG))
 
666
  if (convert_blob_length && convert_blob_length <= Field_varstring::MAX_SIZE && (org_field->flags & BLOB_FLAG))
674
667
  {
675
668
    table->setVariableWidth();
676
 
    new_field= new Field_varstring(convert_blob_length,
677
 
                                   org_field->maybe_null(),
678
 
                                   org_field->field_name,
679
 
                                   org_field->charset());
 
669
    new_field= new Field_varstring(convert_blob_length, org_field->maybe_null(), org_field->field_name, org_field->charset());
680
670
  }
681
671
  else
682
672
  {
683
 
    new_field= org_field->new_field(session->mem_root, table,
684
 
                                    table == org_field->getTable());
 
673
    new_field= org_field->new_field(session->mem_root, table, table == org_field->getTable());
685
674
  }
686
675
  if (new_field)
687
676
  {
798
787
 
799
788
  table::Singular* table= &session->getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
800
789
 
801
 
  if (not table->getMemRoot()->multi_alloc_root(0,
802
 
                                                &default_field, sizeof(Field*) * (field_count),
803
 
                                                &from_field, sizeof(Field*)*field_count,
804
 
                                                &copy_func, sizeof(*copy_func)*(copy_func_count+1),
805
 
                                                &param->keyinfo, sizeof(*param->keyinfo),
806
 
                                                &key_part_info, sizeof(*key_part_info)*(param->group_parts+1),
807
 
                                                &param->start_recinfo, sizeof(*param->recinfo)*(field_count*2+4),
808
 
                                                &group_buff, (group && ! using_unique_constraint ?
809
 
                                                              param->group_length : 0),
810
 
                                                NULL))
811
 
  {
812
 
    return NULL;
813
 
  }
 
790
  table->getMemRoot().multi_alloc(0,
 
791
    &default_field, sizeof(Field*) * (field_count),
 
792
    &from_field, sizeof(Field*)*field_count,
 
793
    &copy_func, sizeof(*copy_func)*(copy_func_count+1),
 
794
    &param->keyinfo, sizeof(*param->keyinfo),
 
795
    &key_part_info, sizeof(*key_part_info)*(param->group_parts+1),
 
796
    &param->start_recinfo, sizeof(*param->recinfo)*(field_count*2+4),
 
797
    &group_buff, (group && ! using_unique_constraint ? param->group_length : 0),
 
798
    NULL);
814
799
  /* CopyField belongs to Tmp_Table_Param, allocate it in Session mem_root */
815
800
  param->copy_field= copy= new (session->mem_root) CopyField[field_count];
816
801
  param->items_to_copy= copy_func;
820
805
  memset(from_field, 0, sizeof(Field*)*field_count);
821
806
 
822
807
  memory::Root* mem_root_save= session->mem_root;
823
 
  session->mem_root= table->getMemRoot();
 
808
  session->mem_root= &table->getMemRoot();
824
809
 
825
810
  table->getMutableShare()->setFields(field_count+1);
826
811
  table->setFields(table->getMutableShare()->getFields(true));
907
892
          }
908
893
          session->mem_root= mem_root_save;
909
894
          *argp= new Item_field(new_field);
910
 
          session->mem_root= table->getMemRoot();
 
895
          session->mem_root= &table->getMemRoot();
911
896
          if (!(new_field->flags & NOT_NULL_FLAG))
912
897
          {
913
898
            null_count++;
1037
1022
  {
1038
1023
    uint32_t alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
1039
1024
    table->getMutableShare()->rec_buff_length= alloc_length;
1040
 
    if (!(table->record[0]= (unsigned char*) table->alloc_root(alloc_length*2)))
1041
 
    {
1042
 
      goto err;
1043
 
    }
 
1025
    table->record[0]= table->alloc(alloc_length*2);
1044
1026
    table->record[1]= table->getInsertRecord()+alloc_length;
1045
1027
    table->getMutableShare()->resizeDefaultValues(alloc_length);
1046
1028
  }
1256
1238
                         (table->getMutableShare()->uniques ? test(null_pack_length) : 0));
1257
1239
    table->distinct= 1;
1258
1240
    table->getMutableShare()->keys= 1;
1259
 
    if (!(key_part_info= (KeyPartInfo*)
1260
 
         table->alloc_root(keyinfo->key_parts * sizeof(KeyPartInfo))))
1261
 
      goto err;
 
1241
    key_part_info= (KeyPartInfo*)table->alloc(keyinfo->key_parts * sizeof(KeyPartInfo));
1262
1242
    memset(key_part_info, 0, keyinfo->key_parts * sizeof(KeyPartInfo));
1263
1243
    table->key_info=keyinfo;
1264
1244
    keyinfo->key_part=key_part_info;