~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2010-10-29 04:00:23 UTC
  • mto: (1890.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1891.
  • Revision ID: brian@tangent.org-20101029040023-q1j7yeq6n52oarn1
Additional C++ warning fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
 
96
96
  if (free_share)
97
97
  {
98
 
    release();
 
98
    if (getShare()->getType() == message::Table::STANDARD)
 
99
    {
 
100
      TableShare::release(getMutableShare());
 
101
    }
 
102
    else
 
103
    {
 
104
      delete getShare();
 
105
    }
 
106
    setShare(NULL);
99
107
  }
100
108
 
101
109
  return error;
247
255
  return (nr);
248
256
} /* set_zone */
249
257
 
 
258
        /* Adjust number to next larger disk buffer */
 
259
 
 
260
ulong next_io_size(register ulong pos)
 
261
{
 
262
  register ulong offset;
 
263
  if ((offset= pos & (IO_SIZE-1)))
 
264
    return pos-offset+IO_SIZE;
 
265
  return pos;
 
266
} /* next_io_size */
 
267
 
250
268
 
251
269
/*
252
270
  Store an SQL quoted string.
335
353
 
336
354
bool check_db_name(Session *session, SchemaIdentifier &schema_identifier)
337
355
{
338
 
  if (not plugin::Authorization::isAuthorized(session->user(), schema_identifier))
 
356
  if (not plugin::Authorization::isAuthorized(session->getSecurityContext(), schema_identifier))
339
357
  {
340
358
    return false;
341
359
  }
521
539
    We must set bit in read set as update_auto_increment() is using the
522
540
    store() to check overflow of auto_increment values
523
541
  */
524
 
  setReadSet(found_next_number_field->position());
525
 
  setWriteSet(found_next_number_field->position());
 
542
  setReadSet(found_next_number_field->field_index);
 
543
  setWriteSet(found_next_number_field->field_index);
526
544
  if (getShare()->next_number_keypart)
527
545
    mark_columns_used_by_index_no_reset(getShare()->next_number_index);
528
546
}
571
589
    for (reg_field= field ; *reg_field ; reg_field++)
572
590
    {
573
591
      if ((*reg_field)->flags & PART_KEY_FLAG)
574
 
        setReadSet((*reg_field)->position());
 
592
        setReadSet((*reg_field)->field_index);
575
593
    }
576
594
  }
577
595
}
620
638
    {
621
639
      /* Merge keys is all keys that had a column refered to in the query */
622
640
      if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
623
 
        setReadSet((*reg_field)->position());
 
641
        setReadSet((*reg_field)->field_index);
624
642
    }
625
643
  }
626
644
 
771
789
 
772
790
Table *
773
791
create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
774
 
                 Order *group, bool distinct, bool save_sum_fields,
 
792
                 order_st *group, bool distinct, bool save_sum_fields,
775
793
                 uint64_t select_options, ha_rows rows_limit,
776
794
                 const char *table_alias)
777
795
{
805
823
    {
806
824
      group= 0;                                 // Can't use group key
807
825
    }
808
 
    else for (Order *tmp=group ; tmp ; tmp=tmp->next)
 
826
    else for (order_st *tmp=group ; tmp ; tmp=tmp->next)
809
827
    {
810
828
      /*
811
829
        marker == 4 means two things:
965
983
            */
966
984
            (*argp)->maybe_null=1;
967
985
          }
968
 
          new_field->setPosition(fieldnr++);
 
986
          new_field->field_index= fieldnr++;
969
987
        }
970
988
      }
971
989
    }
1012
1030
        group_null_items++;
1013
1031
        new_field->flags|= GROUP_FLAG;
1014
1032
      }
1015
 
      new_field->setPosition(fieldnr++);
 
1033
      new_field->field_index= fieldnr++;
1016
1034
      *(reg_field++)= new_field;
1017
1035
    }
1018
1036
    if (!--hidden_field_count)
1238
1256
    keyinfo->rec_per_key= 0;
1239
1257
    keyinfo->algorithm= HA_KEY_ALG_UNDEF;
1240
1258
    keyinfo->name= (char*) "group_key";
1241
 
    Order *cur_group= group;
 
1259
    order_st *cur_group= group;
1242
1260
    for (; cur_group ; cur_group= cur_group->next, key_part_info++)
1243
1261
    {
1244
1262
      Field *field=(*cur_group->item)->get_tmp_table_field();
1472
1490
  return false;
1473
1491
}
1474
1492
 
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
 
  */
 
1493
/* Return false if row hasn't changed */
 
1494
 
 
1495
bool Table::compare_record()
 
1496
{
1532
1497
  if (not getShare()->blob_fields + getShare()->hasVariableWidth())
1533
 
    // Fixed-size record: do bitwise comparison of the records
1534
1498
    return memcmp(this->getInsertRecord(), this->getUpdateRecord(), (size_t) getShare()->getRecordLength());
1535
 
 
 
1499
  
1536
1500
  /* Compare null bits */
1537
1501
  if (memcmp(null_flags, null_flags + getShare()->rec_buff_length, getShare()->null_bytes))
1538
1502
    return true; /* Diff in NULL value */
1540
1504
  /* Compare updated fields */
1541
1505
  for (Field **ptr= field ; *ptr ; ptr++)
1542
1506
  {
1543
 
    if (isWriteSet((*ptr)->position()) &&
 
1507
    if (isWriteSet((*ptr)->field_index) &&
1544
1508
        (*ptr)->cmp_binary_offset(getShare()->rec_buff_length))
1545
1509
      return true;
1546
1510
  }
1731
1695
  return false;
1732
1696
}
1733
1697
 
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
1698
} /* namespace drizzled */