MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ha_ndbcluster_push.h
1 /*
2  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "sql_bitmap.h"
19 
20 class NdbTransaction;
21 class NdbQueryBuilder;
22 class NdbQueryOperand;
25 struct NdbError;
26 
27 namespace AQP{
28  class Join_plan;
29  class Table_access;
30 };
31 
32 void ndbcluster_build_key_map(const NdbDictionary::Table* table,
33  const NDB_INDEX_DATA& index,
34  const KEY *key_def,
35  uint ix_map[]);
36 
37 
44 typedef Bitmap<(MAX_TABLES > 64 ? MAX_TABLES : 64)> table_bitmap;
45 
46 class ndb_table_access_map : public table_bitmap
47 {
48 public:
49  explicit ndb_table_access_map()
50  : table_bitmap(0)
51  {}
52  explicit ndb_table_access_map(uint table_no)
53  : table_bitmap(0)
54  { set_bit(table_no);
55  }
56 
57  void add(const ndb_table_access_map& table_map)
58  { // Require const_cast as signature of class Bitmap::merge is not const correct
59  merge(const_cast<ndb_table_access_map&>(table_map));
60  }
61  void add(uint table_no)
62  {
63  set_bit(table_no);
64  }
65 
66  bool contain(const ndb_table_access_map& table_map) const
67  {
68  return table_map.is_subset(*this);
69  }
70  bool contain(uint table_no) const
71  {
72  return is_set(table_no);
73  }
74 
75  uint first_table(uint start= 0) const;
76  uint last_table(uint start= MAX_TABLES) const;
77 
78 }; // class ndb_table_access_map
79 
80 
89 {
90 public:
91  explicit ndb_pushed_join(const ndb_pushed_builder_ctx& builder_ctx,
92  const NdbQueryDef* query_def);
93 
94  ~ndb_pushed_join();
95 
100  bool match_definition(int type, //NdbQueryOperationDef::Type,
101  const NDB_INDEX_DATA* idx,
102  bool needSorted) const;
103 
106  NdbTransaction* trans,
107  const NdbQueryParamValue* keyFieldParams,
108  uint paramCnt) const;
109 
111  uint get_operation_count() const
112  { return m_operation_count; }
113 
120  { return m_field_count; }
121 
122  const NdbQueryDef& get_query_def() const
123  { return *m_query_def; }
124 
126  TABLE* get_table(uint i) const
127  {
128  DBUG_ASSERT(i < m_operation_count);
129  return m_tables[i];
130  }
131 
136  static const uint MAX_KEY_PART= MAX_KEY;
143  static const uint MAX_REFERRED_FIELDS= 16;
148  static const uint MAX_LINKED_KEYS= MAX_KEY;
153  static const uint MAX_PUSHED_OPERATIONS= MAX_TABLES;
154 
155 private:
156  const NdbQueryDef* const m_query_def; // Definition of pushed join query
157 
159  uint m_operation_count;
160 
162  TABLE* m_tables[MAX_PUSHED_OPERATIONS];
163 
168  const uint m_field_count;
169 
174  Field* m_referred_fields[MAX_REFERRED_FIELDS];
175 }; // class ndb_pushed_join
176 
177 
178 
188 {
189  friend ndb_pushed_join::ndb_pushed_join(
190  const ndb_pushed_builder_ctx& builder_ctx,
191  const NdbQueryDef* query_def);
192 
193 public:
196 
204  int make_pushed_join(const AQP::Table_access* join_root,
205  const ndb_pushed_join* &pushed_join);
206 
207  const NdbError& getNdbError() const;
208 
209 private:
214  bool is_pushable_with_root(
215  const AQP::Table_access* root);
216 
217  bool is_pushable_as_child(
218  const AQP::Table_access* table);
219 
220  bool is_const_item_pushable(
221  const Item* key_item,
222  const KEY_PART_INFO* key_part);
223 
224  bool is_field_item_pushable(
225  const AQP::Table_access* table,
226  const Item* key_item,
227  const KEY_PART_INFO* key_part,
228  ndb_table_access_map& parents);
229 
230  int optimize_query_plan();
231 
232  int build_query();
233 
234  void collect_key_refs(
235  const AQP::Table_access* table,
236  const Item* key_refs[]) const;
237 
238  int build_key(const AQP::Table_access* table,
239  const NdbQueryOperand* op_key[]);
240 
241  uint get_table_no(const Item* key_item) const;
242 
243 private:
244  const AQP::Join_plan& m_plan;
245  const AQP::Table_access* m_join_root;
246 
247  // Scope of tables covered by this pushed join
248  ndb_table_access_map m_join_scope;
249 
250  // Scope of tables evaluated prior to 'm_join_root'
251  // These are effectively const or params wrt. the pushed join
252  ndb_table_access_map m_const_scope;
253 
254  // Set of tables required to have strict sequential dependency
255  ndb_table_access_map m_forced_sequence;
256 
257  uint m_fld_refs;
258  Field* m_referred_fields[ndb_pushed_join::MAX_REFERRED_FIELDS];
259 
260  // Handle to the NdbQuery factory.
261  // Possibly reused if multiple NdbQuery's are pushed.
262  NdbQueryBuilder* m_builder;
263 
264  enum pushability
265  {
266  PUSHABLE_AS_PARENT= 0x01,
267  PUSHABLE_AS_CHILD= 0x02
268  } enum_pushability;
269 
270  struct pushed_tables
271  {
272  pushed_tables() :
273  m_maybe_pushable(0),
274  m_common_parents(),
275  m_extend_parents(),
276  m_depend_parents(),
277  m_parent(MAX_TABLES),
278  m_ancestors(),
279  m_op(NULL)
280  {}
281 
282  int m_maybe_pushable; // OR'ed bits from 'enum_pushability'
283 
293  ndb_table_access_map m_common_parents;
294  ndb_table_access_map m_extend_parents;
295 
300  ndb_table_access_map m_depend_parents;
301 
306  uint m_parent;
307 
311  ndb_table_access_map m_ancestors;
312 
313  const NdbQueryOperationDef* m_op;
314  } m_tables[MAX_TABLES];
315 
319  struct table_remap
320  {
321  Uint16 to_external; // m_remap[] is indexed with internal table_no
322  Uint16 to_internal; // m_remap[] is indexed with external tablenr
323  } m_remap[MAX_TABLES];
324 
325 }; // class ndb_pushed_builder_ctx
326 
327