~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2010-08-08 01:18:02 UTC
  • mto: (1698.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1696.
  • Revision ID: brian@gaz-20100808011802-go9sp57jxgmcgfxn
More encapsulation of thr_lock

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
 
17
17
/* Some general useful functions */
54
54
#include <drizzled/item/null.h>
55
55
#include <drizzled/temporal.h>
56
56
 
57
 
#include "drizzled/table/instance.h"
 
57
#include "drizzled/table_share_instance.h"
58
58
 
59
59
#include "drizzled/table_proto.h"
60
60
 
81
81
 
82
82
  if (db_stat)
83
83
    error= cursor->close();
84
 
  _alias.clear();
 
84
  free((char*) alias);
 
85
  alias= NULL;
85
86
  if (field)
86
87
  {
87
88
    for (Field **ptr=field ; *ptr ; ptr++)
95
96
 
96
97
  if (free_share)
97
98
  {
98
 
    release();
 
99
    if (s->getType() == message::Table::STANDARD)
 
100
    {
 
101
      TableShare::release(s);
 
102
    }
 
103
    else
 
104
    {
 
105
      delete s;
 
106
    }
 
107
 
 
108
    s= NULL;
99
109
  }
 
110
  mem_root.free_root(MYF(0));
100
111
 
101
112
  return error;
102
113
}
103
114
 
104
 
Table::~Table()
105
 
{
106
 
  mem_root.free_root(MYF(0));
107
 
}
108
 
 
109
115
 
110
116
void Table::resetTable(Session *session,
111
117
                       TableShare *share,
112
118
                       uint32_t db_stat_arg)
113
119
{
114
 
  setShare(share);
 
120
  s= share;
115
121
  field= NULL;
116
122
 
117
123
  cursor= NULL;
136
142
 
137
143
  pos_in_table_list= NULL;
138
144
  group= NULL;
139
 
  _alias.clear();
 
145
  alias= NULL;
140
146
  null_flags= NULL;
141
147
 
142
148
  lock_position= 0;
190
196
  memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
191
197
 
192
198
  memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
 
199
  memset(&sort, 0, sizeof(filesort_info_st));
193
200
}
194
201
 
195
202
 
247
254
  return (nr);
248
255
} /* set_zone */
249
256
 
 
257
        /* Adjust number to next larger disk buffer */
 
258
 
 
259
ulong next_io_size(register ulong pos)
 
260
{
 
261
  register ulong offset;
 
262
  if ((offset= pos & (IO_SIZE-1)))
 
263
    return pos-offset+IO_SIZE;
 
264
  return pos;
 
265
} /* next_io_size */
 
266
 
250
267
 
251
268
/*
252
269
  Store an SQL quoted string.
310
327
}
311
328
 
312
329
 
 
330
/*
 
331
  Set up column usage bitmaps for a temporary table
 
332
 
 
333
  IMPLEMENTATION
 
334
    For temporary tables, we need one bitmap with all columns set and
 
335
    a tmp_set bitmap to be used by things like filesort.
 
336
*/
 
337
 
 
338
void Table::setup_tmp_table_column_bitmaps(unsigned char *bitmaps)
 
339
{
 
340
  uint32_t field_count= s->sizeFields();
 
341
 
 
342
  this->def_read_set.init((my_bitmap_map*) bitmaps, field_count);
 
343
  this->tmp_set.init((my_bitmap_map*) (bitmaps+ bitmap_buffer_size(field_count)), field_count);
 
344
 
 
345
  /* write_set and all_set are copies of read_set */
 
346
  def_write_set= def_read_set;
 
347
  s->all_set= def_read_set;
 
348
  this->getMutableShare()->all_set.setAll();
 
349
  default_column_bitmaps();
 
350
}
 
351
 
 
352
 
313
353
int rename_file_ext(const char * from,const char * to,const char * ext)
314
354
{
315
355
  string from_s, to_s;
413
453
    bitmap_clear_all(&table->def_read_set);
414
454
    bitmap_clear_all(&table->def_write_set);
415
455
  */
416
 
  def_read_set.reset();
417
 
  def_write_set.reset();
418
 
  column_bitmaps_set(def_read_set, def_write_set);
 
456
  def_read_set.clearAll();
 
457
  def_write_set.clearAll();
 
458
  column_bitmaps_set(&def_read_set, &def_write_set);
419
459
}
420
460
 
421
461
 
432
472
{
433
473
 
434
474
  if ((cursor->getEngine()->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX)) &&
435
 
      getShare()->hasPrimaryKey())
 
475
      s->hasPrimaryKey())
436
476
  {
437
 
    mark_columns_used_by_index_no_reset(getShare()->getPrimaryKey());
 
477
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
438
478
  }
439
479
  return;
440
480
}
452
492
 
453
493
void Table::mark_columns_used_by_index(uint32_t index)
454
494
{
455
 
  boost::dynamic_bitset<> *bitmap= &tmp_set;
 
495
  MyBitmap *bitmap= &tmp_set;
456
496
 
457
497
  (void) cursor->extra(HA_EXTRA_KEYREAD);
458
 
  bitmap->reset();
459
 
  mark_columns_used_by_index_no_reset(index, *bitmap);
460
 
  column_bitmaps_set(*bitmap, *bitmap);
 
498
  bitmap->clearAll();
 
499
  mark_columns_used_by_index_no_reset(index, bitmap);
 
500
  column_bitmaps_set(bitmap, bitmap);
461
501
  return;
462
502
}
463
503
 
489
529
 
490
530
void Table::mark_columns_used_by_index_no_reset(uint32_t index)
491
531
{
492
 
    mark_columns_used_by_index_no_reset(index, *read_set);
 
532
    mark_columns_used_by_index_no_reset(index, read_set);
493
533
}
494
534
 
495
 
 
496
535
void Table::mark_columns_used_by_index_no_reset(uint32_t index,
497
 
                                                boost::dynamic_bitset<>& bitmap)
 
536
                                                MyBitmap *bitmap)
498
537
{
499
538
  KeyPartInfo *key_part= key_info[index].key_part;
500
 
  KeyPartInfo *key_part_end= (key_part + key_info[index].key_parts);
501
 
  for (; key_part != key_part_end; key_part++)
502
 
  {
503
 
    if (! bitmap.empty())
504
 
      bitmap.set(key_part->fieldnr-1);
505
 
  }
 
539
  KeyPartInfo *key_part_end= (key_part +
 
540
                                key_info[index].key_parts);
 
541
  for (;key_part != key_part_end; key_part++)
 
542
    bitmap->setBit(key_part->fieldnr-1);
506
543
}
507
544
 
