~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

Fixed bashism.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1109
1109
 
1110
1110
  if (exec_tmp_table1)
1111
1111
  {
1112
 
    exec_tmp_table1->cursor->extra(HA_EXTRA_RESET_STATE);
1113
 
    exec_tmp_table1->cursor->ha_delete_all_rows();
 
1112
    exec_tmp_table1->file->extra(HA_EXTRA_RESET_STATE);
 
1113
    exec_tmp_table1->file->ha_delete_all_rows();
1114
1114
    exec_tmp_table1->free_io_cache();
1115
1115
    exec_tmp_table1->filesort_free_buffers();
1116
1116
  }
1117
1117
  if (exec_tmp_table2)
1118
1118
  {
1119
 
    exec_tmp_table2->cursor->extra(HA_EXTRA_RESET_STATE);
1120
 
    exec_tmp_table2->cursor->ha_delete_all_rows();
 
1119
    exec_tmp_table2->file->extra(HA_EXTRA_RESET_STATE);
 
1120
    exec_tmp_table2->file->ha_delete_all_rows();
1121
1121
    exec_tmp_table2->free_io_cache();
1122
1122
    exec_tmp_table2->filesort_free_buffers();
1123
1123
  }
1309
1309
      error= tmp_error;
1310
1310
      return;
1311
1311
    }
1312
 
    curr_tmp_table->cursor->info(HA_STATUS_VARIABLE);
 
1312
    curr_tmp_table->file->info(HA_STATUS_VARIABLE);
1313
1313
 
1314
1314
    if (curr_join->having)
1315
1315
      curr_join->having= curr_join->tmp_having= 0; // Allready done
1874
1874
      for (tab= join_tab, end= tab+tables; tab != end; tab++)
1875
1875
      {
1876
1876
        if (tab->table)
1877
 
          tab->table->cursor->ha_index_or_rnd_end();
 
1877
          tab->table->file->ha_index_or_rnd_end();
1878
1878
      }
1879
1879
    }
1880
1880
  }
2327
2327
          item->save_in_result_field(1);
2328
2328
      }
2329
2329
      copy_sum_funcs(sum_funcs_end[i+1], sum_funcs_end[i]);
2330
 
      if ((write_error= table_arg->cursor->ha_write_row(table_arg->record[0])))
 
2330
      if ((write_error= table_arg->file->ha_write_row(table_arg->record[0])))
2331
2331
      {
2332
2332
  if (create_myisam_from_heap(session, table_arg,
2333
2333
                                    tmp_table_param.start_recinfo,
2493
2493
        return NESTED_LOOP_NO_MORE_ROWS;
2494
2494
    }
2495
2495
    else
2496
 
      join_tab->read_record.cursor->unlock_row();
 
2496
      join_tab->read_record.file->unlock_row();
2497
2497
  }
2498
2498
  else
2499
2499
  {
2503
2503
    */
2504
2504
    join->examined_rows++;
2505
2505
    join->session->row_count++;
2506
 
    join_tab->read_record.cursor->unlock_row();
 
2506
    join_tab->read_record.file->unlock_row();
2507
2507
  }
2508
2508
  return NESTED_LOOP_OK;
2509
2509
}
2691
2691
        if ((join->tables == 1) && !join->tmp_table && !join->sort_and_group
2692
2692
            && !join->send_group_parts && !join->having && !jt->select_cond &&
2693
2693
            !(jt->select && jt->select->quick) &&
2694
 
            (jt->table->cursor->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) &&
 
2694
            (jt->table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) &&
2695
2695
                  (jt->ref.key < 0))
2696
2696
        {
2697
2697
          /* Join over all rows in table;  Return number of found rows */
2706
2706
          }
2707
2707
          else
2708
2708
          {
2709
 
            table->cursor->info(HA_STATUS_VARIABLE);
2710
 
            join->send_records= table->cursor->stats.records;
 
2709
            table->file->info(HA_STATUS_VARIABLE);
 
2710
            join->send_records= table->file->stats.records;
2711
2711
          }
2712
2712
        }
2713
2713
        else
