~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:07:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1009.
  • Revision ID: mordred@inaugust.com-20090508190739-rwas5y9xjg1a92p6
Reverted a crap-ton of padraig's work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
530
530
    share->keynames.type_lengths[keynr]= indx.name().length();
531
531
  }
532
532
 
533
 
  share->keys_for_keyread.reset();
534
 
  set_prefix(share->keys_in_use, share->keys);
 
533
  share->keys_for_keyread.init(0);
 
534
  share->keys_in_use.init(share->keys);
535
535
 
536
536
  if(table_options.has_connect_string())
537
537
  {
556
556
 
557
557
  share->fields= table.field_size();
558
558
  share->vfields= 0;
 
559
  share->stored_fields= share->fields;
559
560
 
560
561
  share->field= (Field**) alloc_root(&share->mem_root,
561
562
                                     ((share->fields+1) * sizeof(Field*)));
855
856
    }
856
857
 
857
858
    enum_field_types field_type;
 
859
    bool field_is_stored= true;
 
860
 
858
861
 
859
862
    field_type= proto_field_type_to_drizzle_type(pfield.type());
860
863
 
963
966
 
964
967
    f->field_index= fieldnr;
965
968
    f->comment= comment;
 
969
    f->is_stored= field_is_stored;
966
970
    if(!default_value
967
971
       && !(f->unireg_check==Field::NEXT_NUMBER)
968
972
       && (f->flags & NOT_NULL_FLAG)
978
982
    if (use_hash) /* supposedly this never fails... but comments lie */
979
983
      (void) my_hash_insert(&share->name_hash,
980
984
                            (unsigned char*)&(share->field[fieldnr]));
 
985
 
 
986
    if(!f->is_stored)
 
987
    {
 
988
      share->stored_fields--;
 
989
    }
981
990
  }
982
991
 
983
992
  keyinfo= share->key_info;
1088
1097
                           (keyinfo->key_parts == 1)) ?
1089
1098
                           UNIQUE_KEY_FLAG : MULTIPLE_KEY_FLAG);
1090
1099
        if (i == 0)
1091
 
          field->key_start.set(key);
 
1100
          field->key_start.set_bit(key);
1092
1101
        if (field->key_length() == key_part->length &&
1093
1102
            !(field->flags & BLOB_FLAG))
1094
1103
        {
1095
1104
          if (handler_file->index_flags(key, i, 0) & HA_KEYREAD_ONLY)
1096
1105
          {
1097
 
            share->keys_for_keyread.set(key);
1098
 
            field->part_of_key.set(key);
1099
 
            field->part_of_key_not_clustered.set(key);
 
1106
            share->keys_for_keyread.set_bit(key);
 
1107
            field->part_of_key.set_bit(key);
 
1108
            field->part_of_key_not_clustered.set_bit(key);
1100
1109
          }
1101
1110
          if (handler_file->index_flags(key, i, 1) & HA_READ_ORDER)
1102
 
            field->part_of_sortkey.set(key);
 
1111
            field->part_of_sortkey.set_bit(key);
1103
1112
        }
1104
1113
        if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
1105
1114
            usable_parts == i)
1115
1124
          if (ha_option & HA_PRIMARY_KEY_IN_READ_INDEX)
1116
1125
          {
1117
1126
            field->part_of_key= share->keys_in_use;
1118
 
            if (field->part_of_sortkey.test(key))
 
1127
            if (field->part_of_sortkey.is_set(key))
1119
1128
              field->part_of_sortkey= share->keys_in_use;
1120
1129
          }
1121
1130
        }
1138
1147
        set_if_bigger(share->max_unique_length,keyinfo->key_length);
1139
1148
    }
1140
1149
    if (primary_key < MAX_KEY &&
1141
 
        (share->keys_in_use.test(primary_key)))
 
1150
        (share->keys_in_use.is_set(primary_key)))