508
545
 
521
558
    We must set bit in read set as update_auto_increment() is using the
522
559
    store() to check overflow of auto_increment values
523
560
  */
524
 
  setReadSet(found_next_number_field->position());
525
 
  setWriteSet(found_next_number_field->position());
526
 
  if (getShare()->next_number_keypart)
527
 
    mark_columns_used_by_index_no_reset(getShare()->next_number_index);
 
561
  setReadSet(found_next_number_field->field_index);
 
562
  setWriteSet(found_next_number_field->field_index);
 
563
  if (s->next_number_keypart)
 
564
    mark_columns_used_by_index_no_reset(s->next_number_index);
528
565
}
529
566
 
530
567
 
555
592
    be able to do an delete
556
593
 
557
594
  */
558
 
  if (not getShare()->hasPrimaryKey())
 
595
  if (not s->hasPrimaryKey())
559
596
  {
560
597
    /* fallback to use all columns in the table to identify row */
561
598
    use_all_columns();
562
599
    return;
563
600
  }
564
601
  else
565
 
    mark_columns_used_by_index_no_reset(getShare()->getPrimaryKey());
 
602
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
566
603
 
567
604
  /* If we the engine wants all predicates we mark all keys */
568
605
  if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
571
608
    for (reg_field= field ; *reg_field ; reg_field++)
572
609
    {
573
610
      if ((*reg_field)->flags & PART_KEY_FLAG)
574
 
        setReadSet((*reg_field)->position());
 
611
        setReadSet((*reg_field)->field_index);
575
612
    }
576
613
  }
577
614
}
603
640
    the primary key, the hidden primary key or all columns to be
604
641
    able to do an update
605
642
  */
606
 
  if (not getShare()->hasPrimaryKey())
 
643
  if (not s->hasPrimaryKey())
607
644
  {
608
645
    /* fallback to use all columns in the table to identify row */
609
646
    use_all_columns();
610
647
    return;
611
648
  }
612
649
  else
613
 
    mark_columns_used_by_index_no_reset(getShare()->getPrimaryKey());
 
650
    mark_columns_used_by_index_no_reset(s->getPrimaryKey());
614
651
 
615
652
  if (cursor->getEngine()->check_flag(HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE))
616
653
  {
620
657
    {
621
658
      /* Merge keys is all keys that had a column refered to in the query */
622
659
      if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
623
 
        setReadSet((*reg_field)->position());
 
660
        setReadSet((*reg_field)->field_index);
624
661
    }
625
662
  }
626
663
 
658
695
  return length;
659
696
}
660
697
 
661
 
void Table::setVariableWidth(void)
662
 
{
663
 
  assert(in_use);
664
 
  if (in_use && in_use->lex->sql_command == SQLCOM_CREATE_TABLE)
665
 
  {
666
 
    getMutableShare()->setVariableWidth();
667
 
    return;
668
 
  }
669
 
 
670
 
  assert(0); // Programming error, you can't set this on a plain old Table.
671
 
}
672
 
 
673
698
/****************************************************************************
674
699
 Functions for creating temporary tables.
675
700
****************************************************************************/
707
732
  */
708
733
  if (convert_blob_length && convert_blob_length <= Field_varstring::MAX_SIZE &&
709
734
      (org_field->flags & BLOB_FLAG))
710
 
  {
711
 
    table->setVariableWidth();
712
735
    new_field= new Field_varstring(convert_blob_length,
713
736
                                   org_field->maybe_null(),
714
 
                                   org_field->field_name,
 
737
                                   org_field->field_name, table->getMutableShare(),
715
738
                                   org_field->charset());
716
 
  }
717
739
  else
718
 
  {
719
740
    new_field= org_field->new_field(session->mem_root, table,
720
741
                                    table == org_field->getTable());
721
 
  }
722
742
  if (new_field)
723
743
  {
724
744
    new_field->init(table);
771
791
 
772
792
Table *
773
793
create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
774
 
                 Order *group, bool distinct, bool save_sum_fields,
 
794
                 order_st *group, bool distinct, bool save_sum_fields,
775
795
                 uint64_t select_options, ha_rows rows_limit,
776
796
                 const char *table_alias)
