Commit f34a7ff4 authored by unknown's avatar unknown

run in loop

parent 042d6209
...@@ -41,152 +41,155 @@ main(void){ ...@@ -41,152 +41,155 @@ main(void){
require(g_ndb.waitUntilReady() == 0); require(g_ndb.waitUntilReady() == 0);
g_trans = g_ndb.startTransaction(); while(true){
require(g_trans); g_trans = g_ndb.startTransaction();
require(g_trans);
size_t i, j; size_t i, j;
const size_t cnt = sizeof(g_scans)/sizeof(g_scans[0]); const size_t cnt = sizeof(g_scans)/sizeof(g_scans[0]);
start = NdbTick_CurrentMillisecond(); start = NdbTick_CurrentMillisecond();
for(i = 0; i<cnt; i++){ for(i = 0; i<cnt; i++){
ndbout_c("starting scan on: %s %s", ndbout_c("starting scan on: %s %s",
g_scans[i].m_table, g_scans[i].m_index); g_scans[i].m_table, g_scans[i].m_index);
g_scans[i].m_scan = g_trans->getNdbIndexScanOperation(g_scans[i].m_index, g_scans[i].m_scan = g_trans->getNdbIndexScanOperation(g_scans[i].m_index,
g_scans[i].m_table); g_scans[i].m_table);
NdbIndexScanOperation* scan = g_scans[i].m_scan; NdbIndexScanOperation* scan = g_scans[i].m_scan;
require(scan); require(scan);
g_scans[i].m_result = scan->readTuples(NdbScanOperation::LM_CommittedRead, g_scans[i].m_result = scan->readTuples(NdbScanOperation::LM_CommittedRead,
0, 0, true); 0, 0, true);
require(g_scans[i].m_result); require(g_scans[i].m_result);
} }
require(!g_scans[0].m_scan->setBound((Uint32)0, require(!g_scans[0].m_scan->setBound((Uint32)0,
NdbIndexScanOperation::BoundEQ, NdbIndexScanOperation::BoundEQ,
&g_affiliateid, &g_affiliateid,
sizeof(g_affiliateid))); sizeof(g_affiliateid)));
#if 0 #if 0
require(!g_scans[1].m_scan->setBound((Uint32)0, require(!g_scans[1].m_scan->setBound((Uint32)0,
NdbIndexScanOperation::BoundLE, NdbIndexScanOperation::BoundLE,
&g_formatids[0], &g_formatids[0],
sizeof(g_formatids[0]))); sizeof(g_formatids[0])));
#endif #endif
NdbScanFilter sf(g_scans[1].m_scan); NdbScanFilter sf(g_scans[1].m_scan);
sf.begin(NdbScanFilter::OR); sf.begin(NdbScanFilter::OR);
sf.eq(2, g_formatids[0]); sf.eq(2, g_formatids[0]);
sf.eq(2, g_formatids[1]); sf.eq(2, g_formatids[1]);
sf.eq(2, g_formatids[2]); sf.eq(2, g_formatids[2]);
sf.end(); sf.end();
// affiliatestometa // affiliatestometa
require(g_scans[0].m_scan->getValue("uniquekey")); require(g_scans[0].m_scan->getValue("uniquekey"));
require(g_scans[0].m_scan->getValue("xml")); require(g_scans[0].m_scan->getValue("xml"));
// media // media
require(g_scans[1].m_scan->getValue("path")); require(g_scans[1].m_scan->getValue("path"));
require(g_scans[1].m_scan->getValue("mediaid")); require(g_scans[1].m_scan->getValue("mediaid"));
require(g_scans[1].m_scan->getValue("formatid")); require(g_scans[1].m_scan->getValue("formatid"));
// meta // meta
require(g_scans[2].m_scan->getValue("name")); require(g_scans[2].m_scan->getValue("name"));
require(g_scans[2].m_scan->getValue("xml")); require(g_scans[2].m_scan->getValue("xml"));
// artiststometamap // artiststometamap
require(g_scans[3].m_scan->getValue("artistid", (char*)&g_artistid)); require(g_scans[3].m_scan->getValue("artistid", (char*)&g_artistid));
// subgenrestometamap // subgenrestometamap
require(g_scans[4].m_scan->getValue("subgenreid", (char*)&g_subgenreid)); require(g_scans[4].m_scan->getValue("subgenreid", (char*)&g_subgenreid));
for(i = 0; i<cnt; i++){ for(i = 0; i<cnt; i++){
g_scans[i].m_scan->getValue("metaid", (char*)&g_scans[i].metaid); g_scans[i].m_scan->getValue("metaid", (char*)&g_scans[i].metaid);
} }
g_trans->execute(NoCommit, AbortOnError, 1); g_trans->execute(NoCommit, AbortOnError, 1);
Uint32 max_val = 0; Uint32 max_val = 0;
Uint32 match_val = 0; Uint32 match_val = 0;
S_Scan * F [5], * Q [5], * nextF [5]; S_Scan * F [5], * Q [5], * nextF [5];
Uint32 F_sz = 0, Q_sz = 0; Uint32 F_sz = 0, Q_sz = 0;
for(i = 0; i<cnt; i++){ for(i = 0; i<cnt; i++){
F_sz++; F_sz++;
F[i] = &g_scans[i]; F[i] = &g_scans[i];
} }
Uint32 match_count = 0; Uint32 match_count = 0;
while(F_sz > 0){ while(F_sz > 0){
Uint32 prev_F_sz = F_sz; Uint32 prev_F_sz = F_sz;
F_sz = 0; F_sz = 0;
bool found = false; bool found = false;
//for(i = 0; i<cnt; i++) //for(i = 0; i<cnt; i++)
//ndbout_c("%s - %d", g_scans[i].m_table, g_scans[i].metaid); //ndbout_c("%s - %d", g_scans[i].m_table, g_scans[i].metaid);
for(i = 0; i<prev_F_sz; i++){ for(i = 0; i<prev_F_sz; i++){
int res = F[i]->m_result->nextResult(); int res = F[i]->m_result->nextResult();
if(res == -1) if(res == -1)
abort(); abort();
if(res == 1){ if(res == 1){
continue; continue;
} }
Uint32 metaid = F[i]->metaid; Uint32 metaid = F[i]->metaid;
F[i]->row_count++; F[i]->row_count++;
if(metaid == match_val){ if(metaid == match_val){
//ndbout_c("flera"); //ndbout_c("flera");
nextF[F_sz++] = F[i]; nextF[F_sz++] = F[i];
require(F_sz >= 0 && F_sz <= cnt); require(F_sz >= 0 && F_sz <= cnt);
F[i]->match_count++; F[i]->match_count++;
Uint32 comb = 1; Uint32 comb = 1;
for(j = 0; j<cnt; j++){ for(j = 0; j<cnt; j++){
comb *= (&g_scans[j] == F[i] ? 1 : g_scans[j].match_count); comb *= (&g_scans[j] == F[i] ? 1 : g_scans[j].match_count);
}
match_count += comb;
found = true;
continue;
} }
match_count += comb; if(metaid < max_val){
found = true; nextF[F_sz++] = F[i];
continue; require(F_sz >= 0 && F_sz <= cnt);
} continue;
if(metaid < max_val){ }
nextF[F_sz++] = F[i]; if(metaid > max_val){
require(F_sz >= 0 && F_sz <= cnt); for(j = 0; j<Q_sz; j++)
continue; nextF[F_sz++] = Q[j];
require(F_sz >= 0 && F_sz <= cnt);
Q_sz = 0;
max_val = metaid;
}
Q[Q_sz++] = F[i];
require(Q_sz >= 0 && Q_sz <= cnt);
} }
if(metaid > max_val){ if(F_sz == 0 && Q_sz > 0){
for(j = 0; j<Q_sz; j++) match_val = max_val;
for(j = 0; j<Q_sz; j++){
nextF[F_sz++] = Q[j]; nextF[F_sz++] = Q[j];
Q[j]->match_count = 1;
}
require(F_sz >= 0 && F_sz <= cnt); require(F_sz >= 0 && F_sz <= cnt);
require(Q_sz >= 0 && Q_sz <= cnt);
Q_sz = 0; Q_sz = 0;
max_val = metaid; match_count++;
} lookup();
Q[Q_sz++] = F[i]; } else if(!found && F_sz + Q_sz < cnt){
require(Q_sz >= 0 && Q_sz <= cnt); F_sz = 0;
}
if(F_sz == 0 && Q_sz > 0){
match_val = max_val;
for(j = 0; j<Q_sz; j++){
nextF[F_sz++] = Q[j];
Q[j]->match_count = 1;
} }
require(F_sz >= 0 && F_sz <= cnt); require(F_sz >= 0 && F_sz <= cnt);
require(Q_sz >= 0 && Q_sz <= cnt); for(i = 0; i<F_sz; i++)
Q_sz = 0; F[i] = nextF[i];
match_count++;
lookup();
} else if(!found && F_sz + Q_sz < cnt){
F_sz = 0;
} }
require(F_sz >= 0 && F_sz <= cnt);
for(i = 0; i<F_sz; i++)
F[i] = nextF[i];
}
start = NdbTick_CurrentMillisecond() - start; start = NdbTick_CurrentMillisecond() - start;
ndbout_c("Elapsed: %lldms", start); ndbout_c("Elapsed: %lldms", start);
ndbout_c("rows: %d", match_count); ndbout_c("rows: %d", match_count);
for(i = 0; i<cnt; i++){ for(i = 0; i<cnt; i++){
ndbout_c("%s : %d", g_scans[i].m_table, g_scans[i].row_count); ndbout_c("%s : %d", g_scans[i].m_table, g_scans[i].row_count);
}
g_trans->close();
} }
} }
......
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