~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Monty Taylor
  • Date: 2009-05-08 19:27:21 UTC
  • mto: This revision was merged to the branch mainline in revision 1009.
  • Revision ID: mordred@inaugust.com-20090508192721-glbsg850k7wqp1rd
Further reversion of P.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <drizzled/field/varstring.h>
33
33
#include <drizzled/field/double.h>
34
34
#include <string>
35
 
#include <bitset>
36
35
 
37
36
#include <drizzled/unireg.h>
38
37
#include <drizzled/message/table.pb.h>
1214
1213
  if (!(bitmaps= (my_bitmap_map*) alloc_root(&share->mem_root,
1215
1214
                                             share->column_bitmap_size)))
1216
1215
    goto err;
1217
 
  share->all_set.set();
 
1216
  bitmap_init(&share->all_set, bitmaps, share->fields, false);
 
1217
  bitmap_set_all(&share->all_set);
1218
1218
 
1219
1219
  if(handler_file)
1220
1220
    delete handler_file;
1490
1490
  }
1491
1491
 
1492
1492
  /* Allocate bitmaps */
 
1493
 
 
1494
  bitmap_size= share->column_bitmap_size;
 
1495
  if (!(bitmaps= (unsigned char*) alloc_root(&outparam->mem_root, bitmap_size*3)))
 
1496
    goto err;
 
1497
  bitmap_init(&outparam->def_read_set,
 
1498
              (my_bitmap_map*) bitmaps, share->fields, false);
 
1499
  bitmap_init(&outparam->def_write_set,
 
1500
              (my_bitmap_map*) (bitmaps+bitmap_size), share->fields, false);
 
1501
  bitmap_init(&outparam->tmp_set,
 
1502
              (my_bitmap_map*) (bitmaps+bitmap_size*2), share->fields, false);
1493
1503
  outparam->default_column_bitmaps();
1494
1504
 
1495
1505
  /* The table struct is now initialized;  Open the table */
1989
1999
    a tmp_set bitmap to be used by things like filesort.
1990
2000
*/
1991
2001
 
1992
 
void Table::setup_tmp_table_column_bitmaps()
 
2002
void Table::setup_tmp_table_column_bitmaps(unsigned char *bitmaps)
1993
2003
{
 
2004
  uint32_t field_count= s->fields;
 
2005
 
 
2006
  bitmap_init(&this->def_read_set, (my_bitmap_map*) bitmaps, field_count, false);
 
2007
  bitmap_init(&this->tmp_set, (my_bitmap_map*) (bitmaps+ bitmap_buffer_size(field_count)), field_count, false);
 
2008
 
1994
2009
  /* write_set and all_set are copies of read_set */
1995
2010
  def_write_set= def_read_set;
1996
2011
  s->all_set= def_read_set;
1997
 
  this->s->all_set.set();
 
2012
  bitmap_set_all(&this->s->all_set);
1998
2013
  default_column_bitmaps();
1999
2014
}
2000
2015
 
2626
2641
void Table::clear_column_bitmaps()
2627
2642
{
2628
2643
  /*
2629
 
    Reset column read/write usage.
 
2644
    Reset column read/write usage. It's identical to:
 
2645
    bitmap_clear_all(&table->def_read_set);
 
2646
    bitmap_clear_all(&table->def_write_set);
2630
2647
  */
2631
 
  def_read_set.reset();
2632
 
  def_write_set.reset(); /* TODO: is this needed here? */
 
2648
  memset(def_read_set.bitmap, 0, s->column_bitmap_size*2);
2633
2649
  column_bitmaps_set(&def_read_set, &def_write_set);
2634
2650
}
2635
2651
 
2669
2685
 
2670
2686
void Table::mark_columns_used_by_index(uint32_t index)
2671
2687
{
2672
 
  bitset<MAX_FIELDS> *bitmap= &tmp_set;
 
2688
  MY_BITMAP *bitmap= &tmp_set;
2673
2689
 
2674
2690
  (void) file->extra(HA_EXTRA_KEYREAD);
2675
 
  bitmap->reset();
 
2691
  bitmap_clear_all(bitmap);
2676
2692
  mark_columns_used_by_index_no_reset(index, bitmap);
2677
2693
  column_bitmaps_set(bitmap, bitmap);
2678
2694
  return;
2731
2747
    We must set bit in read set as update_auto_increment() is using the
2732
2748
    store() to check overflow of auto_increment values
2733
2749
  */
2734
 
  read_set->set(found_next_number_field->field_index);
2735
 
  write_set->set(found_next_number_field->field_index);
 
2750
  bitmap_set_bit(read_set, found_next_number_field->field_index);
 
2751
  bitmap_set_bit(write_set, found_next_number_field->field_index);
2736
2752
  if (s->next_number_keypart)
2737
2753
    mark_columns_used_by_index_no_reset(s->next_number_index, read_set);
2738
2754
  file->column_bitmaps_signal();
2765
2781
    for (reg_field= field ; *reg_field ; reg_field++)
2766
2782
    {
2767
2783
      if ((*reg_field)->flags & PART_KEY_FLAG)
2768
 
        read_set->set((*reg_field)->field_index);
 
2784
        bitmap_set_bit(read_set, (*reg_field)->field_index);
2769
2785
    }
2770
2786
    file->column_bitmaps_signal();
2771
2787
  }
2816
2832
    {
2817
2833
      /* Merge keys is all keys that had a column refered to in the query */
2818
2834
      if (merge_keys.is_overlapping((*reg_field)->part_of_key))
2819
 
        read_set->set((*reg_field)->field_index);
 
2835
        bitmap_set_bit(read_set, (*reg_field)->field_index);
2820
2836
    }