777
797
{
778
798
  memory::Root *mem_root_save;
 
799
  Table *table;
779
800
  uint  i,field_count,null_count,null_pack_length;
780
801
  uint32_t  copy_func_count= param->func_count;
781
802
  uint32_t  hidden_null_count, hidden_null_pack_length, hidden_field_count;
785
806
  bool  using_unique_constraint= false;
786
807
  bool  use_packed_rows= true;
787
808
  bool  not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
788
 
  unsigned char *pos, *group_buff;
 
809
  unsigned char *pos, *group_buff, *bitmaps;
789
810
  unsigned char *null_flags;
790
811
  Field **reg_field, **from_field, **default_field;
791
812
  CopyField *copy= 0;
797
818
  bool force_copy_fields= param->force_copy_fields;
798
819
  uint64_t max_rows= 0;
799
820
 
800
 
  session->status_var.created_tmp_tables++;
 
821
  status_var_increment(session->status_var.created_tmp_tables);
801
822
 
802
823
  if (group)
803
824
  {
805
826
    {
806
827
      group= 0;                                 // Can't use group key
807
828
    }
808
 
    else for (Order *tmp=group ; tmp ; tmp=tmp->next)
 
829
    else for (order_st *tmp=group ; tmp ; tmp=tmp->next)
809
830
    {
810
831
      /*
811
832
        marker == 4 means two things:
838
859
    copy_func_count+= param->sum_func_count;
839
860
  }
840
861
 
841
 
  table::Instance *table;
842
 
  table= session->getInstanceTable(); // This will not go into the tableshare cache, so no key is used.
 
862
  TableShareInstance *share= session->getTemporaryShare(message::Table::INTERNAL); // This will not go into the tableshare cache, so no key is used.
843
863
 
844
 
  if (not table->getMemRoot()->multi_alloc_root(0,
 
864
  if (not share->getMemRoot()->multi_alloc_root(0,
845
865
                                                &default_field, sizeof(Field*) * (field_count),
846
866
                                                &from_field, sizeof(Field*)*field_count,
847
867
                                                &copy_func, sizeof(*copy_func)*(copy_func_count+1),
850
870
                                                &param->start_recinfo, sizeof(*param->recinfo)*(field_count*2+4),
851
871
                                                &group_buff, (group && ! using_unique_constraint ?
852
872
                                                              param->group_length : 0),
 
873
                                                &bitmaps, bitmap_buffer_size(field_count)*2,
853
874
                                                NULL))
854
875
  {
855
876
    return NULL;
862
883
  param->items_to_copy= copy_func;
863
884
  /* make table according to fields */
864
885
 
 
886
  table= share->getTable();
 
887
 
865
888
  memset(default_field, 0, sizeof(Field*) * (field_count));
866
889
  memset(from_field, 0, sizeof(Field*)*field_count);
867
890
 
868
891
  mem_root_save= session->mem_root;
869
892
  session->mem_root= table->getMemRoot();
870
893
 
871
 
  table->getMutableShare()->setFields(field_count+1);
872
 
  table->setFields(table->getMutableShare()->getFields(true));
873
 
  reg_field= table->getMutableShare()->getFields(true);
874
 
  table->setAlias(table_alias);
 
894
  share->setFields(field_count+1);
 
895
  table->setFields(share->getFields(true));
 
896
  reg_field= share->getFields(true);
 
897
  table->alias= table_alias;
875
898
  table->reginfo.lock_type=TL_WRITE;    /* Will be updated */
876
899
  table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
877
900
  table->map=1;
882
905
  table->covering_keys.reset();
883
906
  table->keys_in_use_for_query.reset();
884
907
 
885
 
  table->getMutableShare()->blob_field.resize(field_count+1);
886
 
  uint32_t *blob_field= &table->getMutableShare()->blob_field[0];
887
 
  table->getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
888
 
  table->getMutableShare()->db_low_byte_first=1;                // True for HEAP and MyISAM
889
 
  table->getMutableShare()->table_charset= param->table_charset;
890
 
  table->getMutableShare()->keys_for_keyread.reset();
891
 
  table->getMutableShare()->keys_in_use.reset();
 
908
  table->setShare(share);
 
909
  share->blob_field.resize(field_count+1);
 
910
  uint32_t *blob_field= &share->blob_field[0];
 
911
  share->blob_ptr_size= portable_sizeof_char_ptr;
 
912
  share->db_low_byte_first=1;                // True for HEAP and MyISAM
 
913
  share->table_charset= param->table_charset;
 
914
  share->keys_for_keyread.reset();
 
915
  share->keys_in_use.reset();
892
916
 
893
917
  /* Calculate which type of fields we will store in the temporary table */
894
918
 
965
989
            */
966
990
            (*argp)->maybe_null=1;
967
991
          }
968
 
          new_field->setPosition(fieldnr++);
 
992
          new_field->field_index= fieldnr++;
969
993
        }
970
994
      }
971
995
    }
1012
1036
        group_null_items++;
1013
1037
        new_field->flags|= GROUP_FLAG;
1014
1038
      }
1015
 
      new_field->setPosition(fieldnr++);
 
1039
      new_field->field_index= fieldnr++;
1016
1040
      *(reg_field++)= new_field;
1017
1041
    }
1018
1042
    if (!--hidden_field_count)
1035
1059
  field_count= fieldnr;
1036
1060
  *reg_field= 0;
1037
1061
  *blob_field= 0;                               // End marker
1038
 
  table->getMutableShare()->fields= field_count;
 
1062
  share->fields= field_count;
1039
1063
 
1040
1064
  /* If result table is small; use a heap */
1041
1065
  /* future: storage engine selection can be made dynamic? */
1044
1068
      (session->lex->current_select->olap == ROLLUP_TYPE) ||
1045
1069
      (select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) == OPTION_BIG_TABLES)
1046
1070
  {
1047
 
    table->getMutableShare()->storage_engine= myisam_engine;
1048
 
    table->cursor= table->getMutableShare()->db_type()->getCursor(*table);
 
1071
    share->storage_engine= myisam_engine;
 
1072
    table->cursor= share->db_type()->getCursor(*share);
1049
1073
    if (group &&
1050
1074
        (param->group_parts > table->cursor->getEngine()->max_key_parts() ||
1051
1075
         param->group_length > table->cursor->getEngine()->max_key_length()))
1055
1079
  }
1056
1080
  else
1057
1081
  {
1058
 
    table->getMutableShare()->storage_engine= heap_engine;
1059
 
    table->cursor= table->getMutableShare()->db_type()->getCursor(*table);
 
1082
    share->storage_engine= heap_engine;
 
1083
    table->cursor= share->db_type()->getCursor(*share);
1060
1084
  }
1061
1085
  if (! table->cursor)
1062
1086
    goto err;
1065
1089
  if (! using_unique_constraint)
1066
1090
    reclength+= group_null_items;       // null flag is stored separately
1067
1091
 
1068
 
  table->getMutableShare()->blob_fields= blob_count;
 
1092
  share->blob_fields= blob_count;
1069
1093
  if (blob_count == 0)
1070
1094
  {
1071
1095
    /* We need to ensure that first byte is not 0 for the delete link */
1084
1108
  if (blob_count || ((string_total_length >= STRING_TOTAL_LENGTH_TO_PACK_ROWS) && (reclength / string_total_length <= RATIO_TO_PACK_ROWS || (string_total_length / string_count) >= AVG_STRING_LENGTH_TO_PACK_ROWS)))
1085
1109
    use_packed_rows= 1;
1086
1110
 
1087
 
  table->getMutableShare()->setRecordLength(reclength);
 
1111
  share->setRecordLength(reclength);
1088
1112
  {
1089
1113
    uint32_t alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
1090
 
    table->getMutableShare()->rec_buff_length= alloc_length;
 
1114
    share->rec_buff_length= alloc_length;
1091
1115
    if (!(table->record[0]= (unsigned char*) table->alloc_root(alloc_length*2)))
1092
1116
    {
1093
1117
      goto err;
1094
1118
    }
1095
1119
    table->record[1]= table->getInsertRecord()+alloc_length;
1096
 
    table->getMutableShare()->resizeDefaultValues(alloc_length);
 
1120
    share->resizeDefaultValues(alloc_length);
1097
1121
  }
1098
1122
  copy_func[0]= 0;                              // End marker
1099
1123
  param->func_count= copy_func - param->items_to_copy;
1100
1124
 
1101
 
  table->setup_tmp_table_column_bitmaps();
 
1125
  table->setup_tmp_table_column_bitmaps(bitmaps);
1102
1126
 
1103
1127
  recinfo=param->start_recinfo;
1104
1128
  null_flags=(unsigned char*) table->getInsertRecord();
1112
1136
    memset(null_flags, 255, null_pack_length);  // Set null fields
1113
1137
 
1114
1138
    table->null_flags= (unsigned char*) table->getInsertRecord();
1115
 
    table->getMutableShare()->null_fields= null_count+ hidden_null_count;
1116
 
    table->getMutableShare()->null_bytes= null_pack_length;
 
1139
    share->null_fields= null_count+ hidden_null_count;
 
1140
    share->null_bytes= null_pack_length;
1117
1141
  }
1118
1142
  null_count= (blob_count == 0) ? 1 : 0;
1119
1143
  hidden_field_count=param->hidden_field_count;
1204
1228
  }
1205
1229
  else
1206
1230
  {
1207
 
    max_rows= (uint64_t) (((table->getMutableShare()->db_type() == heap_engine) ?
 
1231
    max_rows= (uint64_t) (((share->db_type() == heap_engine) ?
1208
1232
                           min(session->variables.tmp_table_size,
1209
1233
                               session->variables.max_heap_table_size) :
1210
1234
                           session->variables.tmp_table_size) /
1211
 
                          table->getMutableShare()->getRecordLength());
 
1235
                          share->getRecordLength());
1212
1236
  }
1213
1237
 
1214
1238
  set_if_bigger(max_rows, (uint64_t)1); // For dummy start options
1218
1242
  */
1219
1243
  set_if_smaller(max_rows, rows_limit);
1220
1244
 
1221
 
  table->getMutableShare()->setMaxRows(max_rows);
 
1245
  share->setMaxRows(max_rows);
1222
1246
 
1223
1247
  param->end_write_records= rows_limit;
1224
1248
 
1228
1252
  {
1229
1253
    table->group=group;                         /* Table is grouped by key */
1230
1254
    param->group_buff=group_buff;
1231
 
    table->getMutableShare()->keys=1;
1232
 
    table->getMutableShare()->uniques= test(using_unique_constraint);
 
1255
    share->keys=1;
 
1256
    share->uniques= test(using_unique_constraint);
1233
1257
    table->key_info=keyinfo;
1234
1258
    keyinfo->key_part=key_part_info;
1235
1259
    keyinfo->flags=HA_NOSAME;
1238
1262
    keyinfo->rec_per_key= 0;
1239
1263
    keyinfo->algorithm= HA_KEY_ALG_UNDEF;
1240
1264
    keyinfo->name= (char*) "group_key";
1241
 
    Order *cur_group= group;
 
1265
    order_st *cur_group= group;
1242
1266
    for (; cur_group ; cur_group= cur_group->next, key_part_info++)
1243
1267
    {
1244
1268
      Field *field=(*cur_group->item)->get_tmp_table_field();
1300
1324
        indexes on blobs with arbitrary length. Such indexes cannot be
1301
1325
        used for lookups.
1302
1326
      */
1303
 
      table->getMutableShare()->uniques= 1;
 
1327
      share->uniques= 1;
1304
1328
    }
1305
1329
    null_pack_length-=hidden_null_pack_length;
1306
1330
    keyinfo->key_parts= ((field_count-param->hidden_field_count)+
1307
 
                         (table->getMutableShare()->uniques ? test(null_pack_length) : 0));
 
1331
                         (share->uniques ? test(null_pack_length) : 0));
1308
1332
    table->distinct= 1;
1309
 
    table->getMutableShare()->keys= 1;
 
1333
    share->keys= 1;
1310
1334
    if (!(key_part_info= (KeyPartInfo*)
1311
1335
         table->alloc_root(keyinfo->key_parts * sizeof(KeyPartInfo))))
1312
1336
      goto err;
1324
1348
      blobs can distinguish NULL from 0. This extra field is not needed
1325
1349
      when we do not use UNIQUE indexes for blobs.
1326
1350
    */
1327
 
    if (null_pack_length && table->getMutableShare()->uniques)
 
1351
    if (null_pack_length && share->uniques)
1328
1352
    {
1329
1353
      key_part_info->null_bit= 0;
1330
1354
      key_part_info->offset=hidden_null_pack_length;
1331
1355
      key_part_info->length=null_pack_length;
1332
 
      table->setVariableWidth();
1333
1356
      key_part_info->field= new Field_varstring(table->getInsertRecord(),
1334
1357
                                                (uint32_t) key_part_info->length,
1335
1358
                                                0,
1336
1359
                                                (unsigned char*) 0,
1337
1360
                                                (uint32_t) 0,
1338
1361
                                                NULL,
 
1362
                                                table->getMutableShare(),
1339
1363
                                                &my_charset_bin);
1340
1364
      if (!key_part_info->field)
1341
1365
        goto err;
1379
1403
 
1380
1404
  if (session->is_fatal_error)                          // If end of memory
1381
1405
    goto err;
1382
 
  table->getMutableShare()->db_record_offset= 1;
1383
 
  if (table->getShare()->db_type() == myisam_engine)
 
1406
  share->db_record_offset= 1;
 
1407
  if (share->db_type() == myisam_engine)
1384
1408
  {
1385
1409
    if (table->create_myisam_tmp_table(param->keyinfo, param->start_recinfo,
1386
1410
                                       &param->recinfo, select_options))
1403
1427
 
1404
1428
/****************************************************************************/
1405
1429
 
1406
 
void Table::column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
1407
 
                               boost::dynamic_bitset<>& write_set_arg)
1408
 
{
1409
 
  read_set= &read_set_arg;
1410
 
  write_set= &write_set_arg;
1411
 
}
1412
 
 
1413
 
 
1414
 
const boost::dynamic_bitset<> Table::use_all_columns(boost::dynamic_bitset<>& in_map)
1415
 
{
1416
 
  const boost::dynamic_bitset<> old= in_map;
1417
 
  in_map= getShare()->all_set;
 
1430
/**
 
1431
  Create a reduced Table object with properly set up Field list from a
 
1432
  list of field definitions.
 
1433
 
 
1434
    The created table doesn't have a table Cursor associated with
 
1435
    it, has no keys, no group/distinct, no copy_funcs array.
 
1436
    The sole purpose of this Table object is to use the power of Field
 
1437
    class to read/write data to/from table->getInsertRecord(). Then one can store
 
1438
    the record in any container (RB tree, hash, etc).
 
1439
    The table is created in Session mem_root, so are the table's fields.
 
1440
    Consequently, if you don't BLOB fields, you don't need to free it.
 
1441
 
 
1442
  @param session         connection handle
 
1443
  @param field_list  list of column definitions
 
1444
 
 
1445
  @return
 
1446
    0 if out of memory, Table object in case of success
 
1447
*/
 
1448
 
 
1449
Table *Session::create_virtual_tmp_table(List<CreateField> &field_list)
 
1450
{
 
1451
  uint32_t field_count= field_list.elements;
 
1452
  uint32_t blob_count= 0;
 
1453
  Field **field;
 
1454
  CreateField *cdef;                           /* column definition */
 
1455
  uint32_t record_length= 0;
 
1456
  uint32_t null_count= 0;                 /* number of columns which may be null */
 
1457
  uint32_t null_pack_length;              /* NULL representation array length */
 
1458
  unsigned char *bitmaps;
 
1459
  Table *table;
 
1460
 
 
1461
  TableShareInstance *share= getTemporaryShare(message::Table::INTERNAL); // This will not go into the tableshare cache, so no key is used.
 
1462
 
 
1463
  if (! share->getMemRoot()->multi_alloc_root(0,
 
1464
                                              &bitmaps, bitmap_buffer_size(field_count)*2,
 
1465
                                              NULL))
 
1466
  {
 
1467
    return NULL;
 
1468
  }
 
1469
 
 
1470
  table= share->getTable();
 
1471
  share->setFields(field_count + 1);
 
1472
  table->setFields(share->getFields(true));
 
1473
  field= share->getFields(true);
 
1474
  share->blob_field.resize(field_count+1);
 
1475
  share->fields= field_count;
 
1476
  share->blob_ptr_size= portable_sizeof_char_ptr;
 
1477
  table->setup_tmp_table_column_bitmaps(bitmaps);
 
1478
 
 
1479
  table->in_use= this;           /* field->reset() may access table->in_use */
 
1480
 
 
1481
  /* Create all fields and calculate the total length of record */
 
1482
  List_iterator_fast<CreateField> it(field_list);
 
1483
  while ((cdef= it++))
 
1484
  {
 
1485
    *field= share->make_field(NULL,
 
1486
                              cdef->length,
 
1487
                              (cdef->flags & NOT_NULL_FLAG) ? false : true,
 
1488
                              (unsigned char *) ((cdef->flags & NOT_NULL_FLAG) ? 0 : ""),
 
1489
                              (cdef->flags & NOT_NULL_FLAG) ? 0 : 1,
 
1490
                              cdef->decimals,
 
1491
                              cdef->sql_type,
 
1492
                              cdef->charset,
 
1493
                              cdef->unireg_check,
 
1494
                              cdef->interval,
 
1495
                              cdef->field_name);
 
1496
    if (!*field)
 
1497
      goto error;
 
1498
    (*field)->init(table);
 
1499
    record_length+= (*field)->pack_length();
 
1500
    if (! ((*field)->flags & NOT_NULL_FLAG))
 
1501
      null_count++;
 
1502
 
 
1503
    if ((*field)->flags & BLOB_FLAG)
 
1504
      share->blob_field[blob_count++]= (uint32_t) (field - table->getFields());
 
1505
 
 
1506
    field++;
 
1507
  }
 
1508
  *field= NULL;                             /* mark the end of the list */
 
1509
  share->blob_field[blob_count]= 0;            /* mark the end of the list */
 
1510
  share->blob_fields= blob_count;
 
1511
 
 
1512
  null_pack_length= (null_count + 7)/8;
 
1513
  share->setRecordLength(record_length + null_pack_length);
 
1514
  share->rec_buff_length= ALIGN_SIZE(share->getRecordLength() + 1);
 
1515
  table->record[0]= (unsigned char*)alloc(share->rec_buff_length);
 
1516
  if (not table->getInsertRecord())
 
1517
    goto error;
 
1518
 
 
1519
  if (null_pack_length)
 
1520
  {
 
1521
    table->null_flags= (unsigned char*) table->getInsertRecord();
 
1522
    share->null_fields= null_count;
 
1523
    share->null_bytes= null_pack_length;
 
1524
  }
 
1525
  {
 
1526
    /* Set up field pointers */
 
1527
    unsigned char *null_pos= table->getInsertRecord();
 
1528
    unsigned char *field_pos= null_pos + share->null_bytes;
 
1529
    uint32_t null_bit= 1;
 
1530
 
 
1531
    for (field= table->getFields(); *field; ++field)
 
1532
    {
 
1533
      Field *cur_field= *field;
 
1534
      if ((cur_field->flags & NOT_NULL_FLAG))
 
1535
        cur_field->move_field(field_pos);
 
1536
      else
 
1537
      {
 
1538
        cur_field->move_field(field_pos, (unsigned char*) null_pos, null_bit);
 
1539
        null_bit<<= 1;
 
1540
        if (null_bit == (1 << 8))
 
1541
        {
 
1542
          ++null_pos;
 
1543
          null_bit= 1;
 
1544
        }
 
1545
      }
 
1546
      cur_field->reset();
 
1547
 
 
1548
      field_pos+= cur_field->pack_length();
 
1549
    }
 
1550
  }
 
1551
 
 
1552
  return table;
 
1553
 
 
1554
error:
 
1555
  for (field= table->getFields(); *field; ++field)
 
1556
  {
 
1557
    delete *field;                         /* just invokes field destructor */
 
1558
  }
 
1559
  return 0;
 
1560
}
 
1561
 
 
1562
bool Table::open_tmp_table()
 
1563
{
 
1564
  int error;
 
1565
  
 
1566
  TableIdentifier identifier(s->getSchemaName(), s->getTableName(), s->getPath());
 
1567
  if ((error=cursor->ha_open(identifier,
 
1568
                             this,
 
1569
                             s->getTableName(),
 
1570
                             O_RDWR,
 
1571
                             HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
 
1572
  {
 
1573
    print_error(error, MYF(0));
 
1574
    db_stat= 0;
 
1575
    return true;
 
1576
  }
 
1577
  (void) cursor->extra(HA_EXTRA_QUICK);         /* Faster */
 
1578
  return false;
 
1579
}
 
1580
 
 
1581
 
 
1582
/*
 
1583
  Create MyISAM temporary table
 
1584
 
 
1585
  SYNOPSIS
 
1586
    create_myisam_tmp_table()
 
1587
      keyinfo         Description of the index (there is always one index)
 
1588
      start_recinfo   MyISAM's column descriptions
 
1589
      recinfo INOUT   End of MyISAM's column descriptions
 
1590
      options         Option bits
 
1591
 
 
1592
  DESCRIPTION
 
1593
    Create a MyISAM temporary table according to passed description. The is
 
1594
    assumed to have one unique index or constraint.
 
1595
 
 
1596
    The passed array or MI_COLUMNDEF structures must have this form:
 
1597
 
 
1598
      1. 1-byte column (afaiu for 'deleted' flag) (note maybe not 1-byte
 
1599
         when there are many nullable columns)
 
1600
      2. Table columns
 
1601
      3. One free MI_COLUMNDEF element (*recinfo points here)
 
1602
 
 
1603
    This function may use the free element to create hash column for unique
 
1604
    constraint.
 
1605
 
 
1606
   RETURN
 
1607
     false - OK
 
1608
     true  - Error
 
1609
*/
 
1610
 
 
1611
bool Table::create_myisam_tmp_table(KeyInfo *keyinfo,
 
1612
                                    MI_COLUMNDEF *start_recinfo,
 
1613
                                    MI_COLUMNDEF **recinfo,
 
1614
                                    uint64_t options)
 
1615
{
 
1616
  int error;
 
1617
  MI_KEYDEF keydef;
 
1618
  MI_UNIQUEDEF uniquedef;
 
1619
  TableShare *share= s;
 
1620
 
 
1621
  if (share->sizeKeys())
 
1622
  {                                             // Get keys for ni_create
 
1623
    bool using_unique_constraint= false;
 
1624
    HA_KEYSEG *seg= (HA_KEYSEG*) this->mem_root.alloc_root(sizeof(*seg) * keyinfo->key_parts);
 
1625
    if (!seg)
 
1626
      goto err;
 
1627
 
 
1628
    memset(seg, 0, sizeof(*seg) * keyinfo->key_parts);
 
1629
    if (keyinfo->key_length >= cursor->getEngine()->max_key_length() ||
 
1630
        keyinfo->key_parts > cursor->getEngine()->max_key_parts() ||
 
1631
        share->uniques)
 
1632
    {
 
1633
      /* Can't create a key; Make a unique constraint instead of a key */
 
1634
      share->keys=    0;
 
1635
      share->uniques= 1;
 
1636
      using_unique_constraint= true;
 
1637
      memset(&uniquedef, 0, sizeof(uniquedef));
 
1638
      uniquedef.keysegs=keyinfo->key_parts;
 
1639
      uniquedef.seg=seg;
 
1640
      uniquedef.null_are_equal=1;
 
1641
 
 
1642
      /* Create extra column for hash value */
 
1643
      memset(*recinfo, 0, sizeof(**recinfo));
 
1644
      (*recinfo)->type= FIELD_CHECK;
 
1645
      (*recinfo)->length=MI_UNIQUE_HASH_LENGTH;
 
1646
      (*recinfo)++;
 
1647
      share->setRecordLength(share->getRecordLength() + MI_UNIQUE_HASH_LENGTH);
 
1648
    }
 
1649
    else
 
1650
    {
 
1651
      /* Create an unique key */
 
1652
      memset(&keydef, 0, sizeof(keydef));
 
1653
      keydef.flag=HA_NOSAME | HA_BINARY_PACK_KEY | HA_PACK_KEY;
 
1654
      keydef.keysegs=  keyinfo->key_parts;
 
1655
      keydef.seg= seg;
 
1656
    }
 
1657
    for (uint32_t i= 0; i < keyinfo->key_parts ; i++,seg++)
 
1658
    {
 
1659
      Field *key_field=keyinfo->key_part[i].field;
 
1660
      seg->flag=     0;
 
1661
      seg->language= key_field->charset()->number;
 
1662
      seg->length=   keyinfo->key_part[i].length;
 
1663
      seg->start=    keyinfo->key_part[i].offset;
 
1664
      if (key_field->flags & BLOB_FLAG)
 
1665
      {
 
1666
        seg->type= ((keyinfo->key_part[i].key_type & 1 /* binary */) ?
 
1667
         HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2);
 
1668
        seg->bit_start= (uint8_t)(key_field->pack_length()
 
1669
                                  - share->blob_ptr_size);
 
1670
        seg->flag= HA_BLOB_PART;
 
1671
        seg->length= 0;                 // Whole blob in unique constraint
 
1672
      }
 
1673
      else
 
1674
      {
 
1675
        seg->type= keyinfo->key_part[i].type;
 
1676
      }
 
1677
      if (!(key_field->flags & NOT_NULL_FLAG))
 
1678
      {
 
1679
        seg->null_bit= key_field->null_bit;
 
1680
        seg->null_pos= (uint32_t) (key_field->null_ptr - (unsigned char*) getInsertRecord());
 
1681
        /*
 
1682
          We are using a GROUP BY on something that contains NULL
 
1683
          In this case we have to tell MyISAM that two NULL should
 
1684
          on INSERT be regarded at the same value
 
1685
        */
 
1686
        if (! using_unique_constraint)
 
1687
          keydef.flag|= HA_NULL_ARE_EQUAL;
 
1688
      }
 
1689
    }
 
1690
  }
 
1691
  MI_CREATE_INFO create_info;
 
1692
  memset(&create_info, 0, sizeof(create_info));
 
1693
 
 
1694
  if ((options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) ==
 
1695
      OPTION_BIG_TABLES)
 
1696
    create_info.data_file_length= ~(uint64_t) 0;
 
1697
 
 
1698
  if ((error=mi_create(share->getTableName(), share->sizeKeys(), &keydef,
 
1699
                       (uint32_t) (*recinfo-start_recinfo),
 
1700
                       start_recinfo,
 
1701
                       share->uniques, &uniquedef,
 
1702
                       &create_info,
 
1703
                       HA_CREATE_TMP_TABLE)))
 
1704
  {
 
1705
    print_error(error, MYF(0));
 
1706
    db_stat= 0;
 
1707
    goto err;
 
1708
  }
 
1709
  status_var_increment(in_use->status_var.created_tmp_disk_tables);
 
1710
  share->db_record_offset= 1;
 
1711
  return false;
 
1712
 err:
 
1713
  return true;
 
1714
}
 
1715
 
 
1716
 
 
1717
void Table::free_tmp_table(Session *session)
 
1718
{
 
1719
  memory::Root own_root= mem_root;
 
1720
  const char *save_proc_info;
 
1721
 
 
1722
  save_proc_info= session->get_proc_info();
 
1723
  session->set_proc_info("removing tmp table");
 
1724
 
 
1725
  // Release latches since this can take a long time
 
1726
  plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
 
1727
 
 
1728
  if (cursor)
 
1729
  {
 
1730
    if (db_stat)
 
1731
    {
 
1732
      cursor->closeMarkForDelete(s->getTableName());
 
1733
    }
 
1734
 
 
1735
    TableIdentifier identifier(s->getSchemaName(), s->getTableName(), s->getTableName());
 
1736
    s->db_type()->doDropTable(*session, identifier);
 
1737
 
 
1738
    delete cursor;
 
1739
  }
 
1740
 
 
1741
  /* free blobs */
 
1742
  for (Field **ptr= field ; *ptr ; ptr++)
 
1743
  {
 
1744
    (*ptr)->free();
 
1745
  }
 
1746
  free_io_cache();
 
1747
 
 
1748
  own_root.free_root(MYF(0)); /* the table is allocated in its own root */
 
1749
  session->set_proc_info(save_proc_info);
 
1750
}
 
1751
 
 
1752
my_bitmap_map *Table::use_all_columns(MyBitmap *bitmap)
 
1753
{
 
1754
  my_bitmap_map *old= bitmap->getBitmap();
 
1755
  bitmap->setBitmap(s->all_set.getBitmap());
1418
1756
  return old;
1419
1757
}
1420
1758
 
1421
 
void Table::restore_column_map(const boost::dynamic_bitset<>& old)
 
1759
void Table::restore_column_map(my_bitmap_map *old)
1422
1760
{
1423
 
  for (boost::dynamic_bitset<>::size_type i= 0; i < old.size(); i++)
1424
 
  {
1425
 
    if (old.test(i))
1426
 
    {
1427
 
      read_set->set(i);
1428
 
    }
1429
 
    else
1430
 
    {
1431
 
      read_set->reset(i);
1432
 
    }
1433
 
  }
 
1761
  read_set->setBitmap(old);
1434
1762
}
1435
1763
 
1436
1764
uint32_t Table::find_shortest_key(const key_map *usable_keys)
1439
1767
  uint32_t best= MAX_KEY;
1440
1768
  if (usable_keys->any())
1441
1769
  {
1442
 
    for (uint32_t nr= 0; nr < getShare()->sizeKeys() ; nr++)
 
1770
    for (uint32_t nr= 0; nr < s->sizeKeys() ; nr++)
1443
1771
    {
1444
1772
      if (usable_keys->test(nr))
1445
1773
      {
1466
1794
{
1467
1795
  for (; *ptr ; ptr++)
1468
1796
  {
1469
 
    if ((*ptr)->cmp_offset(getShare()->rec_buff_length))
 
1797
    if ((*ptr)->cmp_offset(s->rec_buff_length))
1470
1798
      return true;
1471
1799
  }
1472
1800
  return false;
1473
1801
}
1474
1802
 
1475
 
/**
1476
 
   True if the table's input and output record buffers are comparable using
1477
 
   compare_records(TABLE*).
1478
 
 */
1479
 
bool Table::records_are_comparable()
1480
 
{
1481
 
  return ((getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) == 0) ||
1482
 
          write_set->is_subset_of(*read_set));
1483
 
}
1484
 
 
1485
 
/**
1486
 
   Compares the input and outbut record buffers of the table to see if a row
1487
 
   has changed. The algorithm iterates over updated columns and if they are
1488
 
   nullable compares NULL bits in the buffer before comparing actual
1489
 
   data. Special care must be taken to compare only the relevant NULL bits and
1490
 
   mask out all others as they may be undefined. The storage engine will not
1491
 
   and should not touch them.
1492
 
 
1493
 
   @param table The table to evaluate.
1494
 
 
1495
 
   @return true if row has changed.
1496
 
   @return false otherwise.
1497
 
*/
1498
 
bool Table::compare_records()
1499
 
{
1500
 
  if (getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) != 0)
1501
 
  {
1502
 
    /*
1503
 
      Storage engine may not have read all columns of the record.  Fields
1504
 
      (including NULL bits) not in the write_set may not have been read and
1505
 
      can therefore not be compared.
1506
 
    */
1507
 
    for (Field **ptr= this->field ; *ptr != NULL; ptr++)
1508
 
    {
1509
 
      Field *f= *ptr;
1510
 
      if (write_set->test(f->position()))
1511
 
      {
1512
 
        if (f->real_maybe_null())
1513
 
        {
1514
 
          unsigned char null_byte_index= f->null_ptr - record[0];
1515
 
 
1516
 
          if (((record[0][null_byte_index]) & f->null_bit) !=
1517
 
              ((record[1][null_byte_index]) & f->null_bit))
1518
 
            return true;
1519
 
        }
1520
 
        if (f->cmp_binary_offset(getShare()->rec_buff_length))
1521
 
          return true;
1522
 
      }
1523
 
    }
1524
 
    return false;
1525
 
  }
1526
 
 
1527
 
  /*
1528
 
    The storage engine has read all columns, so it's safe to compare all bits
1529
 
    including those not in the write_set. This is cheaper than the
1530
 
    field-by-field comparison done above.
1531
 
  */
1532
 
  if (not getShare()->blob_fields + getShare()->hasVariableWidth())
1533
 
    // Fixed-size record: do bitwise comparison of the records
1534
 
    return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) getShare()->getRecordLength());
1535
 
 
 
1803
/* Return false if row hasn't changed */
 
1804
 
 
1805
bool Table::compare_record()
 
1806
{
 
1807
  if (s->blob_fields + s->varchar_fields == 0)
 
1808
    return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) s->getRecordLength());
 
1809
  
1536
1810
  /* Compare null bits */
1537
 
  if (memcmp(null_flags, null_flags + getShare()->rec_buff_length, getShare()->null_bytes))
 
1811
  if (memcmp(null_flags, null_flags + s->rec_buff_length, s->null_bytes))
1538
1812
    return true; /* Diff in NULL value */
1539
1813
 
1540
1814
  /* Compare updated fields */
1541
1815
  for (Field **ptr= field ; *ptr ; ptr++)
1542
1816
  {
1543
 
    if (isWriteSet((*ptr)->position()) &&
1544
 
        (*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
 
1817
    if (isWriteSet((*ptr)->field_index) &&
 
1818
        (*ptr)->cmp_binary_offset(s->rec_buff_length))
1545
1819
      return true;
1546
1820
  }
1547
1821
  return false;
1553
1827
 */
1554
1828
void Table::storeRecord()
1555
1829
{
1556
 
  memcpy(getUpdateRecord(), getInsertRecord(), (size_t) getShare()->getRecordLength());
 
1830
  memcpy(getUpdateRecord(), getInsertRecord(), (size_t) s->getRecordLength());
1557
1831
}
1558
1832
 
1559
1833
/*
1562
1836
 */
1563
1837
void Table::storeRecordAsInsert()
1564
1838
{
1565
 
  assert(insert_values.size() >= getShare()->getRecordLength());
1566
 
  memcpy(&insert_values[0], getInsertRecord(), (size_t) getShare()->getRecordLength());
 
1839
  assert(insert_values.size() >= s->getRecordLength());
 
1840
  memcpy(&insert_values[0], getInsertRecord(), (size_t) s->getRecordLength());
1567
1841
}
1568
1842
 
1569
1843
/*
1572
1846
 */
1573
1847
void Table::storeRecordAsDefault()
1574
1848
{
1575
 
  memcpy(getMutableShare()->getDefaultValues(), getInsertRecord(), (size_t) getShare()->getRecordLength());
 
1849
  memcpy(s->getDefaultValues(), getInsertRecord(), (size_t) s->getRecordLength());
1576
1850
}
1577
1851
 
1578
1852
/*
1581
1855
 */
1582
1856
void Table::restoreRecord()
1583
1857
{
1584
 
  memcpy(getInsertRecord(), getUpdateRecord(), (size_t) getShare()->getRecordLength());
 
1858
  memcpy(getInsertRecord(), getUpdateRecord(), (size_t) s->getRecordLength());
1585
1859
}
1586
1860
 
1587
1861
/*
1590
1864
 */
1591
1865
void Table::restoreRecordAsDefault()
1592
1866
{
1593
 
  memcpy(getInsertRecord(), getMutableShare()->getDefaultValues(), (size_t) getShare()->getRecordLength());
 
1867
  memcpy(getInsertRecord(), s->getDefaultValues(), (size_t) s->getRecordLength());
1594
1868
}
1595
1869
 
1596
1870
/*
1600
1874
void Table::emptyRecord()
1601
1875
{
1602
1876
  restoreRecordAsDefault();
1603
 
  memset(null_flags, 255, getShare()->null_bytes);
 
1877
  memset(null_flags, 255, s->null_bytes);
1604
1878
}
1605
1879
 
1606
1880
Table::Table() : 
 
1881
  s(NULL),
1607
1882
  field(NULL),
1608
1883
  cursor(NULL),
1609
1884
  next(NULL),
1612
1887
  write_set(NULL),
1613
1888
  tablenr(0),
1614
1889
  db_stat(0),
1615
 
  def_read_set(),
1616
 
  def_write_set(),
1617
 
  tmp_set(),
1618
1890
  in_use(NULL),
1619
1891
  key_info(NULL),
1620
1892
  next_number_field(NULL),
1622
1894
  timestamp_field(NULL),
1623
1895
  pos_in_table_list(NULL),
1624
1896
  group(NULL),
 
1897
  alias(NULL),
1625
1898
  null_flags(NULL),
1626
1899
  lock_position(0),
1627
1900
  lock_data_start(0),
1647
1920
  query_id(0),
1648
1921
  quick_condition_rows(0),
1649
1922
  timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
1650
 
  map(0)
 
1923
  map(0),
 
1924
  is_placeholder_created(0)
1651
1925
{
 
1926
  memset(&def_read_set, 0, sizeof(MyBitmap)); /**< Default read set of columns */
 
1927
  memset(&def_write_set, 0, sizeof(MyBitmap)); /**< Default write set of columns */
 
1928
  memset(&tmp_set, 0, sizeof(MyBitmap)); /* Not sure about this... */
 
1929
 
1652
1930
  record[0]= (unsigned char *) 0;
1653
1931
  record[1]= (unsigned char *) 0;
1654
1932
 
1666
1944
 
1667
1945
  memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
1668
1946
  memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
 
1947
 
 
1948
  memset(&mem_root, 0, sizeof(memory::Root));
 
1949
  memset(&sort, 0, sizeof(filesort_info_st));
1669
1950
}
1670
1951
 
1671
1952
/*****************************************************************************
1688
1969
  */
1689
1970
  if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
1690
1971
    errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
1691
 
                  error, getShare()->getPath());
 
1972
                  error, s->getPath());
1692
1973
  print_error(error, MYF(0));
1693
1974
 
1694
1975
  return 1;
1711
1992
  tablenr= table_number;
1712
1993
  map= (table_map) 1 << table_number;
1713
1994
  force_index= table_list->force_index;
1714
 
  covering_keys= getShare()->keys_for_keyread;
 
1995
  covering_keys= s->keys_for_keyread;
1715
1996
  merge_keys.reset();
1716
1997
}
1717
1998
 
1731
2012
  return false;
1732
2013
}
1733
2014
 
1734
 
 
1735
 
void Table::filesort_free_buffers(bool full)
1736
 
{
1737
 
  if (sort.record_pointers)
1738
 
  {
1739
 
    free((unsigned char*) sort.record_pointers);
1740
 
    sort.record_pointers=0;
1741
 
  }
1742
 
  if (full)
1743
 
  {
1744
 
    if (sort.sort_keys )
1745
 
    {
1746
 
      if ((unsigned char*) sort.sort_keys)
1747
 
        free((unsigned char*) sort.sort_keys);
1748
 
      sort.sort_keys= 0;
1749
 
    }
1750
 
    if (sort.buffpek)
1751
 
    {
1752
 
      if ((unsigned char*) sort.buffpek)
1753
 
        free((unsigned char*) sort.buffpek);
1754
 
      sort.buffpek= 0;
1755
 
      sort.buffpek_len= 0;
1756
 
    }
1757
 
  }
1758
 
 
1759
 
  if (sort.addon_buf)
1760
 
  {
1761
 
    free((char *) sort.addon_buf);
1762
 
    free((char *) sort.addon_field);
1763
 
    sort.addon_buf=0;
1764
 
    sort.addon_field=0;
1765
 
  }
1766
 
}
1767
 
 
1768
2015
} /* namespace drizzled */