Column-oriented GPU-accelerated Database Management System
CoGaDB
|
00001 #pragma once 00002 #include <core/table.hpp> 00003 #include <util/time_measurement.hpp> 00004 #include <persistence/storage_manager.hpp> 00005 #include <iostream> 00006 //Unittests 00007 00008 #include <gpu/gpu_algorithms.hpp> 00009 00010 #include <lookup_table/lookup_table.hpp> 00011 #include <util/tpch_benchmark.hpp> 00012 00013 00014 namespace CoGaDB{ 00015 00016 namespace unit_tests{ 00017 00018 bool joinTest(); 00019 00020 bool executeUnitTests(); 00021 00022 bool fillTableTest(); 00023 00024 bool updateTuplesTest(); 00025 00026 bool basicOperationTest(); 00027 00028 bool selectionTest(); 00029 00030 bool joinTest(); 00031 00032 bool JoinPerformanceTest(); 00033 00034 bool crossjoinTest(); 00035 00036 bool complexSelectionTest(); 00037 00038 bool ColumnComputationTest(); 00039 00040 bool TableBasedColumnConstantOperatorTest(); 00041 00042 bool ComplexSortTest(); 00043 00044 bool basicQueryTest(); 00045 00046 bool addConstantColumnTest(); 00047 00048 bool GPUColumnComputationTest(); 00049 00050 bool basicGPUacceleratedQueryTest(); 00051 00052 bool ColumnorientedQueryPlanTest(); 00053 00054 bool memory_benchmark(); 00055 00056 bool compressioned_columns_tests(); 00057 00058 }; 00059 00060 00061 inline bool LoadDatabase(){ 00062 00063 return loadTables(); 00064 00065 } 00066 00067 }; 00068 00069 00070 00071 //inline bool Unittest_Fill_Tables_with_Data(){ 00072 00073 // TableSchema schema; 00074 // schema.push_back(Attribut(INT,"SID")); 00075 // schema.push_back(Attribut(VARCHAR,"Studiengang")); 00076 // 00077 // TablePtr tab1(new Table("Studiengänge",schema)); 00078 00079 // 00080 // {Tuple t; t.push_back(1); t.push_back(string("INF")); if(!tab1->insert(t)) cout << "Failed to insert Tuple" << endl;} 00081 // {Tuple t; t.push_back(2); t.push_back(string("CV")); tab1->insert(t);} 00082 // {Tuple t; t.push_back(3); t.push_back(string("CSE")); tab1->insert(t);} 00083 // {Tuple t; t.push_back(4); t.push_back(string("WIF")); tab1->insert(t);} 00084 // {Tuple t; t.push_back(5); t.push_back(string("INF Fernst.")); tab1->insert(t);} 00085 // {Tuple t; t.push_back(6); t.push_back(string("CV Master")); tab1->insert(t);} 00086 // {Tuple t; t.push_back(7); t.push_back(string("INGINF")); tab1->insert(t);} 00087 // {Tuple t; t.push_back(8); t.push_back(string("Lehramt")); tab1->insert(t);} 00088 // 00090 00098 00099 // TableSchema schema2; 00100 // schema2.push_back(Attribut(VARCHAR,"Name")); 00101 // schema2.push_back(Attribut(INT,"MatrikelNr.")); 00102 // schema2.push_back(Attribut(INT,"SID")); 00103 // 00104 // TablePtr tab2(new Table("Studenten",schema2)); 00105 00106 // {Tuple t; t.push_back(string("Tom")); t.push_back(15487); t.push_back(3); tab2->insert(t);} 00107 // {Tuple t; t.push_back(string("Anja")); t.push_back(12341); t.push_back(1); tab2->insert(t);} 00108 // {Tuple t; t.push_back(string("Maria")); t.push_back(19522); t.push_back(1); tab2->insert(t);} 00109 // {Tuple t; t.push_back(string("Jan")); t.push_back(11241); t.push_back(2); tab2->insert(t);} 00110 // {Tuple t; t.push_back(string("Julia")); t.push_back(19541); t.push_back(7); tab2->insert(t);} 00111 // {Tuple t; t.push_back(string("Chris")); t.push_back(13211); t.push_back(1); tab2->insert(t);} 00112 // {Tuple t; t.push_back(string("Norbert")); t.push_back(19422); t.push_back(2); tab2->insert(t);} 00113 // {Tuple t; t.push_back(string("Maria")); t.push_back(11875); t.push_back(1); tab2->insert(t);} 00114 // {Tuple t; t.push_back(string("Marko")); t.push_back(13487); t.push_back(4); tab2->insert(t);} 00115 // {Tuple t; t.push_back(string("Ingolf")); t.push_back(14267); t.push_back(2); tab2->insert(t);} 00116 // {Tuple t; t.push_back(string("Susanne")); t.push_back(16755); t.push_back(1); tab2->insert(t);} 00117 // {Tuple t; t.push_back(string("Stefanie")); t.push_back(19774); t.push_back(1); tab2->insert(t);} 00118 // {Tuple t; t.push_back(string("Jan")); t.push_back(13254); t.push_back(2); tab2->insert(t);} 00119 // {Tuple t; t.push_back(string("Klaus")); t.push_back(13324); t.push_back(3); tab2->insert(t);} 00120 // //{Tuple t; t.push_back(string("")); t.push_back(); t.push_back(); tab2->insert(t);} 00121 00122 00123 // cout << "initial tables: " << endl; 00124 // tab1->print(); 00125 // tab2->print(); 00126 00127 // return true; 00128 //} 00129 00130 //inline bool Unittest_GPU_Queries(){ 00131 00132 00133 // TableSchema schema; 00134 // schema.push_back(Attribut(INT,"PID")); 00135 // schema.push_back(Attribut(VARCHAR,"Name")); 00136 // schema.push_back(Attribut(INT,"Age")); 00137 // schema.push_back(Attribut(FLOAT,"Score")); 00138 // 00139 // TablePtr tab1(new Table("Person",schema)); 00140 00141 // {Tuple t; t.push_back(1); t.push_back(string("Peter")); t.push_back(24); t.push_back(float(23.1)); tab1->insert(t);} 00142 // {Tuple t; t.push_back(2); t.push_back(string("James")); t.push_back(20); t.push_back(float(40.6)); tab1->insert(t);} 00143 // {Tuple t; t.push_back(3); t.push_back(string("Karl")); t.push_back(30); t.push_back(float(99.4)); tab1->insert(t);} 00144 // {Tuple t; t.push_back(4); t.push_back(string("Max")); t.push_back(17); t.push_back(float(10.8)); tab1->insert(t);} 00145 // {Tuple t; t.push_back(5); t.push_back(string("Bob")); t.push_back(21); t.push_back(float(84.2)); tab1->insert(t);} 00146 // {Tuple t; t.push_back(6); t.push_back(string("Alice")); t.push_back(22); t.push_back(float(30.6)); tab1->insert(t);} 00147 // {Tuple t; t.push_back(7); t.push_back(string("Susanne")); t.push_back(25); t.push_back(float(29.3)); tab1->insert(t);} 00148 // {Tuple t; t.push_back(8); t.push_back(string("Joe")); t.push_back(40); t.push_back(float(72.0)); tab1->insert(t);} 00150 00151 // {Tuple t; t.push_back(9); t.push_back(string("Maik")); t.push_back(33); t.push_back(float(95.4)); tab1->insert(t);} 00152 // {Tuple t; t.push_back(10); t.push_back(string("Anne")); t.push_back(16); t.push_back(float(52.3)); tab1->insert(t);} 00153 // {Tuple t; t.push_back(11); t.push_back(string("Jenny")); t.push_back(9); t.push_back(float(5.0)); tab1->insert(t);} 00154 // 00155 // tab1->print(); 00156 00159 00160 // { //Query 1 00161 // ColumnPtr col = tab1->getColumnbyName(string("Age")); 00162 00163 00164 // gpu::GPU_Base_ColumnPtr dev_col = gpu::copy_column_host_to_device(col); 00165 // dev_col->print(); 00166 // 00167 00168 // gpu::GPU_PositionlistPtr gpu_result_tids = gpu::GPU_Operators::selection(dev_col, int(24), LESSER); 00169 // assert(gpu_result_tids!=NULL); 00170 // 00173 // cout << endl << "Materialize..." << endl; 00174 // gpu::GPU_Base_ColumnPtr dev_col_2 = dev_col->materialize(gpu_result_tids); //create materialized GPU column from existing GPU Column and result tid list 00175 // dev_col_2->print(); 00176 // cout << endl << "Perform Sort..." << endl; 00177 // gpu::GPU_PositionlistPtr gpu_result_tids2 = gpu::GPU_Operators::sort( dev_col_2, ASCENDING); //perform next operation 00178 // gpu_result_tids2->print(); 00179 // cout << endl << "Aggregate Lookup Tables..." << endl; 00180 // gpu::GPU_PositionlistPtr gpu_aggregated_result_positionlist = gpu_result_tids->aggregate(gpu_result_tids2); 00181 // gpu_aggregated_result_positionlist->print(); 00182 // PositionListPtr result_tids = copy_PositionList_device_to_host(gpu_aggregated_result_positionlist); 00183 // assert(result_tids!=NULL); 00184 00185 // TablePtr tab2 = createLookupTableforUnaryOperation(std::string("Lookup_selection_and_sort(")+tab1->getName()+")",tab1, result_tids ); 00186 // assert(tab2!=NULL); 00187 // tab2->print(); 00188 // } 00189 // 00190 // 00191 // 00192 // { //Query 2 00193 // ColumnPtr col = tab1->getColumnbyName(string("Age")); 00194 00195 00196 // gpu::GPU_Base_ColumnPtr dev_col = gpu::copy_column_host_to_device(col); 00197 // dev_col->print(); 00198 // 00199 00200 // gpu::GPU_PositionlistPtr gpu_result_tids = gpu::GPU_Operators::selection(dev_col, int(24), LESSER); 00201 // assert(gpu_result_tids!=NULL); 00202 // 00203 // gpu::GPU_Base_ColumnPtr dev_col_2 = gpu::materializeColumn(dev_col,gpu_result_tids); //create materialized GPU column from existing GPU Column and result tid list 00204 // gpu_result_tids->print(); 00205 // cout << endl << "Materialize..." << endl; 00206 // 00207 // ColumnPtr col2 = tab1->getColumnbyName(string("Score")); 00208 // gpu::GPU_Base_ColumnPtr dev_col3 = gpu::copy_column_host_to_device(col2); 00209 // 00210 // gpu::GPU_Base_ColumnPtr dev_col_4 = dev_col3->materialize(gpu_result_tids); //create materialized GPU column from existing GPU Column and result tid list 00211 // 00212 // dev_col_4->print(); 00213 // cout << endl << "Perform Sort..." << endl; 00214 // gpu::GPU_PositionlistPtr gpu_result_tids2 = gpu::GPU_Operators::sort( dev_col_4, ASCENDING); //perform next operation 00215 // gpu_result_tids2->print(); 00216 // cout << endl << "Aggregate Lookup Tables..." << endl; 00217 // gpu::GPU_PositionlistPtr gpu_aggregated_result_positionlist = gpu_result_tids->aggregate(gpu_result_tids2); 00218 // gpu_aggregated_result_positionlist->print(); 00219 // PositionListPtr result_tids = copy_PositionList_device_to_host(gpu_aggregated_result_positionlist); 00220 // assert(result_tids!=NULL); 00221 00222 // TablePtr tab2 = createLookupTableforUnaryOperation(std::string("Lookup_selection_and_sort(")+tab1->getName()+")",tab1, result_tids ); 00223 // assert(tab2!=NULL); 00224 // tab2->print(); 00225 // } 00226 // 00227 // 00228 // 00229 // 00230 // 00233 00236 00237 00246 00248 00252 00253 00254 00255 00257 00258 00259 00260 00263 00264 // return true; 00265 //} 00266 00267 //vector<int> generate_dataset(unsigned int size_in_number_of_elements, unsigned int maximal_value_size){ 00268 // vector<int> data; 00269 // for(unsigned int i=0;i<size_in_number_of_elements;i++) 00270 // data.push_back(rand()%maximal_value_size); 00271 // return data; 00272 //} 00273 00274 00275 //TablePtr selectionCPU(TablePtr tab, int selection_value, ValueComparator comp){ 00276 00277 // 00278 // return BaseTable::selection(tab,string("Number"),selection_value,comp,LOOKUP,SERIAL); 00279 00280 //} 00281 00282 //TablePtr selectionCPU_parallel(TablePtr tab, int selection_value, ValueComparator comp){ 00283 00284 // 00285 // return BaseTable::selection(tab,string("Number"),selection_value,comp,LOOKUP,PARALLEL); 00286 00287 //} 00288 00289 //TablePtr selectionGPU(TablePtr tab, int selection_value, ValueComparator comp){ 00290 00291 // ColumnPtr col = tab->getColumnbyName(string("Number")); 00292 // assert(col!=NULL); 00293 // gpu::GPU_Base_ColumnPtr dev_col = gpu::copy_column_host_to_device(col); 00294 // assert(dev_col!=NULL); 00295 // 00296 // gpu::GPU_PositionlistPtr gpu_result_tids = gpu::GPU_Operators::selection(dev_col, selection_value, comp); 00297 // assert(gpu_result_tids!=NULL); 00298 // 00299 // PositionListPtr result_tids = copy_PositionList_device_to_host(gpu_result_tids); 00300 // assert(result_tids!=NULL); 00301 00302 // return createLookupTableforUnaryOperation(std::string("Lookup_selection(")+tab->getName()+")",tab, result_tids ); 00303 // 00304 //} 00305 00306 //bool Unittest_GPU_Selection_Benchmark(unsigned int number_of_runs, std::string logfilename){ 00307 // srand(0); 00308 // //const unsigned int MAX_DATASET_SIZE=(10*1000*1000)/sizeof(int); //1000000; 00309 // const unsigned int MAX_DATASET_SIZE=(50*1024*1024)/sizeof(int); //(50*1000*1000)/sizeof(int); //1000000; 00310 // const unsigned int MAX_VALUE_SIZE=1000*1000; 00311 // vector<int> dataset; 00312 // int selection_value; 00313 // int selection_comparison_value; //0 EQUAL, 1 LESSER, 2 LARGER 00314 // //fstream file("selection.data",ios::out); 00315 // fstream file(logfilename.c_str(),ios::out); 00316 // unsigned int warmupcounter=0; 00317 // const unsigned int length_of_warmup_phase=2; 00318 // for(unsigned int i=0;i<number_of_runs+length_of_warmup_phase;i++){ 00319 // selection_value = rand()%MAX_VALUE_SIZE; 00320 // selection_comparison_value = rand()%3; 00321 // dataset=generate_dataset(rand()%MAX_DATASET_SIZE,MAX_VALUE_SIZE); 00322 // TableSchema schema; 00323 // schema.push_back(Attribut(INT,"Number")); 00324 // 00325 // cout << "Run: " << i << "/" << number_of_runs << " Elements to Process: " << dataset.size() << endl; 00326 00327 // TablePtr tab1(new Table("Test_Table",schema)); 00328 // for(unsigned int j=0;j<dataset.size();j++){ 00329 // Tuple t; 00330 // t.push_back(dataset[j]); 00331 // tab1->insert(t); 00332 // } 00333 // ValueComparator comp; 00334 // if(selection_comparison_value==0){ 00335 // comp=EQUAL; 00336 // }else if(selection_comparison_value==1){ 00337 // comp=LESSER; 00338 // }else if(selection_comparison_value==2){ 00339 // comp=GREATER; 00340 // }else{ 00341 // assert(true==false); 00342 // } 00343 // 00344 // 00345 // uint64_t begin_cpu = getTimestamp(); 00346 // TablePtr tab_cpu = selectionCPU(tab1, selection_value, comp); 00347 // uint64_t end_cpu = getTimestamp(); 00348 // assert(tab_cpu!=NULL); 00349 // assert(end_cpu>begin_cpu); 00350 // 00351 00352 // uint64_t begin_cpu_parallel = getTimestamp(); 00353 // TablePtr tab_cpu_parallel = selectionCPU_parallel(tab1, selection_value, comp); 00354 // uint64_t end_cpu_parallel = getTimestamp(); 00355 // assert(tab_cpu_parallel!=NULL); 00356 // assert(end_cpu_parallel>begin_cpu_parallel); 00357 00358 // uint64_t begin_gpu = getTimestamp(); 00359 // TablePtr tab_gpu = selectionGPU(tab1, selection_value, comp); 00360 // uint64_t end_gpu = getTimestamp(); 00361 // assert(tab_gpu!=NULL); 00362 // assert(end_gpu>begin_gpu); 00363 00364 // //tab_cpu->print(); 00365 // //tab_cpu_parallel->print(); 00366 // //tab_gpu->print(); 00367 // //std::string s; 00368 // //cin >> s; 00369 00370 // 00371 // ColumnPtr col_cpu = tab_cpu -> getColumnbyName("Number"); 00372 // ColumnPtr col_cpu_parallel = tab_cpu_parallel -> getColumnbyName("Number"); 00373 // ColumnPtr col_gpu = tab_gpu -> getColumnbyName("Number"); 00374 // assert(col_cpu->size()==col_gpu->size()); 00375 // assert(col_cpu_parallel->size()==col_gpu->size()); 00376 // 00377 // double selectivity = double(col_cpu->size())/dataset.size(); 00378 00379 // if(warmupcounter++>=length_of_warmup_phase) 00380 // file << dataset.size() << " " << selectivity << " " << comp 00381 // << " " << end_cpu - begin_cpu 00382 // << " " << end_gpu-begin_gpu 00383 // << " " << end_cpu_parallel - begin_cpu_parallel 00384 // << endl; 00385 // cout << "number of elements: " << dataset.size() << " selectivity: " << selectivity << " comparison_value: " << comp 00386 // << " CPU: " << end_cpu - begin_cpu 00387 // << " GPU: " << end_gpu-begin_gpu 00388 // << " CPU parallel: " << end_cpu_parallel - begin_cpu_parallel 00389 // << endl; 00390 00391 00392 00393 00394 // } 00395 // return false; 00396 //} 00397 00398 00399 //inline bool Unittest_Basic_Query_Test(){ 00400 00401 // TableSchema schema; 00402 // schema.push_back(Attribut(INT,"SID")); 00403 // schema.push_back(Attribut(VARCHAR,"Studiengang")); 00404 // 00405 // TablePtr tab1(new Table("Studiengänge",schema)); 00406 00407 // {Tuple t; t.push_back(1); t.push_back(string("INF")); tab1->insert(t);} 00408 // {Tuple t; t.push_back(2); t.push_back(string("CV")); tab1->insert(t);} 00409 // {Tuple t; t.push_back(3); t.push_back(string("CSE")); tab1->insert(t);} 00410 // {Tuple t; t.push_back(4); t.push_back(string("WIF")); tab1->insert(t);} 00411 // {Tuple t; t.push_back(5); t.push_back(string("INF Fernst.")); tab1->insert(t);} 00412 // {Tuple t; t.push_back(6); t.push_back(string("CV Master")); tab1->insert(t);} 00413 // {Tuple t; t.push_back(7); t.push_back(string("INGINF")); tab1->insert(t);} 00414 // {Tuple t; t.push_back(8); t.push_back(string("Lehramt")); tab1->insert(t);} 00415 00416 // TableSchema schema2; 00417 // schema2.push_back(Attribut(VARCHAR,"Name")); 00418 // schema2.push_back(Attribut(INT,"MatrikelNr.")); 00419 // schema2.push_back(Attribut(INT,"SID")); 00420 // 00421 // TablePtr tab2(new Table("Studenten",schema2)); 00422 00423 // {Tuple t; t.push_back(string("Tom")); t.push_back(15487); t.push_back(3); tab2->insert(t);} 00424 // {Tuple t; t.push_back(string("Anja")); t.push_back(12341); t.push_back(1); tab2->insert(t);} 00425 // {Tuple t; t.push_back(string("Maria")); t.push_back(19522); t.push_back(1); tab2->insert(t);} 00426 // {Tuple t; t.push_back(string("Jan")); t.push_back(11241); t.push_back(2); tab2->insert(t);} 00427 // {Tuple t; t.push_back(string("Julia")); t.push_back(19541); t.push_back(7); tab2->insert(t);} 00428 // {Tuple t; t.push_back(string("Chris")); t.push_back(13211); t.push_back(1); tab2->insert(t);} 00429 // {Tuple t; t.push_back(string("Norbert")); t.push_back(19422); t.push_back(2); tab2->insert(t);} 00430 // {Tuple t; t.push_back(string("Maria")); t.push_back(11875); t.push_back(1); tab2->insert(t);} 00431 // {Tuple t; t.push_back(string("Marko")); t.push_back(13487); t.push_back(4); tab2->insert(t);} 00432 // {Tuple t; t.push_back(string("Ingolf")); t.push_back(14267); t.push_back(2); tab2->insert(t);} 00433 // {Tuple t; t.push_back(string("Susanne")); t.push_back(16755); t.push_back(1); tab2->insert(t);} 00434 // {Tuple t; t.push_back(string("Stefanie")); t.push_back(19774); t.push_back(1); tab2->insert(t);} 00435 // {Tuple t; t.push_back(string("Jan")); t.push_back(13254); t.push_back(2); tab2->insert(t);} 00436 // {Tuple t; t.push_back(string("Klaus")); t.push_back(13324); t.push_back(3); tab2->insert(t);} 00437 00438 // cout << "initial tables: " << endl; 00439 // tab1->print(); 00440 // tab2->print(); 00442 // cout << endl << "Join Table Studenten, Studiengänge where Studenten.SID=Studiengänge.SID ..." << endl; 00443 00444 // //tab1->join(tab2,"SID","SID",CPU); 00445 00446 // //SORT_MERGE_JOIN,NESTED_LOOP_JOIN,HASH_JOIN 00447 // //TablePtr tab3 = BaseTable::join(tab1,"SID",tab2,"SID",SORT_MERGE_JOIN,MATERIALIZE,CPU); 00448 // //TablePtr tab3 = BaseTable::join(tab1,"SID",tab2,"SID",NESTED_LOOP_JOIN,MATERIALIZE,CPU); 00449 00450 // //TablePtr tab3 = BaseTable::join(tab1,"SID",tab2,"SID",SORT_MERGE_JOIN,MATERIALIZE,CPU); 00451 // //TablePtr tab3 = BaseTable::join(tab1,"SID",tab2,"SID",SORT_MERGE_JOIN,LOOKUP,CPU); 00452 00453 00454 // TablePtr tab3 = BaseTable::join(tab1,"SID",tab2,"SID",NESTED_LOOP_JOIN,MATERIALIZE,CPU); 00455 // tab3->print(); 00456 // cout << "==========================================================================================" << endl; 00457 // tab3 = BaseTable::join(tab1,"SID",tab2,"SID",NESTED_LOOP_JOIN,LOOKUP,CPU); 00458 00460 // tab3->print(); 00461 // 00462 // cout << endl << "Projection on Table with Columns Name, Studiengang..." << endl; 00463 00464 // list<string> columns; 00465 // columns.push_back("Name"); 00466 // columns.push_back("MatrikelNr."); 00467 // columns.push_back("Studiengang"); 00468 // tab3=BaseTable::projection(tab3,columns,MATERIALIZE,CPU); 00469 // tab3->print(); 00470 00471 // cout << endl << "Selection on Table on column Studiengang equals 'INF'..." << endl; 00472 00473 // //ValueComparator{LESSER,GREATER,EQUAL}; 00474 // TablePtr tab4=BaseTable::selection(tab3,string("Studiengang"),string("INF"),EQUAL,MATERIALIZE,CPU); 00475 // tab4->print(); 00476 // cout << "==========================================================================================" << endl; 00477 // tab4=BaseTable::selection(tab3,string("Studiengang"),string("INF"),EQUAL,LOOKUP,CPU); 00478 // tab4->print(); 00479 00480 // cout << endl << "Sorting Table by Name (ascending)..." << endl; 00481 00482 // TablePtr tab5=BaseTable::sort(tab4,"Name",ASCENDING,MATERIALIZE,CPU); 00483 // tab5->print(); 00484 // assert(tab5!=NULL); 00485 // cout << "==========================================================================================" << endl; 00486 // tab5=BaseTable::sort(tab4,"Name",ASCENDING,LOOKUP,CPU); 00487 // assert(tab5!=NULL); 00488 // tab5->print(); 00489 //*/ 00490 00491 00494 00495 00496 // JoinAlgorithm join_alg = HASH_JOIN; //NESTED_LOOP_JOIN; // HASH_JOIN; //SORT_MERGE_JOIN; //HASH_JOIN; //NESTED_LOOP_JOIN NESTED_LOOP_JOIN 00497 00498 // { 00499 // cout << endl << "Join Table Studenten, Studiengänge where Studenten.SID=Studiengänge.SID ..." << endl; 00500 00501 // TablePtr tab3 = BaseTable::join(tab1,"SID",tab2,"SID",join_alg,MATERIALIZE,CPU); 00502 // tab3->print(); 00503 00506 // 00507 // cout << endl << "Projection on Table with Columns Name, Studiengang..." << endl; 00508 00509 // list<string> columns; 00510 // columns.push_back("Name"); 00511 // columns.push_back("MatrikelNr."); 00512 // columns.push_back("Studiengang"); 00513 // tab3=BaseTable::projection(tab3,columns,MATERIALIZE,CPU); 00514 // tab3->print(); 00515 00516 // cout << endl << "Selection on Table on column Studiengang equals 'INF'..." << endl; 00517 00518 // //ValueComparator{LESSER,GREATER,EQUAL}; 00519 // TablePtr tab4=BaseTable::selection(tab3,string("Studiengang"),string("INF"),EQUAL,MATERIALIZE,SERIAL); 00520 // tab4->print(); 00521 00522 // cout << endl << "Sorting Table by Name (ascending)..." << endl; 00523 00524 // TablePtr tab5=BaseTable::sort(tab4,"Name",ASCENDING,MATERIALIZE,CPU); 00525 // tab5->print(); 00526 // assert(tab5!=NULL); 00527 // cout << "==========================================================================================" << endl; 00528 // } 00529 00530 // cout << "Query using Lookup Tables..." << endl; 00531 00532 // { 00533 // cout << endl << "Join Table Studenten, Studiengänge where Studenten.SID=Studiengänge.SID ..." << endl; 00534 00535 // TablePtr tab3 = BaseTable::join(tab1,"SID",tab2,"SID",join_alg,LOOKUP,CPU); 00536 // tab3->print(); 00537 00540 // 00541 // cout << endl << "Projection on Table with Columns Name, Studiengang..." << endl; 00542 00543 // list<string> columns; 00544 // columns.push_back("Name"); 00545 // columns.push_back("MatrikelNr."); 00546 // columns.push_back("Studiengang"); 00547 // tab3=BaseTable::projection(tab3,columns,LOOKUP,CPU); 00548 // tab3->print(); 00549 00550 // cout << endl << "Selection on Table on column Studiengang equals 'INF'..." << endl; 00551 00552 // //ValueComparator{LESSER,GREATER,EQUAL}; 00553 // TablePtr tab4=BaseTable::selection(tab3,string("Studiengang"),string("INF"),EQUAL,LOOKUP,SERIAL); 00554 // tab4->print(); 00555 00556 // cout << endl << "Sorting Table by Name (ascending)..." << endl; 00557 00558 // TablePtr tab5=BaseTable::sort(tab4,"Name",ASCENDING,LOOKUP,CPU); 00559 // tab5->print(); 00560 // assert(tab5!=NULL); 00561 // cout << "==========================================================================================" << endl; 00562 // } 00563 00564 // return true; 00565 //} 00566 00567 00568 00569 //void executeTestQuery(TablePtr tab1, TablePtr tab2, JoinAlgorithm join_alg, MaterializationStatus mat_stat, const ComputeDevice comp_dev){ 00570 00573 00577 00578 // //TablePtr tab4=tab3->sort("Alter",ASCENDING,CPU); 00579 // //tab4->print(); 00580 00582 // TablePtr tab3 = BaseTable::join(tab1,"ID",tab2,"EID",join_alg,mat_stat,comp_dev); 00583 // if(!quiet && verbose)tab3->print(); 00584 00585 // //cout << "Selection on Table on column Alter greater than 60..." << endl; 00586 00587 // //ValueComparator{LESSER,GREATER,EQUAL}; 00588 // TablePtr tab4=BaseTable::selection(tab3,string("Alter"),60,GREATER,mat_stat,SERIAL); 00589 // if(!quiet && verbose)tab4->print(); 00590 00591 // //cout << "Sorting Table by Alter (ascending)..." << endl; 00592 00593 // TablePtr tab5=BaseTable::sort(tab4,"Alter",ASCENDING,mat_stat,CPU); 00594 // if(!quiet && verbose)tab5->print(); 00595 // assert(tab5!=NULL); 00596 // //cout << "==========================================================================================" << endl; 00597 // 00598 00599 //} 00600 00601 00602 //void Unittest_Test_Benchmark(size_t size_of_main_table=20, size_t size_of_foreign_key_table=100, unsigned int number_of_runs_per_query=20){ 00603 00606 00607 // srand(0); 00608 00609 // TableSchema schema; 00610 // schema.push_back(Attribut(INT,"ID")); 00611 // schema.push_back(Attribut(INT,"Alter")); 00612 // 00613 // TablePtr tab1(new Table("Age",schema)); 00614 00615 // cout << "Filling Table Age with " << size_of_main_table << " rows" << endl; 00616 // for(unsigned int i=0;i< size_of_main_table;i++) 00617 // {Tuple t; t.push_back(i); t.push_back(rand()%100); tab1->insert(t);} 00618 00619 // TableSchema schema2; 00620 // schema2.push_back(Attribut(INT,"EID")); 00621 // schema2.push_back(Attribut(FLOAT,"Einkommen")); 00622 00623 // TablePtr tab2(new Table("Salary",schema2)); 00624 00625 // cout << "Filling Table Salary with " << size_of_foreign_key_table << " rows" << endl; 00626 00627 // for(unsigned int i=0;i<size_of_foreign_key_table;i++) 00628 // {Tuple t; t.push_back(int(rand()%size_of_main_table)); t.push_back(float(rand()%10000)/100); tab2->insert(t);} 00629 // 00630 // if(!quiet && verbose){ 00633 // } 00634 00635 // for(unsigned int i=0;i<number_of_runs_per_query;i++){ 00636 // cout << "Query: Materialize Table Join: Sort Merge Join " << endl; 00637 // Timestamp begin,end; 00638 // begin=getTimestamp(); 00639 // executeTestQuery(tab1, tab2, SORT_MERGE_JOIN, MATERIALIZE,CPU); 00640 // end=getTimestamp(); 00641 // assert(end>=begin); 00642 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00643 // cout << "==========================================================================================" << endl; 00644 // } 00645 // for(unsigned int i=0;i<number_of_runs_per_query;i++){ 00646 // cout << "Query: Lookup Table Join: Sort Merge Join " << endl; 00647 // Timestamp begin,end; 00648 // begin=getTimestamp(); 00649 // executeTestQuery(tab1, tab2, SORT_MERGE_JOIN, LOOKUP,CPU); 00650 // end=getTimestamp(); 00651 // assert(end>=begin); 00652 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00653 // cout << "==========================================================================================" << endl; 00654 // } 00675 00676 00677 00678 00679 // /*old*/ 00682 00686 00689 // /*old*/ 00690 00691 // //TODO: add aggregation and group aggregate 00692 // //TODO: hash join 00693 00694 00695 // 00696 00700 00714 00715 00716 00717 00718 //} 00719 00720 //void ColumnJoinBenchmark(size_t size_of_main_table=20, size_t size_of_foreign_key_table=100, unsigned int number_of_runs_per_query=20){ 00721 00724 00725 // srand(0); 00726 00727 // TableSchema schema; 00728 // schema.push_back(Attribut(INT,"ID")); 00729 // //schema.push_back(Attribut(INT,"Alter")); 00730 // 00731 // TablePtr tab1(new Table("Age",schema)); 00732 00733 // cout << "Filling Table Age with " << size_of_main_table << " rows" << endl; 00734 // for(unsigned int i=0;i< size_of_main_table;i++) 00735 // {Tuple t; t.push_back(i); tab1->insert(t);} 00736 00737 // TableSchema schema2; 00738 // schema2.push_back(Attribut(INT,"EID")); 00739 // //schema2.push_back(Attribut(FLOAT,"Einkommen")); 00740 00741 // TablePtr tab2(new Table("Salary",schema2)); 00742 00743 // cout << "Filling Table Salary with " << size_of_foreign_key_table << " rows" << endl; 00744 00745 // for(unsigned int i=0;i<size_of_foreign_key_table;i++) 00746 // {Tuple t; t.push_back(int(rand()%size_of_main_table)); tab2->insert(t);} 00747 00748 00749 // TableSchema schema3; 00750 // schema3.push_back(Attribut(INT,"AID")); 00751 // //schema2.push_back(Attribut(FLOAT,"Einkommen")); 00752 00753 // TablePtr tab3(new Table("Autos",schema3)); 00754 00755 // cout << "Filling Table Autos with " << size_of_foreign_key_table << " rows" << endl; 00756 00757 // for(unsigned int i=0;i<size_of_foreign_key_table;i++) 00758 // {Tuple t; t.push_back(int(rand()%size_of_main_table)); tab3->insert(t);} 00759 // 00760 // if(!quiet && verbose){ 00763 // tab1->print(); 00764 // tab2->print(); 00765 // tab3->print(); 00766 // } 00767 00768 // 00769 // cout << "Press Enter to start benchmark: " << endl; 00770 // string s; 00771 // cin >> s; 00772 // for(unsigned int i=0;i<number_of_runs_per_query;i++){ 00773 // { 00774 // cout << "Query: Materialize Table Join: Sort Merge Join " << endl; 00775 // Timestamp begin,end; 00776 // begin=getTimestamp(); 00777 // TablePtr tab4 = BaseTable::join(tab1,"ID",tab2,"EID", SORT_MERGE_JOIN, MATERIALIZE,CPU); 00778 // assert(tab4!=NULL); 00779 // //tab4->print(); 00780 // TablePtr tab5 = BaseTable::join(tab4,"ID",tab3,"AID", SORT_MERGE_JOIN, MATERIALIZE,CPU); 00781 // //tab5->print(); 00782 // end=getTimestamp(); 00783 // assert(end>=begin); 00784 // if(!quiet && verbose)tab3->print(); 00785 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00786 // cout << "==========================================================================================" << endl; 00787 // } 00788 00789 // { 00790 // cout << "Query: Lookup Table Join: Sort Merge Join " << endl; 00791 // Timestamp begin,end; 00792 // begin=getTimestamp(); 00793 // TablePtr tab4 = BaseTable::join(tab1,"ID",tab2,"EID", SORT_MERGE_JOIN, LOOKUP,CPU); 00794 // assert(tab4!=NULL); 00795 // TablePtr tab5 = BaseTable::join(tab4,"ID",tab3,"AID", SORT_MERGE_JOIN, LOOKUP,CPU); 00796 00797 // if(!quiet && verbose) cout << "Result: " << endl; 00798 // if(!quiet && verbose) tab5->print(); 00799 // TablePtr tab6 = tab5->materialize(); 00800 // if(!quiet && verbose) cout << "Materialized Result: " << endl; 00801 // if(!quiet && verbose) tab6->print(); 00802 // end=getTimestamp(); 00803 // assert(end>=begin); 00804 // if(!quiet && verbose)tab3->print(); 00805 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00806 // cout << "==========================================================================================" << endl; 00807 // } 00808 // /*{ 00809 // cout << "Query: Materialize Table Join: Nested Loop Join " << endl; 00810 // Timestamp begin,end; 00811 // begin=getTimestamp(); 00812 // TablePtr tab4 = BaseTable::join(tab1,"ID",tab2,"EID", NESTED_LOOP_JOIN, MATERIALIZE,CPU); 00813 // assert(tab4!=NULL); 00814 // //tab4->print(); 00815 // TablePtr tab5 = BaseTable::join(tab4,"ID",tab3,"AID", NESTED_LOOP_JOIN, MATERIALIZE,CPU); 00816 // //tab5->print(); 00817 // end=getTimestamp(); 00818 // assert(end>=begin); 00819 // if(!quiet && verbose) tab3->print(); 00820 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00821 // cout << "==========================================================================================" << endl; 00822 // } 00823 00824 // { 00825 // cout << "Query: Lookup Table Join: Nested Loop Join " << endl; 00826 // Timestamp begin,end; 00827 // begin=getTimestamp(); 00828 // TablePtr tab4 = BaseTable::join(tab1,"ID",tab2,"EID", NESTED_LOOP_JOIN, LOOKUP,CPU); 00829 // assert(tab4!=NULL); 00830 // TablePtr tab5 = BaseTable::join(tab4,"ID",tab3,"AID", NESTED_LOOP_JOIN, LOOKUP,CPU); 00831 // cout << "Result: " << endl; 00832 // //tab5->print(); 00833 // TablePtr tab6 = tab5->materialize(); 00834 // cout << "Materialized Result: " << endl; 00835 // //tab6->print(); 00836 // end=getTimestamp(); 00837 // assert(end>=begin); 00838 // if(!quiet && verbose)tab3->print(); 00839 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00840 // cout << "==========================================================================================" << endl; 00841 // }*/ 00842 // { 00843 // cout << "Query: Materialize Table Join: Hash Join " << endl; 00844 // Timestamp begin,end; 00845 // begin=getTimestamp(); 00846 // TablePtr tab4 = BaseTable::join(tab1,"ID",tab2,"EID", HASH_JOIN, MATERIALIZE,CPU); 00847 // assert(tab4!=NULL); 00848 // //tab4->print(); 00849 // TablePtr tab5 = BaseTable::join(tab4,"ID",tab3,"AID", HASH_JOIN, MATERIALIZE,CPU); 00850 // //tab5->print(); 00851 // end=getTimestamp(); 00852 // assert(end>=begin); 00853 // if(!quiet && verbose)tab3->print(); 00854 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00855 // cout << "==========================================================================================" << endl; 00856 // } 00857 00858 // { 00859 // cout << "Query: Lookup Table Join: Hash Join " << endl; 00860 // Timestamp begin,end; 00861 // begin=getTimestamp(); 00862 // TablePtr tab4 = BaseTable::join(tab1,"ID",tab2,"EID", HASH_JOIN, LOOKUP,CPU); 00863 // assert(tab4!=NULL); 00864 // TablePtr tab5 = BaseTable::join(tab4,"ID",tab3,"AID", HASH_JOIN, LOOKUP,CPU); 00865 // cout << "Result: " << endl; 00866 // //tab5->print(); 00867 // TablePtr tab6 = tab5->materialize(); 00868 // cout << "Materialized Result: " << endl; 00869 // //tab6->print(); 00870 // end=getTimestamp(); 00871 // assert(end>=begin); 00872 // if(!quiet && verbose)tab3->print(); 00873 // cout << "Time for Query: " << end-begin << "ns (" << double(end-begin)/1000000 << "ms)" << endl; 00874 // cout << "==========================================================================================" << endl; 00875 // cout << "******************************************************************************************" << endl; 00876 // } 00877 00878 // } 00879 00880 //} 00881 00882 00883 //inline bool LoadDatabase(){ 00884 00885 // return loadTables(); 00886 00887 //} 00888 00889 00890