20 #include <NDBT_Test.hpp>
21 #include <HugoTransactions.hpp>
22 #include <UtilTransactions.hpp>
23 #include <NdbRestarter.hpp>
25 #include <ndbapi_limits.h>
27 const unsigned MaxTableAttrs = NDB_MAX_ATTRIBUTES_IN_TABLE;
28 const unsigned MaxIndexAttrs = NDB_MAX_ATTRIBUTES_IN_INDEX;
29 const unsigned MaxIndexes = 20;
34 unsigned i = random();
42 Ndb* pNdb = GETNDB(step);
46 g_err << pTab->
getName() <<
": listIndexes failed" << endl;
50 for (
unsigned i = 0;
i < list.
count;
i++) {
52 pInd->setTable(pTab->
getName());
53 g_info <<
"Drop index:" << endl << *pInd;
54 if (pInd->dropIndexInDb(pNdb) != 0) {
61 static Uint32 workaround[1000];
67 sprintf(key,
"%s-%s", name, pTab->
getName());
76 sprintf(key,
"%s-%s", name, pTab->
getName());
79 assert(num != (Uint32)-1);
88 Ndb* pNdb = GETNDB(step);
89 unsigned numTabAttrs = pTab->getNumAttributes();
90 unsigned numIndex = 0;
91 while (numIndex < MaxIndexes) {
92 if (numIndex != 0 && urandom(10) == 0)
95 sprintf(buf,
"%s_X%03d", pTab->
getName(), numIndex);
96 NDBT_Index* pInd =
new NDBT_Index(buf);
97 pInd->setTable(pTab->
getName());
99 pInd->setLogging(
false);
100 unsigned numAttrs = 0;
101 while (numAttrs < MaxIndexAttrs) {
102 if (numAttrs != 0 && urandom(5) == 0)
104 unsigned i = urandom(numTabAttrs);
107 for (
unsigned j = 0; j < numAttrs; j++) {
108 if (strcmp(pAttr->
getName(), pInd->getAttribute(j)->getName()) == 0) {
115 pInd->addAttribute(*pAttr);
118 g_info <<
"Create index:" << endl << *pInd;
119 if (pInd->createIndexInDb(pNdb,
false) != 0)
123 setTableProperty(ctx, pTab,
"numIndex", numIndex);
124 g_info <<
"Created " << numIndex <<
" indexes on " << pTab->
getName() << endl;
132 Ndb* pNdb = GETNDB(step);
134 g_info <<
"Insert: " << pTab->
getName() << endl;
136 ret = hugoTrans.loadTable(pNdb, ctx->getNumRecords(), 100);
138 g_err <<
"ERR: " << step->getName() <<
"failed" << endl;
148 Ndb* pNdb = GETNDB(step);
149 unsigned cntIndex = getTableProperty(ctx, pTab,
"numIndex");
150 for (
unsigned numIndex = 0; numIndex < cntIndex; numIndex++) {
152 sprintf(buf,
"%s_X%03d", pTab->
getName(), numIndex);
153 NDBT_Index* pInd = NDBT_Index::discoverIndexFromDb(pNdb, buf, pTab->
getName());
155 g_info <<
"Scan index:" << pInd->getName() << endl << *pInd;
168 if (pOp->openScanRead() != 0) {
173 if (pCon->executeScan() != 0) {
180 int ret = pCon->nextScanResult();
183 }
else if (ret == 1) {
192 g_info <<
"Scanned " << rows <<
" rows" << endl;
197 NDBT_TESTSUITE(testOrderedIndex);
200 "Drop any old indexes") {
201 INITIALIZER(runDropIndex);
205 "Create ordered indexes") {
206 INITIALIZER(runCreateIndex);
210 "Run inserts and updates") {
211 INITIALIZER(runInsertUpdate);
215 "Full scan on each ordered index") {
216 INITIALIZER(runFullScan);
218 NDBT_TESTSUITE_END(testOrderedIndex);
221 main(
int argc,
const char** argv)
224 return testOrderedIndex.execute(argc, argv);