~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/range.cc

  • Committer: Brian Aker
  • Date: 2010-05-20 06:34:25 UTC
  • mto: (1552.1.1 new-staging)
  • mto: This revision was merged to the branch mainline in revision 1553.
  • Revision ID: brian@gaz-20100520063425-0hwu5fx4fmmp2g49
Partial encapsulation of TableShare from Table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
204
204
  cost->zero();
205
205
  if (table->cursor->primary_key_is_clustered())
206
206
  {
207
 
    cost->setIOCount(table->cursor->read_time(table->s->primary_key,
 
207
    cost->setIOCount(table->cursor->read_time(table->getShare()->primary_key,
208
208
                                             static_cast<uint32_t>(nrows),
209
209
                                             nrows));
210
210
  }
467
467
    if (!ord->asc)
468
468
      return MAX_KEY;
469
469
 
470
 
  for (idx= 0; idx < table->s->keys; idx++)
 
470
  for (idx= 0; idx < table->getShare()->keys; idx++)
471
471
  {
472
472
    if (!(table->keys_in_use_for_query.test(idx)))
473
473
      continue;
539
539
  my_bitmap_map *tmp;
540
540
  uint32_t pk;
541
541
  param->tmp_covered_fields.setBitmap(0);
542
 
  param->fields_bitmap_size= table->s->column_bitmap_size;
 
542
  param->fields_bitmap_size= table->getShare()->column_bitmap_size;
543
543
  if (!(tmp= (my_bitmap_map*) param->mem_root->alloc_root(param->fields_bitmap_size)) ||
544
 
      param->needed_fields.init(tmp, table->s->fields))
 
544
      param->needed_fields.init(tmp, table->getShare()->fields))
545
545
  {
546
546
    return 1;
547
547
  }
549
549
  param->needed_fields= *table->read_set;
550
550
  bitmap_union(&param->needed_fields, table->write_set);
551
551
 
552
 
  pk= param->table->s->primary_key;
 
552
  pk= param->table->getShare()->primary_key;
553
553
  if (pk != MAX_KEY && param->table->cursor->primary_key_is_clustered())
554
554
  {
555
555
    /* The table uses clustered PK and it is not internally generated */
685
685
 
686
686
    session->no_errors=1;                               // Don't warn about NULL
687
687
    memory::init_sql_alloc(&alloc, session->variables.range_alloc_block_size, 0);
688
 
    if (!(param.key_parts= (KEY_PART*) alloc.alloc_root( sizeof(KEY_PART) * head->s->key_parts)) ||
 
688
    if (!(param.key_parts= (KEY_PART*) alloc.alloc_root( sizeof(KEY_PART) * head->getShare()->key_parts)) ||
689
689
        fill_used_fields_bitmap(&param))
690
690
    {
691
691
      session->no_errors=0;
701
701
      This is used in get_mm_parts function.
702
702
    */
703
703
    key_info= head->key_info;
704
 
    for (idx=0 ; idx < head->s->keys ; idx++, key_info++)
 
704
    for (idx=0 ; idx < head->getShare()->keys ; idx++, key_info++)
705
705
    {
706
706
      KeyPartInfo *key_part_info;
707
707
      if (! keys_to_use.test(idx))
995
995
    all_scans_rors &= (*cur_child)->is_ror;
996
996
    if (pk_is_clustered &&
997
997
        param->real_keynr[(*cur_child)->key_idx] ==
998
 
        param->table->s->primary_key)
 
998
        param->table->getShare()->primary_key)
999
999
    {
1000
1000
      cpk_scan= cur_child;
1001
1001
      cpk_scan_records= (*cur_child)->records;
1236
1236
    return NULL;
1237
1237
  }
1238
1238
 
1239
 
  if (ror_scan->covered_fields.init(bitmap_buf, param->table->s->fields))
 
1239
  if (ror_scan->covered_fields.init(bitmap_buf, param->table->getShare()->fields))
1240
1240
  {
1241
1241
    return NULL;
1242
1242
  }
1354
1354
  info->param= param;
1355
1355
  if (!(buf= (my_bitmap_map*) param->mem_root->alloc_root(param->fields_bitmap_size)))
1356
1356
    return NULL;
1357
 
  if (info->covered_fields.init(buf, param->table->s->fields))
 
1357
  if (info->covered_fields.init(buf, param->table->getShare()->fields))
1358
1358
    return NULL;
1359
1359
  info->is_covering= false;
1360
1360
  info->index_scan_costs= 0.0;
1686
1686
  }
1687
1687
  if (! covered_fields->getBitmap() ||
1688
1688
      covered_fields->init(covered_fields->getBitmap(),
1689
 
                           param->table->s->fields))
 
1689
                           param->table->getShare()->fields))
1690
1690
    return 0;
1691
1691
  covered_fields->clearAll();
1692
1692
 
1851
1851
    return NULL;
1852
1852
  }
1853
1853
  cpk_no= ((param->table->cursor->primary_key_is_clustered()) ?
1854
 
           param->table->s->primary_key : MAX_KEY);
 
1854
           param->table->getShare()->primary_key : MAX_KEY);
