~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2008-08-19 17:29:21 UTC
  • Revision ID: brian@tangent.org-20080819172921-bc3kpgsrzsdv338l
Moved Field iterator out to its own definition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
      assigned.  No arithmetic is done on the value: it will be
144
144
      overwritten with a value taken from DRIZZLE_BIN_LOG.
145
145
    */
146
 
    share->table_map_version= UINT64_MAX;
 
146
    share->table_map_version= ~(uint64_t)0;
147
147
 
148
148
    /*
149
149
      Since alloc_table_share() can be called without any locking (for
152
152
      elsewhere, and then assign a table map id inside open_table()
153
153
      under the protection of the LOCK_open mutex.
154
154
    */
155
 
    share->table_map_id= UINT32_MAX;
 
155
    share->table_map_id= ~0UL;
156
156
    share->cached_row_logging_check= -1;
157
157
 
158
158
    memcpy(&share->mem_root, &mem_root, sizeof(mem_root));
1386
1386
                  ha_open(outparam, share->normalized_path.str,
1387
1387
                          (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1388
1388
                          (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE :
1389
 
                           (db_stat & HA_WAIT_IF_LOCKED) ?  HA_OPEN_WAIT_IF_LOCKED :
 
1389
                           ((db_stat & HA_WAIT_IF_LOCKED) ||
 
1390
                            (specialflag & SPECIAL_WAIT_IF_LOCKED)) ?
 
1391
                           HA_OPEN_WAIT_IF_LOCKED :
1390
1392
                           (db_stat & (HA_ABORT_IF_LOCKED | HA_GET_INFO)) ?
1391
1393
                          HA_OPEN_ABORT_IF_LOCKED :
1392
1394
                           HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
3101
3103
}
3102
3104
 
3103
3105
 
3104
 
size_t Table::max_row_length(const uchar *data)
 
3106
size_t max_row_length(Table *table, const uchar *data)
3105
3107
{
3106
 
  size_t length= getRecordLength() + 2 * sizeFields();
3107
 
  uint *const beg= getBlobField();
3108
 
  uint *const end= beg + sizeBlobFields();
 
3108
  size_t length= table->getRecordLength() + 2 * table->sizeFields();
 
3109
  uint *const beg= table->getBlobField();
 
3110
  uint *const end= beg + table->sizeBlobFields();
3109
3111
 
3110
3112
  for (uint *ptr= beg ; ptr != end ; ++ptr)
3111
3113
  {
3112
 
    Field_blob* const blob= (Field_blob*) field[*ptr];
 
3114
    Field_blob* const blob= (Field_blob*) table->field[*ptr];
3113
3115
    length+= blob->get_length((const uchar*)
3114
 
                              (data + blob->offset(record[0]))) +
 
3116
                              (data + blob->offset(table->record[0]))) +
3115
3117
      HA_KEY_BLOB_LENGTH;
3116
3118
  }
3117
3119
  return length;
3118
3120
}
3119
3121
 
 
3122
void Field_iterator_table::set(TableList *table) 
 
3123
 
3124
  ptr= table->table->field; 
 
3125
}
 
3126
 
 
3127
 
