~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: brian
  • Date: 2009-11-11 19:42:27 UTC
  • mfrom: (1211 staging)
  • mto: (1211.1.4 staging)
  • mto: This revision was merged to the branch mainline in revision 1212.
  • Revision ID: brian@orisndriz04-20091111194227-mky4am3ym0dlosaa
Update for Cursor renaming.

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