~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join_table.h

  • Committer: Monty Taylor
  • Date: 2008-09-16 00:00:48 UTC
  • mto: This revision was merged to the branch mainline in revision 391.
  • Revision ID: monty@inaugust.com-20080916000048-3rvrv3gv9l0ad3gs
Fixed copyright headers in drizzled/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
/**
22
 
 * @file
23
 
 *
24
 
 * Defines the JoinTable class which is the primary class
25
 
 * used in the nested loops join implementation.
26
 
 */
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 */
51
 
#define TAB_INFO_HAVE_VALUE 1
52
 
#define TAB_INFO_USING_INDEX 2
53
 
#define TAB_INFO_USING_WHERE 4
54
 
#define TAB_INFO_FULL_SCAN_ON_NULL 8
55
 
 
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 
76
 
{
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
 
  {}
125
 
  Table *table;
126
 
  optimizer::KeyUse *keyuse; /**< pointer to first used key */
127
 
  optimizer::SqlSelect *select;
128
 
  COND *select_cond;
129
 
  optimizer::QuickSelectInterface *quick;
130
 
  /**
131
 
    The value of select_cond before we've attempted to do Index Condition
132
 
    Pushdown. We may need to restore everything back if we first choose one
133
 
    index but then reconsider (see test_if_skip_sort_order() for such
134
 
    scenarios).
135
 
    NULL means no index condition pushdown was performed.
136
 
  */
137
 
  Item *pre_idx_push_select_cond;
138
 
  Item **on_expr_ref;   /**< pointer to the associated on expression   */
139
 
  COND_EQUAL *cond_equal;    /**< multiple equalities for the on expression */
140
 
  JoinTable *first_inner;   /**< first inner table for including outerjoin */
141
 
  bool found;         /**< true after all matches or null complement */
142
 
  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     */
146
 
 
147
 
  /* Special content for EXPLAIN 'Extra' column or NULL if none */
148
 
  const char *info;
149
 
  /*
150
 
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
151
 
    column, or 0 if there is no info.
152
 
  */
153
 
  uint32_t packed_info;
154
 
 
155
 
  Read_record_func read_first_record;
156
 
  Next_select_func next_select;
157
 
  ReadRecord    read_record;
158
 
  /*
159
 
    Currently the following two fields are used only for a [NOT] IN subquery
160
 
    if it is executed by an alternative full table scan when the left operand of
161
 
    the subquery predicate is evaluated to NULL.
162
 
  */
163
 
  Read_record_func save_read_first_record; /**< to save read_first_record */
164
 
  int (*save_read_record) (ReadRecord *); /**< to save read_record.read_record */
165
 
  double worst_seeks;
166
 
  key_map       const_keys; /**< Keys with constant part */
167
 
  key_map       checked_keys; /**< Keys checked in find_best */
168
 
  key_map       needed_reg;
169
 
  key_map keys; /**< all keys with can be used */
170
 
 
171
 
  /** Either #rows in the table or 1 for const table.  */
172
 
  ha_rows       records;
173
 
  /**
174
 
    Number of records that will be scanned (yes scanned, not returned) by the
175
 
    best 'independent' access method, i.e. table scan or QUICK_*_SELECT)
176
 
  */
177
 
  ha_rows found_records;
178
 
  /**
179
 
    Cost of accessing the table using "ALL" or range/index_merge access
180
 
    method (but not 'index' for some reason), i.e. this matches method which
181
 
    E(#records) is in found_records.
182
 
  */
183
 
  ha_rows read_time;
184
 
 
185
 
  table_map     dependent;
186
 
  table_map key_dependent;
187
 
  uint32_t use_quick;
188
 
  uint32_t index;
189
 
  uint32_t status; /**< Save status for cache */
190
 
  uint32_t used_fields; /**< Number of used fields in join set */
191
 
  uint32_t used_fieldlength; /**< Not sure... */
192
 
  uint32_t used_blobs; /**< Number of BLOB fields in join set */
193
 
  enum access_method type; /**< Access method. */
194
 
  bool cached_eq_ref_table;
195
 
  bool eq_ref_table;
196
 
  bool not_used_in_distinct;
197
 
  /** True if index-based access method must return records in order */
198
 
  bool sorted;
199
 
  /**
200
 
    If it's not 0 the number stored this field indicates that the index
201
 
    scan has been chosen to access the table data and we expect to scan
202
 
    this number of rows for the table.
203
 
  */
204
 
  ha_rows limit;
205
 
  table_reference_st    ref;
206
 
  JoinCache cache;
207
 
  Join *join;
208
 
 
209
 
  /**
210
 
     ptr  - this join tab should do an InsideOut scan. Points
211
 
            to the tab for which we'll need to check tab->found_match.
212
 
 
213
 
     NULL - Not an insideout scan.
214
 
  */
215
 
  JoinTable *insideout_match_tab;
216
 
  unsigned char *insideout_buf; /**< Buffer to save index tuple to be able to skip dups */
217
 
 
218
 
  /** Used by InsideOut scan. Just set to true when have found a row. */
219
 
  bool found_match;
220
 
 
221
 
  enum 
222
 
  {
223
 
    /* If set, the rowid of this table must be put into the temptable. */
224
 
    KEEP_ROWID=1,
225
 
    /*
226
 
      If set, one should call h->position() to obtain the rowid,
227
 
      otherwise, the rowid is assumed to already be in h->ref
228
 
      (this is because join caching and filesort() save the rowid and then
229
 
      put it back into h->ref)
230
 
    */
231
 
    CALL_POSITION=2
232
 
  };
233
 
  /** A set of flags from the above enum */
234
 
  int rowid_keep_flags;
235
 
 
236
 
  /** Bitmap of nested joins this table is part of */
237
 
  std::bitset<64> embedding_map;
238
 
 
239
 
  void cleanup();
240
 
 
241
 
  inline bool is_using_loose_index_scan()
242
 
  {
243
 
    return (select && select->quick &&
244
 
            (select->quick->get_type() ==
245
 
             optimizer::QuickSelectInterface::QS_TYPE_GROUP_MIN_MAX));
246
 
  }
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 */