~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: Brian Aker
  • Date: 2009-11-12 16:13:04 UTC
  • mfrom: (1211.1.7 staging)
  • Revision ID: brian@gaz-20091112161304-opamiauv36fg0n6u
Rollup of Brian, Padraig, and Stewart patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
728
728
      if (map == 1)                     // Only one table
729
729
      {
730
730
        Table *tmp_table=join->all_tables[tablenr];
731
 
        keyuse->setTableRows(max(tmp_table->file->stats.records, (ha_rows)100));
 
731
        keyuse->setTableRows(max(tmp_table->cursor->stats.records, (ha_rows)100));
732
732
      }
733
733
    }
734
734
    /*
882
882
    rec_length+=sizeof(bool);
883
883
  if (blobs)
884
884
  {
885
 
    uint32_t blob_length=(uint32_t) (join_tab->table->file->stats.mean_rec_length-
 
885
    uint32_t blob_length=(uint32_t) (join_tab->table->cursor->stats.mean_rec_length-
886
886
                                     (join_tab->table->getRecordLength()- rec_length));
887
887
    rec_length+= max((uint32_t)4,blob_length);
888
888
  }
899
899
                         uint32_t maybe_null)
900
900
{
901
901
  Item_ref *key_use_val= static_cast<Item_ref *>(keyuse->getVal());
902
 
  Item_ref **dir_val= reinterpret_cast<Item_ref **>(key_use_val->ref);
903
902
  if (! ((~used_tables) & keyuse->getUsedTables())) // if const item
904
903
  {
905
904
    return new store_key_const_item(session,
912
911
  else if (key_use_val->type() == Item::FIELD_ITEM ||
913
912
           (key_use_val->type() == Item::REF_ITEM &&
914
913
            key_use_val->ref_type() == Item_ref::OUTER_REF &&
915
 
            (*dir_val)->ref_type() == Item_ref::DIRECT_REF &&
 
914
            (*(Item_ref**)((Item_ref*)key_use_val)->ref)->ref_type() == Item_ref::DIRECT_REF &&
916
915
            key_use_val->real_item()->type() == Item::FIELD_ITEM))
917
916
  {
918
917
    return new store_key_field(session,
1477
1476
    if (table->key_read)
1478
1477
    {
1479
1478
      table->key_read= 0;
1480
 
      table->file->extra(HA_EXTRA_NO_KEYREAD);
 
1479
      table->cursor->extra(HA_EXTRA_NO_KEYREAD);
1481
1480
    }
1482
 
    table->file->ha_index_or_rnd_end();
 
1481
    table->cursor->ha_index_or_rnd_end();
1483
1482
    /*
1484
1483
      We need to reset this for next select
1485
1484
      (Tested in part_of_refkey)
3296
3295
 
3297
3296
  if (table)
3298
3297
  {
3299
 
    table->file->extra(HA_EXTRA_WRITE_CACHE);
 
3298
    table->cursor->extra(HA_EXTRA_WRITE_CACHE);
3300
3299
    table->emptyRecord();
3301
3300
    if (table->group && join->tmp_table_param.sum_func_count &&
3302
 
        table->s->keys && !table->file->inited)
3303
 
      table->file->ha_index_init(0, 0);
 
3301
        table->s->keys && !table->cursor->inited)
 
3302
      table->cursor->ha_index_init(0, 0);
3304
3303
  }
3305
3304
  /* Set up select_end */
3306
3305
  Next_select_func end_select= setup_end_select_func(join);
3372
3371
  if (table)
3373
3372
  {
3374
3373
    int tmp, new_errno= 0;
3375
 
    if ((tmp=table->file->extra(HA_EXTRA_NO_CACHE)))
 
3374
    if ((tmp=table->cursor->extra(HA_EXTRA_NO_CACHE)))
3376
3375
    {
3377
3376
      new_errno= tmp;
3378
3377
    }
3379
 
    if ((tmp=table->file->ha_index_or_rnd_end()))
 
3378
    if ((tmp=table->cursor->ha_index_or_rnd_end()))
3380
3379
    {
3381
3380
      new_errno= tmp;
3382
3381
    }
3383
3382
    if (new_errno)
3384
 
      table->file->print_error(new_errno,MYF(0));
 
3383
      table->cursor->print_error(new_errno,MYF(0));
3385
3384
  }
