Embodiment
For the purpose, technical scheme and the advantage that make the embodiment of the invention is clearer, the embodiment of the invention is explained further details below in conjunction with accompanying drawing.At this, illustrative examples of the present invention and explanation thereof are used to explain the present invention, but not as to qualification of the present invention.
As shown in Figure 1, the storage means flow process of relevant database can comprise in the embodiment of the invention:
Elder generation's execution in step 101: set up control table, in order to the sign of storage list section and the minimum and maximum Major key of table section institute stored record, and by the minimum Major key ordering of table section;
When new record inserts table:
If do not have record in the table, then execution in step 102: the newly-built table section that should show, with the memory table of new this table section of record insertion; Then execution in step 103: sign that will show section is stored to control table, and the Major key of new record is stored to control table as the minimum and the maximum Major key of this table section institute's stored record;
If existing record in the table; Then execution in step 104: according to the minimum Major key of all table section institute stored records in the Major key of new record and the control table; Search the table section that new record should insert, new record is inserted the memory table that this shows section, press the Major key ordering during insertion; If insert the minimum or maximum Major key that has changed this table section institute stored record, then also need execution in step 105: in control table, carry out corresponding renewal;
All write down shared internal memory and reach predefined and go up in limited time in the memory table of table section:
Execution in step 106: should a corresponding table segment data file of table section on all recording storage to the hard disk in will the section of showing memory table, by the row storage, and keep press Major key and sort during stored record; Follow execution in step 107: the memory table that empties this table section; Wherein when execution in step 106,, then also comprise: newly-built this table segment data file (step 106a) if should not show the segment data file on the hard disk; Should table segment data file if existing on the hard disk, then also comprise: when storage with the record in the memory table and this table segment data file in existing record merging (step 106b).
Do following the detailed description in the face of flow process shown in Figure 1 down:
In the embodiment of the invention, the indumentum section of being divided in the relevant database is referred to as the table section, and the record number in each table section has a upper limit.The table section is made up of memory table and table segment data file.Memory table is a core resident data structure in the table section; In order to storing the record of new insertion, and by the Major key ordering of record, the internal memory that the record of being stored takies can not surpass the predefined upper limit; Otherwise need with recording storage in table segment data file, empty memory table then.Table segment data file is stored by row in order to the record of storage list section, and presses the Major key ordering of record.Control table is stored the information of each table section in order to the admin table section, comprises the sign of table section and the minimum and maximum Major key of table section institute stored record.The table segment information that control table is stored can sort by the minimum Major key that the table section is stored.
During practical implementation, at first set up control table,, comprise the sign (ID) of table section and the minimum and maximum Major key of table section institute stored record in order to the information of storage list section.
For example, Fig. 2 is the structural representation of control table in the embodiment of the invention.As shown in Figure 2, comprise the sign (TABLET_ID) of showing section in the control table, the minimum Major key (MIN_PK) and the maximum Major key (MAX_PK) of the stored record of table section institute.When record did not insert table, control table was empty.
During practical implementation, when new record inserts table, be divided into two kinds of situation:
The one, there is not record in the table; Control table this moment is empty; Need newly-built table section that should table, new record inserted in memory table of this table section, with information stores of this table section in control table; Comprise that specifically the sign with this table section is stored to control table, the Major key of new record is stored to control table as the minimum and the maximum Major key of this table section institute stored record.Owing to have only a record in the table section, the minimum of table section institute stored record and maximum Major key are for inserting the Major key of record.
For example, Fig. 3 records a synoptic diagram in the empty table for inserting in the embodiment of the invention.As shown in Figure 3, the structure of showing in this example for (ID, NAME), insertion be recorded as (1001; China), inserted record (1001, China) in the memory table of table section; Inserted new table segment information in the control table: (1,1001,1001); Promptly the ID of table section is 1, and the minimum Major key of table section institute stored record is 1001, and the maximum Major key of storage also is 1001.
The 2nd, existing record in the table; Control table this moment is not empty; Need search the table section that new record should insert, then according to the minimum Major key of all table section institute stored records in the Major key of new record and the control table; In the memory table of the table section that finds, insert new record, press the Major key ordering during insertion.If the record that inserts has changed the minimum or maximum Major key of this table section institute stored record, then need upgrade the information of correspondence table section in the control table.Wherein, when searching the table section that new record should insert, can adopt dichotomy to search according to the minimum Major key of all table section institute stored records in the Major key of new record and the control table.
Why the reason with binary search is owing in practical application, have hundreds and thousands of and even up to ten thousand table sections; In order to improve performance; Use binary search; Because the table segment information of storing in the control table is by minimum Major key ordering, searches the object table section of insertion and can locate with binary search according to the minimum Major key of the Major key that inserts record and all table sections:
When new record inserts table, if the Major key of new record is between the minimum Major key of two table sections, the table section that then previous table section should be inserted as new record; If the Major key of new record was then shown the table section that section should be inserted as new record with first before the minimum Major key of first table section; If the Major key of new record is in the end after the minimum Major key of a table section, the table section that then last table section should be inserted as new record.
For example, Fig. 4 records the unconverted synoptic diagram of control table in the nonempty list for inserting in the embodiment of the invention.As shown in Figure 4, two table sections are arranged in the control table: (1,1001,1005) and (2,1010,1011) wherein have record in the table section 1: (1001, China), (1005, Korea S) have record: (1010, the U.S.), (1011, Canada) in the table section 2.Insert record (1003, Japan), the minimum Major key of all table section institute stored records is from small to large in the control table: 1001,1010; The result of binary search be table section 1 (because the minimum Major key of table section 1 and 2 is 1001,1010 from small to large, like this when the storage Major key is 1003 record since 1003 greater than 1001 less than 1010, show section 1 so should insert); So in table section 1, insert record (1003, Japan), inserted (1003, Japan) in the memory table of table section 1; According to the Major key order, be followed successively by: (1001, China), (1003; Japan), (1005, Korea S); Because record is inserted in the centre of table section, the minimum and the maximum Major key of the stored record of table section institute do not change, and therefore need not to change the information of this table section in the control table.
And for example, Fig. 5 records the synoptic diagram that causes in the nonempty list that control table changes for inserting in the embodiment of the invention.As shown in Figure 5, two table sections are arranged in the control table: (1,1001,1005) and (2,1010,1011) wherein have record in the table section 1: (1001, China), (1005, Korea S) have record: (1010, the U.S.), (1011, Canada) in the table section 2.Insert record (1006, India), the minimum Major key of all table section institute stored records is in the control table: 1001,1010; The result of binary search be table section 1 (because the minimum Major key of table section 1 and 2 is 1001,1010 from small to large, like this when the storage Major key is 1006 record since 1006 greater than 1001 less than 1010, show section 1 so should insert); So in table section 1, insert record (1006, India), inserted (1006, India) in the memory table of table section 1; According to the Major key order, be followed successively by: (1001, China), (1005; Korea S), (1006, India).Because record is inserted into the last of table section, variation has taken place in the maximum Major key of table section institute stored record, and the maximum Major key that upgrades first table section in the control table is 1006: (1,1001,1006).
During practical implementation, all write down shared internal memory and reach predefined and go up in limited time in the memory table of table section:
With showing a corresponding table segment data file of section on all recording storage to the hard disk in this table section memory table, then memory table is emptied to reduce the use of internal memory, this operation can be referred to as to tighten memory table; Store by row during stored record, and keep pressing the Major key ordering; If should show the segment data file on the hard disk, the then newly-built table segment data file that is somebody's turn to do; Should table segment data file if existing on the hard disk, did the operation of tightening memory table before showing, then when storage, existing record in the record in the memory table and this table segment data file is merged, still by the row storage, and keep pressing Major key and sort.
For example, Fig. 6 writes down the synoptic diagram that shared internal memory reaches the upper limit for inserting in the embodiment of the invention to write down in the memory table that causes the section of showing.As shown in Figure 6, in the memory table of table section record (1001, China) is arranged, (1003, Japan), (1005, Korea S) store record (1002, Vietnam), (1006, India) in the table segment data file of table section.Insert record (1004, Malaysia) and cause the shared internal memory of memory table to reach the predefined upper limit, for example: suppose that ID is an integer type, NAME is character types; The shared internal memory of integer is 4 bytes, and each Chinese character accounts for 2 bytes, so, inserts (1004; Malaysia) being recorded as in the memory table behind the memory table: (1001, China), (1003, Japan); (1004, Malaysia), (1005, Korea S); The shared internal memory of memory table should be: (4+2 * 2)+(4+2 * 2)+(4+2 * 4)+(4+2 * 2)=36, suppose to be limited to 32 on the predefined internal memory, and the shared internal memory of memory table reaches the upper limit so.Existing record in record in the memory table and the table segment data file is merged storage, keep the ordering of Major key, (1001,1002,1003; 1004,1005,1006), corresponding title train value is: (China, Vietnam; Japan, Malaysia, Korea S, India), the memory table of table section is cleared.
During practical implementation, the data of being stored in the table segment data file can comprise:
Train value data and metadata that record is corresponding; The train value data are ingredients of record, and such as ID train value data and NAME train value data are arranged, all train value data combinations constitute record together.During storage, ID train value data and NAME train value data separate storage.
Wherein:
The train value data number of each row equates; Because the number of record decision train value data number is so they must equate.Such as: record (1001, China) is arranged, (1002, the U.S.), the record number is 2, stores by row: ID:1001,1002; NAME: China, the U.S.; The train value data number of each row is 2, all equals the number 2 that writes down;
The train value data of each row are divided into data block by fixing train value data number, form the train value data block;
Metadata store is in meta data block; Position, record number in table segment data file and meta data block the position in table segment data file of each train value data block of metadata record in table segment data file.The number of record number=each train value data, rather than all train value data numbers, such as: record is arranged: (1001, China), (1002, the U.S.), during by the row storage, ID:1001,1002; NAME: China, the U.S.; The record number is 2, and the number of each train value data also is 2, and it is 4 that all train value data numbers are added up.
During practical implementation, the storage order of train value data and metadata can be in the table segment data file:
The train value data of first row, the train value data of second row are until the train value data and the metadata of last row.
The position of the train value data block of metadata record in table segment data file can obtain by row memory row Value Data the time, and the position of meta data block in table segment data file is last the train value data block that is right after last row.Because metadata is very little usually, can in internal memory, copy to accelerate access speed by the buffer memory portion.
For example, Fig. 7 is the form synoptic diagram of table segment data file in the embodiment of the invention.As shown in Figure 7, stored record is: (1001, China), (1002, Vietnam), (1003, Japan), (1004, Malaysia), (1005, Korea S) and (1006, India).It is 2 that division train value data become the train value data number of train value data block, and the train value data block of first row has three, is respectively: (1001,1002), (1003,1004); (1005,1006), the train value data block of second row has three, is respectively: (China, Vietnam), (Japan; Malaysia), (Korea S, India), meta data block is: (0,8,16; 32,48,68,6,84); Wherein, 0 is the position of train value data block (1001,1002) in table segment data file, and 8 is the position of train value data block (1003,1004) in table segment data file; 16 is the position of train value data block (1005,1006) in table segment data file, and 32 is the position of train value data block (China, Vietnam) in table segment data file, and 48 is train value data block (Japan; Malaysia) position in table segment data file, 68 is the position of train value data block (Korea S, India) in table segment data file, and 6 are the record number, and 84 is the position of meta data block in table segment data file.
During practical implementation, reach predefined as all record counts that the table section is stored and go up in limited time: partial record is retained in this table section, and newly-built table section, with all the other recording storage to newly-built table section; For example, the first half record is retained in this table section, and newly-built table section, with after half recording storage newly-built table section extremely.Because the maximum Major key of this table section changes, in control table, upgrade the maximum Major key of this table section; Minimum and the maximum Major key of the sign of newly-increased newly-built table section and institute's stored record in control table is pressed the minimum Major key ordering of table section during insertion.
For example, Fig. 8 is the synoptic diagram of table section division in the embodiment of the invention.As shown in Figure 8, stored record is in the table section: (1001, China), (1002, Vietnam), (1003; Japan), (1004, Malaysia), (1005, Korea S) and (1006, India); Inserting record (1007, the Hong-Kong), to cause the section of showing to reach the dominant record of table section several 7, and the his-and-hers watches section divides, and becomes two table sections: table section 1 (1,1001,1004) with show sections 2 (2; 1005,1007), wherein show being recorded as of section 1 storage: (1001, China), (1002; Vietnam), (1003, Japan), (1004, Malaysia); And being recorded as of table section 2 storages: (1005, Korea S), (1006, India), (1007; The Hong-Kong), the maximum Major key of table section 1 changes 1004 into from 1006 in the control table, and increases the information of table section 2 newly: the table segment identification is 2, and minimum Major key is 1005, and maximum Major key is 1007.
Following brief account is by some basic database query operations of the relevant database of embodiment of the invention method storage.
One, projection inquiry
The projection inquiry is meant some row that writes down in the question blank; Because the embodiment of the invention is by the row stored record; So just can read row as required; And the database that kind that is different from the row storage need read the data of all row, has so just significantly reduced the hard disk input and output, thereby has improved the query performance of relevant database.
For example, Fig. 9 is the synoptic diagram of a projection inquiry in the embodiment of the invention.As shown in Figure 9, the projection query statement is: " SELECT NAME FROM COUNTRY ", because the embodiment of the invention is pressed row stored record data; Can read-onlyly the fall in lines data of NAME; The output result, and the Value Data of row ID is not read, thus improved query performance.
Two, condition query
Condition query is meant that query statement has querying condition; Because the embodiment of the invention is by the row stored record; Can read the record of relevant row according to querying condition, in case the train value of record has passed through these querying conditions, the every other train value of output that needs just is read; Output in the middle of the final result, reduced IO than line data storehouse like this.
For example, Figure 10 is the synoptic diagram of a condition query in the embodiment of the invention.Shown in figure 10; The statement of condition query is: " SELECT ID FROM COUNTRY WHERE NAME=' Korea S " '; Value Data that can at first sharp scan columns NAME during inquiry is found the 5th record and is satisfied condition, and reads the value of the row ID of the 5th record like this and since in the embodiment of the invention in each train value data block access the train value data of fixed number are arranged; Train value data number like each train value data block access among Figure 10 is 2; Can calculate qualified ID value like this in the 3rd data block, then, can utilize the position data of the train value data block of storing in the metadata to locate the 3rd data block of row ID fast; Thereby read qualified ID value, promptly 1005.
Three, parallel processing
Because the indumentum in the embodiment of the invention is divided into the table section, like this, if in the environment of a cluster and cloud computing; Because the existence of a plurality of servers is arranged, can give each server with the uniform distribution of table section, during record in the question blank; Server in the cluster just can launch computing simultaneously; Deal with the record data in the own hard disk separately, reach the purpose of parallel processing, this just can improve performance of database greatly.
For example, Figure 11 is the synoptic diagram of a Cluster Database parallel processing in the embodiment of the invention.Shown in figure 11, Cluster Database is made up of two servers, and table is made up of two table sections, is stored in respectively in two servers, and each server provides the record queries service of relevant table section.
A kind of memory storage of relevant database also is provided in the embodiment of the invention, of following embodiment.Because the principle of this device solves problem is similar with the storage means of relevant database, so the enforcement of this device can be referring to the enforcement of the storage means of relevant database, and the repetition part repeats no more.
Shown in figure 12, the memory storage of relevant database can comprise in the embodiment of the invention:
Module 1201 is set up in control table, is used to set up control table, in order to the sign of storage list section and the minimum and maximum Major key of table section institute stored record, and by the minimum Major key ordering of table section;
Table section is set up module 1202, is used for when new record insertion table: if table does not have record, and then newly-built table section that should table; The first record insert module 1203 is used for the memory table with new this newly-built table section of record insertion; The first control table update module 1204, the sign that is used for the table section that this is newly-built is stored to control table, and the Major key of new record is stored to control table as the minimum and maximum Major key of this newly-built table section institute stored record;
Table segment search module 1205 is used for when new record insertion table: if the existing record of table, then according to the minimum Major key of all table section institute stored records in the Major key of new record and the control table, search the table section that new record should insert; The second record insert module 1206 is used for the memory table with new this table section of searching of record insertion, presses the Major key ordering during insertion; The second control table update module 1207 is used for then in control table, carrying out corresponding renewal if insert the minimum or maximum Major key that has changed this table section institute stored record of searching;
Record unloading processing module 1208; Being used for as the memory table of table section all writes down shared internal memory and reaches predefined and go up in limited time: show the segment data file for should table section correspondence on all recording storage to the hard disk in will show section memory table one, and empty the memory table of this table section; Store by row during stored record, and keep pressing the Major key ordering; If should show the segment data file on the hard disk, the then newly-built table segment data file that is somebody's turn to do; If the existing table segment data file that is somebody's turn to do on the hard disk then merges existing record in the record in the memory table and this table segment data file when storage.
Among the embodiment, table segment search module 1205 specifically can be used for: according to the Major key of new record and the minimum Major key of all table section institute stored records of control table, and the table section that adopts the new record of binary search to insert:
If the Major key of new record is between the minimum Major key of two table sections, the table section that then previous table section should be inserted as new record;
If the Major key of new record was then shown the table section that section should be inserted as new record with first before the minimum Major key of first table section;
If the Major key of new record is in the end after the minimum Major key of a table section, the table section that then last table section should be inserted as new record.
Among the embodiment, the data of being stored in the table segment data file comprise train value data and the metadata that record is corresponding; Wherein:
The train value data number of each row equates; The train value data of each row are divided into data block by fixing train value data number, form the train value data block;
Metadata store is in meta data block; Position, record number in table segment data file and meta data block the position in table segment data file of each train value data block of metadata record in table segment data file.
Among the embodiment, the storage order of train value data and metadata is in the table segment data file:
The train value data of first row, the train value data of second row are until the train value data and the metadata of last row.
Among the embodiment, metadata cache is in internal memory.
Among the embodiment, the memory storage of relevant database shown in Figure 12 can also comprise:
The table section splits module, is used for reaching predefined as all record counts that the table section is stored and goes up in limited time: partial record is retained in this table section, and newly-built table section, with all the other recording storage to newly-built table section;
The 3rd control update module is used for then in control table, carrying out corresponding renewal if the minimum or maximum Major key of this table section institute stored record changes; Minimum and the maximum Major key of the sign of newly-increased newly-built table section and institute's stored record in control table is pressed the minimum Major key ordering of table section during insertion.
Among the embodiment, table section splits a module and specifically can be used for: the first half record is retained in this table section, and newly-built table section, with after half recording storage newly-built table section extremely.
The embodiment of the invention is compared with prior art one, need not major key is set up index, can save system overhead; And the embodiment of the invention can solve the problem that capable stored data base can not read row as required by the row storage;
The embodiment of the invention sorts to record with table segmenting and by Major key, compares the expense in the time of can reducing storage with prior art two; And be different from prior art two needs and connect data with the row of the separate storage reconstruct raw readings that connects together, the embodiment of the invention need not to connect data and comes the reconstruct record, can not increase to safeguard the system burden that connects data;
Same, need ROWID to connect train value reconstruction record thereby be different from prior art three, the ROWID that the embodiment of the invention need not stored record rebuilds record, can not increase system burden;
Compare with prior art four; The only corresponding data files of table section in the embodiment of the invention; And storage is the record of relevant database, is not the data of Key/Value form, and the embodiment of the invention is the row storage by record during storage; Be not listed as the notion of family, be suitable as the storage basis of relevant database fully.
The embodiment of the invention can improve the query performance of database; And realize the storage of relevant database based on major key ordering and segmentation; Can be used as the basic storage mode of the parallel computation that realizes relevant database; The table data balancing of fragmented storage is assigned in the node of parallel database, utilizes the Map/Reduce algorithm to implement concurrent operation again.
Those skilled in the art should understand that embodiments of the invention can be provided as method, system or computer program.Therefore, the present invention can adopt the form of the embodiment of complete hardware embodiment, complete software implementation example or combination software and hardware aspect.And the present invention can be employed in the form that one or more computer-usable storage medium (including but not limited to magnetic disk memory, CD-ROM, optical memory etc.) that wherein include computer usable program code go up the computer program of implementing.
The present invention is that reference is described according to the process flow diagram and/or the block scheme of method, equipment (system) and the computer program of the embodiment of the invention.Should understand can be by the flow process in each flow process in computer program instructions realization flow figure and/or the block scheme and/or square frame and process flow diagram and/or the block scheme and/or the combination of square frame.Can provide these computer program instructions to the processor of multi-purpose computer, special purpose computer, Embedded Processor or other programmable data processing device to produce a machine, make the instruction of carrying out through the processor of computing machine or other programmable data processing device produce to be used for the device of the function that is implemented in flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame appointments.
These computer program instructions also can be stored in ability vectoring computer or the computer-readable memory of other programmable data processing device with ad hoc fashion work; Make the instruction that is stored in this computer-readable memory produce the manufacture that comprises command device, this command device is implemented in the function of appointment in flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame.
These computer program instructions also can be loaded on computing machine or other programmable data processing device; Make on computing machine or other programmable devices and to carry out the sequence of operations step producing computer implemented processing, thereby the instruction of on computing machine or other programmable devices, carrying out is provided for being implemented in the step of the function of appointment in flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame.
Above-described specific embodiment; The object of the invention, technical scheme and beneficial effect have been carried out further explain, and institute it should be understood that the above is merely specific embodiment of the present invention; And be not used in qualification protection scope of the present invention; All within spirit of the present invention and principle, any modification of being made, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.