19 #include <ndb_global.h> 
   23 #include <my_getopt.h> 
   24 #include <mysql_version.h> 
   30 #include <HugoTransactions.hpp> 
   31 #include <HugoQueryBuilder.hpp> 
   32 #include <HugoQueries.hpp> 
   40 int _loops_per_query = 100;
 
   42 unsigned int _seed = 0;
 
   43 static const char * _options = 
"";
 
   44 static const char * _db = 
"TEST_DB";
 
   46 extern const char *load_default_groups[];
 
   47 static struct my_option my_long_options[] =
 
   49   NDB_STD_OPTS(
"hugoJoin"),
 
   50   { 
"database", 
'd', 
"Database",
 
   51     (uchar**) &_db, (uchar**) &_db,
 
   52     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
   53   { 
"options", 
'o', 
"comma separated list of options",
 
   54     (uchar**) &_options, (uchar**) &_options,
 
   55     0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
   56   { 
"loops", 
'l', 
"Loops",
 
   58     0, GET_INT, REQUIRED_ARG, _loops, 0, 0, 0, 0, 0},
 
   59   { 
"verbose", 
'v', 
"verbosity",
 
   60     (uchar**) &_verbose, 0,
 
   61     0, GET_INT, REQUIRED_ARG, _verbose, 0, 0, 0, 0, 0},
 
   62   { 
"loops_per_query", 
'q', 
"Recreate query each #loops",
 
   63     (uchar**) &_loops_per_query, 0,
 
   64     0, GET_INT, REQUIRED_ARG, _loops_per_query, 0, 0, 0, 0, 0},
 
   65   { 
"batch", 
'b', 
"Batch size (for lookups)",
 
   67     0, GET_INT, REQUIRED_ARG, _batch, 0, 0, 0, 0, 0},
 
   68   { 
"records", 
'r', 
"Records (for lookups)",
 
   69     (uchar**) &_records, 0,
 
   70     0, GET_INT, REQUIRED_ARG, _records, 0, 0, 0, 0, 0},
 
   71   { 
"join-depth", 
'j', 
"Join depth",
 
   73     0, GET_INT, REQUIRED_ARG, _depth, 0, 0, 0, 0, 0},
 
   74   { 
"seed", NDB_OPT_NOSHORT, 
"Random seed",
 
   75     (uchar **) &_seed, (uchar **) &_seed, 0,
 
   76     GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
 
   77   { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
   80 static void short_usage_sub(
void)
 
   82   ndb_short_usage_sub(NULL);
 
   88     "This run random joins on table-list\n";
 
   90   ndb_usage(short_usage_sub, load_default_groups, my_long_options);
 
   93 int main(
int argc, 
char** argv){
 
   95   ndb_opt_set_usage_funcs(short_usage_sub, usage);
 
   96   load_defaults(
"my", load_default_groups, &argc, &argv);
 
   98   if ((ho_error=handle_options(&argc, &argv, my_long_options,
 
   99                                ndb_std_get_one_option)))
 
  107     return NDBT_ProgramExit(NDBT_FAILED);
 
  112     ndbout << 
"Cluster nodes not ready in 30 seconds." << endl;
 
  113     return NDBT_ProgramExit(NDBT_FAILED);
 
  116   Ndb MyNdb( &con, _db);
 
  118   if(MyNdb.init() != 0)
 
  120     ERR(MyNdb.getNdbError());
 
  121     return NDBT_ProgramExit(NDBT_FAILED);
 
  125   for(
int i = 0; 
i<argc; 
i++)
 
  127     const char* _tabname = argv[
i];
 
  130       NDBT_Table::discoverTableFromDb(&MyNdb, _tabname);
 
  133       ndbout << 
" Table " << _tabname << 
" does not exist!" << endl;
 
  134       return NDBT_ProgramExit(NDBT_WRONGARGS);
 
  138       ndbout << 
" Discovered " << _tabname << endl;
 
  140     tables.push_back(pTab);
 
  144   HugoQueryBuilder::OptionMask mask = 0;
 
  160   tmp.split(list, 
",");
 
  161   for (
size_t i = 0; 
i<list.size(); 
i++)
 
  164     for (
int o = 0; _ops[o].name != 0; o++)
 
  166       if (strcasecmp(list[
i].c_str(), _ops[o].
name) == 0)
 
  169         mask |= _ops[o].option;
 
  175       ndbout << 
"Unknown option " << list[
i].c_str() << 
", ignoring" << endl;
 
  181     _seed = (unsigned)NdbTick_CurrentMillisecond();
 
  183   ndbout << 
"--seed=" << _seed << endl;
 
  186   for (
int i = 0; (_loops == 0) || (
i < _loops);)
 
  190       ndbout << 
"******\tbuilding new query (mask: 0x" << hex 
 
  191              << (Uint64)mask << 
")" << endl;
 
  194     builder.setJoinLevel(_depth);
 
  195     const NdbQueryDef * q = builder.createQuery(&MyNdb);
 
  198       q->
print(); ndbout << endl;
 
  201     for (
int j = 0; j < _loops_per_query && ((_loops == 0) || (
i < _loops));
 
  206       if (q->isScanQuery())
 
  208         res = hq.runScanQuery(&MyNdb);
 
  212         res = hq.runLookupQuery(&MyNdb, _records, _batch);
 
  216         return NDBT_ProgramExit(NDBT_FAILED);
 
  218       if (hq.m_rows_found.size() != 0)
 
  220         printf(
"\tfound: [ ");
 
  221         for (
size_t i = 0; i<hq.m_rows_found.size(); i++)
 
  223           printf(
"%u ", (Uint32)hq.m_rows_found[i]);
 
  230   return NDBT_ProgramExit(NDBT_OK);