1142
1151
    {
1143
1152
      share->primary_key= primary_key;
1144
1153
      /*
1198
1207
  }
1199
1208
 
1200
1209
  share->db_low_byte_first= handler_file->low_byte_first();
 
1210
  share->column_bitmap_size= bitmap_buffer_size(share->fields);
 
1211
 
 
1212
  my_bitmap_map *bitmaps;
 
1213
 
 
1214
  if (!(bitmaps= (my_bitmap_map*) alloc_root(&share->mem_root,
 
1215
                                             share->column_bitmap_size)))
 
1216
    goto err;
1201
1217
  share->all_set.set();
1202
1218
 
1203
1219
  if(handler_file)
1342
1358
 
1343
1359
  if (!(outparam->alias= strdup(alias)))
1344
1360
    goto err;
1345
 
  outparam->quick_keys.reset();
1346
 
  outparam->covering_keys.reset();
1347
 
  outparam->keys_in_use_for_query.reset();
 
1361
  outparam->quick_keys.init();
 
1362
  outparam->covering_keys.init();
 
1363
  outparam->keys_in_use_for_query.init();
1348
1364
 
1349
1365
  /* Allocate handler */
1350
1366
  outparam->file= 0;
1528
1544
  memset(bitmaps, 0, bitmap_size*3);
1529
1545
#endif
1530
1546
 
 
1547
  outparam->no_replicate= outparam->file;
1531
1548
  session->status_var.opened_tables++;
1532
1549
 
1533
1550
  return (0);
2629
2646
 
2630
2647
void Table::prepare_for_position()
2631
2648
{
 
2649
 
2632
2650
  if ((file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
2633
2651
      s->primary_key < MAX_KEY)
2634
2652
  {
2635
2653
    mark_columns_used_by_index_no_reset(s->primary_key, read_set);
 
2654
    /* signal change */
 
2655
    file->column_bitmaps_signal();
2636
2656
  }
2637
2657
  return;
2638
2658
}
2677
2697
  key_read= 0;
2678
2698
  (void) file->extra(HA_EXTRA_NO_KEYREAD);
2679
2699
  default_column_bitmaps();
 
2700
  file->column_bitmaps_signal();
 
2701
  return;
2680
2702
}
2681
2703
 
2682
2704
 
2714
2736
  write_set->set(found_next_number_field->field_index);
2715
2737
  if (s->next_number_keypart)
2716
2738
    mark_columns_used_by_index_no_reset(s->next_number_index, read_set);
 
2739
  file->column_bitmaps_signal();
2717
2740
}
2718
2741
 
2719
2742
 
2745
2768
      if ((*reg_field)->flags & PART_KEY_FLAG)
2746
2769
        read_set->set((*reg_field)->field_index);
2747
2770
    }
 
2771
    file->column_bitmaps_signal();
2748
2772
  }
2749
2773
 
2750
2774
  {
2757
2781
    if (s->primary_key == MAX_KEY)
2758
2782
      file->use_hidden_primary_key();
2759
2783
    else
 
2784
    {
2760
2785
      mark_columns_used_by_index_no_reset(s->primary_key, read_set);
 
2786
      file->column_bitmaps_signal();
 
2787
    }
2761
2788
  }
2762
2789
}
2763
2790
 
2789
2816
    for (reg_field= field ; *reg_field ; reg_field++)
2790
2817
    {
2791
2818
      /* Merge keys is all keys that had a column refered to in the query */
2792
 
      if (is_overlapping(merge_keys, (*reg_field)->part_of_key))
 
2819
      if (merge_keys.is_overlapping((*reg_field)->part_of_key))
2793
2820
        read_set->set((*reg_field)->field_index);
2794
2821
    }
 
2822
    file->column_bitmaps_signal();
2795
2823
  }
2796
2824
 
2797
2825
  {
2804
2832
    if (s->primary_key == MAX_KEY)
2805
2833
      file->use_hidden_primary_key();
2806
2834
    else
 
2835
    {
2807
2836
      mark_columns_used_by_index_no_reset(s->primary_key, read_set);
 
2837
      file->column_bitmaps_signal();
 
2838
    }
2808
2839
  }
2809
2840
  return;
2810
2841
}
2944
2975
    /* initialize temporary variables used to collect hints of each kind */
2945
2976
    for (type= INDEX_HINT_IGNORE; type <= INDEX_HINT_FORCE; type++)
2946
2977
    {
2947
 
      index_join[type].reset();
2948
 
      index_order[type].reset();
2949
 
      index_group[type].reset();
 
2978
      index_join[type].clear_all();
 
2979
      index_order[type].clear_all();
 
2980
      index_group[type].clear_all();
2950
2981
    }
2951
2982
 
2952
2983
    /* iterate over the hints list */
