MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_spj.cpp
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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 
17 
18 #include <stdio.h>
19 #include <time.h>
20 #include <assert.h>
21 #include <mysqld_error.h>
22 
23 #include <ndb_global.h>
24 #include <ndb_opts.h>
25 #include <NDBT.hpp>
26 #include <NdbApi.hpp>
27 #include <NdbSleep.h>
28 #include <HugoOperations.hpp>
29 #include <../../src/ndbapi/NdbApiSignal.hpp>
30 #include <kernel/signaldata/ScanTab.hpp>
31 #include <kernel/signaldata/QueryTree.hpp>
32 #include <kernel/AttributeHeader.hpp>
33 
34 
35 typedef uchar* gptr;
36 
37 static int _scan = 0;
38 static const char* _dbname = "TEST_DB";
39 
40 static struct my_option my_long_options[] =
41 {
42  NDB_STD_OPTS("spj_test"),
43  { "database", 'd', "Name of database table is in",
44  (uchar**) &_dbname, (uchar**) &_dbname, 0,
45  GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
46  { "scan", 's', "Table scan followed by key lookup",
47  (uchar**) &_scan, (uchar**) &_scan, 0,
48  GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
49  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
50 };
51 
53 {
54 public:
55 
56 
57  static void set(NdbScanOperation* op, const Uint32 * src, Uint32 len) {
58  op->theTotalCurrAI_Len = 0;
59  op->attrInfoRemain = 0;
60  op->theFirstATTRINFO = 0;
61  op->insertATTRINFOData_NdbRecord((const char*)src, 4*len);
62  }
63  static void setIsLinkedFlag(NdbScanOperation* op){
64  ScanTabReq * req = (ScanTabReq*)(op->theSCAN_TABREQ->getDataPtrSend());
65  ScanTabReq::setViaSPJFlag(req->requestInfo, 1);
66  }
67 };
68 
69 
78 int main(int argc, char** argv)
79 {
80  NDB_INIT(argv[0]);
81 
82  const char *load_default_groups[]= { "mysql_cluster",0 };
83  load_defaults("my",load_default_groups,&argc,&argv);
84  int ho_error;
85 #ifndef DBUG_OFF
86  opt_debug= "d:t:O,/tmp/ndb_desc.trace";
87 #endif
88  if ((ho_error=handle_options(&argc, &argv, my_long_options,
89  ndb_std_get_one_option)))
90  return NDBT_ProgramExit(NDBT_WRONGARGS);
91 
92  Ndb_cluster_connection con(opt_ndb_connectstring);
93  if(con.connect(12, 5, 1) != 0)
94  {
95  ndbout << "Unable to connect to management server." << endl;
96  return NDBT_ProgramExit(NDBT_FAILED);
97  }
98 
99  int res = con.wait_until_ready(30,30);
100  if (res != 0)
101  {
102  ndbout << "Cluster nodes not ready in 30 seconds." << endl;
103  return NDBT_ProgramExit(NDBT_FAILED);
104  }
105 
106  Ndb MyNdb(&con, _dbname);
107  if(MyNdb.init() != 0){
108  ERR(MyNdb.getNdbError());
109  return NDBT_ProgramExit(NDBT_FAILED);
110  }
111 
112  const NdbDictionary::Dictionary * dict= MyNdb.getDictionary();
113  const NdbDictionary::Table * pTab = dict->getTable(argv[0]);
114  if (pTab == 0)
115  {
116  ndbout_c("Failed to retreive table: \"%s\"", argv[0]);
117  exit(0);
118  }
119  else
120  {
121  ndbout_c("Retreived %s", argv[0]);
122  }
123 
124  const NdbDictionary::Index * pIdx = dict->getIndex("PRIMARY", argv[0]);
125  if (pIdx == 0)
126  {
127  ndbout_c("Failed to retreive index PRIMARY for table: \"%s\"", argv[0]);
128  exit(0);
129  }
130  else
131  {
132  ndbout_c("Retreived index PRIMARY for table %s", argv[0]);
133  }
134 
135  NdbTransaction * pTrans = MyNdb.startTransaction();
136  NdbScanOperation * pOp = pTrans->scanTable(pTab->getDefaultRecord(),
138 
139  bool scanindexchild = false;
140 #if 0
141 
151  Uint32 request[] = {
152  // pos: 0
153  0x000d0002,
154 
155  // ScanFragNode
156  0x00050002, // type/len
157  0x00000010, // bits
158  0x00000007, // table id
159  0x00000001, // table version
160  0x00010001, // #cnt linked / [ attr-list ]
161 
162  // LookupNode
163  0x00070001, // type/len
164  0x00000003, // bits
165  0x00000007, // table id
166  0x00000001, // table version
167  0x00000001, // parent list
168  0x00000001, // key pattern: #parameters/#len
169  QueryPattern::col(0), // P_COL col = 0
170 
171  // ScanFragParameters
172  0x000c0002, // type/len
173  0x00000009, // bits
174  0x10000018, // result data
175  0x00000005, // #len subroutine / #len interpreted program
176  0x00043017, // p0: BRANCH_ATTR_OP_COL | LE | OFFSET-JUMP
177  0x00010004, // p0: ATTRID / LEN of VALUE
178  0x00000064, // p1: VALUE (100)
179  0x00000012, // p2: EXIT_OK
180  0x03830013, // p3: EXIT_NOK
181  0x00000002, // len user projection
182  0xfff00002, // read all
183  0xffe90000, // read any value
184 
185  // LookupParameters
186  0x000d0001, // type/len
187  0x00000009, // bits
188  0x1000001c, // result data
189 
190  0x00020004, // #len subroutine / #len interpreted program
191  0x0003301a, // p0: BRANCH_ATTR_OP_COL2 | LE | OFFSET-JUMP
192  0x00010000, // p0: attrid: 1, param ref 0
193  0x00000012, // p1: EXIT_OK
194  0x03830013, // p2: EXIT_NOK
195  0x00000004, // param 0 header
196  0x00000003, // param 0 value (3)
197 
198  0x00000002, // len user projection
199  0xfff00002, // read all
200  0xffe90000 // read any value
201  };
202 #elif 0
203 
215  Uint32 request[] = {
216  // pos: 0
217  0x000d0002,
218 
219  // ScanFragNode
220  0x00050002, // type/len
221  0x00000010, // bits
222  0x00000007, // table id
223  0x00000001, // table version
224  0x00010001, // #cnt linked / [ attr-list ]
225 
226  // LookupNode
227  0x000e0001, // type/len
228  DABits::NI_HAS_PARENT | DABits::NI_KEY_LINKED |
229  DABits::NI_ATTR_INTERPRET | DABits::NI_ATTR_PARAMS,
230  0x00000007, // table id
231  0x00000001, // table version
232  0x00000001, // parent list
233  0x00000001, // key pattern: #parameters/#len
234  QueryPattern::col(0), // P_COL col = 0
235  0x00010004, // attrinfo pattern: #len-pattern / #len interpreted program
236  0x0003301a, // p0: BRANCH_ATTR_OP_COL_2 | LE | OFFSET-JUMP
237  0x00010000, // p0: attrid: 1 / program param 0
238  0x00000012, // p1: EXIT_OK
239  0x03830013, // p2: EXIT_NOK
240  0x00000001, // attr-param pattern: #parameters
241  QueryPattern::paramHeader(0), // P_PARAM_WITH_HEADER col=0
242 
243  // ScanFragParameters
244  0x000c0002, // type/len
245  0x00000009, // bits
246  0x10000018, // result data
247  0x00000005, // #len subroutine / #len interpreted program
248  0x00043017, // p0: BRANCH_ATTR_OP_COL | LE | OFFSET-JUMP
249  0x00010004, // p1: ATTRID / LEN of VALUE
250  0x00000064, // p2: VALUE (100)
251  0x00000012, // p3: EXIT_OK
252  0x03830013, // p4: EXIT_NOK
253  0x00000002, // len user projection
254  0xfff00002, // read all
255  0xffe90000, // read any value
256 
257  // LookupParameters
258  0x00080001, // type/len
259  DABits::PI_ATTR_LIST | DABits::PI_ATTR_PARAMS, // bits
260  0x1000001c, // result data
261  0x00000004, // Param 0 header
262  0x00000003, // Param 0 value
263  0x00000002, // len user projection
264  0xfff00002, // read all
265  0xffe90000 // read any value
266  };
267 #elif 0
268 
280  Uint32 request[] = {
281  // pos: 0
282  0x000d0002,
283 
284  // ScanFragNode
285  0x00050002, // type/len
286  0x00000010, // bits
287  0x00000007, // table id
288  0x00000001, // table version
289  0x00010001, // #cnt linked / [ attr-list ]
290 
291  // LookupNode
292  0x000e0001, // type/len
293  DABits::NI_HAS_PARENT | DABits::NI_KEY_LINKED |
294  DABits::NI_ATTR_INTERPRET | DABits::NI_ATTR_LINKED,
295  0x00000007, // table id
296  0x00000001, // table version
297  0x00000001, // parent list
298  0x00000001, // key pattern: #parameters/#len
299  QueryPattern::col(0), // P_COL col = 0
300  0x00010004, // attrinfo pattern: #len-pattern / #len interpreted program
301  0x0003301a, // p0: BRANCH_ATTR_OP_COL_2 | LE | OFFSET-JUMP
302  0x00010000, // p0: attrid: 1 / program param 0
303  0x00000012, // p1: EXIT_OK
304  0x03830013, // p2: EXIT_NOK
305  0x00000000, // attr-param pattern: #parameters
306  QueryPattern::attrInfo(0), // attr-param pattern: P_ATTRINFO col=0
307 
308  // ScanFragParameters
309  0x000c0002, // type/len
310  0x00000009, // bits
311  0x10000018, // result data
312  0x00000005, // #len subroutine / #len interpreted program
313  0x00043017, // p0: BRANCH_ATTR_OP_COL | LE | OFFSET-JUMP
314  0x00010004, // p1: ATTRID / LEN of VALUE
315  0x00000064, // p2: VALUE (100)
316  0x00000012, // p3: EXIT_OK
317  0x03830013, // p4: EXIT_NOK
318  0x00000002, // len user projection
319  0xfff00002, // read all
320  0xffe90000, // read any value
321 
322  // LookupParameters
323  0x00060001, // type/len
324  DABits::PI_ATTR_LIST, // bits
325  0x1000001c, // result data
326  0x00000002, // len user projection
327  0xfff00002, // read all
328  0xffe90000 // read any value
329  };
330 #else
331 
336  scanindexchild = true;
337  Uint32 request[] = {
338  // pos: 0
339  0x000d0002,
340 
341  // pos: 1 ScanFragNode
342  0x00050002, // len-type
343  DABits::NI_LINKED_ATTR, // bits
344  0x0000000c, // table id
345  0x00000001, // table version
346  0x00010001, // #cnt, linked attr
347 
348  // pos: 6 ScanIndexNode
349  0x00090003, // type len
350  DABits::NI_HAS_PARENT | DABits::NI_KEY_LINKED, // bits
351  0x0000000b, // table id
352  0x00000001, // table version
353  0x00000001, // parent list
354  0x00000003, // key pattern (cnt/len)
355  QueryPattern::data(1), // P_DATA len = 1
356  0x00000002, // BoundLE
357  QueryPattern::attrInfo(0), // P_ATTRINFO col = 0
358 
359  // pos: 15 ScanFragParameters
360  0x00080002, // type len
361  0x00000009, // bits
362  0x10000020, // result data
363  0x00000001, // param/len interpret program
364  0x00000012, // p1 = exit ok
365  0x00000002, // len user projection
366  0xfff00002, // up 1 - read all
367  0xffe90000, // up 2 - read any value
368 
369  // pos: 23 ScanIndexParameters
370  0x000a0003, // type/len
371  0x00020009, // bits
372  0xffff0100, // batch size
373  0x10000024, // result data
374  0x00000001, // param/len interpret program
375  0x00000012, // p1 = exit ok
376  0x00000003, // len user projection
377  0xfff00002, // up 1 - read all
378  0xffe90000, // up 2 - read any value
379  0xfffb0000
380  };
381 #endif
382 
383  Uint32 n0 = (request[1] >> 16);
384  Uint32 n1 = (request[1 + n0] >> 16);
385  request[0] = ((1 + n0 + n1) << 16) | 2;
386 
387  request[1+2] = pTab->getObjectId();
388  request[1+3] = pTab->getObjectVersion();
389 
390  if (scanindexchild == false)
391  {
392  request[1 + n0 + 2] = pTab->getObjectId();
393  request[1 + n0 + 3] = pTab->getObjectVersion();
394  }
395  else
396  {
397  request[1 + n0 + 2] = pIdx->getObjectId();
398  request[1 + n0 + 3] = pIdx->getObjectVersion();
399  }
400 
401  NdbScanFilterImpl::setIsLinkedFlag(pOp);
402  NdbScanFilterImpl::set(pOp, request, NDB_ARRAY_SIZE(request));
403 
404  pTrans->execute(NoCommit);
405  while (true) NdbSleep_SecSleep(1);
406 
407  return NDBT_ProgramExit(NDBT_OK);
408 }
409