mariadb/ndb/test/ndbapi/slow_select.cpp

221 lines
5.3 KiB
C++
Raw Normal View History

#include <NdbApi.hpp>
#include <NdbOut.hpp>
#include <NdbTick.h>
struct
S_Scan {
const char * m_table;
const char * m_index;
NdbIndexScanOperation * m_scan;
Uint32 metaid;
Uint32 match_count;
Uint32 row_count;
};
static S_Scan g_scans[] = {
wl2126 - ndb - fix last unhandled part of read_multi_range reading sorted multi_range with several range-scans BitKeeper/deleted/.del-NdbResultSet.hpp~e0042f4c18088ff6: Delete: ndb/include/ndbapi/NdbResultSet.hpp BitKeeper/deleted/.del-NdbResultSet.cpp~84d192cf3f42600d: Delete: ndb/src/ndbapi/NdbResultSet.cpp ndb/include/ndbapi/NdbApi.hpp: Remove NdbResultSet ndb/include/ndbapi/NdbIndexScanOperation.hpp: Remove NdbResultSet ndb/include/ndbapi/NdbScanOperation.hpp: Remove NdbResultSet ndb/src/ndbapi/Makefile.am: Remove NdbResultSet ndb/src/ndbapi/NdbConnection.cpp: Remove NdbResultSet ndb/src/ndbapi/NdbIndexOperation.cpp: Remove NdbResultSet ndb/src/ndbapi/NdbScanOperation.cpp: Remove NdbResultSet ndb/test/include/HugoOperations.hpp: Remove NdbResultSet ndb/test/ndbapi/ScanFunctions.hpp: Remove NdbResultSet ndb/test/ndbapi/ScanInterpretTest.hpp: Remove NdbResultSet ndb/test/ndbapi/bank/Bank.cpp: Remove NdbResultSet ndb/test/ndbapi/bank/BankLoad.cpp: Remove NdbResultSet ndb/test/ndbapi/slow_select.cpp: Remove NdbResultSet ndb/test/ndbapi/testBlobs.cpp: Remove NdbResultSet ndb/test/ndbapi/testDataBuffers.cpp: Remove NdbResultSet ndb/test/ndbapi/testDeadlock.cpp: Remove NdbResultSet ndb/test/ndbapi/testIndex.cpp: Remove NdbResultSet ndb/test/ndbapi/testOIBasic.cpp: Remove NdbResultSet ndb/test/ndbapi/testReadPerf.cpp: Remove NdbResultSet ndb/test/ndbapi/testScan.cpp: Remove NdbResultSet ndb/test/ndbapi/testScanPerf.cpp: Remove NdbResultSet ndb/test/src/HugoOperations.cpp: Remove NdbResultSet ndb/test/src/HugoTransactions.cpp: Remove NdbResultSet ndb/test/src/UtilTransactions.cpp: Remove NdbResultSet ndb/tools/delete_all.cpp: Remove NdbResultSet ndb/tools/select_all.cpp: Remove NdbResultSet ndb/tools/select_count.cpp: Remove NdbResultSet sql/ha_ndbcluster.cc: 1) Fix a = 3 -> a= 3 2) Impl. last part of wl2126 ordered "multi ordered scan"
2004-12-07 15:15:49 +01:00
{ "affiliatestometa", "ind_affiliatestometa", 0, 0, 0, 0 },
{ "media", "metaid", 0, 0, 0, 0 },
{ "meta", "PRIMARY", 0, 0, 0, 0 },
{ "artiststometamap", "PRIMARY", 0, 0, 0, 0 },
{ "subgenrestometamap", "metaid", 0, 0, 0, 0 }
};
#define require(x) if(!(x)) { ndbout << "LINE: " << __LINE__ << endl;abort(); }
#define require2(o, x) if(!(x)) { ndbout << o->getNdbError() << endl; abort(); }
Uint32 g_affiliateid = 2;
Uint32 g_formatids[] = { 8, 31, 76 };
Uint64 start;
Uint32 g_artistid = 0;
Uint32 g_subgenreid = 0;
NdbConnection* g_trans = 0;
static void lookup();
int
main(void){
ndb_init() to all ndb programs ndb/examples/ndbapi_async_example/ndbapi_async.cpp: ndb_init() ndb/examples/ndbapi_example1/ndbapi_example1.cpp: ndb_init() ndb/examples/ndbapi_example2/ndbapi_example2.cpp: ndb_init() ndb/examples/ndbapi_example3/ndbapi_example3.cpp: ndb_init() ndb/examples/ndbapi_example4/ndbapi_example4.cpp: ndb_init() ndb/examples/ndbapi_example5/ndbapi_example5.cpp: ndb_init() ndb/examples/ndbapi_scan_example/ndbapi_scan.cpp: ndb_init() ndb/examples/select_all/select_all.cpp: ndb_init() ndb/include/ndb_global.h: ndb_init() ndb/src/common/util/Makefile.am: ndb_init() ndb/src/kernel/blocks/backup/read.cpp: ndb_init() ndb/src/kernel/blocks/backup/restore/main.cpp: ndb_init() ndb/src/kernel/main.cpp: ndb_init() ndb/src/kernel/vm/Configuration.cpp: ndb_init() ndb/src/mgmclient/main.cpp: ndb_init() ndb/src/mgmsrv/main.cpp: ndb_init() ndb/src/mgmsrv/mkconfig/mkconfig.cpp: ndb_init() ndb/src/ndbapi/Ndbinit.cpp: ndb_init() ndb/test/ndbapi/acid.cpp: ndb_init() ndb/test/ndbapi/acid2.cpp: ndb_init() ndb/test/ndbapi/benchronja.cpp: ndb_init() ndb/test/ndbapi/bulk_copy.cpp: ndb_init() ndb/test/ndbapi/cdrserver.cpp: ndb_init() ndb/test/ndbapi/celloDb.cpp: ndb_init() ndb/test/ndbapi/create_all_tabs.cpp: ndb_init() ndb/test/ndbapi/create_tab.cpp: ndb_init() ndb/test/ndbapi/drop_all_tabs.cpp: ndb_init() ndb/test/ndbapi/flexAsynch.cpp: ndb_init() ndb/test/ndbapi/flexBench.cpp: ndb_init() ndb/test/ndbapi/flexHammer.cpp: ndb_init() ndb/test/ndbapi/flexScan.cpp: ndb_init() ndb/test/ndbapi/flexTT.cpp: ndb_init() ndb/test/ndbapi/flexTimedAsynch.cpp: ndb_init() ndb/test/ndbapi/flex_bench_mysql.cpp: ndb_init() ndb/test/ndbapi/index.cpp: ndb_init() ndb/test/ndbapi/index2.cpp: ndb_init() ndb/test/ndbapi/initronja.cpp: ndb_init() ndb/test/ndbapi/interpreterInTup.cpp: ndb_init() ndb/test/ndbapi/mainAsyncGenerator.cpp: ndb_init() ndb/test/ndbapi/msa.cpp: ndb_init() ndb/test/ndbapi/restarter.cpp: ndb_init() ndb/test/ndbapi/restarter2.cpp: ndb_init() ndb/test/ndbapi/restarts.cpp: ndb_init() ndb/test/ndbapi/size.cpp: ndb_init() ndb/test/ndbapi/slow_select.cpp: ndb_init() ndb/test/ndbapi/testBackup.cpp: ndb_init() ndb/test/ndbapi/testBasic.cpp: ndb_init() ndb/test/ndbapi/testBasicAsynch.cpp: ndb_init() ndb/test/ndbapi/testBlobs.cpp: ndb_init() ndb/test/ndbapi/testDataBuffers.cpp: ndb_init() ndb/test/ndbapi/testDeadlock.cpp: ndb_init() ndb/test/ndbapi/testDict.cpp: ndb_init() ndb/test/ndbapi/testGrep.cpp: ndb_init() ndb/test/ndbapi/testGrepVerify.cpp: ndb_init() ndb/test/ndbapi/testIndex.cpp: ndb_init() ndb/test/ndbapi/testInterpreter.cpp: ndb_init() ndb/test/ndbapi/testMgm.cpp: ndb_init() ndb/test/ndbapi/bank/bankCreator.cpp: ndb_init() ndb/test/ndbapi/bank/bankMakeGL.cpp: ndb_init() ndb/test/ndbapi/bank/bankSumAccounts.cpp: ndb_init() ndb/test/ndbapi/bank/bankTimer.cpp: ndb_init() ndb/test/ndbapi/bank/bankTransactionMaker.cpp: ndb_init() ndb/test/ndbapi/bank/bankValidateAllGLs.cpp: ndb_init() ndb/test/ndbapi/bank/testBank.cpp: ndb_init() ndb/test/ndbapi/testNdbApi.cpp: ndb_init() ndb/test/ndbapi/testNodeRestart.cpp: ndb_init() ndb/test/ndbapi/testOIBasic.cpp: ndb_init() ndb/test/ndbapi/testOperations.cpp: ndb_init() ndb/test/ndbapi/testOrderedIndex.cpp: ndb_init() ndb/test/ndbapi/testReadPerf.cpp: ndb_init() ndb/test/ndbapi/testRestartGci.cpp: ndb_init() ndb/test/ndbapi/testScan.cpp: ndb_init() ndb/test/ndbapi/testScanInterpreter.cpp: ndb_init() ndb/test/ndbapi/testScanPerf.cpp: ndb_init() ndb/test/ndbapi/testSystemRestart.cpp: ndb_init() ndb/test/ndbapi/testTimeout.cpp: ndb_init() ndb/test/ndbapi/testTransactions.cpp: ndb_init() ndb/test/ndbapi/test_event.cpp: ndb_init() ndb/test/run-test/main.cpp: ndb_init() ndb/test/src/NDBT_Test.cpp: ndb_init() ndb/test/tools/copy_tab.cpp: ndb_init() ndb/test/tools/cpcc.cpp: ndb_init() ndb/test/tools/create_index.cpp: ndb_init() ndb/test/tools/hugoCalculator.cpp: ndb_init() ndb/test/tools/hugoFill.cpp: ndb_init() ndb/test/tools/hugoLoad.cpp: ndb_init() ndb/test/tools/hugoLockRecords.cpp: ndb_init() ndb/test/tools/hugoPkDelete.cpp: ndb_init() ndb/test/tools/hugoPkRead.cpp: ndb_init() ndb/test/tools/hugoPkReadRecord.cpp: ndb_init() ndb/test/tools/hugoPkUpdate.cpp: ndb_init() ndb/test/tools/hugoScanRead.cpp: ndb_init() ndb/test/tools/hugoScanUpdate.cpp: ndb_init() ndb/test/tools/restart.cpp: ndb_init() ndb/test/tools/transproxy.cpp: ndb_init() ndb/test/tools/verify_index.cpp: ndb_init() ndb/tools/delete_all.cpp: ndb_init() ndb/tools/desc.cpp: ndb_init() ndb/tools/drop_index.cpp: ndb_init() ndb/tools/drop_tab.cpp: ndb_init() ndb/tools/listTables.cpp: ndb_init() ndb/tools/ndbsql.cpp: ndb_init() ndb/tools/select_all.cpp: ndb_init() ndb/tools/select_count.cpp: ndb_init() ndb/tools/waiter.cpp: ndb_init()
2004-09-15 11:49:18 +02:00
ndb_init();
Ndb g_ndb("test");
g_ndb.init(1024);
require(g_ndb.waitUntilReady() == 0);
2004-08-31 16:27:31 +02:00
while(true){
g_trans = g_ndb.startTransaction();
require(g_trans);
2004-08-31 16:27:31 +02:00
size_t i, j;
const size_t cnt = sizeof(g_scans)/sizeof(g_scans[0]);
start = NdbTick_CurrentMillisecond();
for(i = 0; i<cnt; i++){
ndbout_c("starting scan on: %s %s",
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_table);
NdbIndexScanOperation* scan = g_scans[i].m_scan;
require(scan);
wl2126 - ndb - fix last unhandled part of read_multi_range reading sorted multi_range with several range-scans BitKeeper/deleted/.del-NdbResultSet.hpp~e0042f4c18088ff6: Delete: ndb/include/ndbapi/NdbResultSet.hpp BitKeeper/deleted/.del-NdbResultSet.cpp~84d192cf3f42600d: Delete: ndb/src/ndbapi/NdbResultSet.cpp ndb/include/ndbapi/NdbApi.hpp: Remove NdbResultSet ndb/include/ndbapi/NdbIndexScanOperation.hpp: Remove NdbResultSet ndb/include/ndbapi/NdbScanOperation.hpp: Remove NdbResultSet ndb/src/ndbapi/Makefile.am: Remove NdbResultSet ndb/src/ndbapi/NdbConnection.cpp: Remove NdbResultSet ndb/src/ndbapi/NdbIndexOperation.cpp: Remove NdbResultSet ndb/src/ndbapi/NdbScanOperation.cpp: Remove NdbResultSet ndb/test/include/HugoOperations.hpp: Remove NdbResultSet ndb/test/ndbapi/ScanFunctions.hpp: Remove NdbResultSet ndb/test/ndbapi/ScanInterpretTest.hpp: Remove NdbResultSet ndb/test/ndbapi/bank/Bank.cpp: Remove NdbResultSet ndb/test/ndbapi/bank/BankLoad.cpp: Remove NdbResultSet ndb/test/ndbapi/slow_select.cpp: Remove NdbResultSet ndb/test/ndbapi/testBlobs.cpp: Remove NdbResultSet ndb/test/ndbapi/testDataBuffers.cpp: Remove NdbResultSet ndb/test/ndbapi/testDeadlock.cpp: Remove NdbResultSet ndb/test/ndbapi/testIndex.cpp: Remove NdbResultSet ndb/test/ndbapi/testOIBasic.cpp: Remove NdbResultSet ndb/test/ndbapi/testReadPerf.cpp: Remove NdbResultSet ndb/test/ndbapi/testScan.cpp: Remove NdbResultSet ndb/test/ndbapi/testScanPerf.cpp: Remove NdbResultSet ndb/test/src/HugoOperations.cpp: Remove NdbResultSet ndb/test/src/HugoTransactions.cpp: Remove NdbResultSet ndb/test/src/UtilTransactions.cpp: Remove NdbResultSet ndb/tools/delete_all.cpp: Remove NdbResultSet ndb/tools/select_all.cpp: Remove NdbResultSet ndb/tools/select_count.cpp: Remove NdbResultSet sql/ha_ndbcluster.cc: 1) Fix a = 3 -> a= 3 2) Impl. last part of wl2126 ordered "multi ordered scan"
2004-12-07 15:15:49 +01:00
require(scan->readTuples(NdbScanOperation::LM_CommittedRead,
0, 0, true) == 0);
2004-08-31 16:27:31 +02:00
}
2004-08-31 16:27:31 +02:00
require(!g_scans[0].m_scan->setBound((Uint32)0,
NdbIndexScanOperation::BoundEQ,
&g_affiliateid,
sizeof(g_affiliateid)));
#if 0
2004-08-31 16:27:31 +02:00
require(!g_scans[1].m_scan->setBound((Uint32)0,
NdbIndexScanOperation::BoundLE,
&g_formatids[0],
sizeof(g_formatids[0])));
#endif
2004-08-31 16:27:31 +02:00
NdbScanFilter sf(g_scans[1].m_scan);
sf.begin(NdbScanFilter::OR);
sf.eq(2, g_formatids[0]);
sf.eq(2, g_formatids[1]);
sf.eq(2, g_formatids[2]);
sf.end();
// affiliatestometa
require(g_scans[0].m_scan->getValue("uniquekey"));
require(g_scans[0].m_scan->getValue("xml"));
// media
require(g_scans[1].m_scan->getValue("path"));
require(g_scans[1].m_scan->getValue("mediaid"));
require(g_scans[1].m_scan->getValue("formatid"));
2004-08-31 16:27:31 +02:00
// meta
require(g_scans[2].m_scan->getValue("name"));
require(g_scans[2].m_scan->getValue("xml"));
2004-08-31 16:27:31 +02:00
// artiststometamap
require(g_scans[3].m_scan->getValue("artistid", (char*)&g_artistid));
2004-08-31 16:27:31 +02:00
// subgenrestometamap
require(g_scans[4].m_scan->getValue("subgenreid", (char*)&g_subgenreid));
2004-08-31 16:27:31 +02:00
for(i = 0; i<cnt; i++){
g_scans[i].m_scan->getValue("metaid", (char*)&g_scans[i].metaid);
}
2004-08-31 16:27:31 +02:00
g_trans->execute(NoCommit, AbortOnError, 1);
2004-08-31 16:27:31 +02:00
Uint32 max_val = 0;
Uint32 match_val = 0;
2004-08-31 16:27:31 +02:00
S_Scan * F [5], * Q [5], * nextF [5];
Uint32 F_sz = 0, Q_sz = 0;
for(i = 0; i<cnt; i++){
F_sz++;
F[i] = &g_scans[i];
}
2004-08-31 16:27:31 +02:00
Uint32 match_count = 0;
while(F_sz > 0){
Uint32 prev_F_sz = F_sz;
F_sz = 0;
bool found = false;
//for(i = 0; i<cnt; i++)
//ndbout_c("%s - %d", g_scans[i].m_table, g_scans[i].metaid);
2004-08-31 16:27:31 +02:00
for(i = 0; i<prev_F_sz; i++){
wl2126 - ndb - fix last unhandled part of read_multi_range reading sorted multi_range with several range-scans BitKeeper/deleted/.del-NdbResultSet.hpp~e0042f4c18088ff6: Delete: ndb/include/ndbapi/NdbResultSet.hpp BitKeeper/deleted/.del-NdbResultSet.cpp~84d192cf3f42600d: Delete: ndb/src/ndbapi/NdbResultSet.cpp ndb/include/ndbapi/NdbApi.hpp: Remove NdbResultSet ndb/include/ndbapi/NdbIndexScanOperation.hpp: Remove NdbResultSet ndb/include/ndbapi/NdbScanOperation.hpp: Remove NdbResultSet ndb/src/ndbapi/Makefile.am: Remove NdbResultSet ndb/src/ndbapi/NdbConnection.cpp: Remove NdbResultSet ndb/src/ndbapi/NdbIndexOperation.cpp: Remove NdbResultSet ndb/src/ndbapi/NdbScanOperation.cpp: Remove NdbResultSet ndb/test/include/HugoOperations.hpp: Remove NdbResultSet ndb/test/ndbapi/ScanFunctions.hpp: Remove NdbResultSet ndb/test/ndbapi/ScanInterpretTest.hpp: Remove NdbResultSet ndb/test/ndbapi/bank/Bank.cpp: Remove NdbResultSet ndb/test/ndbapi/bank/BankLoad.cpp: Remove NdbResultSet ndb/test/ndbapi/slow_select.cpp: Remove NdbResultSet ndb/test/ndbapi/testBlobs.cpp: Remove NdbResultSet ndb/test/ndbapi/testDataBuffers.cpp: Remove NdbResultSet ndb/test/ndbapi/testDeadlock.cpp: Remove NdbResultSet ndb/test/ndbapi/testIndex.cpp: Remove NdbResultSet ndb/test/ndbapi/testOIBasic.cpp: Remove NdbResultSet ndb/test/ndbapi/testReadPerf.cpp: Remove NdbResultSet ndb/test/ndbapi/testScan.cpp: Remove NdbResultSet ndb/test/ndbapi/testScanPerf.cpp: Remove NdbResultSet ndb/test/src/HugoOperations.cpp: Remove NdbResultSet ndb/test/src/HugoTransactions.cpp: Remove NdbResultSet ndb/test/src/UtilTransactions.cpp: Remove NdbResultSet ndb/tools/delete_all.cpp: Remove NdbResultSet ndb/tools/select_all.cpp: Remove NdbResultSet ndb/tools/select_count.cpp: Remove NdbResultSet sql/ha_ndbcluster.cc: 1) Fix a = 3 -> a= 3 2) Impl. last part of wl2126 ordered "multi ordered scan"
2004-12-07 15:15:49 +01:00
int res = F[i]->m_scan->nextResult();
2004-08-31 16:27:31 +02:00
if(res == -1)
abort();
2004-08-31 16:27:31 +02:00
if(res == 1){
continue;
}
2004-08-31 16:27:31 +02:00
Uint32 metaid = F[i]->metaid;
F[i]->row_count++;
2004-08-31 16:27:31 +02:00
if(metaid == match_val){
//ndbout_c("flera");
nextF[F_sz++] = F[i];
require(F_sz >= 0 && F_sz <= cnt);
F[i]->match_count++;
Uint32 comb = 1;
for(j = 0; j<cnt; j++){
comb *= (&g_scans[j] == F[i] ? 1 : g_scans[j].match_count);
}
match_count += comb;
found = true;
continue;
}
2004-08-31 16:27:31 +02:00
if(metaid < max_val){
nextF[F_sz++] = F[i];
require(F_sz >= 0 && F_sz <= cnt);
continue;
}
if(metaid > max_val){
for(j = 0; j<Q_sz; j++)
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);
}
2004-08-31 16:27:31 +02:00
if(F_sz == 0 && Q_sz > 0){
match_val = max_val;
for(j = 0; j<Q_sz; j++){
nextF[F_sz++] = Q[j];
2004-08-31 16:27:31 +02:00
Q[j]->match_count = 1;
}
require(F_sz >= 0 && F_sz <= cnt);
2004-08-31 16:27:31 +02:00
require(Q_sz >= 0 && Q_sz <= cnt);
Q_sz = 0;
2004-08-31 16:27:31 +02:00
match_count++;
lookup();
} else if(!found && F_sz + Q_sz < cnt){
F_sz = 0;
}
require(F_sz >= 0 && F_sz <= cnt);
2004-08-31 16:27:31 +02:00
for(i = 0; i<F_sz; i++)
F[i] = nextF[i];
}
2004-08-31 16:27:31 +02:00
start = NdbTick_CurrentMillisecond() - start;
ndbout_c("Elapsed: %lldms", start);
2004-08-31 16:27:31 +02:00
ndbout_c("rows: %d", match_count);
for(i = 0; i<cnt; i++){
ndbout_c("%s : %d", g_scans[i].m_table, g_scans[i].row_count);
}
g_trans->close();
}
}
static
void
lookup(){
{
NdbOperation* op = g_trans->getNdbOperation("artists");
require2(g_trans, op);
require2(op, op->readTuple() == 0);
require2(op, op->equal("artistid", g_artistid) == 0);
require2(op, op->getValue("name"));
}
{
NdbOperation* op = g_trans->getNdbOperation("subgenres");
require2(g_trans, op);
require2(op, op->readTuple() == 0);
require2(op, op->equal("subgenreid", g_subgenreid) == 0);
require2(op, op->getValue("name"));
}
static int loop = 0;
if(loop++ >= 16){
loop = 0;
require(g_trans->execute(NoCommit) == 0);
}
//require(g_trans->restart() == 0);
}