1855
1855
 
1856
1856
  for (idx= 0, cur_ror_scan= tree->ror_scans; idx < param->keys; idx++)
1857
1857
  {
3868
3868
  bool pk_is_clustered= cursor->primary_key_is_clustered();
3869
3869
  if (index_only &&
3870
3870
      (param->table->index_flags(keynr) & HA_KEYREAD_ONLY) &&
3871
 
      !(pk_is_clustered && keynr == param->table->s->primary_key))
 
3871
      !(pk_is_clustered && keynr == param->table->getShare()->primary_key))
3872
3872
     *mrr_flags |= HA_MRR_INDEX_ONLY;
3873
3873
 
3874
3874
  if (current_session->lex->sql_command != SQLCOM_SELECT)
3903
3903
  else
3904
3904
  {
3905
3905
    /* Clustered PK scan is always a ROR scan (TODO: same as above) */
3906
 
    if (param->table->s->primary_key == keynr && pk_is_clustered)
 
3906
    if (param->table->getShare()->primary_key == keynr && pk_is_clustered)
3907
3907
      param->is_ror_scan= true;
3908
3908
  }
3909
3909
 
3968
3968
    return true;
3969
3969
 
3970
3970
  key_part= table_key->key_part + nparts;
3971
 
  pk_number= param->table->s->primary_key;
 
3971
  pk_number= param->table->getShare()->primary_key;
3972
3972
  if (!param->table->cursor->primary_key_is_clustered() || pk_number == MAX_KEY)
3973
3973
    return false;
3974
3974
 
4613
4613
       (! join->select_distinct)) ||
4614
4614
      (join->select_lex->olap == ROLLUP_TYPE)) /* Check (B3) for ROLLUP */
4615
4615
    return NULL;
4616
 
  if (table->s->keys == 0)        /* There are no indexes to use. */
 
4616
  if (table->getShare()->keys == 0)        /* There are no indexes to use. */
4617
4617
    return NULL;
4618
4618
 
4619
4619
  /* Analyze the query in more detail. */
4673
4673
    first one. Here we set the variables: group_prefix_len and index_info.
4674
4674
  */
4675
4675
  KeyInfo *cur_index_info= table->key_info;
4676
 
  KeyInfo *cur_index_info_end= cur_index_info + table->s->keys;
 
4676
  KeyInfo *cur_index_info_end= cur_index_info + table->getShare()->keys;
4677
4677
  KeyPartInfo *cur_part= NULL;
4678
4678
  KeyPartInfo *end_part= NULL; /* Last part for loops. */
4679
4679
  /* Last index part. */
4698
4698
  uint32_t cur_key_infix_len= 0;
4699
4699
  unsigned char cur_key_infix[MAX_KEY_LENGTH];
4700
4700
  uint32_t cur_used_key_parts= 0;
4701
 
  uint32_t pk= param->table->s->primary_key;
 
4701
  uint32_t pk= param->table->getShare()->primary_key;
4702
4702
 
4703
4703
  for (uint32_t cur_index= 0;
4704
4704
       cur_index_info != cur_index_info_end;
4721
4721
        (table->cursor->getEngine()->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX)))
4722
4722
    {
4723
4723
      /* For each table field */
4724
 
      for (uint32_t i= 0; i < table->s->fields; i++)
 
4724
      for (uint32_t i= 0; i < table->getShare()->fields; i++)
4725
4725
      {
4726
4726
        Field *cur_field= table->field[i];
4727
4727
        /*