CN105159941A - Data record searching method and device - Google Patents

Data record searching method and device Download PDF

Info

Publication number
CN105159941A
CN105159941A CN201510483713.2A CN201510483713A CN105159941A CN 105159941 A CN105159941 A CN 105159941A CN 201510483713 A CN201510483713 A CN 201510483713A CN 105159941 A CN105159941 A CN 105159941A
Authority
CN
China
Prior art keywords
data record
index
line number
address
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201510483713.2A
Other languages
Chinese (zh)
Other versions
CN105159941B (en
Inventor
沈建荣
窦锦帅
谭国斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Xiaomi Technology Co Ltd
Xiaomi Inc
Original Assignee
Xiaomi Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xiaomi Inc filed Critical Xiaomi Inc
Priority to CN201510483713.2A priority Critical patent/CN105159941B/en
Publication of CN105159941A publication Critical patent/CN105159941A/en
Application granted granted Critical
Publication of CN105159941B publication Critical patent/CN105159941B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/31Indexing; Data structures therefor; Storage structures
    • G06F16/316Indexing structures
    • G06F16/328Management therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/335Filtering based on additional data, e.g. user or group profiles
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9535Search customisation based on user profiles and personalisation

Abstract

The invention discloses a data record searching method and a data record searching device and belongs to the field of data storage. The method comprises: receiving an instruction of inquiring a target data record in a database; inquiring an initial search address from a preset address index, wherein the initial search address is an address of an index data record of which a storage position is the closest to the target data record; and searching the target data record from a position corresponding to the initial search address. According to the invention, through receiving the instruction of inquiring the target data record in the database, inquiring the initial search address from the preset address index, searching the target data record from the initial search address and storing addresses of a plurality of index data records in advance, only the address of the index data record closest to the target data record needs to be determined and then line-by-line search is performed from the position corresponding to the address during the target data record searching process, so that the target data record search time is shortened and the search efficiency is improved.

Description

Data record search method and device
Technical field
The disclosure relates to field of data storage, particularly a kind of data record search method and device.
Background technology
Along with the development of network application, the situation of data page is also more and more common.Such as, a user adds up to have issued a large amount of microbloggings, and these microbloggings all cannot show in same one page, and the microblogging now can issued this user carries out paging.
In the correlation technique stored paged data, each data record all separately branch stores, and such as, each microblogging that user delivers can as a data record, and each microblogging is stored as a line separately in a database; A certain bar microblogging line number in a database the number in this page can be determined according to the number of pages at this microblogging place and this microblogging, this line number just represents this microblogging stores which row in a database, when searching this microblogging in a database, line by line scan from the 1st row in database, record scanned line number, till the line number scanning this microblogging place simultaneously.Such as, every one page in microblog page is set and shows 10 microbloggings, a certain article of microblogging is the 3rd article in the 5th page, then this microblogging line number is in a database 53, when retrieving this microblogging, can scan 1st row from database, scan the 53rd row always, the data in the 53rd row are extracted as the data of this article of microblogging.
It is all need to line by line scan from the Article 1 data record in database that scheme in correlation technique is searched at every turn, when the data record number in database is more, can affect the search efficiency of data record.
Summary of the invention
In order to overcome Problems existing in correlation technique, present disclose provides a kind of data record search method and device.Described technical scheme is as follows:
According to first aspect of the present disclosure, provide a kind of data record search method, described method comprises:
Receive the instruction of query aim data record in a database, in described database, store at least one data record;
From the allocation index pre-set, inquire about initial seek address, described initial seek address is the address of the index data record that in described database, memory location is nearest apart from described target data record; Described index data record is in described database, memory address by described allocation index the data record of including;
Described target data record is searched from the position that described initial seek address is corresponding.
In first aspect of the present disclosure, only need the address determining the index data record that distance objective data record is nearest, from this address, the position at place is searched one by one, do not need to search from Article 1 data record, thus shorten target data objects search the time, improve search efficiency.
Optionally, each data records list in described at least one data record is solely stored as a line, the corresponding relation between index line number and index line mark is stored in described allocation index, described index line number is preassigned line number, the mark of the row at the data record place of described index mark to be line number be corresponding index line number;
Inquiring about initial seek address the described allocation index from pre-setting, comprising:
Obtain the line number of described target data record;
Calculate the immediate index line number of line number with described target data record;
By in described allocation index, the index line corresponding with the line number of described target data record immediate index line number identifies and is retrieved as described initial seek address.
In this possibility, index is carried out by the line number of data record, search the immediate index line number of distance objective data record, search from the index line that this index line number found is corresponding identifies the position at place, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Optionally, described method also comprises:
Search described target data record the position corresponding from described initial seek address before, determine described target data record line number and and the immediate index line number of line number of described target data record between magnitude relationship;
According to described magnitude relationship determination search direction;
Describedly from described initial seek address, search described target data record, comprising:
From the position that described initial seek address is corresponding, search described target data record according to described search direction.
In this possibility, while determining in fact to search address, also determine search direction, select the shortest accessed path to search, improve search efficiency further.
Optionally, described method also comprises:
When in described database, total line number of pieces of data record meets or exceeds designated value, by described designated value, and line number is the mark of the row at the data record place of described designated value, and corresponding stored is index line number in described allocation index and index line mark.
In this optional scheme, when the quantity of data record is increased to certain value in database, allocation index is expanded, while Data expansion in a database, keep search efficiency.
Optionally, described method also comprises:
When the data record stored in described database occurs to change, obtain the mark of the row at the data record place in the corresponding database after change of described index line number;
Index line corresponding for index line number described in described allocation index is identified, is updated to the mark of the row at the data record place in the corresponding database after change of described index line number.
In this optional scheme, when the data record stored in database occurs to change, allocation index is upgraded, ensures the accuracy of searching.
According to second aspect of the present disclosure, provide a kind of data record search device, it is characterized in that, described device comprises:
Command reception module, for receiving the instruction of query aim data record in a database, stores at least one data record one by one in described database;
Address lookup module, for inquiring about initial seek address from the allocation index pre-set, described initial seek address is the address of the nearest index data record of target data record that in described database, memory location receives apart from described command reception module; Described index data record is in described database, memory address by described allocation index the data record of including;
Search module, for from described address lookup module polls to position corresponding to initial seek address search described target data record.
In second aspect of the present disclosure, only need the address determining the index data record that distance objective data record is nearest, from this address, the position at place is searched one by one, do not need to search from Article 1 data record, thus shorten target data objects search the time, improve search efficiency.
Optionally, each data records list in described at least one data record is solely stored as a line, the corresponding relation between index line number and index line mark is stored in described allocation index, described index line number is preassigned line number, the mark of the row at the data record place of described index mark to be line number be corresponding index line number;
Described address lookup module, comprising:
Line number obtains submodule, for obtaining the line number of the target data record that described command reception module receives;
For calculating, calculating sub module, to obtain with described line number that submodule gets, the immediate index line number of line number of described target data record;
Address acquisition submodule, for by described allocation index, the index line corresponding with the line number of described target data record immediate index line number that described calculating sub module calculates identifies and is retrieved as described initial seek address.
In this optional scheme, index is carried out by the line number of data record, search the immediate index line number of distance objective data record, search from the index line that this index line number found is corresponding identifies the position at place, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Optionally, described device also comprises:
Relationship determination module, for searching before module searches described target data record from the position that described initial seek address is corresponding described, determine that the line number of the target data record that described command reception module receives and described calculating sub module calculate and between the immediate index line number of line number of described target data record magnitude relationship;
Direction determination module, for the magnitude relationship determination search direction determined according to described relationship determination module;
Describedly search module, for the position corresponding from described initial seek address, the search direction determined according to described direction determination module searches described target data record.
In this optional scheme, while determining in fact to search address, also determine search direction, select the shortest accessed path to search, improve search efficiency further.
Optionally, described device also comprises:
Index stores module, for when in described database, total line number of pieces of data record meets or exceeds designated value, by described designated value, and line number is the mark of the row at the data record place of described designated value, and corresponding stored is index line number in described allocation index and index line mark.
In this optional scheme, when the quantity of the data record in database is increased to certain value, allocation index is expanded, while Data expansion in a database, keep search efficiency.
Optionally, described device also comprises:
Identifier acquisition module, during for occurring to change when the data record stored in described database, obtains the mark of the row at the data record place in the corresponding database after change of described index line number;
Index upgrade module, for being identified by index line corresponding for index line number described in described allocation index, is updated to the mark of the row at the data record place in the corresponding database after change of described index line number.
In this optional scheme, when the data record stored in database occurs to change, allocation index is upgraded, ensures the accuracy of searching.
According to the third aspect of the present disclosure, provide a kind of data record search device, it is characterized in that, described device comprises:
Processor;
For the storer of storage of processor executable instruction;
Wherein, described processor is configured to:
Receive the instruction of query aim data record in a database, in described database, store at least one data record one by one;
From the allocation index pre-set, inquire about initial seek address, described initial seek address is the address of the index data record that in described database, memory location is nearest apart from described target data record; Described index data record is in described database, memory address by described allocation index the data record of including;
Described target data record is searched from the position that described initial seek address is corresponding.
In the third aspect of the present disclosure, only need the address determining the index data record that distance objective data record is nearest, from this address, the position at place is searched one by one, do not need to search from Article 1 data record, thus shorten target data objects search the time, improve search efficiency.
The technical scheme that embodiment of the present disclosure provides can comprise following beneficial effect:
By receiving the instruction of query aim data record in a database, initial seek address is inquired about from the allocation index pre-set, this initial seek address is the address of the index data record that in this database, memory location is nearest apart from this target data record, this target data record is searched from the position that this initial seek address is corresponding, prestore the address of some index data records, when searching target data record, only need the address determining the index data record that distance objective data record is nearest, search line by line from this address, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Should be understood that, it is only exemplary that above general description and details hereinafter describe, and can not limit the disclosure.
Accompanying drawing explanation
Accompanying drawing to be herein merged in instructions and to form the part of this instructions, shows embodiment according to the invention, and is used from instructions one and explains principle of the present invention.
Fig. 1 is the process flow diagram of a kind of data record search method according to an exemplary embodiment;
Fig. 2 A is the process flow diagram of a kind of data record search method according to another exemplary embodiment;
Fig. 2 B is the process flow diagram of a kind of initial seek address inquiring method according to another exemplary embodiment;
Fig. 3 is the process flow diagram of a kind of data record search method according to another exemplary embodiment;
Fig. 4 is the block diagram of a kind of data record search device according to an exemplary embodiment;
Fig. 5 is the block diagram of a kind of data record search device according to another exemplary embodiment;
Fig. 6 is the block diagram of a kind of device according to an exemplary embodiment.
Embodiment
Here will perform explanation to exemplary embodiment in detail, its sample table shows in the accompanying drawings.When description below relates to accompanying drawing, unless otherwise indicated, the same numbers in different accompanying drawing represents same or analogous key element.Embodiment described in following exemplary embodiment does not represent all embodiments consistent with the present invention.On the contrary, they only with as in appended claims describe in detail, the example of apparatus and method that aspects more of the present invention are consistent.
Fig. 1 is the process flow diagram of a kind of data record search method according to an exemplary embodiment.This data record search method is for comprising in the equipment of database.As shown in Figure 1, this data record search method can comprise the following steps.
In a step 101, receive the instruction of query aim data record in a database, in this database, store at least one data record.
In the optional implementation of the one of the present embodiment, store data record in a database and comprise: the line number that data record is expert at, and the line identifier corresponding to this line number.
In a step 102, from the allocation index pre-set, initial seek address is inquired about.
Wherein, initial seek address is the address of the index data record that in this database, memory location distance objective data record is nearest; This index data record is in database, memory address by allocation index the data record of including.
Wherein, the index data record that memory location distance objective data record is nearest, when referring to the position at target data record place of lining by line scan from the position at each index data record place, needs the index data record that the line number of scanning is minimum.
In step 103, from the position that this initial seek address is corresponding, this target data record is searched.
In sum, data record search method shown in disclosure embodiment, by receiving the instruction of query aim data record in a database, initial seek address is inquired about from the allocation index pre-set, this initial seek address is the address of the index data record that in this database, memory location is nearest apart from this target data record, this target data record is searched from this initial seek address, prestore the address of some index data records, when searching target data record, only need the address determining the index data record that distance objective data record is nearest, search line by line from this address, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Article one, after data are recorded as a line that merit is stored as in database, database can be row distribution one mark at this data record place, the mark of this row can be the numerical value distributed from 1, and database can according to the position of this line identifier quick position to this data record place.Scheme below the disclosure shown in embodiment, pre-set an allocation index exactly, the mark of the row at the segment data record place in database is stored in this allocation index, when searching target data record, first search by the mark of row of including in allocation index, the mark of the row of memory location and the nearest data record of target data record, and quick position to this row mark indicated by a line, and search target data record line by line from this line.Such as, target data record is the 1010th row data record in database, the mark of the row at place has been included in allocation index, and nearest apart from this target data record one article of data record is the 1000th row data record, then can find out that the 1010th article of data record is the 10th article of data record after the 1000th article of data record, when each data is recorded as a line, only need to line by line scan backward from the 1000th article of data record, the 10th row data record scanned is defined as target data record.
Fig. 2 A is the process flow diagram of a kind of data record search method according to another exemplary embodiment.This data record search method is for comprising in the equipment of database.As shown in Figure 2 A, this data record search method can comprise the following steps.
In step 201, receive the instruction of query aim data record in a database, in this database, store at least one data record.
In step 202., from the allocation index pre-set, initial seek address is inquired about.
This initial seek address is the address of the index data record that in database, memory location distance objective data record is nearest; This index data record is in database, memory address by this allocation index the data record of including.
Database is except storing data record, also pre-set and safeguard an allocation index, the address of some index data records is stored in this allocation index, further, this allocation index also provides the function of the address inquiring about the nearest index data record of distance objective data record in a database.
Optionally, in a kind of possible implementation of above-mentioned index address, each data records list in this at least one data record is solely stored as a line, the corresponding relation between index line number and index line mark is stored in this allocation index, this index line number is preassigned line number, the mark of the row at the data record place of this index mark to be line number be corresponding index line number; Please refer to Fig. 2 B, it illustrates the process flow diagram of a kind of initial seek address inquiring method that disclosure embodiment provides, this initial seek address inquiring method can be as follows:
In step 202a, obtain the line number of this target data record.
In step 202b, calculate the immediate index line number of line number with this target data record.
Wherein, immediate index line number here can be in each index line number of storing of allocation index, less than the line number of target data record, and and the minimum index line number of the absolute value of difference between the line number of target data record; Or immediate index line number here also can be in each index line number of storing of allocation index, larger than the line number of target data record, and and the minimum index line number of the absolute value of difference between the line number of target data record.
In step 202c, by this allocation index, the index line corresponding with the line number of this target data record immediate index line number identifies and is retrieved as this initial seek address.
Database is when storing data record, and stored one by one in a database by each data record, each data records list is solely stored as a line.Namely the line number of each data record represents these data and is recorded in database to be in which row, and also represent this data record is which bar in the pieces of data record stored in database simultaneously.After data are recorded as a line that merit is stored as in database, database also distributes a mark for that a line at this data record place, and this mark can be the numeral increased progressively from 1.The mark of the row at each data record place can as the address of this data record.
What store in allocation index can be corresponding relation between index line number and index line identify, wherein, this index line number is the preassigned line number of developer, such as, developer can specify 1000,2000,3000 ... be index line number etc. the line numbers of whole thousand numbers, then the corresponding relation between the mark storing the row at index line number 1000 and the 1000th article of data record place in allocation index.The storage organization of this allocation index can be as follows:
Wherein, store 5 corresponding relations in said structure, the first half of every bar corresponding relation is index line number, and latter half is index line mark, i.e. the mark of data record that a line in a database that first half index line number is corresponding.Such as, if some index line numbers are 1000, in database the data record place of corresponding 1000th row row be designated 9985, then namely can comprise the corresponding relation between 1000 and 9985 in allocation index, wherein the 9985 index lines marks being index line number 1000 correspondence.
When receiving the instruction of query aim data record, first the line number of this target data record is obtained, determine to store in allocation index, apart from the immediate index line number of the line number of this target data record, and using index line mark corresponding for this index line number of determining as initial seek address.
In step 203, from the position that initial seek address is corresponding, this target data record is searched.
Such as, when initial seek address is a line being designated 9985 in database, namely can quick position to the position at this line place being designated 9985, and to line by line scan from this position, to search target data record.Do not need like this to line by line scan from the first row of database, but can search from the index data record that distance objective data record is nearer, that effectively can reduce target data record searches the time, improves search efficiency.
Optionally, when searching target data record, can calculate target data record line number and and the immediate index line number of line number of this target data record between the absolute value d of difference, and line by line scan from the position that this initial seek address is corresponding, capable for the d scanned after position corresponding for this initial seek address data record is defined as target data record.
In the disclosed embodiments, when can specify to line by line scan in a database, only scan from front to back, namely when determining initial seek address, can determine closest apart from the line number of this target data record, numerical value is less than the index line number of the line number of this target data record simultaneously, and identifies index line corresponding for this index line number determined as this initial seek address.Such as, the line number of target data record is 1050, two the index line numbers be in before and after line number 1050 are respectively 1000 and 2000, then can determine that the index line of index line number 1000 correspondence less than 1050 is designated initial seek address, and line by line scan backward from the position that this initial seek address is corresponding.
Or, when also can specify to line by line scan in a database, only scan from back to front, namely when determining initial seek address, can determine closest apart from the line number of this target data record, simultaneously numerical value is greater than the index line number of the line number number of this target data record, and using index line mark corresponding for this index line number of determining as this initial seek address.Such as, the line number of target data record is 1050, two the index line numbers be in before and after line number 1050 are respectively 1000 and 2000, then can determine that the index line of index line number 2000 correspondence larger than 1050 is designated initial seek address, and line by line scan forward from this initial seek address.
Microblogging is checked for a certain user, microblog data is stored in the database of server, after user carries out checking the operation of lower one page microblogging in the client, user end to server sends the instruction of the 10th article of microblogging in inquiry the 10th page, after server receives this instruction, determine that this microblogging line number is in a database 1010, inquiry address above mentioned index determine with this line number closest to and the index line number less than 1010 is 1000, corresponding index line is designated 9985, then server is directly positioned to the position that line identifier in database is a line place of 9985, and line by line scan backward from this row.It is searched code and can be expressed as:
SELECT*FROMLIST_TABLEWHEREid>9985LIMIT10,row_count;
The implication of above-mentioned code is: obtain the 10th row data record be designated after the data line record of 9985.Namely line by line scan backward from that a line being designated 9985, until scan the 10th row.
Wherein, database when data query record, when only knowing target data record at which row, the position of target data record cannot be directly targeted to, can only the scanning of a line a line, record the line number scanned, until scan the line number at target data record place simultaneously.
In step 204, when in this database, total line number of pieces of data record meets or exceeds designated value, by this designated value, and line number is the mark of the row at the data record place of this designated value, and corresponding stored is index line number in this allocation index and index line mark.
Developer can pre-set the designated value as index line number, such as, when the line numbers that developer specifies whole thousand numbers are index line number, then 1000,2000 ... 10000,11000,12000 ... Deng being all designated value.Along with the quantity of the data record in database is in increase, the line number of the data record stored recently in database is also in continuous increase, when the maximum line number of the data record in database meets or exceeds a certain designated value that developer pre-sets, namely can be the mark of the row at the data record place of this designated value by this designated value and line number, corresponding stored be index line number in this allocation index and index line mark.
Such as, developer specifies the line number of whole thousand numbers to be index line number, originally had 4999 data records in database, have the corresponding relation between four index line numbers and index line mark in allocation index, corresponding index line number is respectively 1000,2000,3000 and 4000.Data record in follow-up data storehouse has increased again one newly, the total number of the data record in database is made to reach 5000,5000 is a designated value, then need to add index line number 5000 in allocation index, and the mark of the row at the 5000th article of data record place in database is stored as the index line mark of index line number 5000 correspondence.
In step 205, when the data record stored in this database occurs to change, obtain the mark of the row at the data record place in the corresponding database after change of index line number; Index line corresponding for this index line number in this allocation index is identified, is updated to the mark of the row at the data record place in the corresponding database after change of index line number.
What deserves to be explained is, in conjunction with the description in above-mentioned steps 101, store the line number of data record in a database, and the line identifier that this line number is corresponding, then when the data record in database occurs to change, namely the line number of this data record changes.
When the deleted data records of the data record that stored in database, or in the middle of the data record stored, insert new data record, the line number of other data record after the data record deleted or insert all may be caused to change, now need to upgrade allocation index.When scheduler index, keep the index line number in allocation index constant, inquire about the mark of the row at the data record place of these index line numbers separately in corresponding database after change, and corresponding separately as these index line numbers by the mark of the row at the data record place in these index line numbers separately corresponding database in the updated, new index line identifies.
Such as, at a time, allocation index can described above shown in storage organization, set now line number in database as 1001 data record place row be designated 9988, line number be the row at the data record place of 2001 be designated 10903, line number be the row at the data record place of 3001 be designated 50086, line number be the row at the data record place of 4001 be designated 86782, line number be the row at the data record place of 5001 be designated 90083; If certain the data record that then in database, line number is within front 1000 is deleted, now, after this deleted data record, the line number of all data records all will deduct 1, namely delete in the database after a data record, line number be 1000 data record to be original line number be 1001 data record, now, the mark of the row at each data record place after needing according to deletion data record carrys out scheduler index, and the allocation index after renewal is as follows:
In addition, during the data record that between two the data records existed in a database, insertion one is new, the mode that allocation index is upgraded and above-mentioned delete data record similar, such as, after supposing the data record that insertion one article is new between the 1st article of data record and Article 2 data record, index line mark is updated to the mark of row corresponding to the 999th, 1999,2999,3999 and 4999 original row data records respectively.
In sum, data record search method shown in disclosure embodiment, by receiving the instruction of query aim data record in a database, initial seek address is inquired about from the allocation index pre-set, this initial seek address is the address of the index data record that in this database, memory location is nearest apart from this target data record, this target data record is searched from the position that this initial seek address is corresponding, prestore the address of some index data records, when searching target data record, only need the address determining the index data record that distance objective data record is nearest, search line by line from this position, address, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Fig. 3 is the process flow diagram of a kind of data record search method according to another exemplary embodiment.This data record search method is for comprising in the equipment of database.As shown in Figure 3, this data record search method can comprise the following steps.
In step 301, receive the instruction of query aim data record in a database, in this database, store at least one data record.
In step 302, from the allocation index pre-set, initial seek address is inquired about.
This initial seek address is the address of the index data record that in database, memory location distance objective data record is nearest; This index data record is in database, memory address by this allocation index the data record of including.
Optionally, in a kind of possible implementation of above-mentioned index address, each data records list in this at least one data record is solely stored as a line, the corresponding relation between index line number and index line mark is stored in this allocation index, this index line number is preassigned line number, the mark of the row at the data record place of this index mark to be line number be corresponding index line number.When inquiring about initial seek address, the line number of this target data record can be obtained, calculate the immediate index line number of line number with this target data record, by in this allocation index, the index line corresponding with the line number of this target data record immediate index line number identifies and is retrieved as this initial seek address.
Wherein, immediate index line number here, refers in each index line number that allocation index stores, and the index line number that the absolute value of difference between the line number of target data record is minimum.
The step of inquiry initial seek address can description under step 201 corresponding to reference diagram 2A and step 202, repeats no more herein.
In step 303, search direction is determined.
Optionally, when determining search direction, can determine this target data record line number and and the immediate index line number of line number of this target data record between magnitude relationship; According to this magnitude relationship determination search direction.
In step 304, from the position that initial seek address is corresponding, target data record is searched according to this search direction.
In the disclosed embodiments, direction of scanning when lining by line scan in a database can not be limited, when determining initial seek address, only can determine apart from the immediate index line number of the line number of this target data record, determine direction of scanning according to the magnitude relationship between the line number of target data record and the index line number determined.Such as, the line number of target data record is 1010, be 1000 with the immediate index line number of line number 1010, simultaneously because line number 1010 is greater than index line number 1000, then illustrate that target data record is after the data record of index line number 1000 correspondence, then can determine that initial seek address is the index line mark of index line number 1000 correspondence, and search direction is for search backward.
Microblogging is checked for a certain user, microblog data is stored in the database of server, after user carries out checking the operation of lower one page microblogging in the client, user end to server sends the instruction of the 10th article of microblogging in inquiry the 10th page, after server receives this instruction, determine that this microblogging line number is in a database 1010, inquiry address above mentioned index determines that immediate index line number is 1000 with this line number, and this index line number 1000 is less than 1010, then determine that corresponding index line is designated 9985, and search direction is for search backward, then server is directly positioned in database a line being designated 9985, and line by line scan backward from this row.
In the disclosed embodiments, owing to not limiting direction of scanning when lining by line scan in a database, likely can cause from allocation index, inquire two satisfactory initial seek addresses, namely the interval between the line number of target data record and former and later two index line numbers is identical, for this situation, can be pre-set by developer and get previous index line number or get a rear index line number, or, also can Stochastic choice one.
In step 305, when in this database, total line number of pieces of data record meets or exceeds designated value, by this designated value, and line number is the mark of the row at the data record place of this designated value, and corresponding stored is index line number in this allocation index and index line mark.
Within step 306, when the data record stored in this database occurs to change, obtain the mark of the row at the data record place in the corresponding database after change of index line number; Index line corresponding for this index line number in this allocation index is identified, is updated to the mark of the row at the data record place in the corresponding database after change of index line number.
The mode increased allocation index and upgrade can step 204 in the corresponding embodiment of reference diagram 2 and step 205, repeats no more herein.
In sum, data record search method shown in disclosure embodiment, by receiving the instruction of query aim data record in a database, initial seek address is inquired about from the allocation index pre-set, this initial seek address is the address of the index data record that in this database, memory location is nearest apart from this target data record, this target data record is searched from this initial seek address, prestore the address of some index data records, when searching target data record, only need the address determining the index data record that distance objective data record is nearest, search one by one from this address, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Following is disclosure device embodiment, may be used for performing disclosure embodiment of the method.For the details do not disclosed in disclosure device embodiment, please refer to disclosure embodiment of the method.
Fig. 4 is the block diagram of a kind of data record search device according to an exemplary embodiment, and this data record search device may be used for comprising in the equipment of database, performs the method as shown in Fig. 1,2A or 3.As shown in Figure 4, this data record search device includes but not limited to: command reception module 401, address lookup module 402 and search module 403.
Described command reception module 401 is set to the instruction for receiving query aim data record in a database, stores at least one data record in described database.
Described address lookup module 402 is set to for inquiring about initial seek address from the allocation index pre-set, and described initial seek address is the address of the nearest index data record of target data record that in described database, memory location receives apart from described command reception module 401; Described index data record is in described database, memory address by described allocation index the data record of including.
Described searching module 403 is set to position corresponding to initial seek address for inquiring from described address lookup module 402 searches described target data record.
In sum, data record search device shown in disclosure embodiment, by receiving the instruction of query aim data record in a database, initial seek address is inquired about from the allocation index pre-set, this initial seek address is the address of the index data record that in this database, memory location is nearest apart from this target data record, this target data record is searched from this initial seek address, prestore the address of some index data records, when searching target data record, only need the address determining the index data record that distance objective data record is nearest, search line by line from this address, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Fig. 5 is the block diagram of a kind of data record search device according to another exemplary embodiment, and this data record search device may be used for comprising in the equipment of database, performs the method as shown in Fig. 1,2A or 3.As shown in Figure 4, this data record search device includes but not limited to: command reception module 401, address lookup module 402 and search module 403.
Described command reception module 401 is set to the instruction for receiving query aim data record in a database, stores at least one data record in described database;
Described address lookup module 402 is set to for inquiring about initial seek address from the allocation index pre-set, and described initial seek address is the address of the nearest index data record of target data record that in described database, memory location receives apart from described command reception module 401; Described index data record is in described database, memory address by described allocation index the data record of including;
Described searching module 403 is set to position corresponding to initial seek address for inquiring from described address lookup module 402 searches described target data record.
Optionally, each data records list in described at least one data record is solely stored as a line, the corresponding relation between index line number and index line mark is stored in described allocation index, described index line number is preassigned line number, the mark of the row at the data record place of described index mark to be line number be corresponding index line number;
Described address lookup module 402, comprising: line number obtains submodule 402a, calculating sub module 402b and address acquisition submodule 402c.
Described line number acquisition submodule 402a is set to the line number for obtaining the target data record that described command reception module 401 receives;
Described calculating sub module 402b is set to obtain with described line number that submodule 402a gets, the immediate index line number of line number of described target data record for calculating;
Described address acquisition submodule 402c is set to for by described allocation index, and the index line corresponding with the line number of described target data record immediate index line number that described calculating sub module 402b calculates identifies and be retrieved as described initial seek address.
Optionally, described device also comprises: relationship determination module 404 and direction determination module 405.
Search before module 403 searches described target data record from the position that described initial seek address is corresponding described in described relationship determination module 404 is arranged in use in, determine that the line number of the target data record that described command reception module 401 receives and described calculating sub module 402b calculate and between the immediate index line number of line number of described target data record magnitude relationship;
Described direction determination module 405 is set to the magnitude relationship determination search direction for determining according to described relationship determination module 404;
Describedly search module 403 is set to position corresponding to initial seek address for inquiring from described address lookup module 402, the search direction determined according to described direction determination module 405 searches described target data record.
Optionally, the described absolute value d searching that module 403 line number and described calculating sub module 402b be set to for calculating the target data record that described command reception module 401 receives calculates and between the immediate index line number of line number of described target data record difference, and line by line scan from the position that the initial seek address that described address acquisition submodule 402c gets is corresponding, the d capable data record scanned after position corresponding for described initial seek address is defined as described target data record.
Optionally, described device also comprises: index stores module 406.
Described index stores module 406 is set to for when in described database, total line number of pieces of data record meets or exceeds designated value, by described designated value, and line number is the mark of the row at the data record place of described designated value, corresponding stored is index line number in described allocation index and index line mark.
Optionally, described device also comprises: identifier acquisition module 407 and index upgrade module 408.
When described identifier acquisition module 407 is set to for occurring to change when the data record stored in described database, obtain the mark of the row at the data record place in the corresponding database after change of described index line number;
Described index upgrade module 408 is set to for being identified by index line corresponding for index line number described in described allocation index, is updated to the mark of the row at the data record place in the corresponding database after change of described index line number.
In sum, data record search device shown in disclosure embodiment, by receiving the instruction of query aim data record in a database, initial seek address is inquired about from the allocation index pre-set, this initial seek address is the address of the index data record that in this database, memory location is nearest apart from this target data record, this target data record is searched from this initial seek address, prestore the address of some index data records, when searching target data record, only need the address determining the index data record that distance objective data record is nearest, search line by line from this address, do not need to search from Article 1 data record, thus shorten target data record search the time, improve search efficiency.
Fig. 6 is the block diagram of a kind of device 600 according to an exemplary embodiment.This device 600 can produce larger difference because of configuration or performance difference, one or more central processing units (centralprocessingunits can be comprised, CPU) 622 (such as, one or more processors) and storer 632, one or more store the storage medium 630 (such as one or more mass memory units) of application program 642 or data 644.Wherein, storer 632 and storage medium 630 can be of short duration storages or store lastingly.The program being stored in storage medium 630 can comprise one or more modules (diagram does not mark), each module can comprise a series of command operatings in device, and this series of command operating may be used for realizing as shown Overall Steps arbitrary in Fig. 1,2A, 2B and Fig. 3 or part steps.Further, central processing unit 622 can be set to communicate with storage medium 630, and device 600 performs a series of command operatings in storage medium 630.
Device 600 can also comprise one or more power supplys 626, one or more wired or wireless network interfaces 650, one or more IO interface 658, one or more keyboards 656, and/or, one or more operating systems 641, such as WindowsServerTM, MacOSXTM, UnixTM, LinuxTM, FreeBSDTM etc.
About the device in above-described embodiment, wherein the concrete mode of modules executable operations performs detailed description in about the embodiment of the method, will not elaborate explanation herein.
Should be understood that, the present invention is not limited to precision architecture described above and illustrated in the accompanying drawings, and can perform various amendment and change not departing from its scope.Scope of the present invention is only limited by appended claim.

Claims (11)

1. a data record search method, is characterized in that, described method comprises:
Receive the instruction of query aim data record in a database, in described database, store at least one data record;
From the allocation index pre-set, inquire about initial seek address, described initial seek address is the address of the index data record that in described database, memory location is nearest apart from described target data record; Described index data record is in described database, memory address by described allocation index the data record of including;
Described target data record is searched from the position that described initial seek address is corresponding.
2. method according to claim 1, it is characterized in that, each data records list in described at least one data record is solely stored as a line, the corresponding relation between index line number and index line mark is stored in described allocation index, described index line number is preassigned line number, the mark of the row at the data record place of described index mark to be line number be corresponding index line number;
Inquiring about initial seek address the described allocation index from pre-setting, comprising:
Obtain the line number of described target data record;
Calculate the immediate index line number of line number with described target data record;
By in described allocation index, the index line corresponding with the line number of described target data record immediate index line number identifies and is retrieved as described initial seek address.
3. method according to claim 2, is characterized in that, described method also comprises:
Search described target data record the position corresponding from described initial seek address before, determine described target data record line number and and the immediate index line number of line number of described target data record between magnitude relationship;
According to described magnitude relationship determination search direction;
Describedly from described initial seek address, search described target data record, comprising:
From the position that described initial seek address is corresponding, search described target data record according to described search direction.
4. method according to claim 2, is characterized in that, described method also comprises:
When in described database, total line number of pieces of data record meets or exceeds designated value, by described designated value, and line number is the mark of the row at the data record place of described designated value, and corresponding stored is index line number in described allocation index and index line mark.
5. method according to claim 2, is characterized in that, described method also comprises:
When the data record stored in described database occurs to change, obtain the mark of the row at the data record place in the corresponding database after change of described index line number;
Index line corresponding for index line number described in described allocation index is identified, is updated to the mark of the row at the data record place in the corresponding database after change of described index line number.
6. a data record search device, is characterized in that, described device comprises:
Command reception module, for receiving the instruction of query aim data record in a database, stores at least one data record in described database;
Address lookup module, for inquiring about initial seek address from the allocation index pre-set, described initial seek address is the address of the nearest index data record of target data record that in described database, memory location receives apart from described command reception module; Described index data record is in described database, memory address by described allocation index the data record of including;
Search module, for from described address lookup module polls to position corresponding to initial seek address search described target data record.
7. device according to claim 6, it is characterized in that, each data records list in described at least one data record is solely stored as a line, the corresponding relation between index line number and index line mark is stored in described allocation index, described index line number is preassigned line number, the mark of the row at the data record place of described index mark to be line number be corresponding index line number;
Described address lookup module, comprising:
Line number obtains submodule, for obtaining the line number of the target data record that described command reception module receives;
For calculating, calculating sub module, to obtain with described line number that submodule gets, the immediate index line number of line number of described target data record;
Address acquisition submodule, for by described allocation index, the index line corresponding with the line number of described target data record immediate index line number that described calculating sub module calculates identifies and is retrieved as described initial seek address.
8. device according to claim 7, is characterized in that, described device also comprises:
Relationship determination module, for searching before module searches described target data record from the position that described initial seek address is corresponding described, determine that the line number of the target data record that described command reception module receives and described calculating sub module calculate and between the immediate index line number of line number of described target data record magnitude relationship;
Direction determination module, for the magnitude relationship determination search direction determined according to described relationship determination module;
Describedly search module, for the position corresponding from described initial seek address, the search direction determined according to described direction determination module searches described target data record.
9. device according to claim 7, is characterized in that, described device also comprises:
Index stores module, for when in described database, total line number of pieces of data record meets or exceeds designated value, by described designated value, and line number is the mark of the row at the data record place of described designated value, and corresponding stored is index line number in described allocation index and index line mark.
10. device according to claim 7, is characterized in that, described device also comprises:
Identifier acquisition module, during for occurring to change when the data record stored in described database, obtains the mark of the row at the data record place in the corresponding database after change of described index line number;
Index upgrade module, for being identified by index line corresponding for index line number described in described allocation index, is updated to the mark of the row at the data record place in the corresponding database after change of described index line number.
11. 1 kinds of data record search devices, it is characterized in that, described device comprises:
Processor;
For the storer of storage of processor executable instruction;
Wherein, described processor is configured to:
Receive the instruction of query aim data record in a database, in described database, store at least one data record;
From the allocation index pre-set, inquire about initial seek address, described initial seek address is the address of the index data record that in described database, memory location is nearest apart from described target data record; Described index data record is in described database, memory address by described allocation index the data record of including;
Described target data record is searched from the position that described initial seek address is corresponding.
CN201510483713.2A 2015-08-07 2015-08-07 Data record lookup method and device Active CN105159941B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510483713.2A CN105159941B (en) 2015-08-07 2015-08-07 Data record lookup method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510483713.2A CN105159941B (en) 2015-08-07 2015-08-07 Data record lookup method and device

Publications (2)

Publication Number Publication Date
CN105159941A true CN105159941A (en) 2015-12-16
CN105159941B CN105159941B (en) 2019-02-19

Family

ID=54800797

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510483713.2A Active CN105159941B (en) 2015-08-07 2015-08-07 Data record lookup method and device

Country Status (1)

Country Link
CN (1) CN105159941B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107291746A (en) * 2016-03-31 2017-10-24 阿里巴巴集团控股有限公司 A kind of method and apparatus for storing and reading data
CN109992535A (en) * 2017-12-29 2019-07-09 华为技术有限公司 A kind of storage controlling method, device and system
CN111134974A (en) * 2019-12-09 2020-05-12 西安交通大学 Wheelchair robot system based on augmented reality and multi-mode biological signals
CN113535173A (en) * 2021-07-23 2021-10-22 上海米哈游璃月科技有限公司 Information searching method, device, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102375852A (en) * 2010-08-24 2012-03-14 中国移动通信集团公司 Method for building data index as well as method and system using data index for inquiring data
US8402198B1 (en) * 2009-06-03 2013-03-19 Violin Memory, Inc. Mapping engine for a storage device
CN103646102A (en) * 2013-12-23 2014-03-19 北京四方继保自动化股份有限公司 Method for quickly sequencing real-time database query results
CN103886022A (en) * 2014-02-24 2014-06-25 上海上讯信息技术股份有限公司 Paging-query querying device and method based on primary key fields

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8402198B1 (en) * 2009-06-03 2013-03-19 Violin Memory, Inc. Mapping engine for a storage device
CN102375852A (en) * 2010-08-24 2012-03-14 中国移动通信集团公司 Method for building data index as well as method and system using data index for inquiring data
CN103646102A (en) * 2013-12-23 2014-03-19 北京四方继保自动化股份有限公司 Method for quickly sequencing real-time database query results
CN103886022A (en) * 2014-02-24 2014-06-25 上海上讯信息技术股份有限公司 Paging-query querying device and method based on primary key fields

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107291746A (en) * 2016-03-31 2017-10-24 阿里巴巴集团控股有限公司 A kind of method and apparatus for storing and reading data
CN107291746B (en) * 2016-03-31 2021-08-17 阿里巴巴集团控股有限公司 Method and equipment for storing and reading data
CN109992535A (en) * 2017-12-29 2019-07-09 华为技术有限公司 A kind of storage controlling method, device and system
CN109992535B (en) * 2017-12-29 2024-01-30 华为技术有限公司 Storage control method, device and system
CN111134974A (en) * 2019-12-09 2020-05-12 西安交通大学 Wheelchair robot system based on augmented reality and multi-mode biological signals
CN111134974B (en) * 2019-12-09 2021-04-20 西安交通大学 Wheelchair robot system based on augmented reality and multi-mode biological signals
CN113535173A (en) * 2021-07-23 2021-10-22 上海米哈游璃月科技有限公司 Information searching method, device, equipment and storage medium
CN113535173B (en) * 2021-07-23 2024-03-08 上海米哈游璃月科技有限公司 Information searching method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN105159941B (en) 2019-02-19

Similar Documents

Publication Publication Date Title
CN106648446B (en) Storage method and device for time sequence data and electronic equipment
CN103218404B (en) A kind of multi-dimensional metadata management method based on associate feature and system
JP6222680B2 (en) Method, apparatus and system for implementing location information services
CN105159941A (en) Data record searching method and device
CN104871154A (en) Optimizing data block size for deduplication
CN104090897A (en) Method, server and system for accessing metadata
CN107783985B (en) Distributed database query method, device and management system
CN104809129A (en) Method, device and system for storing distributed data
CN104778266A (en) Multi-data source searching method and device
CN103870202A (en) Distributed storage method and system of block device
CN103942209A (en) Data processing method
CN109254981B (en) Data management method and device of distributed cache system
CN105808622A (en) File storage method and device
JP2011090351A (en) Retrieval data management device
CN104572845A (en) File distribution method and device, equipment and system
CN105138281A (en) Physical disk sharing method and apparatus
CN110765151A (en) Calculation formula processing method and device
CN111400301B (en) Data query method, device and equipment
CN105447187A (en) Webpage search method and system
CN117009453B (en) Method and system for inquiring customer group list of customers in real time through digital marketing
CN109739854A (en) A kind of date storage method and device
CN111796931B (en) Information processing method, device, computing equipment and medium
CN102724301A (en) Cloud database system and method and equipment for reading and writing cloud data
CN104754555A (en) Number-backfilling method and device
CN105094688A (en) Deduplication in storage system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant