~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2010-07-30 20:31:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1679.
  • Revision ID: brian@gaz-20100730203119-89g2ye4zwnvcacxg
First pass in encapsulating row

Show diffs side-by-side

added added

removed removed

Lines of Context:
689
689
  {
690
690
    Field_blob* const blob= (Field_blob*) field[*ptr];
691
691
    length+= blob->get_length((const unsigned char*)
692
 
                              (data + blob->offset(record[0]))) +
 
692
                              (data + blob->offset(getInsertRecord()))) +
693
693
      HA_KEY_BLOB_LENGTH;
694
694
  }
695
695
  return length;
1112
1112
  {
1113
1113
    uint32_t alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
1114
1114
    share->rec_buff_length= alloc_length;
1115
 
    if (!(table->record[0]= (unsigned char*)
1116
 
                            table->alloc_root(alloc_length*2)))
 
1115
    if (!(table->record[0]= (unsigned char*) table->alloc_root(alloc_length*2)))
1117
1116
    {
1118
1117
      goto err;
1119
1118
    }
1120
 
    table->record[1]= table->record[0]+alloc_length;
 
1119
    table->record[1]= table->getInsertRecord()+alloc_length;
1121
1120
    share->resizeDefaultValues(alloc_length);
1122
1121
  }
1123
1122
  copy_func[0]= 0;                              // End marker
1126
1125
  table->setup_tmp_table_column_bitmaps(bitmaps);
1127
1126
 
1128
1127
  recinfo=param->start_recinfo;
1129
 
  null_flags=(unsigned char*) table->record[0];
1130
 
  pos=table->record[0]+ null_pack_length;
 
1128
  null_flags=(unsigned char*) table->getInsertRecord();
 
1129
  pos=table->getInsertRecord()+ null_pack_length;
1131
1130
  if (null_pack_length)
1132
1131
  {
1133
1132
    memset(recinfo, 0, sizeof(*recinfo));
1136
1135
    recinfo++;
1137
1136
    memset(null_flags, 255, null_pack_length);  // Set null fields
1138
1137
 
1139
 
    table->null_flags= (unsigned char*) table->record[0];
 
1138
    table->null_flags= (unsigned char*) table->getInsertRecord();
1140
1139
    share->null_fields= null_count+ hidden_null_count;
1141
1140
    share->null_bytes= null_pack_length;
1142
1141
  }
1189
1188
      ptrdiff_t diff;
1190
1189
      Field *orig_field= default_field[i];
1191
1190
      /* Get the value from default_values */
1192
 
      diff= (ptrdiff_t) (orig_field->getTable()->getDefaultValues() - orig_field->getTable()->record[0]);
 
1191
      diff= (ptrdiff_t) (orig_field->getTable()->getDefaultValues() - orig_field->getTable()->getInsertRecord());
1193
1192
      orig_field->move_field_offset(diff);      // Points now at default_values
1194
1193
      if (orig_field->is_real_null())
1195
1194
        field->set_null();
1198
1197
        field->set_notnull();
1199
1198
        memcpy(field->ptr, orig_field->ptr, field->pack_length());
1200
1199
      }
1201
 
      orig_field->move_field_offset(-diff);     // Back to record[0]
 
1200
      orig_field->move_field_offset(-diff);     // Back to getInsertRecord()
1202
1201
    }
1203
1202
 
1204
1203
    if (from_field[i])
1270
1269
      bool maybe_null=(*cur_group->item)->maybe_null;
1271
1270
      key_part_info->null_bit= 0;
1272
1271
      key_part_info->field=  field;
1273
 
      key_part_info->offset= field->offset(table->record[0]);
 
1272
      key_part_info->offset= field->offset(table->getInsertRecord());
1274
1273
      key_part_info->length= (uint16_t) field->key_length();
1275
1274
      key_part_info->type=   (uint8_t) field->key_type();
1276
1275
      key_part_info->key_type= 
1298
1297
          keyinfo->flags|= HA_NULL_ARE_EQUAL;   // def. that NULL == NULL
1299
1298
          key_part_info->null_bit=field->null_bit;
1300
1299
          key_part_info->null_offset= (uint32_t) (field->null_ptr -
1301
 
                                              (unsigned char*) table->record[0]);
 
1300
                                              (unsigned char*) table->getInsertRecord());
1302
1301
          cur_group->buff++;                        // Pointer to field data
1303
1302
          group_buff++;                         // Skipp null flag
1304
1303
        }
1354
1353
      key_part_info->null_bit= 0;
1355
1354
      key_part_info->offset=hidden_null_pack_length;
1356
1355
      key_part_info->length=null_pack_length;
