~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join_tab.h

  • Committer: Brian Aker
  • Date: 2009-06-16 00:53:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: brian@gaz-20090616005322-w0ode4jul9z8s2y9
Partial fix for tests for tmp

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
/**
22
22
 * @file
23
23
 *
24
 
 * Defines the JoinTable class which is the primary class
 
24
 * Defines the JOIN_TAB class which is the primary class
25
25
 * used in the nested loops join implementation.
26
26
 */
27
27
 
28
 
#ifndef DRIZZLED_JOIN_TABLE_H
29
 
#define DRIZZLED_JOIN_TABLE_H
30
 
 
31
 
#include "drizzled/enum_nested_loop_state.h"
32
 
#include "drizzled/table_reference.h"
33
 
#include "drizzled/optimizer/range.h"
34
 
#include "drizzled/join_cache.h"
35
 
#include "drizzled/optimizer/key_use.h"
36
 
 
37
 
#include "drizzled/records.h"
38
 
 
39
 
#include <bitset>
40
 
 
41
 
namespace drizzled
42
 
{
43
 
 
44
 
class Table;
45
 
 
46
 
namespace optimizer
47
 
{
48
 
  class Position;
49
 
}
50
 
/* Values for JoinTable::packed_info */
 
28
#ifndef DRIZZLED_JOIN_TAB_H
 
29
#define DRIZZLED_JOIN_TAB_H
 
30
 
 
31
/* Values for JOIN_TAB::packed_info */
51
32
#define TAB_INFO_HAVE_VALUE 1
52
33
#define TAB_INFO_USING_INDEX 2
53
34
#define TAB_INFO_USING_WHERE 4
54
35
#define TAB_INFO_FULL_SCAN_ON_NULL 8
55
36
 
56
 
/** Description of an access method */
57
 
enum access_method
58
 
59
 
  AM_UNKNOWN,
60
 
  AM_SYSTEM,
61
 
  AM_CONST,
62
 
  AM_EQ_REF,
63
 
  AM_REF,
64
 
  AM_MAYBE_REF,
65
 
        AM_ALL,
66
 
  AM_RANGE,
67
 
  AM_NEXT,
68
 
  AM_REF_OR_NULL,
69
 
  AM_UNIQUE_SUBQUERY,
70
 
  AM_INDEX_SUBQUERY,
71
 
  AM_INDEX_MERGE
72
 
};
73
 
 
74
 
 
75
 
class JoinTable 
 
