~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
 *
4
 *  Copyright (C) 2008-2009 Sun Microsystems
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
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
28
#ifndef DRIZZLED_JOINTABLE_H
29
#define DRIZZLED_JOINTABLE_H
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
30
1089.1.8 by Brian Aker
Shuffled around a few structures.
31
#include <drizzled/enum_nested_loop_state.h>
32
#include <drizzled/table_reference.h>
1089.1.13 by Brian Aker
Sorting methods into class files.
33
#include <drizzled/opt_range.h>
34
#include <drizzled/join_cache.h>
1089.1.8 by Brian Aker
Shuffled around a few structures.
35
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
36
/* 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.
37
#define TAB_INFO_HAVE_VALUE 1
38
#define TAB_INFO_USING_INDEX 2
39
#define TAB_INFO_USING_WHERE 4
40
#define TAB_INFO_FULL_SCAN_ON_NULL 8
41
1089.1.8 by Brian Aker
Shuffled around a few structures.
42
class SemiJoinTable;
43
class KeyUse;
1089.1.13 by Brian Aker
Sorting methods into class files.
44
class Table;
45
class SQL_SELECT;
46
1089.1.8 by Brian Aker
Shuffled around a few structures.
47
48
/** Description of a join type */
49
enum join_type 
50
{ 
51
  JT_UNKNOWN,
52
  JT_SYSTEM,
53
  JT_CONST,
54
  JT_EQ_REF,
55
  JT_REF,
56
  JT_MAYBE_REF,
57
	JT_ALL,
58
  JT_RANGE,
59
  JT_NEXT,
60
  JT_REF_OR_NULL,
61
  JT_UNIQUE_SUBQUERY,
62
  JT_INDEX_SUBQUERY,
63
  JT_INDEX_MERGE
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:
70
  JoinTable() {} /* Remove gcc warning */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
71
  Table *table;
1089.1.8 by Brian Aker
Shuffled around a few structures.
72
  KeyUse *keyuse; /**< pointer to first used key */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
73
  SQL_SELECT *select;
74
  COND *select_cond;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
75
  QUICK_SELECT_I *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.
76
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
77
    The value of select_cond before we've attempted to do Index Condition
78
    Pushdown. We may need to restore everything back if we first choose one
79
    index but then reconsider (see test_if_skip_sort_order() for such
80
    scenarios).
81
    NULL means no index condition pushdown was performed.
82
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
83
  Item *pre_idx_push_select_cond;
84
  Item **on_expr_ref;   /**< pointer to the associated on expression   */
85
  COND_EQUAL *cond_equal;    /**< multiple equalities for the on expression */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
86
  JoinTable *first_inner;   /**< first inner table for including outerjoin */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
87
  bool found;         /**< true after all matches or null complement */
88
  bool not_null_compl;/**< true before null complement is added      */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
89
  JoinTable *last_inner;    /**< last table table for embedding outer join */
90
  JoinTable *first_upper;  /**< first inner table for embedding outer join */
91
  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.
92
93
  /* Special content for EXPLAIN 'Extra' column or NULL if none */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
94
  const char *info;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
95
  /*
96
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
97
    column, or 0 if there is no info.
98
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
99
  uint32_t packed_info;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
100
101
  Read_record_func read_first_record;
102
  Next_select_func next_select;
103
  READ_RECORD	read_record;
104
  /*
105
    Currently the following two fields are used only for a [NOT] IN subquery
106
    if it is executed by an alternative full table scan when the left operand of
107
    the subquery predicate is evaluated to NULL.
108
  */
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.
109
  Read_record_func save_read_first_record; /**< to save read_first_record */
110
  int (*save_read_record) (READ_RECORD *); /**< to save read_record.read_record */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
111
  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.
112
  key_map	const_keys; /**< Keys with constant part */
113
  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.
114
  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.
115
  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.
116
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.
117
  /** 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.
118
  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.
119
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
120
    Number of records that will be scanned (yes scanned, not returned) by the
121
    best 'independent' access method, i.e. table scan or QUICK_*_SELECT)
122
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
123
  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.
124
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
125
    Cost of accessing the table using "ALL" or range/index_merge access
126
    method (but not 'index' for some reason), i.e. this matches method which
127
    E(#records) is in found_records.
128
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
129
  ha_rows read_time;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
130
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.
131
  table_map	dependent;
132
  table_map key_dependent;
133
  uint32_t use_quick;
134
  uint32_t index;
135
  uint32_t status; /**< Save status for cache */
136
  uint32_t used_fields; /**< Number of used fields in join set */
137
  uint32_t used_fieldlength; /**< Not sure... */
138
  uint32_t used_blobs; /**< Number of BLOB fields in join set */
139
  enum join_type type; /**< Access pattern or join type... */
140
  bool cached_eq_ref_table;
141
  bool eq_ref_table;
142
  bool not_used_in_distinct;
143
  /** True if index-based access method must return records in order */
144
  bool sorted;
145
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
146
    If it's not 0 the number stored this field indicates that the index
147
    scan has been chosen to access the table data and we expect to scan
148
    this number of rows for the table.
149
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
150
  ha_rows limit;
1089.1.14 by Brian Aker
Fix TABLE_REF structure
151
  table_reference_st	ref;
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
152
  JOIN_CACHE cache;
153
  JOIN *join;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
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
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
156
    Embedding SJ-nest (may be not the direct parent), or NULL if none.
157
    This variable holds the result of table pullout.
158
  */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
159
  TableList *emb_sj_nest;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
160
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
  /** Variables for semi-join duplicate elimination */
1089.1.2 by Brian Aker
Rename work (cheery pick from new-cleanup). Jay's fix for auth_http. Update
162
  SemiJoinTable *flush_weedout_table;
163
  SemiJoinTable *check_weed_out_table;
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
164
  JoinTable *do_firstmatch;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
165
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
  /**
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
167
     ptr  - this join tab should do an InsideOut scan. Points
168
            to the tab for which we'll need to check tab->found_match.
169
170
     NULL - Not an insideout scan.
171
  */
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
172
  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.
173
  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.
174
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
  /** 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.
176
  bool found_match;
177
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.
178
  enum 
179
  {
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
180
    /* If set, the rowid of this table must be put into the temptable. */
181
    KEEP_ROWID=1,
182
    /*
183
      If set, one should call h->position() to obtain the rowid,
184
      otherwise, the rowid is assumed to already be in h->ref
185
      (this is because join caching and filesort() save the rowid and then
186
      put it back into h->ref)
187
    */
188
    CALL_POSITION=2
189
  };
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.
190
  /** A set of flags from the above enum */
1039.2.7 by Jay Pipes
Yet more style and indentation cleanups.
191
  int rowid_keep_flags;
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
192
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.
193
  /** Bitmap of nested joins this table is part of */
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
194
  nested_join_map embedding_map;
195
196
  void cleanup();
1089.1.13 by Brian Aker
Sorting methods into class files.
197
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
198
  inline bool is_using_loose_index_scan()
199
  {
200
    return (select && select->quick &&
201
            (select->quick->get_type() ==
202
             QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX));
203
  }
1089.1.13 by Brian Aker
Sorting methods into class files.
204
205
  void readCachedRecord();
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
206
};
1039.2.5 by Jay Pipes
Style cleanups and moves JOIN_TAB definition out into its own header.
207
1089.1.1 by Brian Aker
Remove of JOIN_TAB to JoinTable
208
#endif /* DRIZZLED_JOINTABLE_H */