1357
 
      key_part_info->field= new Field_varstring(table->record[0],
 
1356
      key_part_info->field= new Field_varstring(table->getInsertRecord(),
1358
1357
                                                (uint32_t) key_part_info->length,
1359
1358
                                                0,
1360
1359
                                                (unsigned char*) 0,
1376
1375
    {
1377
1376
      key_part_info->null_bit= 0;
1378
1377
      key_part_info->field=    *reg_field;
1379
 
      key_part_info->offset=   (*reg_field)->offset(table->record[0]);
 
1378
      key_part_info->offset=   (*reg_field)->offset(table->getInsertRecord());
1380
1379
      key_part_info->length=   (uint16_t) (*reg_field)->pack_length();
1381
1380
      /* @todo The below method of computing the key format length of the
1382
1381
        key part is a copy/paste from optimizer/range.cc, and table.cc.
1435
1434
    The created table doesn't have a table Cursor associated with
1436
1435
    it, has no keys, no group/distinct, no copy_funcs array.
1437
1436
    The sole purpose of this Table object is to use the power of Field
1438
 
    class to read/write data to/from table->record[0]. Then one can store
 
1437
    class to read/write data to/from table->getInsertRecord(). Then one can store
1439
1438
    the record in any container (RB tree, hash, etc).
1440
1439
    The table is created in Session mem_root, so are the table's fields.
1441
1440
    Consequently, if you don't BLOB fields, you don't need to free it.
1514
1513
  share->setRecordLength(record_length + null_pack_length);
1515
1514
  share->rec_buff_length= ALIGN_SIZE(share->getRecordLength() + 1);
1516
1515
  table->record[0]= (unsigned char*)alloc(share->rec_buff_length);
1517
 
  if (!table->record[0])
 
1516
  if (not table->getInsertRecord())
1518
1517
    goto error;
1519
1518
 
1520
1519
  if (null_pack_length)
1521
1520
  {
1522
 
    table->null_flags= (unsigned char*) table->record[0];
 
1521
    table->null_flags= (unsigned char*) table->getInsertRecord();
1523
1522
    share->null_fields= null_count;
1524
1523
    share->null_bytes= null_pack_length;
1525
1524
  }
1526
1525
  {
1527
1526
    /* Set up field pointers */
1528
 
    unsigned char *null_pos= table->record[0];
 
1527
    unsigned char *null_pos= table->getInsertRecord();
1529
1528
    unsigned char *field_pos= null_pos + share->null_bytes;
1530
1529
    uint32_t null_bit= 1;
1531
1530
 
1678
1677
      if (!(key_field->flags & NOT_NULL_FLAG))
1679
1678
      {
1680
1679
        seg->null_bit= key_field->null_bit;
1681
 
        seg->null_pos= (uint32_t) (key_field->null_ptr - (unsigned char*) record[0]);
 
1680
        seg->null_pos= (uint32_t) (key_field->null_ptr - (unsigned char*) getInsertRecord());
1682
1681
        /*
1683
1682
          We are using a GROUP BY on something that contains NULL
1684
1683
          In this case we have to tell MyISAM that two NULL should
1806
1805
bool Table::compare_record()
1807
1806
{
1808
1807
  if (s->blob_fields + s->varchar_fields == 0)
1809
 
    return memcmp(this->record[0], this->record[1], (size_t) s->getRecordLength());
 
1808
    return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) s->getRecordLength());
1810
1809
  
1811
1810
  /* Compare null bits */
1812
1811
  if (memcmp(null_flags, null_flags + s->rec_buff_length, s->null_bytes))
1828
1827
 */
1829
1828
void Table::storeRecord()
1830
1829
{
1831
 
  memcpy(record[1], record[0], (size_t) s->getRecordLength());
 
1830
  memcpy(getUpdateRecord(), getInsertRecord(), (size_t) s->getRecordLength());
1832
1831
}
1833
1832
 
1834
1833
/*
1838
1837
void Table::storeRecordAsInsert()
1839
1838
{
1840
1839
  assert(insert_values.size() >= s->getRecordLength());
1841
 
  memcpy(&insert_values[0], record[0], (size_t) s->getRecordLength());
 
1840
  memcpy(&insert_values[0], getInsertRecord(), (size_t) s->getRecordLength());
1842
1841
}
1843
1842
 
1844
1843
/*
1847
1846
 */
1848
1847
void Table::storeRecordAsDefault()
1849
1848
{
1850
 
  memcpy(s->getDefaultValues(), record[0], (size_t) s->getRecordLength());
 
1849
  memcpy(s->getDefaultValues(), getInsertRecord(), (size_t) s->getRecordLength());
1851
1850
}
1852
1851
 
1853
1852
/*
1856
1855
 */
1857
1856
void Table::restoreRecord()
1858
1857
{
1859
 
  memcpy(record[0], record[1], (size_t) s->getRecordLength());
 
1858
  memcpy(getInsertRecord(), getUpdateRecord(), (size_t) s->getRecordLength());
1860
1859
}
1861
1860
 
1862
1861
/*
1865
1864
 */
1866
1865
void Table::restoreRecordAsDefault()
1867
1866
{
1868
 
  memcpy(record[0], s->getDefaultValues(), (size_t) s->getRecordLength());
 
1867
  memcpy(getInsertRecord(), s->getDefaultValues(), (size_t) s->getRecordLength());
1869
1868
}
1870
1869
 
1871
1870
/*