2959
2990
      {
2960
2991
        if (hint->clause & INDEX_HINT_MASK_JOIN)
2961
2992
        {
2962
 
          index_join[hint->type].reset();
 
2993
          index_join[hint->type].clear_all();
2963
2994
          have_empty_use_join= true;
2964
2995
        }
2965
2996
        if (hint->clause & INDEX_HINT_MASK_ORDER)
2966
2997
        {
2967
 
          index_order[hint->type].reset();
 
2998
          index_order[hint->type].clear_all();
2968
2999
          have_empty_use_order= true;
2969
3000
        }
2970
3001
        if (hint->clause & INDEX_HINT_MASK_GROUP)
2971
3002
        {
2972
 
          index_group[hint->type].reset();
 
3003
          index_group[hint->type].clear_all();
2973
3004
          have_empty_use_group= true;
2974
3005
        }
2975
3006
        continue;
2991
3022
 
2992
3023
      /* add to the appropriate clause mask */
2993
3024
      if (hint->clause & INDEX_HINT_MASK_JOIN)
2994
 
        index_join[hint->type].set(pos);
 
3025
        index_join[hint->type].set_bit (pos);
2995
3026
      if (hint->clause & INDEX_HINT_MASK_ORDER)
2996
 
        index_order[hint->type].set(pos);
 
3027
        index_order[hint->type].set_bit (pos);
2997
3028
      if (hint->clause & INDEX_HINT_MASK_GROUP)
2998
 
        index_group[hint->type].set(pos);
 
3029
        index_group[hint->type].set_bit (pos);
2999
3030
    }
3000
3031
 
3001
3032
    /* cannot mix USE INDEX and FORCE INDEX */
3002
 
    if ((index_join[INDEX_HINT_FORCE].any() ||
3003
 
         index_order[INDEX_HINT_FORCE].any() ||
3004
 
         index_group[INDEX_HINT_FORCE].any()) &&
3005
 
        (index_join[INDEX_HINT_USE].any() ||  have_empty_use_join ||
3006
 
         index_order[INDEX_HINT_USE].any() || have_empty_use_order ||
3007
 
         index_group[INDEX_HINT_USE].any() || have_empty_use_group))
 
3033
    if ((!index_join[INDEX_HINT_FORCE].is_clear_all() ||
 
3034
         !index_order[INDEX_HINT_FORCE].is_clear_all() ||
 
3035
         !index_group[INDEX_HINT_FORCE].is_clear_all()) &&
 
3036
        (!index_join[INDEX_HINT_USE].is_clear_all() ||  have_empty_use_join ||
 
3037
         !index_order[INDEX_HINT_USE].is_clear_all() || have_empty_use_order ||
 
3038
         !index_group[INDEX_HINT_USE].is_clear_all() || have_empty_use_group))
3008
3039
    {
3009
3040
      my_error(ER_WRONG_USAGE, MYF(0), index_hint_type_name[INDEX_HINT_USE],
3010
3041
               index_hint_type_name[INDEX_HINT_FORCE]);
3012
3043
    }
3013
3044
 
3014
3045
    /* process FORCE INDEX as USE INDEX with a flag */
3015
 
    if (index_join[INDEX_HINT_FORCE].any() ||
3016
 
        index_order[INDEX_HINT_FORCE].any() ||
3017
 
        index_group[INDEX_HINT_FORCE].any())
 
3046
    if (!index_join[INDEX_HINT_FORCE].is_clear_all() ||
 
3047
        !index_order[INDEX_HINT_FORCE].is_clear_all() ||
 
3048
        !index_group[INDEX_HINT_FORCE].is_clear_all())
3018
3049
    {
3019
3050
      tbl->force_index= true;
3020
 
      index_join[INDEX_HINT_USE]|= index_join[INDEX_HINT_FORCE];
3021
 
      index_order[INDEX_HINT_USE]|= index_order[INDEX_HINT_FORCE];
3022
 
      index_group[INDEX_HINT_USE]|= index_group[INDEX_HINT_FORCE];
 
3051
      index_join[INDEX_HINT_USE].merge(index_join[INDEX_HINT_FORCE]);
 
3052
      index_order[INDEX_HINT_USE].merge(index_order[INDEX_HINT_FORCE]);
 
3053
      index_group[INDEX_HINT_USE].merge(index_group[INDEX_HINT_FORCE]);
3023
3054
    }
3024
3055
 
3025
3056
    /* apply USE INDEX */
3026
 
    if (index_join[INDEX_HINT_USE].any() || have_empty_use_join)
