#include <NdbApi.hpp>#include <NdbOut.hpp>#include <NdbTick.h>Include dependency graph for slow_select.cpp:

Classes | |
| struct | S_Scan |
Defines | |
| #define | require(x) if(!(x)) { ndbout << "LINE: " << __LINE__ << endl;abort(); } |
| #define | require2(o, x) if(!(x)) { ndbout << o->getNdbError() << endl; abort(); } |
Functions | |
| void | lookup () |
| int | main (void) |
Variables | |
| S_Scan | g_scans [] |
| Uint32 | g_affiliateid = 2 |
| Uint32 | g_formatids [] = { 8, 31, 76 } |
| Uint64 | start |
| Uint32 | g_artistid = 0 |
| Uint32 | g_subgenreid = 0 |
| NdbConnection * | g_trans = 0 |
|
|
|
|
|
|
|
|
00199 {
00200 {
00201 NdbOperation* op = g_trans->getNdbOperation("artists");
00202 require2(g_trans, op);
00203 require2(op, op->readTuple() == 0);
00204 require2(op, op->equal("artistid", g_artistid) == 0);
00205 require2(op, op->getValue("name"));
00206 }
00207
00208 {
00209 NdbOperation* op = g_trans->getNdbOperation("subgenres");
00210 require2(g_trans, op);
00211 require2(op, op->readTuple() == 0);
00212 require2(op, op->equal("subgenreid", g_subgenreid) == 0);
00213 require2(op, op->getValue("name"));
00214 }
00215
00216 static int loop = 0;
00217 if(loop++ >= 16){
00218 loop = 0;
00219 require(g_trans->execute(NoCommit) == 0);
00220 }
00221 //require(g_trans->restart() == 0);
00222 }
|
|
|
00038 {
00039 ndb_init();
00040 Ndb g_ndb("test");
00041 g_ndb.init(1024);
00042
00043 require(g_ndb.waitUntilReady() == 0);
00044
00045 while(true){
00046 g_trans = g_ndb.startTransaction();
00047 require(g_trans);
00048
00049 size_t i, j;
00050 const size_t cnt = sizeof(g_scans)/sizeof(g_scans[0]);
00051
00052 start = NdbTick_CurrentMillisecond();
00053
00054 for(i = 0; i<cnt; i++){
00055 ndbout_c("starting scan on: %s %s",
00056 g_scans[i].m_table, g_scans[i].m_index);
00057 g_scans[i].m_scan = g_trans->getNdbIndexScanOperation(g_scans[i].m_index,
00058 g_scans[i].m_table);
00059 NdbIndexScanOperation* scan = g_scans[i].m_scan;
00060 require(scan);
00061 g_scans[i].m_result = scan->readTuples(NdbScanOperation::LM_CommittedRead,
00062 0, 0, true);
00063 require(g_scans[i].m_result);
00064 }
00065
00066 require(!g_scans[0].m_scan->setBound((Uint32)0,
00067 NdbIndexScanOperation::BoundEQ,
00068 &g_affiliateid,
00069 sizeof(g_affiliateid)));
00070 #if 0
00071 require(!g_scans[1].m_scan->setBound((Uint32)0,
00072 NdbIndexScanOperation::BoundLE,
00073 &g_formatids[0],
00074 sizeof(g_formatids[0])));
00075 #endif
00076
00077 NdbScanFilter sf(g_scans[1].m_scan);
00078 sf.begin(NdbScanFilter::OR);
00079 sf.eq(2, g_formatids[0]);
00080 sf.eq(2, g_formatids[1]);
00081 sf.eq(2, g_formatids[2]);
00082 sf.end();
00083
00084 // affiliatestometa
00085 require(g_scans[0].m_scan->getValue("uniquekey"));
00086 require(g_scans[0].m_scan->getValue("xml"));
00087
00088 // media
00089 require(g_scans[1].m_scan->getValue("path"));
00090 require(g_scans[1].m_scan->getValue("mediaid"));
00091 require(g_scans[1].m_scan->getValue("formatid"));
00092
00093 // meta
00094 require(g_scans[2].m_scan->getValue("name"));
00095 require(g_scans[2].m_scan->getValue("xml"));
00096
00097 // artiststometamap
00098 require(g_scans[3].m_scan->getValue("artistid", (char*)&g_artistid));
00099
00100 // subgenrestometamap
00101 require(g_scans[4].m_scan->getValue("subgenreid", (char*)&g_subgenreid));
00102
00103 for(i = 0; i<cnt; i++){
00104 g_scans[i].m_scan->getValue("metaid", (char*)&g_scans[i].metaid);
00105 }
00106
00107 g_trans->execute(NoCommit, AbortOnError, 1);
00108
00109 Uint32 max_val = 0;
00110 Uint32 match_val = 0;
00111
00112 S_Scan * F [5], * Q [5], * nextF [5];
00113 Uint32 F_sz = 0, Q_sz = 0;
00114 for(i = 0; i<cnt; i++){
00115 F_sz++;
00116 F[i] = &g_scans[i];
00117 }
00118
00119 Uint32 match_count = 0;
00120 while(F_sz > 0){
00121 Uint32 prev_F_sz = F_sz;
00122 F_sz = 0;
00123 bool found = false;
00124 //for(i = 0; i<cnt; i++)
00125 //ndbout_c("%s - %d", g_scans[i].m_table, g_scans[i].metaid);
00126
00127 for(i = 0; i<prev_F_sz; i++){
00128 int res = F[i]->m_result->nextResult();
00129 if(res == -1)
00130 abort();
00131
00132 if(res == 1){
00133 continue;
00134 }
00135
00136 Uint32 metaid = F[i]->metaid;
00137 F[i]->row_count++;
00138
00139 if(metaid == match_val){
00140 //ndbout_c("flera");
00141 nextF[F_sz++] = F[i];
00142 require(F_sz >= 0 && F_sz <= cnt);
00143 F[i]->match_count++;
00144 Uint32 comb = 1;
00145 for(j = 0; j<cnt; j++){
00146 comb *= (&g_scans[j] == F[i] ? 1 : g_scans[j].match_count);
00147 }
00148 match_count += comb;
00149 found = true;
00150 continue;
00151 }
00152 if(metaid < max_val){
00153 nextF[F_sz++] = F[i];
00154 require(F_sz >= 0 && F_sz <= cnt);
00155 continue;
00156 }
00157 if(metaid > max_val){
00158 for(j = 0; j<Q_sz; j++)
00159 nextF[F_sz++] = Q[j];
00160 require(F_sz >= 0 && F_sz <= cnt);
00161 Q_sz = 0;
00162 max_val = metaid;
00163 }
00164 Q[Q_sz++] = F[i];
00165 require(Q_sz >= 0 && Q_sz <= cnt);
00166 }
00167 if(F_sz == 0 && Q_sz > 0){
00168 match_val = max_val;
00169 for(j = 0; j<Q_sz; j++){
00170 nextF[F_sz++] = Q[j];
00171 Q[j]->match_count = 1;
00172 }
00173 require(F_sz >= 0 && F_sz <= cnt);
00174 require(Q_sz >= 0 && Q_sz <= cnt);
00175 Q_sz = 0;
00176 match_count++;
00177 lookup();
00178 } else if(!found && F_sz + Q_sz < cnt){
00179 F_sz = 0;
00180 }
00181 require(F_sz >= 0 && F_sz <= cnt);
00182 for(i = 0; i<F_sz; i++)
00183 F[i] = nextF[i];
00184 }
00185
00186 start = NdbTick_CurrentMillisecond() - start;
00187 ndbout_c("Elapsed: %lldms", start);
00188
00189 ndbout_c("rows: %d", match_count);
00190 for(i = 0; i<cnt; i++){
00191 ndbout_c("%s : %d", g_scans[i].m_table, g_scans[i].row_count);
00192 }
00193 g_trans->close();
00194 }
00195 }
|
|
|
|
|
|
|
|
|
|
|
|
Initial value: {
{ "affiliatestometa", "ind_affiliatestometa", 0, 0, 0, 0, 0 },
{ "media", "metaid", 0, 0, 0, 0, 0 },
{ "meta", "PRIMARY", 0, 0, 0, 0, 0 },
{ "artiststometamap", "PRIMARY", 0, 0, 0, 0, 0 },
{ "subgenrestometamap", "metaid", 0, 0, 0, 0, 0 }
}
|
|
|
|
|
|
|
|
|
|
1.3.9.1