2821
2837
    file->column_bitmaps_signal();
2822
2838
  }
3233
3249
  uint32_t  copy_func_count= param->func_count;
3234
3250
  uint32_t  hidden_null_count, hidden_null_pack_length, hidden_field_count;
3235
3251
  uint32_t  blob_count,group_null_items, string_count;
3236
 
  uint32_t  temp_pool_slot= MY_BIT_NONE;
 
3252
  uint32_t  temp_pool_slot=MY_BIT_NONE;
3237
3253
  uint32_t fieldnr= 0;
3238
3254
  ulong reclength, string_total_length;
3239
3255
  bool  using_unique_constraint= 0;
3255
3271
  status_var_increment(session->status_var.created_tmp_tables);
3256
3272
 
3257
3273
  if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
3258
 
    temp_pool_slot = temp_pool.setNextBit();
 
3274
    temp_pool_slot = bitmap_lock_set_next(&temp_pool);
3259
3275
 
3260
3276
  if (temp_pool_slot != MY_BIT_NONE) // we got a slot
3261
3277
    sprintf(path, "%s_%lx_%i", TMP_FILE_PREFIX,
3331
3347
                        NULL))
3332
3348
  {
3333
3349
    if (temp_pool_slot != MY_BIT_NONE)
3334
 
      temp_pool.resetBit(temp_pool_slot);
 
3350
      bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
3335
3351
    return(NULL);                               /* purecov: inspected */
3336
3352
  }
3337
3353
  /* Copy_field belongs to Tmp_Table_Param, allocate it in Session mem_root */
3338
3354
  if (!(param->copy_field= copy= new (session->mem_root) Copy_field[field_count]))
3339
3355
  {
3340
3356
    if (temp_pool_slot != MY_BIT_NONE)
3341
 
      temp_pool.resetBit(temp_pool_slot);
 
3357
      bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
3342
3358
    free_root(&own_root, MYF(0));               /* purecov: inspected */
3343
3359
    return(NULL);                               /* purecov: inspected */
3344
3360
  }
3360
3376
  table->reginfo.lock_type=TL_WRITE;    /* Will be updated */
3361
3377
  table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
3362
3378
  table->map=1;
3363
 
  table->temp_pool_slot= temp_pool_slot;
 
3379
  table->temp_pool_slot = temp_pool_slot;
3364
3380
  table->copy_blobs= 1;
3365
3381
  table->in_use= session;
3366
3382
  table->quick_keys.init();
3592
3608
  copy_func[0]=0;                               // End marker
3593
3609
  param->func_count= copy_func - param->items_to_copy;
3594
3610
 
3595
 
  table->setup_tmp_table_column_bitmaps();
 
3611
  table->setup_tmp_table_column_bitmaps(bitmaps);
3596
3612
 
3597
3613
  recinfo=param->start_recinfo;
3598
3614
  null_flags=(unsigned char*) table->record[0];
3890
3906
  session->mem_root= mem_root_save;
3891
3907
  table->free_tmp_table(session);                    /* purecov: inspected */
3892
3908
  if (temp_pool_slot != MY_BIT_NONE)
3893
 
    temp_pool.resetBit(temp_pool_slot);
 
3909
    bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
3894
3910
  return(NULL);                         /* purecov: inspected */
3895
3911
}
3896
3912
 
3945
3961
  share->blob_field= blob_field;
3946
3962
  share->fields= field_count;
3947
3963
  share->blob_ptr_size= portable_sizeof_char_ptr;
3948
 
  table->setup_tmp_table_column_bitmaps();
 
3964
  table->setup_tmp_table_column_bitmaps(bitmaps);
3949
3965
 
3950
3966
  /* Create all fields and calculate the total length of record */
3951
3967
  List_iterator_fast<Create_field> it(field_list);
4200
4216
  free_io_cache(this);
4201
4217
 
4202
4218
  if (temp_pool_slot != MY_BIT_NONE)
4203
 
    temp_pool.resetBit(temp_pool_slot);
 
4219
    bitmap_lock_clear_bit(&temp_pool, temp_pool_slot);
4204
4220
 
4205
4221
  free_root(&own_root, MYF(0)); /* the table is allocated in its own root */
4206
4222
  session->set_proc_info(save_proc_info);
4315
4331
  return(1);
4316
4332
}
4317
4333
 
4318
 
bitset<MAX_FIELDS> *Table::use_all_columns(bitset<MAX_FIELDS> *bitmap)
 
4334
my_bitmap_map *Table::use_all_columns(MY_BITMAP *bitmap)
4319
4335
{
4320
 
  bitset<MAX_FIELDS> *old= bitmap;
4321
 
  bitmap= &s->all_set;
 
4336
  my_bitmap_map *old= bitmap->bitmap;
 
4337
  bitmap->bitmap= s->all_set.bitmap;
4322
4338
  return old;
4323
4339
}
4324
4340
 
4325
 
void Table::restore_column_map(bitset<MAX_FIELDS> *old)
 
4341
void Table::restore_column_map(my_bitmap_map *old)
4326
4342
{
4327
 
  read_set= old;
 
4343
  read_set->bitmap= old;
4328
4344
}
4329
4345
 
4330
4346
uint32_t Table::find_shortest_key(const key_map *usable_keys)
4380
4396
  /* Compare updated fields */
4381
4397
  for (Field **ptr= field ; *ptr ; ptr++)
4382
4398
  {
4383
 
    if (write_set->test((*ptr)->field_index) &&
 
4399
    if (bitmap_is_set(write_set, (*ptr)->field_index) &&
4384
4400
        (*ptr)->cmp_binary_offset(s->rec_buff_length))
4385
4401
      return true;
4386
4402
  }