2750
2750
    {
2751
2751
      int error;
2752
2752
      join->found_records++;
2753
 
      if ((error=table->cursor->ha_write_row(table->record[0])))
 
2753
      if ((error=table->file->ha_write_row(table->record[0])))
2754
2754
      {
2755
 
        if (!table->cursor->is_fatal_error(error, HA_CHECK_DUP))
 
2755
        if (!table->file->is_fatal_error(error, HA_CHECK_DUP))
2756
2756
          goto end;
2757
2757
        if (create_myisam_from_heap(join->session, table,
2758
2758
                                          join->tmp_table_param.start_recinfo,
2801
2801
    if (item->maybe_null)
2802
2802
      group->buff[-1]= (char) group->field->is_null();
2803
2803
  }
2804
 
  if (!table->cursor->index_read_map(table->record[1],
 
2804
  if (!table->file->index_read_map(table->record[1],
2805
2805
                                   join->tmp_table_param.group_buff,
2806
2806
                                   HA_WHOLE_KEY,
2807
2807
                                   HA_READ_KEY_EXACT))
2808
2808
  {                                             /* Update old record */
2809
2809
    table->restoreRecord();
2810
2810
    update_tmptable_sum_func(join->sum_funcs,table);
2811
 
    if ((error= table->cursor->ha_update_row(table->record[1],
 
2811
    if ((error= table->file->ha_update_row(table->record[1],
2812
2812
                                          table->record[0])))
2813
2813
    {
2814
 
      table->cursor->print_error(error,MYF(0));
 
2814
      table->file->print_error(error,MYF(0));
2815
2815
      return NESTED_LOOP_ERROR;
2816
2816
    }
2817
2817
    return NESTED_LOOP_OK;
2832
2832
  }
2833
2833
  init_tmptable_sum_functions(join->sum_funcs);
2834
2834
  copy_funcs(join->tmp_table_param.items_to_copy);
2835
 
  if ((error=table->cursor->ha_write_row(table->record[0])))
 
2835
  if ((error=table->file->ha_write_row(table->record[0])))
2836
2836
  {
2837
2837
    if (create_myisam_from_heap(join->session, table,
2838
2838
                                join->tmp_table_param.start_recinfo,
2840
2840
                                error, 0))
2841
2841
      return NESTED_LOOP_ERROR;            // Not a table_is_full error
2842
2842
    /* Change method to update rows */
2843
 
    table->cursor->ha_index_init(0, 0);
 
2843
    table->file->ha_index_init(0, 0);
2844
2844
    join->join_tab[join->tables-1].next_select= end_unique_update;
2845
2845
  }
2846
2846
  join->send_records++;
2865
2865
  copy_fields(&join->tmp_table_param);          // Groups are copied twice.
2866
2866
  copy_funcs(join->tmp_table_param.items_to_copy);
2867
2867
 
2868
 
  if (!(error= table->cursor->ha_write_row(table->record[0])))
 
2868
  if (!(error= table->file->ha_write_row(table->record[0])))
2869
2869
    join->send_records++;                       // New group
2870
2870
  else
2871
2871
  {
2872
 
    if ((int) table->cursor->get_dup_key(error) < 0)
 
2872
    if ((int) table->file->get_dup_key(error) < 0)
2873
2873
    {
2874
 
      table->cursor->print_error(error,MYF(0));
 
2874
      table->file->print_error(error,MYF(0));
2875
2875
      return NESTED_LOOP_ERROR;
2876
2876
    }
2877
 
    if (table->cursor->rnd_pos(table->record[1],table->cursor->dup_ref))
 
2877
    if (table->file->rnd_pos(table->record[1],table->file->dup_ref))
2878
2878
    {
2879
 
      table->cursor->print_error(error,MYF(0));
 
2879
      table->file->print_error(error,MYF(0));
2880
2880
      return NESTED_LOOP_ERROR;
2881
2881
    }
2882
2882
    table->restoreRecord();
2883
2883
    update_tmptable_sum_func(join->sum_funcs,table);
2884
 
    if ((error= table->cursor->ha_update_row(table->record[1],
 
2884
    if ((error= table->file->ha_update_row(table->record[1],
2885
2885
                                          table->record[0])))
2886
2886
    {
2887
 
      table->cursor->print_error(error,MYF(0));
 
2887
      table->file->print_error(error,MYF(0));
2888
2888
      return NESTED_LOOP_ERROR;
2889
2889
    }
2890
2890
  }
3458
3458
            if (table->covering_keys.test(key))
3459
3459
            {
3460
3460
              /* we can use only index tree */
3461
 
              tmp= record_count * table->cursor->index_only_read_time(key, tmp);
 
3461
              tmp= record_count * table->file->index_only_read_time(key, tmp);
3462
3462
            }
3463
3463
            else
3464
3464
              tmp= record_count * min(tmp,s->worst_seeks);
3472
3472
            Set tmp to (previous record count) * (records / combination)
3473
3473
          */
3474
3474
          if ((found_part & 1) &&
3475
 
              (!(table->cursor->index_flags(key, 0, 0) & HA_ONLY_WHOLE_INDEX) ||
 
3475
              (!(table->file->index_flags(key, 0, 0) & HA_ONLY_WHOLE_INDEX) ||
3476
3476
               found_part == PREV_BITS(uint,keyinfo->key_parts)))
3477
3477
          {
3478
3478
            max_key_part= max_part_bit(found_part);
3552
3552
              else
3553
3553
              {
3554
3554
                /*
3555
 
                  Assume that the first key part matches 1% of the cursor
 
3555
                  Assume that the first key part matches 1% of the file
3556
3556
                  and that the whole key matches 10 (duplicates) or 1
3557
3557
                  (unique) records.
3558
3558
                  Assume also that more key matches proportionally more
3623
3623
            if (table->covering_keys.test(key))
3624
3624
            {
3625
3625
              /* we can use only index tree */
3626
 
              tmp= record_count * table->cursor->index_only_read_time(key, tmp);
 
3626
              tmp= record_count * table->file->index_only_read_time(key, tmp);
3627
3627
            }
3628
3628
            else
3629
3629
              tmp= record_count * min(tmp,s->worst_seeks);
3677
3677
  if ((records >= s->found_records || best > s->read_time) &&            // (1)
3678
3678
      ! (s->quick && best_key && s->quick->index == best_key->getKey() &&      // (2)
3679
3679
        best_max_key_part >= s->table->quick_key_parts[best_key->getKey()]) &&// (2)
3680
 
      ! ((s->table->cursor->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX) &&   // (3)
 
3680
      ! ((s->table->file->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX) &&   // (3)
3681
3681
        ! s->table->covering_keys.none() && best_key && !s->quick) && // (3)
3682
3682
      ! (s->table->force_index && best_key && !s->quick))                 // (4)
3683
3683
  {                                             // Check full join
3724
3724
    else
3725
3725
    {
3726
3726
      /* Estimate cost of reading table. */
3727
 
      tmp= s->table->cursor->scan_time();
 
3727
      tmp= s->table->file->scan_time();
3728
3728
      if (s->table->map & join->outer_join)     // Can't use join cache
3729
3729
      {
3730
3730
        /*
4815
4815
    Table *table=tab->table;
4816
4816
    bool using_join_cache;
4817
4817
    tab->read_record.table= table;
4818
 
    tab->read_record.cursor= table->cursor;
 
4818
    tab->read_record.file=table->file;
4819
4819
    tab->next_select=sub_select;                /* normal select */
4820
4820
    /*
4821
4821
      TODO: don't always instruct first table's ref/range access method to
4844
4844
          !table->no_keyread)
4845
4845
      {
4846
4846
        table->key_read=1;
4847
 
        table->cursor->extra(HA_EXTRA_KEYREAD);
 
4847
        table->file->extra(HA_EXTRA_KEYREAD);
4848
4848
      }
4849
4849
      break;
4850
4850
    case AM_EQ_REF:
4861
4861
      if (table->covering_keys.test(tab->ref.key) && !table->no_keyread)
4862
4862
      {
4863
4863
        table->key_read=1;
4864
 
        table->cursor->extra(HA_EXTRA_KEYREAD);
 
4864
        table->file->extra(HA_EXTRA_KEYREAD);
4865
4865
      }
4866
4866
      break;
4867
4867
    case AM_REF_OR_NULL:
4877
4877
      if (table->covering_keys.test(tab->ref.key) && !table->no_keyread)
4878
4878
      {
4879
4879
        table->key_read=1;
4880
 
        table->cursor->extra(HA_EXTRA_KEYREAD);
 
4880
        table->file->extra(HA_EXTRA_KEYREAD);
4881
4881
      }
4882
4882
      if (tab->type == AM_REF)
4883
4883
      {
4956
4956
              table->covering_keys.test(tab->select->quick->index))
4957
4957
          {
4958
4958
            table->key_read=1;
4959
 
            table->cursor->extra(HA_EXTRA_KEYREAD);
 
4959
            table->file->extra(HA_EXTRA_KEYREAD);
4960
4960
          }
4961
4961
          else if (!table->covering_keys.none() &&
4962
4962
            !(tab->select && tab->select->quick))
4968
4968
                      is always faster than using a secondary index".
4969
4969
                    */
4970
4970
                    if (table->s->primary_key != MAX_KEY &&
4971
 
                        table->cursor->primary_key_is_clustered())
 
4971
                        table->file->primary_key_is_clustered())
4972
4972
                      tab->index= table->s->primary_key;
4973
4973
                    else
4974
4974
                      tab->index= table->find_shortest_key(&table->covering_keys);
5462
5462
  reclength= entry->s->reclength-offset;
5463
5463
 
5464
5464
  entry->free_io_cache();                               // Safety
5465
 
  entry->cursor->info(HA_STATUS_VARIABLE);
 
5465
  entry->file->info(HA_STATUS_VARIABLE);
5466
5466
  if (entry->s->db_type() == heap_engine ||
5467
5467
      (!entry->s->blob_fields &&
5468
 
       ((ALIGN_SIZE(reclength) + HASH_OVERHEAD) * entry->cursor->stats.records <
 
5468
       ((ALIGN_SIZE(reclength) + HASH_OVERHEAD) * entry->file->stats.records <
5469
5469
        session->variables.sortbuff_size)))
5470
5470
    error= remove_dup_with_hash_index(join->session, entry,
5471
5471
                                     field_count, first_field,
5567
5567
    s->needed_reg.reset();
5568
5568
    table_vector[i]=s->table=table=tables->table;
5569
5569
    table->pos_in_table_list= tables;
5570
 
    error= table->cursor->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
 
5570
    error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
5571
5571
    if (error)
5572
5572
    {
5573
 
        table->cursor->print_error(error, MYF(0));
 
5573
        table->file->print_error(error, MYF(0));
5574
5574
        return 1;
5575
5575
    }
5576
5576
    table->quick_keys.reset();
5585
5585
    s->dependent= tables->dep_tables;
5586
5586
    s->key_dependent= 0;
5587
5587
    if (tables->schema_table)
5588
 
      table->cursor->stats.records= 2;
5589
 
    table->quick_condition_rows= table->cursor->stats.records;
 
5588
      table->file->stats.records= 2;
 
5589
    table->quick_condition_rows= table->file->stats.records;
5590
5590
 
5591
5591
    s->on_expr_ref= &tables->on_expr;
5592
5592
    if (*s->on_expr_ref)
5593
5593
    {
5594
5594
      /* s is the only inner table of an outer join */
5595
 
      if (!table->cursor->stats.records && !embedding)
 
5595
      if (!table->file->stats.records && !embedding)
5596
5596
      {                                         // Empty table
5597
5597
        s->dependent= 0;                        // Ignore LEFT JOIN depend.
5598
5598
        set_position(join, const_count++, s, (optimizer::KeyUse*) 0);
5619
5619
      while (embedding);
5620
5620
      continue;
5621
5621
    }
5622
 
    if ((table->cursor->stats.records <= 1) && !s->dependent &&
5623
 
              (table->cursor->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) && 
 
5622
    if ((table->file->stats.records <= 1) && !s->dependent &&
 
5623
              (table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) && 
5624
5624
        !join->no_const_tables)
5625
5625
    {
5626
5626
      set_position(join, const_count++, s, (optimizer::KeyUse*) 0);
5745
5745
        // All dep. must be constants
5746
5746
        if (s->dependent & ~(found_const_table_map))
5747
5747
          continue;
5748
 
        if (table->cursor->stats.records <= 1L &&
5749
 
            (table->cursor->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) &&
 
5748
        if (table->file->stats.records <= 1L &&
 
5749
            (table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) &&
5750
5750
                  !table->pos_in_table_list->embedding)
5751
5751
        {                                       // system table
5752
5752
          int tmp= 0;
5859
5859
      continue;
5860
5860
    }
5861
5861
    /* Approximate found rows and time to read them */
5862
 
    s->found_records=s->records=s->table->cursor->stats.records;
5863
 
    s->read_time=(ha_rows) s->table->cursor->scan_time();
 
5862
    s->found_records=s->records=s->table->file->stats.records;
 
5863
    s->read_time=(ha_rows) s->table->file->scan_time();
5864
5864
 
5865
5865
    /*
5866
5866
      Set a max range of how many seeks we can expect when using keys