3386
3385
  return(join->session->is_error() ? -1 : rc);
3387
3386
}
3598
3597
{
3599
3598
  int error;
3600
3599
  Table *table= tab->table;
3601
 
  if ((error=table->file->index_read_map(table->record[0],
 
3600
  if ((error=table->cursor->index_read_map(table->record[0],
3602
3601
                                         tab->ref.key_buff,
3603
3602
                                         make_prev_keypart_map(tab->ref.key_parts),
3604
3603
                                         HA_READ_KEY_EXACT)))
3634
3633
        (int) table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS)
3635
3634
    {
3636
3635
      table->key_read=1;
3637
 
      table->file->extra(HA_EXTRA_KEYREAD);
 
3636
      table->cursor->extra(HA_EXTRA_KEYREAD);
3638
3637
      tab->index= tab->ref.key;
3639
3638
    }
3640
3639
    error=join_read_const(tab);
3641
3640
    if (table->key_read)
3642
3641
    {
3643
3642
      table->key_read=0;
3644
 
      table->file->extra(HA_EXTRA_NO_KEYREAD);
 
3643
      table->cursor->extra(HA_EXTRA_NO_KEYREAD);
3645
3644
    }
3646
3645
    if (error)
3647
3646
    {
3690
3689
  int error;
3691
3690
  if (table->status & STATUS_GARBAGE)           // If first read
3692
3691
  {
3693
 
    if ((error=table->file->read_first_row(table->record[0],
 
3692
    if ((error=table->cursor->read_first_row(table->record[0],
3694
3693
                                           table->s->primary_key)))
3695
3694
    {
3696
3695
      if (error != HA_ERR_END_OF_FILE)
3730
3729
      error= HA_ERR_KEY_NOT_FOUND;
3731
3730
    else
3732
3731
    {
3733
 
      error=table->file->index_read_idx_map(table->record[0],tab->ref.key,
 
3732
      error=table->cursor->index_read_idx_map(table->record[0],tab->ref.key,
3734
3733
                                            (unsigned char*) tab->ref.key_buff,
3735
3734
                                            make_prev_keypart_map(tab->ref.key_parts),
3736
3735
                                            HA_READ_KEY_EXACT);
3776
3775
  int error;
3777
3776
  Table *table= tab->table;
3778
3777
 
3779
 
  if (!table->file->inited)
 
3778
  if (!table->cursor->inited)
3780
3779
  {
3781
 
    table->file->ha_index_init(tab->ref.key, tab->sorted);
 
3780
    table->cursor->ha_index_init(tab->ref.key, tab->sorted);
3782
3781
  }
3783
3782
 
3784
3783
  /* TODO: Why don't we do "Late NULLs Filtering" here? */
3790
3789
      table->status=STATUS_NOT_FOUND;
3791
3790
      return -1;
3792
3791
    }
3793
 
    error=table->file->index_read_map(table->record[0],
 
3792
    error=table->cursor->index_read_map(table->record[0],
3794
3793
                                      tab->ref.key_buff,
3795
3794
                                      make_prev_keypart_map(tab->ref.key_parts),
3796
3795
                                      HA_READ_KEY_EXACT);
3825
3824
  Table *table= tab->table;
3826
3825
 
3827
3826
  /* Initialize the index first */
3828
 
  if (!table->file->inited)
3829
 
    table->file->ha_index_init(tab->ref.key, tab->sorted);
 
3827
  if (!table->cursor->inited)
 
3828
    table->cursor->ha_index_init(tab->ref.key, tab->sorted);
3830
3829
 
3831
3830
  /* Perform "Late NULLs Filtering" (see internals manual for explanations) */
3832
3831
  for (uint32_t i= 0 ; i < tab->ref.key_parts ; i++)
3837
3836
 
3838
3837
  if (cp_buffer_from_ref(tab->join->session, &tab->ref))
3839
3838
    return -1;
3840
 
  if ((error=table->file->index_read_map(table->record[0],
 
3839
  if ((error=table->cursor->index_read_map(table->record[0],
3841
3840
                                         tab->ref.key_buff,
3842
3841
                                         make_prev_keypart_map(tab->ref.key_parts),
3843
3842
                                         HA_READ_KEY_EXACT)))
3859
3858
  int error;
3860
3859
  Table *table= tab->table;
3861
3860
 
3862
 
  if (!table->file->inited)
3863
 
    table->file->ha_index_init(tab->ref.key, tab->sorted);
 
3861
  if (!table->cursor->inited)
 
3862
    table->cursor->ha_index_init(tab->ref.key, tab->sorted);
3864
3863
  if (cp_buffer_from_ref(tab->join->session, &tab->ref))
3865
3864
    return -1;
3866
 
  if ((error=table->file->index_read_last_map(table->record[0],
 
3865
  if ((error=table->cursor->index_read_last_map(table->record[0],
3867
3866
                                              tab->ref.key_buff,
3868
3867
                                              make_prev_keypart_map(tab->ref.key_parts))))
3869
3868
  {
3892
3891
      /* Save index tuple from record to the buffer */
3893
3892
      key_copy(tab->insideout_buf, info->record, key, 0);
3894
3893
 
3895
 
      if ((error=table->file->index_next_same(table->record[0],
 
3894
      if ((error=table->cursor->index_next_same(table->record[0],
3896
3895
                                              tab->ref.key_buff,
3897
3896
                                              tab->ref.key_length)))
3898
3897
      {
3916
3915
  Table *table= info->table;
3917
3916
  JoinTable *tab=table->reginfo.join_tab;
3918
3917
 
3919
 
  if ((error=table->file->index_next_same(table->record[0],
 
3918
  if ((error=table->cursor->index_next_same(table->record[0],
3920
3919
                                          tab->ref.key_buff,
3921
3920
                                          tab->ref.key_length)))
3922
3921
  {
3935
3934
  Table *table= info->table;
3936
3935
  JoinTable *tab=table->reginfo.join_tab;
3937
3936
 
3938
 
  if ((error=table->file->index_prev(table->record[0])))
 
3937
  if ((error=table->cursor->index_prev(table->record[0])))
3939
3938
    return table->report_error(error);
3940
3939
  if (key_cmp_if_same(table, tab->ref.key_buff, tab->ref.key,
3941
3940
                      tab->ref.key_length))
3957
3956
int init_read_record_seq(JoinTable *tab)
3958
3957
{
3959
3958
  tab->read_record.read_record= rr_sequential;
3960
 
  if (tab->read_record.file->ha_rnd_init(1))
 
3959
  if (tab->read_record.cursor->ha_rnd_init(1))
3961
3960
    return 1;
3962
3961
  return (*tab->read_record.read_record)(&tab->read_record);
3963
3962
}
3987
3986
      !table->no_keyread)
3988
3987
  {
3989
3988
    table->key_read=1;
3990
 
    table->file->extra(HA_EXTRA_KEYREAD);
 
3989
    table->cursor->extra(HA_EXTRA_KEYREAD);
3991
3990
  }
3992
3991
  tab->table->status=0;
3993
3992
  tab->read_record.table=table;
3994
 
  tab->read_record.file=table->file;
 
3993
  tab->read_record.cursor=table->cursor;
3995
3994
  tab->read_record.index=tab->index;
3996
3995
  tab->read_record.record=table->record[0];
3997
3996
  if (tab->insideout_match_tab)
4006
4005
    tab->read_record.do_insideout_scan= 0;
4007
4006
  }
4008
4007
 
4009
 
  if (!table->file->inited)
4010
 
    table->file->ha_index_init(tab->index, tab->sorted);
4011
 
  if ((error=tab->table->file->index_first(tab->table->record[0])))
 
4008
  if (!table->cursor->inited)
 
4009
    table->cursor->ha_index_init(tab->index, tab->sorted);
 
4010
  if ((error=tab->table->cursor->index_first(tab->table->record[0])))
4012
4011
  {
4013
4012
    if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
4014
4013
      table->report_error(error);
4030
4029
      /* Save index tuple from record to the buffer */
4031
4030
      key_copy(tab->insideout_buf, info->record, key, 0);
4032
4031
 
4033
 
      if ((error=info->file->index_next(info->record)))
 
4032
      if ((error=info->cursor->index_next(info->record)))
4034
4033
        return info->table->report_error(error);
4035
4034
    } while (!key_cmp(tab->table->key_info[tab->index].key_part,
4036
4035
                      tab->insideout_buf, key->key_length));
4044
4043
int join_read_next(READ_RECORD *info)
4045
4044
{
4046
4045
  int error;
4047
 
  if ((error=info->file->index_next(info->record)))
 
4046
  if ((error=info->cursor->index_next(info->record)))
4048
4047
    return info->table->report_error(error);
4049
4048
  return 0;
4050
4049
}
4057
4056
      !table->no_keyread)
4058
4057
  {
4059
4058
    table->key_read=1;
4060
 
    table->file->extra(HA_EXTRA_KEYREAD);
 
4059
    table->cursor->extra(HA_EXTRA_KEYREAD);
4061
4060
  }
4062
4061
  tab->table->status=0;
4063
4062
  tab->read_record.read_record=join_read_prev;
4064
4063
  tab->read_record.table=table;
4065
 
  tab->read_record.file=table->file;
 
4064
  tab->read_record.cursor=table->cursor;
4066
4065
  tab->read_record.index=tab->index;
4067
4066
  tab->read_record.record=table->record[0];
4068
 
  if (!table->file->inited)
4069
 
    table->file->ha_index_init(tab->index, 1);
4070
 
  if ((error= tab->table->file->index_last(tab->table->record[0])))
 
4067
  if (!table->cursor->inited)
 
4068
    table->cursor->ha_index_init(tab->index, 1);
 
4069
  if ((error= tab->table->cursor->index_last(tab->table->record[0])))
4071
4070
    return table->report_error(error);
4072
4071
 
4073
4072
  return 0;
4076
4075
int join_read_prev(READ_RECORD *info)
4077
4076
{
4078
4077
  int error;
4079
 
  if ((error= info->file->index_prev(info->record)))
 
4078
  if ((error= info->cursor->index_prev(info->record)))
4080
4079
    return info->table->report_error(error);
4081
4080
 
4082
4081
  return 0;
4228
4227
        copy_sum_funcs(join->sum_funcs, join->sum_funcs_end[send_group_parts]);
4229
4228
        if (!join->having || join->having->val_int())
4230
4229
        {
4231
 
          int error= table->file->ha_write_row(table->record[0]);
 
4230
          int error= table->cursor->ha_write_row(table->record[0]);
4232
4231
          if (error && create_myisam_from_heap(join->session, table,
4233
4232
                                              join->tmp_table_param.start_recinfo,
4234
4233
                                                &join->tmp_table_param.recinfo,
4534
4533
        the primary key as a suffix.
4535
4534
      */
4536
4535
      if (!on_primary_key &&
4537
 
          (table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
 
4536
          (table->cursor->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
4538
4537
          table->s->primary_key != MAX_KEY)
4539
4538
      {
4540
4539
        on_primary_key= true;
4568
4567
  }
4569
4568
  *used_key_parts= on_primary_key ? table->key_info[idx].key_parts :
4570
4569
    (uint32_t) (key_part - table->key_info[idx].key_part);
4571
 
  if (reverse == -1 && !(table->file->index_flags(idx, *used_key_parts-1, 1) &
 
4570
  if (reverse == -1 && !(table->cursor->index_flags(idx, *used_key_parts-1, 1) &
4572
4571
                         HA_READ_PREV))
4573
4572
    reverse= 0;                                 // Index can't be used
4574
4573
  return(reverse);
4932
4931
    double fanout= 1;
4933
4932
    JOIN *join= tab->join;
4934
4933
    uint32_t tablenr= tab - join->join_tab;
4935
 
    ha_rows table_records= table->file->stats.records;
 
4934
    ha_rows table_records= table->cursor->stats.records;
4936
4935
    bool group= join->group && order == join->group_list;
4937
4936
    optimizer::Position cur_pos;
4938
4937
 
4949
4948
        */
4950
4949
      if (tab->type == AM_ALL && tab->join->tables > tab->join->const_tables + 1)
4951
4950
        return(0);
4952
 
      keys= *table->file->keys_to_use_for_scanning();
 
4951
      keys= *table->cursor->keys_to_use_for_scanning();
4953
4952
      keys|= table->covering_keys;
4954
4953
 
4955
4954
      /*
4979
4978
      if (keys.test(nr) &&
4980
4979
          (direction= test_if_order_by_key(order, table, nr, &used_key_parts)))
4981
4980
      {
4982
 
        bool is_covering= table->covering_keys.test(nr) || (nr == table->s->primary_key && table->file->primary_key_is_clustered());
 
4981
        bool is_covering= table->covering_keys.test(nr) || (nr == table->s->primary_key && table->cursor->primary_key_is_clustered());
4983
4982
 
4984
4983
        /*
4985
4984
          Don't use an index scan with order_st BY without limit.
5049
5048
            Rows in such a sequence are supposed to be ordered
5050
5049
            by rowid/primary key. When reading the data
5051
5050
            in a sequence we'll touch not more pages than the
5052
 
            table file contains.
 
5051
            table cursor contains.
5053
5052
            TODO. Use the formula for a disk sweep sequential access
5054
5053
            to calculate the cost of accessing data rows for one
5055
5054
            index entry.
5056
5055
          */
5057
5056
          index_scan_time= select_limit/rec_per_key *
5058
 
                           min(rec_per_key, table->file->scan_time());
 
5057
                           min(rec_per_key, table->cursor->scan_time());
5059
5058
          if (is_covering || (ref_key < 0 && (group || table->force_index)) ||
5060
5059
              index_scan_time < read_time)
5061
5060
          {
5110
5109
          if (table->covering_keys.test(best_key))
5111
5110
          {
5112
5111
            table->key_read=1;
5113
 
            table->file->extra(HA_EXTRA_KEYREAD);
 
5112
            table->cursor->extra(HA_EXTRA_KEYREAD);
5114
5113
          }
5115
 
          table->file->ha_index_or_rnd_end();
 
5114
          table->cursor->ha_index_or_rnd_end();
5116
5115
          if (join->select_options & SELECT_DESCRIBE)
5117
5116
          {
5118
5117
            tab->ref.key= -1;
5216
5215
  IMPLEMENTATION
5217
5216
   - If there is an index that can be used, 'tab' is modified to use
5218
5217
     this index.
5219
 
   - If no index, create with filesort() an index file that can be used to
 
5218
   - If no index, create with filesort() an index cursor that can be used to
5220
5219
     retrieve rows in order (should be done with 'read_record').
5221
5220
     The sorted data is stored in tab->table and will be freed when calling
5222
5221
     tab->table->free_io_cache().
5277
5276
      if (table->key_read && ((uint32_t) tab->ref.key != select->quick->index))
5278
5277
      {
5279
5278
        table->key_read=0;
5280
 
        table->file->extra(HA_EXTRA_NO_KEYREAD);
 
5279
        table->cursor->extra(HA_EXTRA_NO_KEYREAD);
5281
5280
      }
5282
5281
    }
5283
5282
    else
5300
5299
    goto err;
5301
5300
 
5302
5301
  if (table->s->tmp_table)
5303
 
    table->file->info(HA_STATUS_VARIABLE);      // Get record count
 
5302
    table->cursor->info(HA_STATUS_VARIABLE);    // Get record count
5304
5303
  table->sort.found_records=filesort(session, table,join->sortorder, length,
5305
5304
                                     select, filesort_limit, 0,
5306
5305
                                     &examined_rows);
5319
5318
  if (table->key_read)                          // Restore if we used indexes
5320
5319
  {
5321
5320
    table->key_read=0;
5322
 
    table->file->extra(HA_EXTRA_NO_KEYREAD);
 
5321
    table->cursor->extra(HA_EXTRA_NO_KEYREAD);
5323
5322
  }
5324
5323
  return(table->sort.found_records == HA_POS_ERROR);
5325
5324
err:
5328
5327
 
5329
5328
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having)
5330
5329
{
5331
 
  Cursor *file=table->file;
 
5330
  Cursor *cursor=table->cursor;
5332
5331
  char *org_record,*new_record;
5333
5332
  unsigned char *record;
5334
5333
  int error;
5337
5336
  org_record=(char*) (record=table->record[0])+offset;
5338
5337
  new_record=(char*) table->record[1]+offset;
5339
5338
 
5340
 
  file->ha_rnd_init(1);
5341
 
  error=file->rnd_next(record);
 
5339
  cursor->ha_rnd_init(1);
 
5340
  error=cursor->rnd_next(record);
5342
5341
  for (;;)
5343
5342
  {
5344
5343
    if (session->killed)
5357
5356
    }
5358
5357
    if (having && !having->val_int())
5359
5358
    {
5360
 
      if ((error=file->ha_delete_row(record)))
 
5359
      if ((error=cursor->ha_delete_row(record)))
5361
5360
        goto err;
5362
 
      error=file->rnd_next(record);
 
5361
      error=cursor->rnd_next(record);
5363
5362
      continue;
5364
5363
    }
5365
5364
    if (copy_blobs(first_field))
5370
5369
    }
5371
5370
    memcpy(new_record,org_record,reclength);
5372
5371
 
5373
 
    /* Read through rest of file and mark duplicated rows deleted */
 
5372
    /* Read through rest of cursor and mark duplicated rows deleted */
5374
5373
    bool found=0;
5375
5374
    for (;;)
5376
5375
    {
5377
 
      if ((error=file->rnd_next(record)))
 
5376
      if ((error=cursor->rnd_next(record)))
5378
5377
      {
5379
5378
        if (error == HA_ERR_RECORD_DELETED)
5380
5379
          continue;
5384
5383
      }
5385
5384
      if (table->compare_record(first_field) == 0)
5386
5385
      {
5387
 
        if ((error=file->ha_delete_row(record)))
 
5386
        if ((error=cursor->ha_delete_row(record)))
5388
5387
          goto err;
5389
5388
      }
5390
5389
      else if (!found)
5391
5390
      {
5392
5391
        found= 1;
5393
 
        file->position(record); // Remember position
 
5392
        cursor->position(record);       // Remember position
5394
5393
      }
5395
5394
    }
5396
5395
    if (!found)
5397
 
      break;                                    // End of file
 
5396
      break;                                    // End of cursor
5398
5397
    /* Restart search on next row */
5399
 
    error=file->restart_rnd_next(record,file->ref);
 
5398
    error=cursor->restart_rnd_next(record,cursor->ref);
5400
5399
  }
5401
5400
 
5402
 
  file->extra(HA_EXTRA_NO_CACHE);
 
5401
  cursor->extra(HA_EXTRA_NO_CACHE);
5403
5402
  return(0);
5404
5403
err:
5405
 
  file->extra(HA_EXTRA_NO_CACHE);
 
5404
  cursor->extra(HA_EXTRA_NO_CACHE);
5406
5405
  if (error)
5407
 
    file->print_error(error,MYF(0));
 
5406
    cursor->print_error(error,MYF(0));
5408
5407
  return(1);
5409
5408
}
5410
5409
 
5423
5422
{
5424
5423
  unsigned char *key_buffer, *key_pos, *record=table->record[0];
5425
5424
  int error;
5426
 
  Cursor *file= table->file;
 
5425
  Cursor *cursor= table->cursor;
5427
5426
  uint32_t extra_length= ALIGN_SIZE(key_length)-key_length;
5428
5427
  uint32_t *field_lengths,*field_length;
5429
5428
  HASH hash;
5431
5430
  if (! memory::multi_malloc(false,
5432
5431
                       &key_buffer,
5433
5432
                       (uint32_t) ((key_length + extra_length) *
5434
 
                               (long) file->stats.records),
 
5433
                               (long) cursor->stats.records),
5435
5434
                       &field_lengths,
5436
5435
                       (uint32_t) (field_count*sizeof(*field_lengths)),
5437
5436
                       NULL))
5451
5450
    extra_length= ALIGN_SIZE(key_length)-key_length;
5452
5451
  }
5453
5452
 
5454
 
  if (hash_init(&hash, &my_charset_bin, (uint32_t) file->stats.records, 0,
 
5453
  if (hash_init(&hash, &my_charset_bin, (uint32_t) cursor->stats.records, 0,
5455
5454
                key_length, (hash_get_key) 0, 0, 0))
5456
5455
  {
5457
5456
    free((char*) key_buffer);
5458
5457
    return(1);
5459
5458
  }
5460
5459
 
5461
 
  file->ha_rnd_init(1);
 
5460
  cursor->ha_rnd_init(1);
5462
5461
  key_pos=key_buffer;
5463
5462
  for (;;)
5464
5463
  {
5469
5468
      error=0;
5470
5469
      goto err;
5471
5470
    }
5472
 
    if ((error=file->rnd_next(record)))
 
5471
    if ((error=cursor->rnd_next(record)))
5473
5472
    {
5474
5473
      if (error == HA_ERR_RECORD_DELETED)
5475
5474
        continue;
5479
5478
    }
5480
5479
    if (having && !having->val_int())
5481
5480
    {
5482
 
      if ((error=file->ha_delete_row(record)))
 
5481
      if ((error=cursor->ha_delete_row(record)))
5483
5482
        goto err;
5484
5483
      continue;
5485
5484
    }
5496
5495
    if (hash_search(&hash, org_key_pos, key_length))
5497
5496
    {
5498
5497
      /* Duplicated found ; Remove the row */
5499
 
      if ((error=file->ha_delete_row(record)))
 
5498
      if ((error=cursor->ha_delete_row(record)))
5500
5499
        goto err;
5501
5500
    }
5502
5501
    else
5505
5504
  }
5506
5505
  free((char*) key_buffer);
5507
5506
  hash_free(&hash);
5508
 
  file->extra(HA_EXTRA_NO_CACHE);
5509
 
  (void) file->ha_rnd_end();
 
5507
  cursor->extra(HA_EXTRA_NO_CACHE);
 
5508
  (void) cursor->ha_rnd_end();
5510
5509
  return(0);
5511
5510
 
5512
5511
err:
5513
5512
  free((char*) key_buffer);
5514
5513
  hash_free(&hash);
5515
 
  file->extra(HA_EXTRA_NO_CACHE);
5516
 
  (void) file->ha_rnd_end();
 
5514
  cursor->extra(HA_EXTRA_NO_CACHE);
 
5515
  (void) cursor->ha_rnd_end();
5517
5516
  if (error)
5518
 
    file->print_error(error,MYF(0));
 
5517
    cursor->print_error(error,MYF(0));
5519
5518
  return(1);
5520
5519
}
5521
5520
 
6822
6821
          examined_rows= rows2double(tab->select->quick->records);
6823
6822
        else if (tab->type == AM_NEXT || tab->type == AM_ALL)
6824
6823
          examined_rows= rows2double(tab->limit ? tab->limit :
6825
 
                                     tab->table->file->records());
 
6824
                                     tab->table->cursor->records());
6826
6825
        else
6827
6826
        {
6828
6827
          optimizer::Position cur_pos= join->getPosFromOptimalPlan(i);