~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-08-10 23:35:59 UTC
  • mto: (1115.3.10 captain)
  • mto: This revision was merged to the branch mainline in revision 1120.
  • Revision ID: osullivan.padraig@gmail.com-20090810233559-2ax654ye148d7fst
Added an optimizer namespace and sub-directory within drizzled. Moved the
Position class into its own header file within this sub-dir and declared the
Position class within the drizzled::optimizer namespace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "drizzled/join_cache.h"
43
43
#include "drizzled/show.h"
44
44
#include "drizzled/field/blob.h"
 
45
#include "drizzled/optimizer/position.h"
45
46
#include "mysys/my_bit.h"
46
47
 
47
48
#include <algorithm>
48
49
 
49
50
using namespace std;
 
51
using namespace drizzled;
50
52
 
51
53
/** Declarations of static functions used in this source file. */
52
54
static bool make_group_fields(JOIN *main_join, JOIN *curr_join);
3081
3083
static double prev_record_reads(JOIN *join, uint32_t idx, table_map found_ref)
3082
3084
{
3083
3085
  double found=1.0;
3084
 
  Position *pos_end= join->getSpecificPosInPartialPlan(-1);
3085
 
  for (Position *pos= join->getSpecificPosInPartialPlan(idx - 1); 
 
3086
  optimizer::Position *pos_end= join->getSpecificPosInPartialPlan(-1);
 
3087
  for (optimizer::Position *pos= join->getSpecificPosInPartialPlan(idx - 1); 
3086
3088
       pos != pos_end; 
3087
3089
       pos--)
3088
3090
  {
3123
3125
  KeyUse *keyuse;
3124
3126
  uint32_t table_count;
3125
3127
  Session *session=join->session;
3126
 
  Position cur_pos;
 
3128
  optimizer::Position cur_pos;
3127
3129
 
3128
3130
  table_count=join->tables;
3129
3131
  if (!(join->join_tab=join_tab=
3170
3172
/** Save const tables first as used tables. */
3171
3173
static void set_position(JOIN *join,uint32_t idx,JoinTable *table,KeyUse *key)
3172
3174
{
3173
 
  Position tmp_pos(1.0, /* This is a const table */
3174
 
                   0.0,
3175
 
                   table,
3176
 
                   key,
3177
 
                   0);
 
3175
  optimizer::Position tmp_pos(1.0, /* This is a const table */
 
3176
                              0.0,
 
3177
                              table,
 
3178
                              key,
 
3179
                              0);
3178
3180
  join->setPosInPartialPlan(idx, tmp_pos);
3179
3181
 
3180
3182
  /* Move the const table as down as possible in best_ref */
3765
3767
  }
3766
3768
 
3767
3769
  /* Update the cost information for the current partial plan */
3768
 
  Position tmp_pos(records,
3769
 
                   best,
3770
 
                   s,
3771
 
                   best_key,
3772
 
                   best_ref_depends_map);
 
3770
  optimizer::Position tmp_pos(records,
 
3771
                              best,
 
3772
                              s,
 
3773
                              best_key,
 
3774
                              best_ref_depends_map);
3773
3775
  join->setPosInPartialPlan(idx, tmp_pos);
3774
3776
 
3775
3777
  if (!best_key &&
3806
3808
static void optimize_straight_join(JOIN *join, table_map join_tables)
3807
3809
{
3808
3810
  JoinTable *s;
3809
 
  Position partial_pos;
 
3811
  optimizer::Position partial_pos;
3810
3812
  uint32_t idx= join->const_tables;
3811
3813
  double    record_count= 1.0;
3812
3814
  double    read_time=    0.0;
3923
3925
  uint32_t      idx= join->const_tables; // index into 'join->best_ref'
3924
3926
  uint32_t      best_idx;
3925
3927
  uint32_t      size_remain;    // cardinality of remaining_tables
3926
 
  Position best_pos;
 
3928
  optimizer::Position best_pos;
3927
3929
  JoinTable  *best_table; // the next plan node to be added to the curr QEP
3928
3930
 
3929
3931
  /* number of tables that remain to be optimized */
3965
3967
    std::swap(join->best_ref[idx], join->best_ref[best_idx]);
3966
3968
 
3967
3969
    /* compute the cost of the new plan extended with 'best_table' */
3968
 
    Position partial_pos= join->getPosFromPartialPlan(idx);
 
3970
    optimizer::Position partial_pos= join->getPosFromPartialPlan(idx);
3969
3971
    record_count*= partial_pos.getFanout();
3970
3972
    read_time+=    partial_pos.getCost();
3971
3973
 
4111
4113
  JoinTable *s;
4112
4114
  double best_record_count= DBL_MAX;
4113
4115
  double best_read_time=    DBL_MAX;
4114
 
  Position partial_pos;
 
4116
  optimizer::Position partial_pos;
4115
4117
 
4116
4118
  for (JoinTable **pos= join->best_ref + idx ; (s= *pos) ; pos++)
4117
4119
  {
4420
4422
static bool make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
4421
4423
{
4422
4424
  Session *session= join->session;
4423
 
  Position cur_pos;
 
4425
  optimizer::Position cur_pos;
4424
4426
  if (select)
4425
4427
  {
4426
4428
    add_not_null_conds(join);
5519
5521
  table_map outer_join=0;
5520
5522
  SARGABLE_PARAM *sargables= 0;
5521
5523
  JoinTable *stat_vector[MAX_TABLES+1];
5522
 
  Position *partial_pos;
 
5524
  optimizer::Position *partial_pos;
5523
5525
 
5524
5526
  table_count=join->tables;
5525
5527
  stat=(JoinTable*) join->session->calloc(sizeof(JoinTable)*table_count);
5651
5653
  /* Read tables with 0 or 1 rows (system tables) */
5652
5654
  join->const_table_map= 0;
5653
5655
 
5654
 
  Position *p_pos= join->getFirstPosInPartialPlan();
5655
 
  Position *p_end= join->getSpecificPosInPartialPlan(const_count);
 
5656
  optimizer::Position *p_pos= join->getFirstPosInPartialPlan();
 
5657
  optimizer::Position *p_end= join->getSpecificPosInPartialPlan(const_count);
5656
5658
  while (p_pos < p_end)
5657
5659
  {
5658
5660
    int tmp;