20 #include <NDBT_Test.hpp>
21 #include <HugoTransactions.hpp>
22 #include <UtilTransactions.hpp>
55 {
"parallelism", 0, 0, 1 },
57 {
"filter", 0, 0, 3 },
61 {
"access", 0, 0, 2 },
63 {
"size", 1000000, 1, ~0 },
64 {
"iterations", 3, 1, ~0 },
65 {
"create_drop", 1, 0, 2 },
67 {
"multi read range", 1000, 1, ~0 }
70 static Ndb* g_ndb = 0;
73 static char g_tablename[256];
74 static char g_indexname[256];
82 main(
int argc,
const char** argv){
87 struct getargs args[1+P_MAX] = {
88 {
"verbose",
'v', arg_flag, &verbose,
"Print verbose status",
"verbose" }
90 const int num_args = 1 + P_MAX;
92 for(i = 0; i<P_MAX; i++){
93 args[i+1].long_name = g_paramters[
i].name;
94 args[i+1].short_name = * g_paramters[
i].name;
95 args[i+1].type = arg_integer;
96 args[i+1].value = &g_paramters[
i].value;
98 tmp.
assfmt(
"min: %d max: %d", g_paramters[i].min, g_paramters[i].max);
99 args[i+1].help = strdup(tmp.
c_str());
100 args[i+1].arg_help = 0;
103 if(getarg(args, num_args, argc, argv, &optind)) {
104 arg_printusage(args, num_args, argv[0],
"tabname1 tabname2 ...");
105 return NDBT_WRONGARGS;
108 myRandom48Init((
long)NdbTick_CurrentMillisecond());
113 return NDBT_ProgramExit(NDBT_FAILED);
116 g_ndb =
new Ndb(&con,
"TEST_DB");
117 if(g_ndb->
init() != 0){
118 g_err <<
"init() failed" << endl;
122 g_err <<
"Wait until ready failed" << endl;
125 for(i = optind; i<argc; i++){
126 const char * T = argv[
i];
127 g_info <<
"Testing " << T << endl;
132 if(g_paramters[P_CREATE].value != 2 && run_scan())
136 if(g_ndb)
delete g_ndb;
139 if(g_ndb)
delete g_ndb;
147 if(g_paramters[P_CREATE].value){
154 g_err <<
"Failed to create table: " << g_tablename << endl;
159 x.setTable(g_tablename);
169 g_err <<
"Failed to create index: " << endl;
173 g_table = dict->
getTable(g_tablename);
174 g_index = dict->
getIndex(g_indexname, g_tablename);
184 for (Uint32 colNum=0; colNum<cols; colNum++)
189 spec[colNum].column= col;
190 spec[colNum].offset=
offset;
194 spec[colNum].nullbit_byte_offset= offset++;
195 spec[colNum].nullbit_bit_in_byte= 0;
198 g_table_record= dict->createRecord(g_table,
203 assert(g_table_record);
210 for (Uint32 colNum=0; colNum<cols; colNum++)
220 spec[colNum].column= col;
221 spec[colNum].offset=
offset;
225 spec[colNum].nullbit_byte_offset= offset++;
226 spec[colNum].nullbit_bit_in_byte= 0;
229 g_index_record= dict->createRecord(g_index,
234 assert(g_index_record);
238 if(g_paramters[P_CREATE].value)
240 int rows = g_paramters[P_ROWS].value;
242 if (hugoTrans.loadTable(g_ndb, rows)){
243 g_err.println(
"Failed to load %s with %d rows",
268 ib.low_key= ib.high_key= (
char*) &space;
269 ib.low_key_count= ib.high_key_count= 1;
270 ib.low_inclusive= ib.high_inclusive=
true;
271 ib.range_no= rangeNum;
273 return isop->
setBound(key_record, ib);
278 int iter = g_paramters[P_LOOPS].value;
279 NDB_TICKS start1, stop;
282 Uint32 sample_rows = 0;
284 NDB_TICKS sample_start = NdbTick_CurrentMillisecond();
286 Uint32 tot = g_paramters[P_ROWS].value;
288 if(g_paramters[P_BOUND].value >= 2 || g_paramters[P_FILT].value == 2)
289 iter *= g_paramters[P_ROWS].value;
296 for(
int i = 0; i<iter; i++){
297 start1 = NdbTick_CurrentMillisecond();
300 g_err <<
"Failed to start transaction" << endl;
305 int par = g_paramters[P_PARRA].value;
306 int bat = g_paramters[P_BATCH].value;
308 switch(g_paramters[P_LOCK].value){
323 bzero(&options,
sizeof(options));
325 options.optionsPresent=
326 NdbScanOperation::ScanOptions::SO_SCANFLAGS |
327 NdbScanOperation::ScanOptions::SO_PARALLEL |
328 NdbScanOperation::ScanOptions::SO_BATCH;
330 bool ord= g_paramters[P_ACCESS].value == 2;
331 bool mrr= (g_paramters[P_ACCESS].value != 0) &&
332 (g_paramters[P_BOUND].value == 3);
335 ( ord ? NdbScanOperation::SF_OrderBy:0 ) |
336 ( mrr ? NdbScanOperation::SF_MultiRange:0 );
337 options.parallel= par;
340 switch(g_paramters[P_FILT].value){
350 int tot = g_paramters[P_ROWS].value;
351 int row = rand() % tot;
358 options.scan_flags|= NdbScanOperation::SF_Interpreted;
359 options.interpretedCode= ⁣
365 if(g_paramters[P_ACCESS].value == 0){
373 pOp= pIOp= pTrans->
scanIndex(g_index_record,
388 switch(g_paramters[P_BOUND].value){
392 check= setEqBound(pIOp, g_index_record, 0, 0);
398 int tot = g_paramters[P_ROWS].value;
399 int row = rand() % tot;
401 check= setEqBound(pIOp, g_index_record, row, 0);
406 int multi = g_paramters[P_MULTI].value;
407 int tot = g_paramters[P_ROWS].value;
409 for(; multi > 0 && i < iter; --multi, i++)
411 int row = rand() % tot;
413 check= setEqBound(pIOp, g_index_record, row, i- rangeStart);
430 check = pTrans->
execute(NoCommit);
432 int fetch = g_paramters[P_FETCH].value;
434 const char * result_row_ptr;
436 while((check = pOp->
nextResult(&result_row_ptr,
true,
false)) == 0){
439 }
while(!fetch && ((check = pOp->
nextResult(&result_row_ptr,
false,
false)) == 0));
456 stop = NdbTick_CurrentMillisecond();
458 int time_passed= (int)(stop - start1);
460 sum_time+= time_passed;
463 if(sample_rows >= tot)
465 int sample_time = (int)(stop - sample_start);
466 g_info <<
"Found " << sample_rows <<
" rows" << endl;
467 g_err.println(
"Time: %d ms = %u rows/sec", sample_time,
468 (1000*sample_rows)/sample_time);
474 g_err.println(
"Avg time: %d ms = %u rows/sec", sum_time/tot_rows,
475 (1000*tot_rows)/sum_time);