3027
 
      tbl->keys_in_use_for_query&= index_join[INDEX_HINT_USE];
3028
 
    if (index_order[INDEX_HINT_USE].any() || have_empty_use_order)
3029
 
      tbl->keys_in_use_for_order_by&= index_order[INDEX_HINT_USE];
3030
 
    if (index_group[INDEX_HINT_USE].any() || have_empty_use_group)
3031
 
      tbl->keys_in_use_for_group_by&= index_group[INDEX_HINT_USE];
 
3057
    if (!index_join[INDEX_HINT_USE].is_clear_all() || have_empty_use_join)
 
3058
      tbl->keys_in_use_for_query.intersect(index_join[INDEX_HINT_USE]);
 
3059
    if (!index_order[INDEX_HINT_USE].is_clear_all() || have_empty_use_order)
 
3060
      tbl->keys_in_use_for_order_by.intersect (index_order[INDEX_HINT_USE]);
 
3061
    if (!index_group[INDEX_HINT_USE].is_clear_all() || have_empty_use_group)
 
3062
      tbl->keys_in_use_for_group_by.intersect (index_group[INDEX_HINT_USE]);
3032
3063
 
3033
3064
    /* apply IGNORE INDEX */
3034
 
    key_map_subtract(tbl->keys_in_use_for_query, index_join[INDEX_HINT_IGNORE]);
3035
 
    key_map_subtract(tbl->keys_in_use_for_order_by, index_order[INDEX_HINT_IGNORE]);
3036
 
    key_map_subtract(tbl->keys_in_use_for_group_by, index_group[INDEX_HINT_IGNORE]);
 
3065
    tbl->keys_in_use_for_query.subtract (index_join[INDEX_HINT_IGNORE]);
 
3066
    tbl->keys_in_use_for_order_by.subtract (index_order[INDEX_HINT_IGNORE]);
 
3067
    tbl->keys_in_use_for_group_by.subtract (index_group[INDEX_HINT_IGNORE]);
3037
3068
  }
3038
3069
 
3039
3070
  /* make sure covering_keys don't include indexes disabled with a hint */
3040
 
  tbl->covering_keys&= tbl->keys_in_use_for_query;
 
3071
  tbl->covering_keys.intersect(tbl->keys_in_use_for_query);
3041
3072
  return 0;
3042
3073
}
3043
3074
 
3203
3234
  uint32_t  copy_func_count= param->func_count;
3204
3235
  uint32_t  hidden_null_count, hidden_null_pack_length, hidden_field_count;
3205
3236
  uint32_t  blob_count,group_null_items, string_count;
3206
 
  uint32_t  temp_pool_slot= BIT_NONE;
 
3237
  uint32_t  temp_pool_slot= MY_BIT_NONE;
3207
3238
  uint32_t fieldnr= 0;
3208
3239
  ulong reclength, string_total_length;
3209
3240
  bool  using_unique_constraint= 0;
3210
3241
  bool  use_packed_rows= 0;
3211
3242
  bool  not_all_columns= !(select_options & TMP_TABLE_ALL_COLUMNS);
3212
3243
  char  *tmpname,path[FN_REFLEN];
3213
 
  unsigned char *pos, *group_buff;
 
3244
  unsigned char *pos, *group_buff, *bitmaps;
3214
3245
  unsigned char *null_flags;
3215
3246
  Field **reg_field, **from_field, **default_field;
3216
3247
  uint32_t *blob_field;
3227
3258
  if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
3228
3259
    setNextBit(temp_pool);
3229
3260
 
3230
 
  if (temp_pool_slot != BIT_NONE) // we got a slot
 
3261
  if (temp_pool_slot != MY_BIT_NONE) // we got a slot
3231
3262
    sprintf(path, "%s_%lx_%i", TMP_FILE_PREFIX,
3232
3263
            (unsigned long)current_pid, temp_pool_slot);
3233
3264
  else
3297
3328
                        &tmpname, (uint32_t) strlen(path)+1,
3298
3329
                        &group_buff, (group && ! using_unique_constraint ?
3299
3330
                                      param->group_length : 0),
 
3331
                        &bitmaps, bitmap_buffer_size(field_count)*2,
3300
3332
                        NULL))
