~drizzle-trunk/drizzle/development

1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
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
 *
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
24
 * Defines the JoinTable class which is the primary class
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
25
 * used in the nested loops join implementation.
26
 */
27
1122.2.10 by Monty Taylor
Fixed all of the include guards.
28
#ifndef DRIZZLED_JOIN_TABLE_H
29
#define DRIZZLED_JOIN_TABLE_H
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
30
1237.9.2 by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to
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"
1108.6.56 by Padraig O'Sullivan
Extracted KeyUse into its own header file and placed it within the
35
#include "drizzled/optimizer/key_use.h"
1089.1.8 by Brian Aker
Shuffled around a few structures.
36
1538 by Brian Aker
Code shuffle on ReadRecord
37
#include "drizzled/records.h"
38
1100.4.2 by Padraig O'Sullivan
Removed the typedef for nested_join_map and instead just declare these
39
#include <bitset>
40
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
41
namespace drizzled
42
{
43
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
44
/* Values for JoinTable::packed_info */
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
45
#define TAB_INFO_HAVE_VALUE 1
46
#define TAB_INFO_USING_INDEX 2
47
#define TAB_INFO_USING_WHERE 4
48
#define TAB_INFO_FULL_SCAN_ON_NULL 8
49
1089.1.13 by Brian Aker
Sorting methods into class files.
50
class Table;
51
1089.1.8 by Brian Aker
Shuffled around a few structures.
52
1108.6.20 by Padraig O'Sullivan
Renamed access_type to access_method due to conflicts on Solaris.
53
/** Description of an access method */
54
enum access_method
1089.1.8 by Brian Aker
Shuffled around a few structures.
55
{ 
1108.6.20 by Padraig O'Sullivan
Renamed access_type to access_method due to conflicts on Solaris.
56
  AM_UNKNOWN,
57
  AM_SYSTEM,
58
  AM_CONST,
59
  AM_EQ_REF,
60
  AM_REF,
61
  AM_MAYBE_REF,
62
	AM_ALL,
63
  AM_RANGE,
64
  AM_NEXT,
65
  AM_REF_OR_NULL,
66
  AM_UNIQUE_SUBQUERY,
67
  AM_INDEX_SUBQUERY,
68
  AM_INDEX_MERGE
1089.1.8 by Brian Aker
Shuffled around a few structures.
69
};
70
71
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
72
class JoinTable 
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
73
{
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
74
public:
1221.1.1 by Jay Pipes
Fixes some valgrind warnings regarding conditionals depending on unintialized variables. Use initializer lists properly, dang it. :) Also, removed the new_Cached_item() function's use_result_field, as this was only used for views and was producing a valgrind warning unnecessarily.
75
  JoinTable() :
76
    table(NULL),
77
    keyuse(NULL),
78
    select(NULL),
79
    select_cond(NULL),
80
    quick(NULL),
81
    pre_idx_push_select_cond(NULL),
82
    on_expr_ref(NULL),
83
    cond_equal(NULL),
84
    first_inner(NULL),
85
    found(false),
86
    not_null_compl(false),
87
    last_inner(NULL),
88
    first_upper(NULL),
89
    first_unmatched(NULL),
90
    packed_info(0),
91
    read_first_record(NULL),
92
    next_select(NULL),
93
    worst_seeks(0.0),
94
    const_keys(0),
95
    checked_keys(0),
96
    needed_reg(0),
97
    keys(0),
98
    records(0),
99
    found_records(0),
100
    read_time(0),
101
    dependent(0),
102
    key_dependent(0),
103
    use_quick(0),
104
    index(0),
105
    status(0),
106
    used_fields(0),
107
    used_fieldlength(0),
108
    used_blobs(0),
109
    type(AM_UNKNOWN),
110
    cached_eq_ref_table(0),
111
    eq_ref_table(0),
112
    not_used_in_distinct(0),
113
    sorted(0),
114
    limit(0),
115
    join(NULL),
116
    insideout_match_tab(NULL),
117
    insideout_buf(NULL),
118
    found_match(false),
119
    rowid_keep_flags(0),
120
    embedding_map(0)
121
  {}
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
122
  Table *table;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
123
  optimizer::KeyUse *keyuse; /**< pointer to first used key */
124
  optimizer::SqlSelect *select;
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
125
  COND *select_cond;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
126
  optimizer::QuickSelectInterface *quick;
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
127
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
128
    The value of select_cond before we've attempted to do Index Condition
129
    Pushdown. We may need to restore everything back if we first choose one
130
    index but then reconsider (see test_if_skip_sort_order() for such
131
    scenarios).
132
    NULL means no index condition pushdown was performed.
133
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
134
  Item *pre_idx_push_select_cond;
135
  Item **on_expr_ref;   /**< pointer to the associated on expression   */
136
  COND_EQUAL *cond_equal;    /**< multiple equalities for the on expression */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
137
  JoinTable *first_inner;   /**< first inner table for including outerjoin */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
138
  bool found;         /**< true after all matches or null complement */
139
  bool not_null_compl;/**< true before null complement is added      */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
140
  JoinTable *last_inner;    /**< last table table for embedding outer join */
141
  JoinTable *first_upper;  /**< first inner table for embedding outer join */
142
  JoinTable *first_unmatched; /**< used for optimization purposes only     */
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
143
144
  /* Special content for EXPLAIN 'Extra' column or NULL if none */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
145
  const char *info;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
146
  /*
147
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
148
    column, or 0 if there is no info.
149
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
150
  uint32_t packed_info;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
151
152
  Read_record_func read_first_record;
153
  Next_select_func next_select;
1538 by Brian Aker
Code shuffle on ReadRecord
154
  ReadRecord	read_record;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
155
  /*
156
    Currently the following two fields are used only for a [NOT] IN subquery
157
    if it is executed by an alternative full table scan when the left operand of
158
    the subquery predicate is evaluated to NULL.
159
  */
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
160
  Read_record_func save_read_first_record; /**< to save read_first_record */
1538 by Brian Aker
Code shuffle on ReadRecord
161
  int (*save_read_record) (ReadRecord *); /**< to save read_record.read_record */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
162
  double worst_seeks;
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
163
  key_map	const_keys; /**< Keys with constant part */
164
  key_map	checked_keys; /**< Keys checked in find_best */
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
165
  key_map	needed_reg;
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
166
  key_map keys; /**< all keys with can be used */
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
167
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
168
  /** Either #rows in the table or 1 for const table.  */
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
169
  ha_rows	records;
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
170
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
171
    Number of records that will be scanned (yes scanned, not returned) by the
172
    best 'independent' access method, i.e. table scan or QUICK_*_SELECT)
