~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/opt_range.cc

  • Committer: Brian Aker
  • Date: 2009-06-08 16:52:16 UTC
  • mfrom: (1054.2.7 mordred)
  • Revision ID: brian@gaz-20090608165216-prwpfo3ixrsoo3ke
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
8072
8072
  SEL_ARG *cur_index_tree= NULL;
8073
8073
  ha_rows cur_quick_prefix_records= 0;
8074
8074
  uint32_t cur_param_idx=MAX_KEY;
8075
 
  key_map cur_used_key_parts;
 
8075
  key_map used_key_parts_map;
 
8076
  uint32_t cur_key_infix_len= 0;
 
8077
  unsigned char cur_key_infix[MAX_KEY_LENGTH];
 
8078
  uint32_t cur_used_key_parts= 0;
8076
8079
  uint32_t pk= param->table->s->primary_key;
8077
8080
 
8078
8081
  for (uint32_t cur_index= 0 ; cur_index_info != cur_index_info_end ;
8147
8150
    else if (join->select_distinct)
8148
8151
    {
8149
8152
      select_items_it.rewind();
8150
 
      cur_used_key_parts.reset();
 
8153
      used_key_parts_map.reset();
8151
8154
      uint32_t max_key_part= 0;
8152
8155
      while ((item= select_items_it++))
8153
8156
      {
8158
8161
          Check if this attribute was already present in the select list.
8159
8162
          If it was present, then its corresponding key part was alredy used.
8160
8163
        */
8161
 
        if (cur_used_key_parts.test(key_part_nr))
 
8164
        if (used_key_parts_map.test(key_part_nr))
8162
8165
          continue;
8163
8166
        if (key_part_nr < 1 || key_part_nr > join->fields_list.elements)
8164
8167
          goto next_index;
8165
8168
        cur_part= cur_index_info->key_part + key_part_nr - 1;
8166
8169
        cur_group_prefix_len+= cur_part->store_length;
8167
 
        cur_used_key_parts.set(key_part_nr);
 
8170
        used_key_parts_map.set(key_part_nr);
8168
8171
        ++cur_group_key_parts;
8169
8172
        max_key_part= cmax(max_key_part,key_part_nr);
8170
8173
      }
8177
8180
      key_map all_parts, cur_parts;
8178
8181
      for (uint32_t pos= 0; pos < max_key_part; pos++)
8179
8182
        all_parts.set(pos);
8180
 
      cur_parts= cur_used_key_parts >> 1;
 
8183
      cur_parts= used_key_parts_map >> 1;
8181
8184
      if (all_parts != cur_parts)
8182
8185
        goto next_index;
8183
8186
    }
8227
8230
                                                        &dummy);
8228
8231
        if (!get_constant_key_infix(cur_index_info, index_range_tree,
8229
8232
                                    first_non_group_part, min_max_arg_part,
8230
 
                                    last_part, session, key_infix, &key_infix_len,
 
8233
                                    last_part, session, cur_key_infix, 
 
8234
                                    &cur_key_infix_len,
8231
8235
                                    &first_non_infix_part))
8232
8236
          goto next_index;
8233
8237
      }
8281
8285
    }
8282
8286
 
8283
8287
    /* If we got to this point, cur_index_info passes the test. */
8284
 
    key_infix_parts= key_infix_len ?
 
8288
    key_infix_parts= cur_key_infix_len ?
8285
8289
                     (first_non_infix_part - first_non_group_part) : 0;
8286
 
    used_key_parts= cur_group_key_parts + key_infix_parts;
 
8290
    cur_used_key_parts= cur_group_key_parts + key_infix_parts;
8287
8291
 
8288
8292
    /* Compute the cost of using this index. */
8289
8293
    if (tree)
8301
8305
                                                   &mrr_flags, &mrr_bufsize,
8302
8306
                                                   &dummy_cost);
8303
8307
    }
8304
 
    cost_group_min_max(table, cur_index_info, used_key_parts,
 
8308
    cost_group_min_max(table, cur_index_info, cur_used_key_parts,
8305
8309
                       cur_group_key_parts, tree, cur_index_tree,
8306
8310
                       cur_quick_prefix_records, have_min, have_max,
8307
8311
                       &cur_read_cost, &cur_records);
8322
8326
      best_param_idx= cur_param_idx;
8323
8327
      group_key_parts= cur_group_key_parts;
8324
8328
      group_prefix_len= cur_group_prefix_len;
 
8329
      key_infix_len= cur_key_infix_len;
 
8330
      if (key_infix_len)
 
8331
        memcpy (key_infix, cur_key_infix, sizeof (key_infix));
 
8332
      used_key_parts= cur_used_key_parts;
8325
8333
    }
8326
8334
 
8327
8335
  next_index:
8328
8336
    cur_group_key_parts= 0;
8329
8337
    cur_group_prefix_len= 0;
 
8338
    cur_key_infix_len= 0;
8330
8339
  }
8331
8340
  if (!index_info) /* No usable index found. */
8332
8341
    return NULL;