37
typedef struct st_join_table 
76
38
{
77
 
public:
78
 
  JoinTable() :
79
 
    table(NULL),
80
 
    keyuse(NULL),
81
 
    select(NULL),
82
 
    select_cond(NULL),
83
 
    quick(NULL),
84
 
    pre_idx_push_select_cond(NULL),
85
 
    on_expr_ref(NULL),
86
 
    cond_equal(NULL),
87
 
    first_inner(NULL),
88
 
    found(false),
89
 
    not_null_compl(false),
90
 
    last_inner(NULL),
91
 
    first_upper(NULL),
92
 
    first_unmatched(NULL),
93
 
    packed_info(0),
94
 
    read_first_record(NULL),
95
 
    next_select(NULL),
96
 
    worst_seeks(0.0),
97
 
    const_keys(0),
98
 
    checked_keys(0),
99
 
    needed_reg(0),
100
 
    keys(0),
101
 
    records(0),
102
 
    found_records(0),
103
 
    read_time(0),
104
 
    dependent(0),
105
 
    key_dependent(0),
106
 
    use_quick(0),
107
 
    index(0),
108
 
    status(0),
109
 
    used_fields(0),
110
 
    used_fieldlength(0),
111
 
    used_blobs(0),
112
 
    type(AM_UNKNOWN),
113
 
    cached_eq_ref_table(0),
114
 
    eq_ref_table(0),
115
 
    not_used_in_distinct(0),
116
 
    sorted(0),
117
 
    limit(0),
118
 
    join(NULL),
119
 
    insideout_match_tab(NULL),
120
 
    insideout_buf(NULL),
121
 
    found_match(false),
122
 
    rowid_keep_flags(0),
123
 
    embedding_map(0)
124
 
  {}
 
39
  st_join_table() {} /* Remove gcc warning */
125
40
  Table *table;
126
 
  optimizer::KeyUse *keyuse; /**< pointer to first used key */
127
 
  optimizer::SqlSelect *select;
 
41
  KEYUSE *keyuse; /**< pointer to first used key */
 
42
  SQL_SELECT *select;
128
43
  COND *select_cond;
129
 
  optimizer::QuickSelectInterface *quick;
 
44
  QUICK_SELECT_I *quick;
130
45
  /**
131
46
    The value of select_cond before we've attempted to do Index Condition
132
47
    Pushdown. We may need to restore everything back if we first choose one
137
52
  Item *pre_idx_push_select_cond;
138
53
  Item **on_expr_ref;   /**< pointer to the associated on expression   */
139
54
  COND_EQUAL *cond_equal;    /**< multiple equalities for the on expression */
140
 
  JoinTable *first_inner;   /**< first inner table for including outerjoin */
 
55
  st_join_table *first_inner;   /**< first inner table for including outerjoin */
141
56
  bool found;         /**< true after all matches or null complement */
142
57
  bool not_null_compl;/**< true before null complement is added      */
143
 
  JoinTable *last_inner;    /**< last table table for embedding outer join */
144
 
  JoinTable *first_upper;  /**< first inner table for embedding outer join */
145
 
  JoinTable *first_unmatched; /**< used for optimization purposes only     */
 
58
  st_join_table *last_inner;    /**< last table table for embedding outer join */
 
59
  st_join_table *first_upper;  /**< first inner table for embedding outer join */
 
60
  st_join_table *first_unmatched; /**< used for optimization purposes only     */
146
61
 
147
62
  /* Special content for EXPLAIN 'Extra' column or NULL if none */
148
63
  const char *info;
154
69
 
155
70
  Read_record_func read_first_record;
156
71
  Next_select_func next_select;
157
 
  ReadRecord    read_record;
 
72
  READ_RECORD   read_record;
158
73
  /*
159
74
    Currently the following two fields are used only for a [NOT] IN subquery
160
75
    if it is executed by an alternative full table scan when the left operand of
161
76
    the subquery predicate is evaluated to NULL.
162
77
  */
163
78
  Read_record_func save_read_first_record; /**< to save read_first_record */
164
 
  int (*save_read_record) (ReadRecord *); /**< to save read_record.read_record */
 
79
  int (*save_read_record) (READ_RECORD *); /**< to save read_record.read_record */
165
80
  double worst_seeks;
166
81
  key_map       const_keys; /**< Keys with constant part */
167
82
  key_map       checked_keys; /**< Keys checked in find_best */
190
105
  uint32_t used_fields; /**< Number of used fields in join set */
191
106
  uint32_t used_fieldlength; /**< Not sure... */
192
107
  uint32_t used_blobs; /**< Number of BLOB fields in join set */
193
 
  enum access_method type; /**< Access method. */
 
108
  enum join_type type; /**< Access pattern or join type... */
194
109
  bool cached_eq_ref_table;
195
110
  bool eq_ref_table;
196
111
  bool not_used_in_distinct;
202
117
    this number of rows for the table.
203
118
  */
204
119
  ha_rows limit;
205
 
  table_reference_st    ref;
206
 
  JoinCache cache;
207
 
  Join *join;
 
120
  TABLE_REF     ref;
 
121
  JOIN_CACHE cache;
 
122
  JOIN *join;
 
123
 
 
124
  /**
 
125
    Embedding SJ-nest (may be not the direct parent), or NULL if none.
 
126
    This variable holds the result of table pullout.
 
127
  */
 
128
  TableList *emb_sj_nest;
 
129
 
 
130
  /** Variables for semi-join duplicate elimination */
 
131
  SJ_TMP_TABLE *flush_weedout_table;
 
132
  SJ_TMP_TABLE *check_weed_out_table;
 
133
  struct st_join_table *do_firstmatch;
208
134
 
209
135
  /**
210
136
     ptr  - this join tab should do an InsideOut scan. Points
212
138
 
213
139
     NULL - Not an insideout scan.
214
140
  */
215
 
  JoinTable *insideout_match_tab;
 
141
  struct st_join_table *insideout_match_tab;
216
142
  unsigned char *insideout_buf; /**< Buffer to save index tuple to be able to skip dups */
217
143
 
218
144
  /** Used by InsideOut scan. Just set to true when have found a row. */
234
160
  int rowid_keep_flags;
235
161
 
236
162
  /** Bitmap of nested joins this table is part of */
237
 
  std::bitset<64> embedding_map;
 
163
  nested_join_map embedding_map;
238
164
 
239
165
  void cleanup();
240
 
 
241
166
  inline bool is_using_loose_index_scan()
242
167
  {
243
168
    return (select && select->quick &&
244
169
            (select->quick->get_type() ==
245
 
             optimizer::QuickSelectInterface::QS_TYPE_GROUP_MIN_MAX));
 
170
             QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX));
246
171
  }
247
 
 
248
 
  void readCachedRecord();
249
 
  int joinReadConstTable(optimizer::Position *pos);
250
 
  int joinReadSystem();
251
 
};
252
 
 
253
 
} /* namespace drizzled */
254
 
 
255
 
#endif /* DRIZZLED_JOIN_TABLE_H */
 
172
} JOIN_TAB;
 
173
 
 
174
#endif /* DRIZZLED_JOIN_TAB_H */