3120
3128
/*
3121
3129
  Check type of .frm if we are not going to parse it
3122
3130
 
4510
4518
  MEM_ROOT own_root= mem_root;
4511
4519
  const char *save_proc_info;
4512
4520
 
4513
 
  save_proc_info=thd->get_proc_info();
 
4521
  save_proc_info=thd->proc_info;
4514
4522
  thd_proc_info(thd, "removing tmp table");
4515
4523
 
4516
4524
  if (file)
4567
4575
                                        new_table.s->db_type())))
4568
4576
    return(1);                          // End of memory
4569
4577
 
4570
 
  save_proc_info=thd->get_proc_info();
 
4578
  save_proc_info=thd->proc_info;
4571
4579
  thd_proc_info(thd, "converting HEAP to MyISAM");
4572
4580
 
4573
4581
  if (new_table.create_myisam_tmp_table(table->key_info, start_recinfo,
4652
4660
  return(1);
4653
4661
}
4654
4662
 
4655
 
my_bitmap_map *Table::use_all_columns(MY_BITMAP *bitmap)
4656
 
{
4657
 
  my_bitmap_map *old= bitmap->bitmap;
4658
 
  bitmap->bitmap= s->all_set.bitmap;
4659
 
  return old;
4660
 
}
4661
 
 
4662
 
void Table::restore_column_map(my_bitmap_map *old)
4663
 
{
4664
 
  read_set->bitmap= old;
4665
 
}
4666
 
 
4667
 
uint Table::find_shortest_key(const key_map *usable_keys)
4668
 
{
4669
 
  uint32_t min_length= UINT32_MAX;
4670
 
  uint32_t best= MAX_KEY;
4671
 
  if (!usable_keys->is_clear_all())
4672
 
  {
4673
 
    for (uint nr=0; nr < s->keys ; nr++)
4674
 
    {
4675
 
      if (usable_keys->is_set(nr))
4676
 
      {
4677
 
        if (key_info[nr].key_length < min_length)
4678
 
        {
4679
 
          min_length= key_info[nr].key_length;
4680
 
          best=nr;
4681
 
        }
4682
 
      }
4683
 
    }
4684
 
  }
4685
 
  return best;
4686
 
}
4687
 
 
4688
 
/*****************************************************************************
4689
 
  Remove duplicates from tmp table
4690
 
  This should be recoded to add a unique index to the table and remove
4691
 
  duplicates
4692
 
  Table is a locked single thread table
4693
 
  fields is the number of fields to check (from the end)
4694
 
*****************************************************************************/
4695
 
 
4696
 
bool Table::compare_record(Field **ptr)
4697
 
{
4698
 
  for (; *ptr ; ptr++)
4699
 
  {
4700
 
    if ((*ptr)->cmp_offset(s->rec_buff_length))
4701
 
      return true;
4702
 
  }
4703
 
  return false;
4704
 
}
4705
 
 
4706
 
/* Return false if row hasn't changed */
4707
 
 
4708
 
bool Table::compare_record()
4709
 
{
4710
 
  if (s->blob_fields + s->varchar_fields == 0)
4711
 
    return cmp_record(this, record[1]);
4712
 
  /* Compare null bits */
4713
 
  if (memcmp(null_flags,
4714
 
             null_flags + s->rec_buff_length,
4715
 
             s->null_bytes))
4716
 
    return true;                                // Diff in NULL value
4717
 
  /* Compare updated fields */
4718
 
  for (Field **ptr= field ; *ptr ; ptr++)
4719
 
  {
4720
 
    if (bitmap_is_set(write_set, (*ptr)->field_index) &&
4721
 
        (*ptr)->cmp_binary_offset(s->rec_buff_length))
4722
 
      return true;
4723
 
  }
4724
 
  return false;
4725
 
}
4726
 
 
4727
 
 
4728
 
 
4729
 
 
4730
 
 
4731
 
/*****************************************************************************
4732
 
  The different ways to read a record
4733
 
  Returns -1 if row was not found, 0 if row was found and 1 on errors
4734
 
*****************************************************************************/
4735
 
 
4736
 
/** Help function when we get some an error from the table handler. */
4737
 
 
4738
 
int Table::report_error(int error)
4739
 
{
4740
 
  if (error == HA_ERR_END_OF_FILE || error == HA_ERR_KEY_NOT_FOUND)
4741
 
  {
4742
 
    status= STATUS_GARBAGE;
4743
 
    return -1;                                  // key not found; ok
4744
 
  }
4745
 
  /*
4746
 
    Locking reads can legally return also these errors, do not
4747
 
    print them to the .err log
4748
 
  */
4749
 
  if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
4750
 
    sql_print_error(_("Got error %d when reading table '%s'"),
4751
 
                    error, s->path.str);
4752
 
  file->print_error(error,MYF(0));
4753
 
 
4754
 
  return 1;
4755
 
}
4756
 
 
4757
4663
 
4758
4664
/*****************************************************************************
4759
4665
** Instansiate templates