MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HugoQueryBuilder.hpp
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 #ifndef HUGO_QUERY_BUILDER_HPP
19 #define HUGO_QUERY_BUILDER_HPP
20 
21 #include <NDBT.hpp>
22 #include <Vector.hpp>
23 #include "../../src/ndbapi/NdbQueryBuilder.hpp"
24 
26 public:
27 
28  typedef Uint64 OptionMask;
29 
34  {
38  O_LOOKUP = 0x1,
39 
43  O_SCAN = 0x2,
44 
48  O_PK_INDEX = 0x4,
49 
54 
59 
63  O_TABLE_SCAN = 0x20,
64 
68  O_RANDOM_OPTIONS = (OptionMask)((~(OptionMask)0) &
69  ~(OptionMask)(O_SCAN | O_LOOKUP))
70  };
71  static const OptionMask OM_RANDOM_OPTIONS = (OptionMask)O_RANDOM_OPTIONS;
72 
73  HugoQueryBuilder(Ndb* ndb, const NdbDictionary::Table**tabptr,
74  OptionMask om = OM_RANDOM_OPTIONS){
75  init();
76  for (; * tabptr != 0; tabptr++)
77  addTable(ndb, * tabptr);
78  setOptionMask(om);
79  fixOptions();
80  }
82  init();
83  addTable(ndb, tab);
84  setOption(o);
85  fixOptions();
86  }
87  virtual ~HugoQueryBuilder();
88 
89  void setMinJoinLevel(int level) { m_joinLevel[0] = level;}
90  int getMinJoinLevel() const { return m_joinLevel[0];}
91  void setMaxJoinLevel(int level) { m_joinLevel[1] = level;}
92  int getMaxJoinLevel() const { return m_joinLevel[1];}
93 
94  void setJoinLevel(int level) { setMinJoinLevel(level);setMaxJoinLevel(level);}
95  int getJoinLevel() const;
96 
97  void addTable(Ndb*, const NdbDictionary::Table*);
98  void removeTable(const NdbDictionary::Table*);
99 
100  void setOption(QueryOption o) { m_options |= (OptionMask)o;}
101  void clearOption(QueryOption o) const { m_options &= ~(OptionMask)o;}
102  bool testOption(QueryOption o) const { return (m_options & o) != 0;}
103 
104  OptionMask getOptionMask() const { return m_options;}
105  void setOptionMask(OptionMask om) { m_options = om;}
106 
107  const NdbQueryDef * createQuery(bool takeOwnership = false);
108 
109 private:
110  struct TableDef
111  {
112  const NdbDictionary::Table * m_table;
113  Vector<const NdbDictionary::Index*> m_unique_indexes;
114  Vector<const NdbDictionary::Index*> m_ordered_indexes;
115  };
116 
117  void init();
118  mutable OptionMask m_options;
119  int m_joinLevel[2]; // min/max
120  Vector<TableDef> m_tables;
121  Vector<const NdbQueryDef*> m_queries;
122 
123  // get random table
124  struct TableDef getTable() const;
125 
126  struct OpIdx
127  {
129  const NdbDictionary::Table * m_table;
130  const NdbDictionary::Index * m_index;
131  };
132  OpIdx getOp() const;
133 
134  struct Op
135  {
136  int m_parent;
137  int m_idx;
138  const NdbQueryOperationDef * m_op;
139  };
140 
141  Vector<Op> m_query; // Query built sofar
142 
147  static bool checkBindable(Vector<const NdbDictionary::Column*> cols,
148  Vector<Op> ops,
149  bool allow_bind_nullable);
150 
151  Vector<Op> getParents(OpIdx); //
153  Vector<Op> & parents,
154  bool allow_bind_nullable);
155  const NdbQueryOperationDef* createOp(NdbQueryBuilder&);
156 
157  void fixOptions();
158 
162  bool checkBusyScan(Op) const;
163  bool isAncestor(const Op& parent, const Op& child) const;
164 
165  friend NdbOut& operator<<(NdbOut& out, const HugoQueryBuilder::Op& op);
166 };
167 
168 #endif