173
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
174
  ha_rows found_records;
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
175
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
176
    Cost of accessing the table using "ALL" or range/index_merge access
177
    method (but not 'index' for some reason), i.e. this matches method which
178
    E(#records) is in found_records.
179
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
180
  ha_rows read_time;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
181
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
182
  table_map	dependent;
183
  table_map key_dependent;
184
  uint32_t use_quick;
185
  uint32_t index;
186
  uint32_t status; /**< Save status for cache */
187
  uint32_t used_fields; /**< Number of used fields in join set */
188
  uint32_t used_fieldlength; /**< Not sure... */
189
  uint32_t used_blobs; /**< Number of BLOB fields in join set */
1108.6.20 by Padraig O'Sullivan
Renamed access_type to access_method due to conflicts on Solaris.
190
  enum access_method type; /**< Access method. */
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
191
  bool cached_eq_ref_table;
192
  bool eq_ref_table;
193
  bool not_used_in_distinct;
194
  /** True if index-based access method must return records in order */
195
  bool sorted;
196
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
197
    If it's not 0 the number stored this field indicates that the index
198
    scan has been chosen to access the table data and we expect to scan
199
    this number of rows for the table.
200
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
201
  ha_rows limit;
1089.1.14 by Brian Aker
Fix TABLE_REF structure
202
  table_reference_st	ref;
1539.1.6 by Brian Aker
Update for Join structure changes.
203
  JoinCache cache;
1541.1.1 by Brian Aker
JOIN -> Join rename
204
  Join *join;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
205
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
206
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
207
     ptr  - this join tab should do an InsideOut scan. Points
208
            to the tab for which we'll need to check tab->found_match.
209
210
     NULL - Not an insideout scan.
211
  */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
212
  JoinTable *insideout_match_tab;
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
213
  unsigned char *insideout_buf; /**< Buffer to save index tuple to be able to skip dups */
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
214
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
215
  /** Used by InsideOut scan. Just set to true when have found a row. */
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
216
  bool found_match;
217
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
218
  enum 
219
  {
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
220
    /* If set, the rowid of this table must be put into the temptable. */
221
    KEEP_ROWID=1,
222
    /*
223
      If set, one should call h->position() to obtain the rowid,
224
      otherwise, the rowid is assumed to already be in h->ref
225
      (this is because join caching and filesort() save the rowid and then
226
      put it back into h->ref)
227
    */
228
    CALL_POSITION=2
229
  };
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
230
  /** A set of flags from the above enum */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
231
  int rowid_keep_flags;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
232
1055.2.21 by Jay Pipes
Documentation and indentation/style cleanups in sql_select, opt_range.h and join_tab.h. This patch doxygenates classes/structs and their member variables.
233
  /** Bitmap of nested joins this table is part of */
1100.4.2 by Padraig O'Sullivan
Removed the typedef for nested_join_map and instead just declare these
234
  std::bitset<64> embedding_map;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
235
236
  void cleanup();
1089.1.13 by Brian Aker
Sorting methods into class files.
237
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
238
  inline bool is_using_loose_index_scan()
239
  {
240
    return (select && select->quick &&
241
            (select->quick->get_type() ==
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
242
             optimizer::QuickSelectInterface::QS_TYPE_GROUP_MIN_MAX));
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
243
  }
1089.1.13 by Brian Aker
Sorting methods into class files.
244
245
  void readCachedRecord();
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
246
};
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
247
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
248
} /* namespace drizzled */
249
1122.2.10 by Monty Taylor
Fixed all of the include guards.
250
#endif /* DRIZZLED_JOIN_TABLE_H */