~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-18 00:22:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: osullivan.padraig@gmail.com-20090918002238-zq7mui4r2yzoidz1
Extracted KeyUse into its own header file and placed it within the
drizzled::optimizer namespace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include "drizzled/field/blob.h"
45
45
#include "drizzled/optimizer/position.h"
46
46
#include "drizzled/optimizer/sargable_param.h"
 
47
#include "drizzled/optimizer/key_use.h"
47
48
#include "mysys/my_bit.h"
48
49
 
49
50
#include <algorithm>
58
59
static uint32_t cache_record_length(JOIN *join, uint32_t index);
59
60
static double prev_record_reads(JOIN *join, uint32_t idx, table_map found_ref);
60
61
static bool get_best_combination(JOIN *join);
61
 
static void set_position(JOIN *join,uint32_t index,JoinTable *table,KeyUse *key);
 
62
static void set_position(JOIN *join,
 
63
                         uint32_t index,
 
64
                         JoinTable *table,
 
65
                         optimizer::KeyUse *key);
62
66
static bool choose_plan(JOIN *join,table_map join_tables);
63
67
static void best_access_path(JOIN *join, JoinTable *s,
64
68
                             Session *session,
3122
3126
  uint32_t i,tablenr;
3123
3127
  table_map used_tables;
3124
3128
  JoinTable *join_tab,*j;
3125
 
  KeyUse *keyuse;
 
3129
  optimizer::KeyUse *keyuse;
3126
3130
  uint32_t table_count;
3127
3131
  Session *session=join->session;
3128
3132
  optimizer::Position cur_pos;
3170
3174
}
3171
3175
 
3172
3176
/** Save const tables first as used tables. */
3173
 
static void set_position(JOIN *join,uint32_t idx,JoinTable *table,KeyUse *key)
 
3177
static void set_position(JOIN *join,
 
3178
                         uint32_t idx,
 
3179
                         JoinTable *table,
 
3180
                         optimizer::KeyUse *key)
3174
3181
{
3175
3182
  optimizer::Position tmp_pos(1.0, /* This is a const table */
3176
3183
                              0.0,
3284
3291
                             double record_count,
3285
3292
                             double)
3286
3293
{
3287
 
  KeyUse *best_key=         0;
 
3294
  optimizer::KeyUse *best_key=         0;
3288
3295
  uint32_t best_max_key_part=   0;
3289
3296
  bool found_constraint= 0;
3290
3297
  double best=              DBL_MAX;
3297
3304
  if (s->keyuse)
3298
3305
  {                                            /* Use key if possible */
3299
3306
    Table *table= s->table;
3300
 
    KeyUse *keyuse,*start_key=0;
 
3307
    optimizer::KeyUse *keyuse,*start_key=0;
3301
3308
    double best_records= DBL_MAX;
3302
3309
    uint32_t max_key_part=0;
3303
3310
 
5517
5524
  key_map const_ref, eq_part;
5518
5525
  Table **table_vector;
5519
5526
  JoinTable *stat,*stat_end,*s,**stat_ref;
5520
 
  KeyUse *keyuse,*start_keyuse;
 
5527
  optimizer::KeyUse *keyuse,*start_keyuse;
5521
5528
  table_map outer_join=0;
5522
5529
  vector<optimizer::SargableParam> sargables;
5523
5530
  JoinTable *stat_vector[MAX_TABLES+1];
5576
5583
      if (!table->file->stats.records && !embedding)
5577
5584
      {                                         // Empty table
5578
5585
        s->dependent= 0;                        // Ignore LEFT JOIN depend.
5579
 
        set_position(join,const_count++,s,(KeyUse*) 0);
 
5586
        set_position(join,const_count++,s,(optimizer::KeyUse*) 0);
5580
5587
        continue;
5581
5588
      }
5582
5589
      outer_join|= table->map;
5604
5611
              (table->file->ha_table_flags() & HA_STATS_RECORDS_IS_EXACT) && 
5605
5612
        !join->no_const_tables)
5606
5613
    {
5607
 
      set_position(join,const_count++,s,(KeyUse*) 0);
 
5614
      set_position(join,const_count++,s,(optimizer::KeyUse*) 0);
5608
5615
    }
5609
5616
  }
5610
5617
  stat_vector[i]=0;
5714
5721
            table->mark_as_null_row();
5715
5722
            found_const_table_map|= table->map;
5716
5723
            join->const_table_map|= table->map;
5717
 
            set_position(join,const_count++,s,(KeyUse*) 0);
 
5724
            set_position(join,const_count++,s,(optimizer::KeyUse*) 0);
5718
5725
            goto more_const_tables_found;
5719
5726
           }
5720
5727
          keyuse++;
5733
5740
          int tmp= 0;
5734
5741
          s->type= AM_SYSTEM;
5735
5742
          join->const_table_map|=table->map;
5736
 
          set_position(join,const_count++,s,(KeyUse*) 0);
 
5743
          set_position(join,const_count++,s,(optimizer::KeyUse*) 0);
5737
5744
          partial_pos= join->getSpecificPosInPartialPlan(const_count - 1);
5738
5745
          if ((tmp= join_read_const_table(s, partial_pos)))
5739
5746
          {
5879
5886
          caller to abort with a zero row result.
5880
5887
        */
5881
5888
        join->const_table_map|= s->table->map;
5882
 
        set_position(join,const_count++,s,(KeyUse*) 0);
 
5889
        set_position(join,const_count++,s,(optimizer::KeyUse*) 0);
5883
5890
        s->type= AM_CONST;
5884
5891
        if (*s->on_expr_ref)
5885
5892
        {