3301
3333
  {
3302
 
    if (temp_pool_slot != BIT_NONE)
 
3334
    if (temp_pool_slot != MY_BIT_NONE)
3303
3335
      temp_pool.reset(temp_pool_slot);
3304
3336
    return(NULL);                               /* purecov: inspected */
3305
3337
  }
3306
3338
  /* Copy_field belongs to Tmp_Table_Param, allocate it in Session mem_root */
3307
3339
  if (!(param->copy_field= copy= new (session->mem_root) Copy_field[field_count]))
3308
3340
  {
3309
 
    if (temp_pool_slot != BIT_NONE)
 
3341
    if (temp_pool_slot != MY_BIT_NONE)
3310
3342
      temp_pool.reset(temp_pool_slot);
3311
3343
    free_root(&own_root, MYF(0));               /* purecov: inspected */
3312
3344
    return(NULL);                               /* purecov: inspected */
3332
3364
  table->temp_pool_slot= temp_pool_slot;
3333
3365
  table->copy_blobs= 1;
3334
3366
  table->in_use= session;
3335
 
  table->quick_keys.reset();
3336
 
  table->covering_keys.reset();
3337
 
  table->keys_in_use_for_query.reset();
 
3367
  table->quick_keys.init();
 
3368
  table->covering_keys.init();
 
3369
  table->keys_in_use_for_query.init();
3338
3370
 
3339
3371
  table->setShare(share);
3340
3372
  share->init(tmpname, tmpname);
3343
3375
  share->db_low_byte_first=1;                // True for HEAP and MyISAM
3344
3376
  share->table_charset= param->table_charset;
3345
3377
  share->primary_key= MAX_KEY;               // Indicate no primary key
3346
 
  share->keys_for_keyread.reset();
3347
 
  share->keys_in_use.reset();
 
3378
  share->keys_for_keyread.init();
 
3379
  share->keys_in_use.init();
3348
3380
 
3349
3381
  /* Calculate which type of fields we will store in the temporary table */
3350
3382
 
3858
3890
err:
3859
3891
  session->mem_root= mem_root_save;
3860
3892
  table->free_tmp_table(session);                    /* purecov: inspected */
3861
 
  if (temp_pool_slot != BIT_NONE)
 
3893
  if (temp_pool_slot != MY_BIT_NONE)
3862
3894
    temp_pool.reset(temp_pool_slot);
3863
3895
  return(NULL);                         /* purecov: inspected */
3864
3896
}
3894
3926
  uint32_t null_count= 0;                 /* number of columns which may be null */
3895
3927
  uint32_t null_pack_length;              /* NULL representation array length */
3896
3928
  uint32_t *blob_field;
 
3929
  unsigned char *bitmaps;
3897
3930
  Table *table;
3898
3931
  TableShare *share;
3899
3932
 
3902
3935
                        &share, sizeof(*share),
3903
3936
                        &field, (field_count + 1) * sizeof(Field*),
3904
3937
                        &blob_field, (field_count+1) *sizeof(uint32_t),
 
3938
                        &bitmaps, bitmap_buffer_size(field_count)*2,
3905
3939
                        NULL))
3906
3940
    return 0;
3907
3941
 
4166
4200
    (*ptr)->free();
4167
4201
  free_io_cache(this);
4168
4202
 
4169
 
  if (temp_pool_slot != BIT_NONE)
 
4203
  if (temp_pool_slot != MY_BIT_NONE)
4170
4204
    temp_pool.reset(temp_pool_slot);
4171
4205
 
4172
4206
  free_root(&own_root, MYF(0)); /* the table is allocated in its own root */
4298
4332
{
4299
4333
  uint32_t min_length= UINT32_MAX;
4300
4334
  uint32_t best= MAX_KEY;
4301
 
  if (usable_keys->any())
 
4335
  if (!usable_keys->is_clear_all())
4302
4336
  {
4303
4337
    for (uint32_t nr=0; nr < s->keys ; nr++)
4304
4338
    {
4305
 
      if (usable_keys->test(nr))
 
4339
      if (usable_keys->is_set(nr))
4306
4340
      {
4307
4341
        if (key_info[nr].key_length < min_length)
4308
4342
        {
4453
4487
  map= (table_map) 1 << table_number;
4454
4488
  force_index= table_list->force_index;
4455
4489
  covering_keys= s->keys_for_keyread;
4456
 
  merge_keys.reset();
 
4490
  merge_keys.clear_all();
4457
4491
}
4458
4492
 
4459
4493