~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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
28
#pragma once
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
29
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
30
#include <drizzled/enum_nested_loop_state.h>
31
#include <drizzled/table_reference.h>
32
#include <drizzled/optimizer/range.h>
33
#include <drizzled/join_cache.h>
34
#include <drizzled/optimizer/key_use.h>
1089.1.8 by Brian Aker
Shuffled around a few structures.
35
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
36
#include <drizzled/records.h>
1538 by Brian Aker
Code shuffle on ReadRecord
37
1100.4.2 by Padraig O'Sullivan
Removed the typedef for nested_join_map and instead just declare these
38
#include <bitset>
39
2252.1.15 by Olaf van der Spek
Common fwd
40
namespace drizzled {
41
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
42
/* 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.
43
#define TAB_INFO_HAVE_VALUE 1
44
#define TAB_INFO_USING_INDEX 2
45
#define TAB_INFO_USING_WHERE 4
46
#define TAB_INFO_FULL_SCAN_ON_NULL 8
47
1108.6.20 by Padraig O'Sullivan
Renamed access_type to access_method due to conflicts on Solaris.
48
/** Description of an access method */
49
enum access_method
1089.1.8 by Brian Aker
Shuffled around a few structures.
50
{ 
1108.6.20 by Padraig O'Sullivan
Renamed access_type to access_method due to conflicts on Solaris.
51
  AM_UNKNOWN,
52
  AM_SYSTEM,
53
  AM_CONST,
54
  AM_EQ_REF,
55
  AM_REF,
56
  AM_MAYBE_REF,
57
	AM_ALL,
58
  AM_RANGE,
59
  AM_NEXT,
60
  AM_REF_OR_NULL,
61
  AM_UNIQUE_SUBQUERY,
62
  AM_INDEX_SUBQUERY,
63
  AM_INDEX_MERGE
1089.1.8 by Brian Aker
Shuffled around a few structures.
64
};
65
66
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
67
class JoinTable 
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
68
{
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
69
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.
70
  JoinTable() :
71
    table(NULL),
72
    keyuse(NULL),
73
    select(NULL),
74
    select_cond(NULL),
75
    quick(NULL),
76
    pre_idx_push_select_cond(NULL),
77
    on_expr_ref(NULL),
78
    cond_equal(NULL),
79
    first_inner(NULL),
80
    found(false),
81
    not_null_compl(false),
82
    last_inner(NULL),
83
    first_upper(NULL),
84
    first_unmatched(NULL),
85
    packed_info(0),
86
    read_first_record(NULL),
87
    next_select(NULL),
88
    worst_seeks(0.0),
89
    const_keys(0),
90
    checked_keys(0),
91
    needed_reg(0),
92
    keys(0),
93
    records(0),
94
    found_records(0),
95
    read_time(0),
96
    dependent(0),
97
    key_dependent(0),
98
    use_quick(0),
99
    index(0),
100
    status(0),
101
    used_fields(0),
102
    used_fieldlength(0),
103
    used_blobs(0),
104
    type(AM_UNKNOWN),
105
    cached_eq_ref_table(0),
106
    eq_ref_table(0),
107
    not_used_in_distinct(0),
108
    sorted(0),
109
    limit(0),
110
    join(NULL),
111
    insideout_match_tab(NULL),
112
    insideout_buf(NULL),
113
    found_match(false),
114
    rowid_keep_flags(0),
115
    embedding_map(0)
116
  {}
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
117
  Table *table;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
118
  optimizer::KeyUse *keyuse; /**< pointer to first used key */
119
  optimizer::SqlSelect *select;
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
120
  COND *select_cond;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
121
  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.
122
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
123
    The value of select_cond before we've attempted to do Index Condition
124
    Pushdown. We may need to restore everything back if we first choose one
125
    index but then reconsider (see test_if_skip_sort_order() for such
126
    scenarios).
127
    NULL means no index condition pushdown was performed.
128
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
129
  Item *pre_idx_push_select_cond;
130
  Item **on_expr_ref;   /**< pointer to the associated on expression   */
131
  COND_EQUAL *cond_equal;    /**< multiple equalities for the on expression */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
132
  JoinTable *first_inner;   /**< first inner table for including outerjoin */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
133
  bool found;         /**< true after all matches or null complement */
134
  bool not_null_compl;/**< true before null complement is added      */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
135
  JoinTable *last_inner;    /**< last table table for embedding outer join */
136
  JoinTable *first_upper;  /**< first inner table for embedding outer join */
137
  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.
138
139
  /* Special content for EXPLAIN 'Extra' column or NULL if none */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
140
  const char *info;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
141
  /*
142
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
143
    column, or 0 if there is no info.
144
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
145
  uint32_t packed_info;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
146
147
  Read_record_func read_first_record;
148
  Next_select_func next_select;
1538 by Brian Aker
Code shuffle on ReadRecord
149
  ReadRecord	read_record;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
150
  /*
151
    Currently the following two fields are used only for a [NOT] IN subquery
152
    if it is executed by an alternative full table scan when the left operand of
153
    the subquery predicate is evaluated to NULL.
154
  */
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.
155
  Read_record_func save_read_first_record; /**< to save read_first_record */
1538 by Brian Aker
Code shuffle on ReadRecord
156
  int (*save_read_record) (ReadRecord *); /**< to save read_record.read_record */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
157
  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.
158
  key_map	const_keys; /**< Keys with constant part */
159
  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.
160
  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.
161
  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.
162
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
  /** 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.
164
  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.
165
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
166
    Number of records that will be scanned (yes scanned, not returned) by the
167
    best 'independent' access method, i.e. table scan or QUICK_*_SELECT)
168
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
169
  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.
170
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
171
    Cost of accessing the table using "ALL" or range/index_merge access
172
    method (but not 'index' for some reason), i.e. this matches method which
173
    E(#records) is in found_records.
174
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
175
  ha_rows read_time;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
176
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.
177
  table_map	dependent;
178
  table_map key_dependent;
179
  uint32_t use_quick;
180
  uint32_t index;
181
  uint32_t status; /**< Save status for cache */
182
  uint32_t used_fields; /**< Number of used fields in join set */
183
  uint32_t used_fieldlength; /**< Not sure... */
184
  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.
185
  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.
186
  bool cached_eq_ref_table;
187
  bool eq_ref_table;
188
  bool not_used_in_distinct;
189
  /** True if index-based access method must return records in order */
190
  bool sorted;
191
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
192
    If it's not 0 the number stored this field indicates that the index
193
    scan has been chosen to access the table data and we expect to scan
194
    this number of rows for the table.
195
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
196
  ha_rows limit;
1089.1.14 by Brian Aker
Fix TABLE_REF structure
197
  table_reference_st	ref;
1539.1.6 by Brian Aker
Update for Join structure changes.
198
  JoinCache cache;
1541.1.1 by Brian Aker
JOIN -> Join rename
199
  Join *join;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
200
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.
201
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
202
     ptr  - this join tab should do an InsideOut scan. Points
203
            to the tab for which we'll need to check tab->found_match.
204
205
     NULL - Not an insideout scan.
206
  */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
207
  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.
208
  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.
209
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.
210
  /** 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.
211
  bool found_match;
212
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
  enum 
214
  {
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
215
    /* If set, the rowid of this table must be put into the temptable. */
216
    KEEP_ROWID=1,
217
    /*
218
      If set, one should call h->position() to obtain the rowid,
219
      otherwise, the rowid is assumed to already be in h->ref
220
      (this is because join caching and filesort() save the rowid and then
221
      put it back into h->ref)
222
    */
223
    CALL_POSITION=2
224
  };
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.
225
  /** A set of flags from the above enum */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
226
  int rowid_keep_flags;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
227
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.
228
  /** 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
229
  std::bitset<64> embedding_map;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
230
231
  void cleanup();
1089.1.13 by Brian Aker
Sorting methods into class files.
232
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
233
  inline bool is_using_loose_index_scan()
234
  {
235
    return (select && select->quick &&
236
            (select->quick->get_type() ==
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
237
             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.
238
  }
1089.1.13 by Brian Aker
Sorting methods into class files.
239
240
  void readCachedRecord();
2141.3.3 by vjsamuel1990 at gmail
Merge change nested_join_st to NestedJoin
241
  int joinReadConstTable(optimizer::Position *pos);
2147.5.3 by vjsamuel1990 at gmail
Merge re write encapsulated join_read_system() function name to abide to coding standards.
242
  int joinReadSystem();
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
243
};
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
244
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
245
} /* namespace drizzled */
246