MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryTree.hpp
1 /*
2  Copyright (c) 2004, 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 NDB_QUERY_TREE_HPP
19 #define NDB_QUERY_TREE_HPP
20 
21 #include <ndb_global.h>
22 #include <ndb_types.h>
23 
24 struct QueryNode // Effectively used as a base class for QN_xxxNode
25 {
26  Uint32 len;
27  Uint32 requestInfo;
28  Uint32 tableId; // 16-bit
29  Uint32 tableVersion;
30 
31  enum OpType
32  {
33  QN_LOOKUP = 0x1,
34  QN_SCAN_FRAG = 0x2,
35  QN_SCAN_INDEX = 0x3,
36  QN_END = 0
37  };
38 
39  static Uint32 getOpType(Uint32 op_len) { return op_len & 0xFFFF;}
40  static Uint32 getLength(Uint32 op_len) { return op_len >> 16;}
41 
42  static void setOpLen(Uint32 &d, Uint32 o, Uint32 l) { d = (l << 16) | o;}
43 
44  // If possible we should change the above static methods to non-static:
45 //Uint32 getOpType() const { return len & 0xFFFF;}
46 //Uint32 getLength() const { return len >> 16;}
47 //void setOpLen(Uint32 o, Uint32 l) { len = (l << 16) | o;}
48 };
49 
50 struct QueryNodeParameters // Effectively used as a base class for QN_xxxParameters
51 {
52  Uint32 len;
53  Uint32 requestInfo;
54  Uint32 resultData; // Api connect ptr
55 
56  enum OpType
57  {
58  QN_LOOKUP = 0x1,
59  QN_SCAN_FRAG = 0x2,
60  QN_SCAN_INDEX = 0x3,
61  QN_END = 0
62  };
63 
64  static Uint32 getOpType(Uint32 op_len) { return op_len & 0xFFFF;}
65  static Uint32 getLength(Uint32 op_len) { return op_len >> 16;}
66 
67  static void setOpLen(Uint32 &d, Uint32 o, Uint32 l) { d = (l << 16) | o;}
68 
69  // If possible we should change the above static methods to non-static:
70 //Uint32 getOpType() const { return len & 0xFFFF;}
71 //Uint32 getLength() const { return len >> 16;}
72 //void setOpLen(Uint32 o, Uint32 l) { len = (l << 16) | o;}
73 };
74 
75 struct DABits
76 {
82  {
83  NI_HAS_PARENT = 0x01,
84 
85  NI_KEY_LINKED = 0x02, // Does keyinfo contain linked values
86  NI_KEY_PARAMS = 0x04, // Does keyinfo contain parameters
87  NI_KEY_CONSTS = 0x08, // Does keyinfo contain const values
88 
89  NI_LINKED_ATTR = 0x10, // List of attributes to be used by children
90 
91  NI_ATTR_INTERPRET = 0x20, // Is attr-info a interpreted program
92  NI_ATTR_PARAMS = 0x40, // Does attrinfo contain parameters
93  NI_ATTR_LINKED = 0x80, // Does attrinfo contain linked values
94 
100  NI_LINKED_DISK = 0x100,
101 
112 
113  NI_END = 0
114  };
115 
121  {
122  PI_ATTR_LIST = 0x1, // "user" projection list
123 
127  PI_ATTR_PARAMS = 0x2, // attr-info parameters (NI_ATTR_PARAMS)
128  PI_KEY_PARAMS = 0x4, // key-info parameters (NI_KEY_PARAMS)
129 
136 
141  PI_DISK_ATTR = 0x10,
142  PI_END = 0
143  };
144 };
145 
146 
150 struct QN_LookupNode // Is a QueryNode subclass
151 {
152  Uint32 len;
153  Uint32 requestInfo;
154  Uint32 tableId; // 16-bit
155  Uint32 tableVersion;
156  STATIC_CONST ( NodeSize = 4 );
157 
161  Uint32 optional[1];
162 
164  {
168  L_UNIQUE_INDEX = 0x10000,
169 
170  L_END = 0
171  };
172 
173 //Uint32 getLength() const { return len >> 16;}
174 //void setOpLen(Uint32 o, Uint32 l) { len = (l << 16) | o;}
175 };
176 
181 struct QN_LookupParameters // Is a QueryNodeParameters subclass
182 {
183  Uint32 len;
184  Uint32 requestInfo;
185  Uint32 resultData; // Api connect ptr
186  STATIC_CONST ( NodeSize = 3 );
187 
191  Uint32 optional[1];
192 };
193 
197 struct QN_ScanFragNode // Is a QueryNode subclass
198 {
199  Uint32 len;
200  Uint32 requestInfo;
201  Uint32 tableId; // 16-bit
202  Uint32 tableVersion;
203  STATIC_CONST ( NodeSize = 4 );
204 
208  Uint32 optional[1];
209 };
210 
215 struct QN_ScanFragParameters // Is a QueryNodeParameters subclass
216 {
217  Uint32 len;
218  Uint32 requestInfo;
219  Uint32 resultData; // Api connect ptr
220  STATIC_CONST ( NodeSize = 3 );
221 
225  Uint32 optional[1];
226 };
227 
232 {
233  Uint32 len;
234  Uint32 requestInfo;
235  Uint32 tableId; // 16-bit
236  Uint32 tableVersion;
237  STATIC_CONST( NodeSize = 4 );
238 
240  {
246  SI_PRUNE_PATTERN = 0x10000,
247 
248  // Do pattern contain parameters
249  SI_PRUNE_PARAMS = 0x20000,
250 
251  // Is prune pattern dependant on parent key (or only on parameters / constants)
252  SI_PRUNE_LINKED = 0x40000,
253 
254  // Should it be parallel scan (can also be set as in parameters)
255  SI_PARALLEL = 0x80000,
256 
257  SI_END = 0
258  };
259 
263  Uint32 optional[1];
264 };
265 
271 {
272  Uint32 len;
273  Uint32 requestInfo;
274  Uint32 batchSize; // (bytes << 11) | (rows)
275  Uint32 resultData; // Api connect ptr
276  STATIC_CONST ( NodeSize = 4 );
277  // Number of bits for representing row count in 'batchSize'.
278  STATIC_CONST ( BatchRowBits = 11 );
279 
281  {
285  SIP_PRUNE_PARAMS = 0x10000,
286 
292  SIP_PARALLEL = 0x20000,
293 
294  SIP_END = 0
295  };
296 
300  Uint32 optional[1];
301 };
302 
306 struct QueryTree
307 {
308  Uint32 cnt_len; // Length in words describing full tree + #nodes
309  Uint32 nodes[1]; // The nodes
310 
311  static Uint32 getNodeCnt(Uint32 cnt_len) { return cnt_len & 0xFFFF;}
312  static Uint32 getLength(Uint32 cnt_len) { return cnt_len >> 16;}
313  static void setCntLen(Uint32 &d, Uint32 c, Uint32 l) { d=(l << 16) | c;}
314 };
315 
321 {
322  Uint32 m_info;
323  enum
324  {
325  P_DATA = 0x1, // Raw data of len-words (constants)
326  P_COL = 0x2, // Get column value from RowRef
327  P_UNQ_PK = 0x3, // NDB$PK column from a unique index
328  P_PARAM = 0x4, // User specified parameter value
329  P_PARENT = 0x5, // Move up in tree
330  P_PARAM_HEADER = 0x6, // User specified param val including AttributeHeader
331  P_ATTRINFO = 0x7,// Get column including header from RowRef
332  P_END = 0
333  };
334 
335  static Uint32 getType(const Uint32 info) { return info >> 16;}
336 
340  static Uint32 getLength(Uint32 info) { return info & 0xFFFF;}
341  static Uint32 data(Uint32 length)
342  {
343  assert(length <= 0xFFFF);
344  return (P_DATA << 16) | length;
345  }
346 
350  static Uint32 getColNo(Uint32 info) { return info & 0xFFFF;}
351  static Uint32 col(Uint32 no) { return (P_COL << 16) | no; }
352 
356  static Uint32 colPk(Uint32 no) { return (P_UNQ_PK << 16) | no; }
357 
361  static Uint32 getParamNo(Uint32 info) { return info & 0xFFFF;}
362  static Uint32 param(Uint32 no) { return (P_PARAM << 16) | no; }
363 
364  static Uint32 paramHeader(Uint32 no) { return (P_PARAM_HEADER << 16) | no; }
365 
369  static Uint32 attrInfo(Uint32 no) { return (P_ATTRINFO << 16) | no;}
370 
375  static Uint32 parent(Uint32 no) { return (P_PARENT << 16) | no;}
376 };
377 
378 #endif