The present invention relates to a method for managing records on a data page in a database, particularly relates to a method for fast locating records on a data page in a database.
Database system is a very effective software system for managing a large amount of data. The least unit to be managed in a database is record, each of which memorizes a group of relative information. Data page is a physical unit for storing record, each of which can store multiple records. Every record on data page has an index, which refers to a next record, thereby all the records on the whole page link one by one to form a linearity record chain; when searching a certain record, it can be located by searching along the linearity record chain. However, this kind of method has a disadvantage that the search efficiency on a page is quite low, which leads to a low efficiency of database search.
The object of the present invention is to provide a method for fast locating records on a data page in a database, thereby enhancing the speed of locating data record in database.
The records on a data page are stored in sequence, and the scheme employed in the present invention is as follows: at the end of a data page, setting a directory structure which is composed of a group of record deviations—the position deviations of records in the data page; each directory in the directory structure is called dir_slot, each of which stores position deviation of a record; according to the position deviation, a certain record can be located immediately. But not the position deviation of all records is stored in the dir_slot, in the linearity record chain of the data page, the deviation of one record is selected to be stored in dir_slot every certain number of records (this number of records is between the maximum records number and minimum records number in the dir_slot). Thus, each page has a directory structure, when searching, it is to search the relative record in dir_slot by adopting a fast dichotomizing locating algorithm rather than search the specific record, after locating a certain dir_slot, searching the relative group of records according to the record deviation stored in the dir_slot, as such the record to be searched can be located accurately.
Specially, the present invention discloses a method for fast locating records on a data page in database, comprising the following steps of:
(1) setting a directory structure at the end of a data page, which is composed of a group of record deviations, a record deviation is a position deviation of a record in the data page; each directory in the directory structure is called dir_slot, and each dir_slot stores position deviation of one record;
(2) searching for relative records in the dir_slot by adopting a fast dichotomizing locating algorithm, searching for a relative group of records according to the record deviations stored in the dir_slot after locating one certain dir_slot, and locating the record to be searched for accurately.
Said method for fast locating record on a data page in database further includes: putting the record to be searched into a field structure, and comparing the record on the data page with the field structure.
Said method for fast locating record on a data page in database comprises the steps of: first endowing two variables (low, up) which represent the number of dir_slot with initial value, low is endowed with a value of 0, up is endowed with a value that is the total number of dir_slot on a page, then searching by adopting locating algorithm, and judging which dir_slot the record belongs to.
Said locating algorithm is dichotomizing locating algorithm.
Said dichotomizing locating is to compare medial value with field structure continuously, until the value of up-low is not more than 1.
After finding the record, select record orderly from the dir_slot with the number of low to compare with the field structure, till the next record of the record is the up record up_rec on the dir_slot with the number of up; if the record is found during this process, finishing the search on this page; if the record is not found, turning to the next page to perform the same match.
Said method for fast locating record on a data page in database, when the number of record on dir_slot is full due to the addition of one record onto a data page in database, splitting the current dir_slot into two ones, so as to increase one dir_slot.
After the record inserting into a chain table, if the total number of records on the dir_slot where the record locates exceeds a maximum value, moving all of the dir_slots behind this dir_slot one bit backward, thus, one dir_slot is added, and dividing all records on the dir_slot which this record belongs to into two parts, and attaching these two parts to the two dir_slots respectively.
Said method for fast locating record on a data page in database, wherein when deleting a record, taking it out from the chain table and sets a deleting mark to it.
First, obtaining a dir_slot next to this dir_slot, and judging the record number on the next dir_slot, if the record number exceeds the minimum value, taking out a record from the next dir_slot, and adding it to the current dir_slot; if the record number is less than or equal to the minimum value, combining these two dir_slots, and deleting the current dir_slot.
For example, supposing that 300 records are stored on one page, if locating in order, it needs to match for 300 times. While by employing the method of the present invention, about 40 dir_slots are needed to store the deviation of part of the records, by employing dichotomizing locating algorithm, it only needs to match 5 times at best to locate the specific dir_slot, 8 times at best to locate in dir_slot, and 13 times to locate in the worst situation, thereby the search speed on the page is improved 23 times. Because dir_slot is put at the end of the page, it is not necessary to preset space on the page, and the records on the page are managed efficiently. Because dir_slot only stores the deviation of one record, the space occupied is very little, supposing that each deviation is 4 bytes, 300 records need a storage space of about 160 bytes in all.
The advantage of the present invention compared to prior art is in that: the speed for locating a record on a page is improved greatly. When searching for a record, it only needs to fast locate and search in dir_slot in directory structure rather than search and compare in the order of record chain, thus, the large overhead for sequential search is saved, and after locating the specific dir_slot, the largest number of searching and comparing times is the maximum value of records of dir_slot. By employing this method, the times for seaching and comparing is greatly reduced. Because the dir_slot is put at the end of the page, it is not necessary to preset space on the page, and the records on the page are managed efficiently. Because dir_slot only stores the deviation of one record, the space occupied is very little.
Number | Date | Country | Kind |
---|---|---|---|
200310124201.4 | Dec 2003 | CN | national |
Filing Document | Filing Date | Country | Kind | 371c Date |
---|---|---|---|---|
PCT/CN04/00668 | 6/22/2004 | WO | 6/21/2006 |