Since i have no course to choose, so i have to choose this one. On the other hand, this course can help me to understand better about database. Although this course is called Database Implementation, it does not teach you how to write a database application. Instead, the course is full of various algorithms, taking Postgre as example.
The quiz almost does not change every year. It aims to help you check whether you grasp the knowledge taught on lectures.
Even though you don’t pay attention to this special usage, malloc can also helps you pass lots of tests provided by the convener.
Note 2:
This problem is about precision.
For function Convert2DMS:
1 2 3 4
It converts the greographical coordinates from decimal to DMS(degree, minute, second). The calculation can be described as: D = floor(Ddec), M = floor(60 × |Ddec-D|), S = floor(3600 × |Ddec-D| - 60 × M),
Because latitude_value in my struct is double and double will cause precision loss when executing operation like:
1 2 3 4 5 6
intmain(){ double x = 73.55; int result = (int)((x - 73) * 60); printf("result: %d", result); // result: 32 return0; }
The result should be 33 but program gives us 32.
Since the coordinate value do not have more than 4 decimal places, so we can solve it as shown below:
for (int tid = 0; tid < get_tuples_num(buffer_p); tid++) { Tuple tuple = get_tuple_by_tuple_id(buffer_p, tid); if (tuple[idx] == cond_val) { result->tuples[counter++] = tuple; } else { free(tuple); } } release_page(buffer_p); log_release_page(buffer_p->page_id); }
The thought seems simple but i didn’t come out at the beginning. I read all pages from files and then read tuples from pages.
Note2: buffer pool
Take Sel as example. We check whether current page is stored in buffer pool and if it has been stored, then just read it from pool. Otherwise, we read page from file by page index and then store the page in pool. When storing page in pool, we check whether the number of pages is greater than the buffer limit. If it is greater than buffer limit, then we use buffer replacement to replace page. Otherwise, we directly store the page in buffer pool.
For request_page, it implements the clock-sweep strategy which is the Postgre default buffer replacement policy.
Note3: file pool
Because we have the limit for the number of opened files. So we need to maintain a file pool.
If we want to read or write a page from file, we firstly check whether the file pointer has been stored in file pool by oid. If it has been stored, then we use it directly. Otherwise, we check whether the num of opened files is greater than the file limit. If it is greater than file limit, we use buffer replacement strategy the same as buffer pool. If not, we open a new file and store related oid in file pool.
The tool is used to check memory leak. It also can check error like:
1 2 3 4
char* result = (char*) malloc(tuple_size); memcpy(result, curr, tuple_size);
Address 0x4a40299 is 0 bytes after a block of size 25 alloc'd
For the code above, it should be written as below because the last byte is for \0.
1 2
char* result = (char*) malloc(tuple_size+1); memcpy(result, curr, tuple_size+1);
Final exam
3 programs are all about assessment2. It is not difficult but it is really hard to figure it out in 3 hours because we have another 5 questions to do.
Q1
Note1: convert big tuple to small tuple
Q2
I forgot to use r+. So funny…as a result, i write nothing back to the file.
Conclusion
The course has challenging assessment. Ass1 strengthens my ability to collect information from official documents. Ass2 makes me have better understanding of clock sweep, simple hash join and merge sort join. It also enhances the ability to maintain C pointer.