int main() { struct dbSysHead head; long fid1, fid2; /* ≥ı ºªØ£¨»ª∫Û¥Ú”°≥ˆµ±«∞œµÕ≥µƒ–≈œ¢ */ init_database(&head); showDesc(&head); // printf("create file1...\n"); fid1 = creatFileSpace(&head);//Œ™Œƒº˛“ª∑÷≈‰ø’º‰ fid2 = creatFileSpace(&head); // showFileDesc(&head); /* printf("extend 10 pages for file1...\n"); extendFileSpace(&head, fid1, 10);//¿©’π Æ“≥ showFileDesc(&head); printf("extend 10 pages for file1...\n"); extendFileSpace(&head, fid1, 10);//‘Ÿ¿©’π Æ“≥ showFileDesc(&head); printf("create file2...\n"); fid2 = creatFileSpace(&head); showFileDesc(&head); printf("extend 10 pages for file2...\n"); extendFileSpace(&head, fid2, 10); showFileDesc(&head); printf("extend 10 pages for file2...\n"); extendFileSpace(&head, fid2, 10); showFileDesc(&head); printf("delete file1...\n"); recyFileSpace(&head, fid1); showFileDesc(&head); printf("delete file2...\n"); recyFileSpace(&head, fid2); showFileDesc(&head);*/ //use dictID to scan file1 /* int dictID = 1; int scanPointer = 0; int rec_length = head.redef[dictID].getRecordLength(); printf("attributeName::%s", head.redef[dictID].getAttributeByNo(0).getName()); RecordCursor scanTable(&head, 1, rec_length, 0); char * one_Row_ = (char *)malloc(sizeof(char)*rec_length); while (true == scanTable.getNextRecord(one_Row_)) { //only scan scanPointer ++; if(scanPointer > 230) getOneRecord(one_Row_, head.redef[dictID]); //get each attribute value and print } free(one_Row_); */ // if(initTable(&head, fid1) == 0) if(initTable(&head, FIRST_FID) == 0) printf("1 initTable: customer.tbl\n"); if(showTable(&head, "customer") == -1 ) printf("2 showTable: customer\n"); if(initTable(&head, FIRST_FID+1) == 0) printf("1 initTable: nation.tbl\n"); if(showTable(&head, "nation") == -1 ) printf("2 showTable: nation\n"); //read customer.tbl and write into our file1, 一次性 loaddata(&head, FIRST_FID); //Scan Table relation * temp_data_dict = new relation[MAX_FILE_NUM]; TableScan(&head, FIRST_FID, temp_data_dict); //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1] int buffer_ID_ = - temp_data_dict[0].fileID; //find which buffer int record_num_ = temp_data_dict[0].getRecordNum(); int record_len_ = temp_data_dict[0].getRecordLength(); // RecordCursorTmp t1(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; /* int scanPointer = 0; int dictID = queryFileID(&head, FIRST_FID); char * one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t1.getNextRecord(one_Row_)) { //only scan scanPointer ++; if(scanPointer < 20) getOneRecord(one_Row_, &head.redef[dictID]); //get each attribute value and print } free(one_Row_);*/ loaddata(&head, FIRST_FID + 1); TableScan(&head, FIRST_FID + 1, temp_data_dict); //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1] buffer_ID_ = - temp_data_dict[1].fileID; //find which buffer record_num_ = temp_data_dict[1].getRecordNum(); record_len_ = temp_data_dict[1].getRecordLength(); // RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; /* scanPointer = 0; dictID = queryFileID(&head, FIRST_FID + 1); char * one_Row_2 = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_2)) { //only scan scanPointer ++; if(scanPointer < 20) getOneRecord(one_Row_2, &head.redef[dictID]); //get each attribute value and print } free(one_Row_2);*/ // create index /* printf("recordNum:%d\n",head.redef[dictID].recordNum); if(true == createIndexOn(&head, 1, "custkey")){ char* index_filename= "b_plus_tree_index_1custkey.dat"; FILE* fp = fopen(index_filename,"rb+"); printf("search(fp,-10):%d\n",search(fp,-10)); printf("search(fp,1):%d\n",search(fp,1)); printf("search(fp,2):%d\n",search(fp,2)); printf("search(fp,50):%d\n",search(fp,50)); display(fp); fclose(fp); } // insert one record relationDefine dic = head.redef[0]; int size_per_record = dic.recordLength; char *oneRec = (char *)malloc(sizeof(char)*size_per_record); char * insertTest = (char *)malloc(sizeof(char)* 256); strcpy(insertTest,"501|Customer#000000001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets. regular, ironic epitaphs nag eHHHHHH|"); parserOneLineFromFile(insertTest, oneRec, dic); insertOneRecord(&head, 1, oneRec);//≤»ΓªÃı ˝æ›£¨◊‘∂Ø∏¸–¬À˜“˝ free(insertTest); free(oneRec); // look up key in index char* index_filename= "b_plus_tree_index_1custkey.dat"; FILE* fp = fopen(index_filename,"rb+"); int pos = search(fp,501); printf("pos:::%d\n",pos); fclose(fp); one_Row_ = (char *)malloc(sizeof(char)*rec_length); rdFile( &head, 0, 1, pos, rec_length,one_Row_); printf("reading from index:\n"); getOneRecord(one_Row_, dic); */ /* relation result; result.init("customer", "TianzhenWu"); result.insertAttribute("name", 2, 64); result.insertAttribute("phone", 2, 64); showRelation(&result); project(&head, &temp_data_dict[0], &result);********/ printf("start tableScanEqualFilter()...\n"); // if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"custkey","3",&temp_data_dict[5])){ // printf("tableScanEqualFilter()\n"); // } /* if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"name","Customer#000000009",&temp_data_dict[5])){ printf("tableScanEqualFilter()\n"); } buffer_ID_ = - temp_data_dict[5].fileID; //find which buffer record_num_ = temp_data_dict[5].getRecordNum(); record_len_ = temp_data_dict[5].getRecordLength(); RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_)) { //only scan getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print } free(one_Row_); //head.buff[buffer_ID_].emptyOrnot = false; */ if(true == tableScanScopeFilter(&head, FIRST_FID, temp_data_dict,"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&temp_data_dict[5])){ printf("tableScanScopeFilter()\n"); } buffer_ID_ = - temp_data_dict[5].fileID; //find which buffer record_num_ = temp_data_dict[5].getRecordNum(); record_len_ = temp_data_dict[5].getRecordLength(); RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; char *one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_)) { //only scan getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print } free(one_Row_); //head.buff[buffer_ID_].emptyOrnot = false; showFileDesc(&head); exit_database(&head); system("pause"); return 0; }
int main() { struct dbSysHead head; long fid1, fid2; /* ≥ı ºªØ£¨»ª∫Û¥Ú”°≥ˆµ±«∞œµÕ≥µƒ–≈œ¢ */ init_database(&head); showDesc(&head); // printf("create file1...\n"); showFileDesc(&head); /* printf("extend 10 pages for file1...\n"); extendFileSpace(&head, fid1, 10);//¿©’π Æ“≥ showFileDesc(&head); printf("extend 10 pages for file1...\n"); extendFileSpace(&head, fid1, 10);//‘Ÿ¿©’π Æ“≥ showFileDesc(&head); printf("create file2...\n"); fid2 = creatFileSpace(&head); showFileDesc(&head); printf("extend 10 pages for file2...\n"); extendFileSpace(&head, fid2, 10); showFileDesc(&head); printf("extend 10 pages for file2...\n"); extendFileSpace(&head, fid2, 10); showFileDesc(&head); printf("delete file1...\n"); recyFileSpace(&head, fid1); showFileDesc(&head); printf("delete file2...\n"); recyFileSpace(&head, fid2); showFileDesc(&head);*/ //use dictID to scan file1 /* int dictID = 1; int scanPointer = 0; int rec_length = head.redef[dictID].getRecordLength(); printf("attributeName::%s", head.redef[dictID].getAttributeByNo(0).getName()); RecordCursor scanTable(&head, 1, rec_length, 0); char * one_Row_ = (char *)malloc(sizeof(char)*rec_length); while (true == scanTable.getNextRecord(one_Row_)) { //only scan scanPointer ++; if(scanPointer > 230) getOneRecord(one_Row_, head.redef[dictID]); //get each attribute value and print } free(one_Row_); */ /* fid1 = creatFileSpace(&head);//Œ™Œƒº˛“ª∑÷≈‰ø’º‰ fid2 = creatFileSpace(&head); if(initTable(&head, FIRST_FID) == 0) printf("1 initTable: customer.tbl\n"); if(showTable(&head, "customer") == -1 ) printf("2 showTable: customer\n"); if(initTable(&head, FIRST_FID+1) == 0) printf("1 initTable: nation.tbl\n"); if(showTable(&head, "nation") == -1 ) printf("2 showTable: nation\n"); */ if(createTable(&head) == -1) printf("Create Table1 failed\n"); if(createTable(&head) == -1) printf("Create Table2 failed\n"); if(createTable(&head) == -1) printf("Create Table3 failed\n"); /* struct eachAttribute * nation_att = new struct eachAttribute[12]; strcpy(nation_att[0].attribute_name_,"custkey"); nation_att[0].attribute_type_ = 1; nation_att[0].attribute_length_ = 4; strcpy(nation_att[1].attribute_name_,"name"); nation_att[1].attribute_type_ = 2; nation_att[1].attribute_length_ =32; strcpy(nation_att[2].attribute_name_,"address"); nation_att[2].attribute_type_ = 2; nation_att[2].attribute_length_ =40; strcpy(nation_att[3].attribute_name_,"nationkey"); nation_att[3].attribute_type_ = 1; nation_att[3].attribute_length_ = 4; strcpy(nation_att[4].attribute_name_,"phone"); nation_att[4].attribute_type_ = 2; nation_att[4].attribute_length_ =16; strcpy(nation_att[5].attribute_name_,"acctbal"); nation_att[5].attribute_type_ = 2; nation_att[5].attribute_length_ =64; strcpy(nation_att[6].attribute_name_,"mktsemgent"); nation_att[6].attribute_type_ = 2; nation_att[6].attribute_length_ =12; strcpy(nation_att[7].attribute_name_,"comment"); nation_att[7].attribute_type_ = 2; nation_att[7].attribute_length_ =128; if (createTable( &head, "customer", "TianzhenWu", 8, nation_att) == -1) { printf("Create Table failed\n"); } struct eachAttribute * region_att = new struct eachAttribute[3]; strcpy(region_att[0].attribute_name_,"regionkey"); region_att[0].attribute_type_ = 1; region_att[0].attribute_length_ = 4; strcpy(region_att[1].attribute_name_,"regionname"); region_att[1].attribute_type_ = 2; region_att[1].attribute_length_ = 12; strcpy(region_att[2].attribute_name_,"regioncomment"); region_att[2].attribute_type_ = 2; region_att[2].attribute_length_ = 152; if (createTable( &head, "region", "Mengxi", 3, region_att) == -1) { printf("Create Table failed\n"); } */ relation * temp_data_dict = new relation[MAX_FILE_NUM]; //read customer.tbl and write into our file1, 一次性 // loaddata(&head, FIRST_FID); loaddata(&head, FIRST_FID + 1); loaddata(&head, FIRST_FID + 2); sysUpdate(&head); insertOneTuple(&head, "customer", "501|Customer#000000501|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.H|"); insertOneTuple(&head, "customer", "1002|Customer#000001001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.HH|"); insertOneTuple(&head, "customer", "1003|Customer#000001002|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.HHH|"); // sysUpdate(&head); //Scan Table int customer_scan = -1; customer_scan = TableScan(&head, temp_data_dict, "customer"); if (customer_scan>=0) { printf("tablescan succeed!\n"); } printTempTable(&head, temp_data_dict,0); //char attribute_list[3][NAMELENGTH] = {"address", "name", "custkey"}; //if(project(&head, temp_data_dict, customer_scan, 3, attribute_list)>=0) // printf("project succeed!\n"); //for each old table, only one time SPJ operator allowed, because it will be freed by this SPJ operator. /* printf("start tableScanEqualFilter()...\n"); relation filter_result1; if(true == tableScanEqualFilter(&head, &temp_data_dict[0],"custkey","3", &filter_result1)){ printf("tableScanEqualFilter()\n"); } relation filter_result2; if(true == tableScanEqualFilter(&head, &temp_data_dict[0],"name","Customer#000000009", &filter_result2)){ printf("tableScanEqualFilter()\n"); } relation filter_result3; if(true == tableScanScopeFilter(&head, &temp_data_dict[0],"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&filter_result3)){ printf("tableScanScopeFilter()\n"); } RecordCursorTmp t2(&head,-2,filter_result3.getRecordLength(), - filter_result3.fileID,filter_result3.getRecordNum()); char * one_Row_ = (char *)malloc(sizeof(char)* filter_result3.getRecordLength()); while (true == t2.getNextRecord(one_Row_)) { //only scan getOneRecord(one_Row_, &filter_result3); //get each attribute value and print } free(one_Row_); */ /* //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1] int buffer_ID_ = - temp_data_dict[1].fileID; //find which buffer int record_num_ = temp_data_dict[1].getRecordNum(); int record_len_ = temp_data_dict[1].getRecordLength(); RecordCursorTmp t1(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; char * one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t1.getNextRecord(one_Row_)) { //only scan getOneRecord(one_Row_, &temp_data_dict[1]); //get each attribute value and print } free(one_Row_); *//* printf("customer_scan:%d\n",customer_scan); deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",LESS_THAN,0); printf("start tableScanEqualFilter()...\n"); int filterFlag=-1; // filterFlag = tableScanSemiscopeFilter(&head, temp_data_dict, customer_scan,"custkey","3",LESS_THAN); filterFlag = tableScanSemiscopeFilter(&head, temp_data_dict,customer_scan, "name","Customer#000000009",NOT_MORE_THAN); int buffer_ID_,record_num_,record_len_; buffer_ID_ = - temp_data_dict[filterFlag].fileID; //find which buffer record_num_ = temp_data_dict[filterFlag].getRecordNum(); record_len_ = temp_data_dict[filterFlag].getRecordLength(); RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; char * one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_)) { //only scan //printf("%s\n",one_Row_); //if(strcpy(one_Row_,"\0") == 0) // break; // getOneRecord(one_Row_, &temp_data_dict[filterFlag]); //get each attribute value and print } free(one_Row_); printf("HERE~~~\n\n"); deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",EQUAL,0); customer_scan = -1; customer_scan = TableScan(&head, temp_data_dict, "customer"); if (customer_scan>=0) { printf("tablescan succeed!\n"); } printf("customer_scan:%d\n",customer_scan); buffer_ID_ = - temp_data_dict[customer_scan].fileID; //find which buffer record_num_ = temp_data_dict[customer_scan].getRecordNum(); record_len_ = temp_data_dict[customer_scan].getRecordLength(); RecordCursorTmp t3(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; while (true == t3.getNextRecord(one_Row_)) { //only scan //printf("%s\n",one_Row_); //if(strcpy(one_Row_,"\0") == 0) // break; getOneRecord(one_Row_, &temp_data_dict[filterFlag]); //get each attribute value and print } free(one_Row_); // TableScan(&head, FIRST_FID + 1, temp_data_dict); /* //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1] buffer_ID_ = - temp_data_dict[1].fileID; //find which buffer record_num_ = temp_data_dict[1].getRecordNum(); record_len_ = temp_data_dict[1].getRecordLength(); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; RecordCursorTmp t2(&head,2,record_len_,buffer_ID_,record_num_); one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_)) { //only scan getOneRecord(one_Row_, &temp_data_dict[1]); //get each attribute value and print } free(one_Row_); */ // create index /* printf("recordNum:%d\n",head.redef[dictID].recordNum); if(true == createIndexOn(&head, 1, "custkey")){ char* index_filename= "b_plus_tree_index_1custkey.dat"; FILE* fp = fopen(index_filename,"rb+"); printf("search(fp,-10):%d\n",search(fp,-10)); printf("search(fp,1):%d\n",search(fp,1)); printf("search(fp,2):%d\n",search(fp,2)); printf("search(fp,50):%d\n",search(fp,50)); display(fp); fclose(fp); } // insert one record relationDefine dic = head.redef[0]; int size_per_record = dic.recordLength; char *oneRec = (char *)malloc(sizeof(char)*size_per_record); char * insertTest = (char *)malloc(sizeof(char)* 256); strcpy(insertTest,"501|Customer#000000001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets. regular, ironic epitaphs nag eHHHHHH|"); parserOneLineFromFile(insertTest, oneRec, dic); insertOneRecord(&head, 1, oneRec);//≤»ΓªÃı ˝æ›£¨◊‘∂Ø∏¸–¬À˜“˝ free(insertTest); free(oneRec); // look up key in index char* index_filename= "b_plus_tree_index_1custkey.dat"; FILE* fp = fopen(index_filename,"rb+"); int pos = search(fp,501); printf("pos:::%d\n",pos); fclose(fp); one_Row_ = (char *)malloc(sizeof(char)*rec_length); rdFile( &head, 0, 1, pos, rec_length,one_Row_); printf("reading from index:\n"); getOneRecord(one_Row_, dic); */ /* //nestloop_cp relation result; result.init("cus_nation", "zhangwenhui"); /*merge_relation_cp(&head,temp_data_dict[0],temp_data_dict[1],&result); showRelation(&result); nestloop_cp(&head, &temp_data_dict[0],&temp_data_dict[1], &result);*/ /* //nestloop_equal merge_relation(&head,temp_data_dict[0],temp_data_dict[1],&result); //nestloop_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey"); //nestloop_bigger(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey"); //nestloop_smaller(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey"); nestloop_smaller_or_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey"); //nestloop_bigger_or_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey"); */ //project customer /* relation c_result; c_result.init("customer", "TianzhenWu"); c_result.insertAttribute("name", 2, 64); c_result.insertAttribute("nationkey",1,4); c_result.insertAttribute("phone", 2, 64); showRelation(&c_result); project(&head, &temp_data_dict[0], &c_result); //project nation.tbl relation n_result; n_result.init("nation", "MengxiZhou"); n_result.insertAttribute("nationkey", 1, 4); n_result.insertAttribute("name", 2, 16); n_result.insertAttribute("regionkey", 1, 4); showRelation(&n_result); project(&head, &temp_data_dict[1], &n_result); */ /* // relation hashjoin_result_; // hashjoin_result_.init("customer_nation_hash", "irenewu"); // hashjoin(&head, &c_result, &n_result, &hashjoin_result_,"nationkey"); relation result; result.init("sortmergejoin zmx","zmx"); // merge_relation(&head, c_result, n_result, &result); // result.insertAttribute("custkey", 1, 4); result.insertAttribute("name", 2, 32); // result.insertAttribute("address", 2, 40); result.insertAttribute("nationkey", 1, 4); result.insertAttribute("phone", 2, 16); // result.insertAttribute("acctbal", 2, 64); // result.insertAttribute("mktsegment", 2, 12); // result.insertAttribute("comment", 2, 128); result.insertAttribute("nationkey", 1, 4); result.insertAttribute("name", 2, 32); result.insertAttribute("regionkey", 1, 4); // result.insertAttribute("comment", 2, 160); showRelation(&result); sortmergejoin(&head, &c_result, &n_result, "nationkey", &result); int buffer_ID_ = - result.fileID; //find which buffer int record_num_ = result.getRecordNum(); int record_len_ = result.getRecordLength(); RecordCursorTmp t2(&head,-11,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; char * one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_)) { //only scan getOneRecord(one_Row_, &result); //get each attribute value and print } free(one_Row_); /* //filter printf("start tableScanEqualFilter()...\n"); if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"custkey","3",&temp_data_dict[5])){ printf("tableScanEqualFilter()\n"); } if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"name","Customer#000000009",&temp_data_dict[5])){ printf("tableScanEqualFilter()\n"); } buffer_ID_ = - temp_data_dict[5].fileID; //find which buffer record_num_ = temp_data_dict[5].getRecordNum(); record_len_ = temp_data_dict[5].getRecordLength(); RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; char * one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_)) { //only scan getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print } free(one_Row_); //head.buff[buffer_ID_].emptyOrnot = false; if(true == tableScanScopeFilter(&head, FIRST_FID, temp_data_dict,"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&temp_data_dict[5])){ printf("tableScanScopeFilter()\n"); } */ showFileDesc(&head); dropTable(&head,"customer"); deleteAllTuples(&head,"nation"); dropTable(&head,"nation"); /* if(true == createIndexOn(&head, FIRST_FID, "custkey")){ char* index_filename = "/Users/Irene/Desktop/b_plus_tree_index_1custkey.dat"; FILE* fp; int pos; if( !(fp = fopen(index_filename,"rb+"))) printf("error indexFile name.\n"); printf("search(fp,-10):%d\n",search(fp,-10)); printf("search(fp,1):%d\n",search(fp,1)); printf("search(fp,2):%d\n",search(fp,2)); printf("search(fp,50):%d\n",search(fp,50)); //display(fp); deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",LESS_THAN,0); pos = search(fp,5); fclose(fp); printf("%d\n",pos); printf("start indexScanEqualFilter()...\n"); if(true == indexScanEqualFilter(&head, FIRST_FID, "custkey","4",&temp_data_dict[5])){ printf("indexScanEqualFilter(9) end!\n"); buffer_ID_ = - temp_data_dict[5].fileID; //find which buffer record_num_ = temp_data_dict[5].getRecordNum(); record_len_ = temp_data_dict[5].getRecordLength(); RecordCursorTmp t3(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t3.getNextRecord(one_Row_)) { //only scan if(one_Row_[0] == '$') printf("empty\n"); //getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print } free(one_Row_); head.buff[buffer_ID_].emptyOrnot = true; } }//end of createIndexOn if */ sysUpdate(&head); showFileDesc(&head); exit_database(&head); system("pause"); return 0; }
int main(int argc,char *args[]) { int n,c; unsigned long long prof,start,end; end_of_data_ptr=sbrk(0); time_now=time(NULL); printf("\n"); printf(" ********************************************\n"); printf(" * Astonia 3 - The Conflict Server *\n"); printf(" * Version %d.%02d.%02d *\n",VERSION>>16,(VERSION>>8)&255,VERSION&255); printf(" ********************************************\n"); printf(" * Copyright (C) 2001-2008 Intent Software *\n"); printf(" * Copyright (C) 1997-2001 Daniel Brockhaus *\n"); printf(" ********************************************\n"); printf("\n"); if (argc>1) { while (1) { c=getopt(argc,args,"a:m:i:dhc"); if (c==-1) break; switch (c) { case 'a': if (optarg) areaID=atoi(optarg); break; case 'm': if (optarg) areaM=atoi(optarg); break; case 'd': demon=1; break; case 'h': fprintf(stderr,"Usage: %s [-a <areaID>] [-m <mirror>] [-n <use this class A net>] [-d] [-c]\n\n-d Demonize\n-c Disable concurrent database access\n\n",args[0]); exit(0); case 'c': multi=0; break; //case 'n': if (optarg) server_net=atoi(optarg); break; case 'i': if (optarg) serverID=atoi(optarg); break; } } } if (!areaID) { printf("No areaID given, assuming areaID=1\n"); areaID=1; } if (!areaM) { printf("No mirror given, assuming areaM=1\n"); areaM=1; } if (!serverID) { printf("No serverID given, assuming serverID=1\n"); serverID=1; } #ifdef STAFF while (!check_staff_start()) sleep(1); #endif // set character number limit depending on area switch(areaID) { case 1: maxchars=512; break; case 2: maxchars=896; break; case 3: maxchars=384; break; case 4: maxchars=2048; break; case 5: maxchars=768; break; case 6: maxchars=384; break; case 7: maxchars=1280; break; case 8: maxchars=384; break; case 9: maxchars=1280; break; case 10: maxchars=512; break; case 11: maxchars=384; break; case 12: maxitem=1024*48; maxchars=384; break; case 13: maxchars=9*50+200; break; case 14: maxchars=16*50+200; break; case 15: maxchars=384; break; case 16: maxchars=384; break; case 17: maxchars=512; break; case 18: maxchars=768; break; case 19: maxchars=384; break; case 20: maxchars=768; break; case 21: maxchars=768; break; case 22: maxchars=512; break; case 23: maxchars=512; break; case 24: maxchars=384; break; case 25: maxchars=384+8*25*2; break; case 26: maxchars=256; break; case 27: maxchars=2048; break; case 28: maxchars=384; break; case 29: maxchars=512; break; case 30: maxchars=384; break; case 31: maxitem=1024*40; maxchars=512; break; case 32: maxchars=1280; break; case 33: maxchars=1600; break; case 34: maxchars=1280; break; case 35: maxchars=768; break; case 36: maxchars=768; break; case 37: maxchars=1024; break; default: maxchars=768; break; } // set item and effect limit if (!maxitem) maxitem=max(maxchars*12+10240,20480); if (!maxeffect) maxeffect=max(maxchars*2,1024); printf("serverID=%d, areaID=%d, areaM=%d, maxchars=%d, maxitem=%d, maxeffect=%d\n\n", serverID,areaID,areaM,maxchars,maxitem,maxeffect); if (demon) { printf("Demonizing...\n\n"); if (fork()) exit(0); for (n=0; n<256; n++) close(n); setsid(); #ifndef STAFF nologin=1; #endif } // ignore the silly pipe errors: signal(SIGPIPE,SIG_IGN); // ignore sighup - just to be safe signal(SIGHUP,SIG_IGN); /*signal(SIGSEGV,sig_crash); signal(SIGFPE,sig_crash); signal(SIGBUS,sig_crash); signal(SIGSTKFLT,sig_crash);*/ // shutdown gracefully if possible: signal(SIGQUIT,sig_leave); signal(SIGINT,sig_leave); signal(SIGTERM,sig_leave); // show profile info on CTRL-Z signal(SIGTSTP,sig_showprof); // init random number generator srand(time_now); if (!init_smalloc()) exit(1); if (!init_mem()) exit(1); if (!init_prof()) exit(1); if (!init_log()) exit(1); if (!init_database()) exit(1); if (!init_lookup()) exit(1); if (!init_sector()) exit(1); if (!init_los()) exit(1); if (!init_timer()) exit(1); if (!init_notify()) exit(1); if (!init_create()) exit(1); if (!init_lib()) exit(1); if (!init_io()) exit(1); if (!init_path()) exit(1); if (!init_effect()) exit(1); if (!init_container()) exit(1); if (!init_store()) exit(1); if (!init_chat()) exit(1); init_sound_sector(); xlog("AreaID=%d, AreaM=%d, entering game loop...",areaID,areaM); dlog(0,0,"Server started"); prof_reset(); while (!quit) { sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (busy)",areaID,areaM,serverID,online,(10000-server_idle)/100); start=rdtsc(); lock_server(); time_now=time(NULL); prof=prof_start(26); tick_date(); prof_stop(26,prof); prof=prof_start(22); tick_timer(); prof_stop(22,prof); prof=prof_start(4); tick_char(); prof_stop(4,prof); prof=prof_start(24); tick_effect(); prof_stop(24,prof); prof=prof_start(36); tick_clan(); prof_stop(36,prof); prof=prof_start(39); tick_club(); prof_stop(39,prof); prof=prof_start(5); tick_player(); prof_stop(5,prof); prof=prof_start(34); tick_login(); prof_stop(34,prof); prof=prof_start(6); pflush(); prof_stop(6,prof); prof=prof_start(7); io_loop(); prof_stop(7,prof); prof=prof_start(3); tick_chat(); prof_stop(3,prof); if (showprof) { show_prof(); showprof=0; } prof=prof_start(8); prof_update(); prof_stop(8,prof); end=rdtsc(); cycles=end-start; if ((ticker&2047)==0) { prof=prof_start(27); area_alive(0); prof_stop(27,prof); prof=prof_start(28); backup_players(); prof_stop(28,prof); call_stat_update(); read_motd(); reinit_log(); } if ((ticker&255)==0) { call_check_task(); call_area_load(); shutdown_warn(); #ifdef STAFF check_staff_stop(); #endif } if ((ticker&255)==168) { prof=prof_start(38); consistency_check_items(); consistency_check_map(); consistency_check_chars(); consistency_check_containers(); prof_stop(38,prof); } unlock_server(); sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (idle)",areaID,areaM,serverID,online,(10000-server_idle)/100); prof=prof_start(1); tick_sleep(0); prof_stop(1,prof); ticker++; } xlog("Left game loop"); respawn_check(); for (n=1; n<MAXCHARS; n++) { if (ch[n].flags&CF_PLAYER) { exit_char(n); } } area_alive(1); show_prof(); dlog(0,0,"Server stopped"); xlog("map check"); check_map(); exit_lib(); exit_database(); xlog("Clean shutdown"); showmem(); exit_log(); exit_io(); return 0; }