Commit 64382cdc authored by joreland@mysql.com's avatar joreland@mysql.com

wl2077 - ndb scan optimizations

parent 5e0d7711
...@@ -39,8 +39,9 @@ struct Parameter { ...@@ -39,8 +39,9 @@ struct Parameter {
#define P_LOOPS 8 #define P_LOOPS 8
#define P_CREATE 9 #define P_CREATE 9
#define P_LOAD 10 #define P_LOAD 10
#define P_RESET 11
#define P_MAX 11 #define P_MAX 12
static static
Parameter Parameter
...@@ -55,7 +56,8 @@ g_paramters[] = { ...@@ -55,7 +56,8 @@ g_paramters[] = {
{ "size", 1000000, 1, ~0 }, { "size", 1000000, 1, ~0 },
{ "iterations", 3, 1, ~0 }, { "iterations", 3, 1, ~0 },
{ "create_drop", 1, 0, 1 }, { "create_drop", 1, 0, 1 },
{ "data", 1, 0, 1 } { "data", 1, 0, 1 },
{ "q-reset bounds", 0, 1, 0 }
}; };
static Ndb* g_ndb = 0; static Ndb* g_ndb = 0;
...@@ -218,21 +220,29 @@ run_scan(){ ...@@ -218,21 +220,29 @@ run_scan(){
NDB_TICKS start1, stop; NDB_TICKS start1, stop;
int sum_time= 0; int sum_time= 0;
int sample_rows = 0;
NDB_TICKS sample_start = NdbTick_CurrentMillisecond();
Uint32 tot = g_paramters[P_ROWS].value; Uint32 tot = g_paramters[P_ROWS].value;
if(g_paramters[P_BOUND].value == 2 || g_paramters[P_FILT].value == 2)
iter *= g_paramters[P_ROWS].value;
NdbScanOperation * pOp = 0;
NdbIndexScanOperation * pIOp = 0;
NdbConnection * pTrans = 0;
NdbResultSet * rs = 0;
int check = 0;
for(int i = 0; i<iter; i++){ for(int i = 0; i<iter; i++){
start1 = NdbTick_CurrentMillisecond(); start1 = NdbTick_CurrentMillisecond();
NdbConnection * pTrans = g_ndb->startTransaction(); pTrans = pTrans ? pTrans : g_ndb->startTransaction();
if(!pTrans){ if(!pTrans){
g_err << "Failed to start transaction" << endl; g_err << "Failed to start transaction" << endl;
err(g_ndb->getNdbError()); err(g_ndb->getNdbError());
return -1; return -1;
} }
NdbScanOperation * pOp;
NdbIndexScanOperation * pIOp;
NdbResultSet * rs;
int par = g_paramters[P_PARRA].value; int par = g_paramters[P_PARRA].value;
int bat = g_paramters[P_BATCH].value; int bat = g_paramters[P_BATCH].value;
NdbScanOperation::LockMode lm; NdbScanOperation::LockMode lm;
...@@ -255,9 +265,17 @@ run_scan(){ ...@@ -255,9 +265,17 @@ run_scan(){
assert(pOp); assert(pOp);
rs = pOp->readTuples(lm, bat, par); rs = pOp->readTuples(lm, bat, par);
} else { } else {
pOp = pIOp = pTrans->getNdbIndexScanOperation(g_indexname, g_tablename); if(g_paramters[P_RESET].value == 0 || pIOp == 0)
{
pOp= pIOp= pTrans->getNdbIndexScanOperation(g_indexname, g_tablename);
bool ord = g_paramters[P_ACCESS].value == 2; bool ord = g_paramters[P_ACCESS].value == 2;
rs = pIOp->readTuples(lm, bat, par, ord); rs = pIOp->readTuples(lm, bat, par, ord);
}
else
{
pIOp->reset_bounds();
}
switch(g_paramters[P_BOUND].value){ switch(g_paramters[P_BOUND].value){
case 0: // All case 0: // All
break; break;
...@@ -267,20 +285,22 @@ run_scan(){ ...@@ -267,20 +285,22 @@ run_scan(){
case 2: { // 1 row case 2: { // 1 row
default: default:
assert(g_table->getNoOfPrimaryKeys() == 1); // only impl. so far assert(g_table->getNoOfPrimaryKeys() == 1); // only impl. so far
abort();
#if 0
int tot = g_paramters[P_ROWS].value; int tot = g_paramters[P_ROWS].value;
int row = rand() % tot; int row = rand() % tot;
#if 0
fix_eq_bound(pIOp, row); fix_eq_bound(pIOp, row);
#else
pIOp->setBound((Uint32)0, NdbIndexScanOperation::BoundEQ, &row);
#endif #endif
break; break;
} }
} }
if(g_paramters[P_RESET].value == 1)
goto execute;
} }
assert(pOp); assert(pOp);
assert(rs); assert(rs);
int check = 0;
switch(g_paramters[P_FILT].value){ switch(g_paramters[P_FILT].value){
case 0: // All case 0: // All
check = pOp->interpret_exit_ok(); check = pOp->interpret_exit_ok();
...@@ -312,7 +332,7 @@ run_scan(){ ...@@ -312,7 +332,7 @@ run_scan(){
for(int i = 0; i<g_table->getNoOfColumns(); i++){ for(int i = 0; i<g_table->getNoOfColumns(); i++){
pOp->getValue(i); pOp->getValue(i);
} }
execute:
int rows = 0; int rows = 0;
check = pTrans->execute(NoCommit); check = pTrans->execute(NoCommit);
assert(check == 0); assert(check == 0);
...@@ -333,19 +353,29 @@ run_scan(){ ...@@ -333,19 +353,29 @@ run_scan(){
return -1; return -1;
} }
assert(check == 1); assert(check == 1);
g_info << "Found " << rows << " rows" << endl; if(g_paramters[P_RESET].value == 0)
{
pTrans->close(); pTrans->close();
pTrans = 0;
}
stop = NdbTick_CurrentMillisecond(); stop = NdbTick_CurrentMillisecond();
int time_passed= (int)(stop - start1); int time_passed= (int)(stop - start1);
g_err.println("Time: %d ms = %u rows/sec", time_passed, sample_rows += rows;
(1000*tot)/time_passed);
sum_time+= time_passed; sum_time+= time_passed;
if(sample_rows >= tot)
{
int sample_time = (int)(stop - sample_start);
g_info << "Found " << sample_rows << " rows" << endl;
g_err.println("Time: %d ms = %u rows/sec", sample_time,
(1000*sample_rows)/sample_time);
sample_rows = 0;
sample_start = stop;
}
} }
sum_time= sum_time / iter;
g_err.println("Avg time: %d ms = %u rows/sec", sum_time, g_err.println("Avg time: %d ms = %u rows/sec", sum_time/iter,
(1000*tot)/sum_time); (1000*tot*iter)/sum_time);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment