~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2010-12-07 09:12:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1985.
  • Revision ID: brian@tangent.org-20101207091212-1m0w20tck6z7632m
This is a fix for bug lp:686197

Show diffs side-by-side

added added

removed removed

Lines of Context:
521
521
    We must set bit in read set as update_auto_increment() is using the
522
522
    store() to check overflow of auto_increment values
523
523
  */
524
 
  setReadSet(found_next_number_field->position());
525
 
  setWriteSet(found_next_number_field->position());
 
524
  setReadSet(found_next_number_field->field_index);
 
525
  setWriteSet(found_next_number_field->field_index);
526
526
  if (getShare()->next_number_keypart)
527
527
    mark_columns_used_by_index_no_reset(getShare()->next_number_index);
528
528
}
571
571
    for (reg_field= field ; *reg_field ; reg_field++)
572
572
    {
573
573
      if ((*reg_field)->flags & PART_KEY_FLAG)
574
 
        setReadSet((*reg_field)->position());
 
574
        setReadSet((*reg_field)->field_index);
575
575
    }
576
576
  }
577
577
}
620
620
    {
621
621
      /* Merge keys is all keys that had a column refered to in the query */
622
622
      if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
623
 
        setReadSet((*reg_field)->position());
 
623
        setReadSet((*reg_field)->field_index);
624
624
    }
625
625
  }
626
626
 
965
965
            */
966
966
            (*argp)->maybe_null=1;
967
967
          }
968
 
          new_field->setPosition(fieldnr++);
 
968
          new_field->field_index= fieldnr++;
969
969
        }
970
970
      }
971
971
    }
1012
1012
        group_null_items++;
1013
1013
        new_field->flags|= GROUP_FLAG;
1014
1014
      }
1015
 
      new_field->setPosition(fieldnr++);
 
1015
      new_field->field_index= fieldnr++;
1016
1016
      *(reg_field++)= new_field;
1017
1017
    }
1018
1018
    if (!--hidden_field_count)
1472
1472
  return false;
1473
1473
}
1474
1474
 
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
 
  */
 
1475
/* Return false if row hasn't changed */
 
1476
 
 
1477
bool Table::compare_record()
 
1478
{
1532
1479
  if (not getShare()->blob_fields + getShare()->hasVariableWidth())
1533
 
    // Fixed-size record: do bitwise comparison of the records
1534
1480
    return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) getShare()->getRecordLength());
1535
 
 
 
1481
  
1536
1482
  /* Compare null bits */
1537
1483
  if (memcmp(null_flags, null_flags + getShare()->rec_buff_length, getShare()->null_bytes))
1538
1484
    return true; /* Diff in NULL value */
1540
1486
  /* Compare updated fields */
1541
1487
  for (Field **ptr= field ; *ptr ; ptr++)
1542
1488
  {
1543
 
    if (isWriteSet((*ptr)->position()) &&
 
1489
    if (isWriteSet((*ptr)->field_index) &&
1544
1490
        (*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
1545
1491
      return true;
1546
1492
  }