📄 testjoin.cpp
字号:
/******************************************************************* * * * testjoin.cpp * * * * This file is a part of the eXtremeDB source code * * Copyright (c) 2001-2007 McObject LLC * * All Rights Reserved * * * *******************************************************************/#include "mcosql.h"#include "testjoindb.h"#include "platform.h"using namespace McoSql;#ifndef MCO_PLATFORM_X64size_t const PAGE_SIZE = 128; // define eXtremeDB page sizeconst size_t DATABASE_SIZE = 64 * 1024 * 1024;#elsesize_t const PAGE_SIZE = 256;const size_t DATABASE_SIZE = 128 * 1024 * 1024;#endif/* If you change the number of objects inserted, make sure that you * first have enough memory (DBSIZE), and also decalred hash table * size appropriatelly (hkey[estimated_numeber_of_entries] in perf2.mco */const int nRecords = 100000;int main() { int i; time_t start_time; McoSqlEngine engine; char city[32]; char street[256]; char company[64]; char order[64]; engine.open("testjoindb", testjoindb_get_dictionary(), DATABASE_SIZE, PAGE_SIZE); /* insert Records */ printf("Insert "); start_time = msec(); for (i=1; i <= nRecords; i++) { sprintf(city, "Arzamas-%d", i); sprintf(street, "%dth Aveny, %d", i+3, i); engine.executeStatement("insert into Address (zipcode, city, street) values (%i,%s,%s)", i, city, street); sprintf(company, "Factory %d", 100+i); engine.executeStatement("insert into Company (location, name) values ((select autoid from Address where zipcode=%i),%s)", i, company); sprintf(order, "Microcontroller XYZ-%d", i); engine.executeStatement("insert into Orders (company,shipment,amount,description) values ((select autoid from Company where name=%s),now,%i,%s)", company, i%100, order); if (i%(nRecords/10)==0) { printf ("."); } } printf(" %d objects: %d millisecs (%d microsecs/object)\n", nRecords, (int)(msec() - start_time), (int)(((msec() - start_time) * 1000)/nRecords)); printf("Direct search "); start_time = msec(); for (i=1; i <= nRecords; i++) { DataSource* source = engine.executeQuery("select * from Address where zipcode=%i", i); Cursor* iterator = source->records(); assert(iterator->hasNext()); Record* rec = iterator->next(); assert(rec->get(0)->intValue() == i); assert(!iterator->hasNext()); source->release(); if (i%(nRecords/10)==0) { printf ("."); } } printf("% d searches: %d millisecs (%d microsecs/search)\n", nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords)); printf("One join "); start_time = msec(); for (i=1; i <= nRecords; i++) { DataSource* source = engine.executeQuery("SELECT C.name FROM Address A,Company C WHERE A.zipcode=%i AND A.autoid=C.location", i); Cursor* iterator = source->records(); assert(iterator->hasNext()); Record* rec = iterator->next(); sprintf(company, "Factory %d", 100+i); assert(((String*)rec->get(0))->compare(company) == 0); assert(!iterator->hasNext()); source->release(); if (i%(nRecords/10)==0) { printf ("."); } } printf("% d searches: %d millisecs (%d microsecs/search)\n", nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords)); printf("Two joins "); start_time = msec(); for (i=1; i <= nRecords; i++) { DataSource* source = engine.executeQuery("SELECT O.description FROM Address A,Company C,Orders O WHERE A.zipcode=%i AND A.autoid=C.location AND C.autoid=O.company", i); Cursor* iterator = source->records(); assert(iterator->hasNext()); Record* rec = iterator->next(); sprintf(order, "Microcontroller XYZ-%d", i); assert(((String*)rec->get(0))->compare(order) == 0); assert(!iterator->hasNext()); source->release(); if (i%(nRecords/10)==0) { printf ("."); } } printf("% d searches: %d millisecs (%d microsecs/search)\n", nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords)); printf("Extra condition "); start_time = msec(); for (i=1; i <= nRecords; i++) { DataSource* source = engine.executeQuery("SELECT O.description FROM Address A, Company C, Orders O WHERE O.description like '%1' AND A.zipcode=%i AND A.autoid=C.location AND C.autoid=O.company", i); Cursor* iterator = source->records(); if (i % 10 == 1) { assert(iterator->hasNext()); Record* rec = iterator->next(); sprintf(order, "Microcontroller XYZ-%d", i); assert(((String*)rec->get(0))->compare(order) == 0); } assert(!iterator->hasNext()); source->release(); if (i%(nRecords/10)==0) { printf ("."); } } printf("% d searches: %d millisecs (%d microsecs/search)\n", nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords)); printf("Delete "); start_time = msec(); engine.executeStatement("delete from Orders"); engine.executeStatement("delete from Company"); engine.executeStatement("delete from Address"); printf(" %d objects: %d millisecs (%d microsecs/object)\n", nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords)); engine.close(); printf( "\nPress Enter to exit" ); getchar(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -