Detailed description of the invention
For making the purpose of the application, technical scheme and advantage clearly, below in conjunction with the application specific embodiment and corresponding accompanying drawing, technical scheme is clearly and completely described.Obviously, described embodiment is only some embodiments of the present application, rather than whole embodiments.Based on the embodiment in the application, the every other embodiment that those of ordinary skill in the art obtain under not making creative work premise, broadly fall into the scope of the application protection.
The data query process that Fig. 1 provides for the embodiment of the present application, specifically includes:
S101: receive inquiry request.
In the embodiment of the present application, when user to inquire about certain data, user end to server can be first passed through and send inquiry request, wherein, carrying the Data Identification of the data to inquire about in this inquiry request, make server pass through this Data Identification, which data is the data knowing to inquiry be.This Data Identification can be generally the major key of data.Described server can be single server, it is also possible to a server cluster or distributed server.
S102: according to the Data Identification carried in this inquiry request, and the first Bloom filter pre-saved, it is judged that whether the data that this Data Identification is corresponding exist, if so, then perform step S103, otherwise, perform step S104.
In the embodiment of the present application, server has pre-saved the first Bloom filter, and this first Bloom filter is to generate previously according to all data stored in data base.By the Data Identification carried in inquiry request and this first Bloom filter, server can judge whether the data that this Data Identification is corresponding are present in data base.
Concrete, the concrete grammar generating Bloom filter is: preset the Serial No. of n position, each is 0, preset k hash function, the codomain of each hash function is 0~n, n and k is natural number, Data Identification for each data preserved in data base, the Data Identification of these data is inputted respectively this k hash function, obtain k hashed value, it is designated as H1 respectively, H2, H3, ... Hk, again by the H1 position in n bit digital sequence, H2 position, H3 position, ... Hk bit digital is set to 1, so, it is equivalent to the Data Identification " input " of these data Bloom filter, after the Data Identification of data all in data base is all inputted Bloom filter by Using such method, just obtain the first Bloom filter described in the embodiment of the present application.That is, the Bloom filter described in the embodiment of the present application specifically includes: n bit digital sequence (is made up of 0 or 1) and k hash function.
After server receives inquiry request by step S101, according to the Data Identification carried in this inquiry request and this first Bloom filter, judge whether the data that this Data Identification is corresponding are present in the method in data base and are: the Data Identification carried in this inquiry request is inputted respectively this k hash function, obtain k hashed value, it is designated as L1 respectively, L2, L3, ... Lk, in n bit digital sequence, judge L1 position respectively, L2 position, L3 position, ... whether the numeral of Lk position is 1, if being 1, then determine that the data that this Data Identification is corresponding are present in data base, if at least one is not 1, then determine that the data that this Data Identification is corresponding are not present in data base.
S103: obtain and return these data.
If the server determine that data exist, then can inquire about data corresponding to this Data Identification from data base and return to client.
S104: determine and inquire about unsuccessfully.
If the server determine that data are absent from, then can determine that this inquiry is looked into for sky, and then determine that this inquires about unsuccessfully, client can be returned to by inquiring about failed information.
From the generation method of above-mentioned Bloom filter with judge, based on Bloom filter, the method whether data exist, Bloom filter is not real data are all stored, but only record whether data exist with the Serial No. of a n position, therefore, server is for an inquiry request, only need to according to this Bloom filter, can judge whether it is that sky is looked into, if not sky is looked into, data are inquired about again from data base, otherwise, can no longer inquire about from data base, therefore can be prevented effectively from sky to check data base and cause unnecessary pressure, reduce database overhead, improve search efficiency.
Certainly, by the generation method of above-mentioned Bloom filter it can also be seen that, for being present in the data in data base, must can determine that it is present in data base by Bloom filter, for being not present in the data in data base, characteristic due to hash function itself, being also possible to be mistaken for by Bloom filter is present in data base, but, this False Rate (also referred to as false percent of pass) can be calculated by above-mentioned n and k, that is, by adjusting the value of n and k, False Rate can be made to be reduced to below acceptable scope, False Rate is such as made to be reduced to below one thousandth.
Additionally, for common Bloom filter, inputting data in Bloom filter is very easily, but, from Bloom filter, " deletion " data are comparatively difficult, such as, tentation data storehouse deletes certain data, then corresponding, the first Bloom filter in the embodiment of the present application is also answered the Data Identification of " deletion " these data, if but the simple H1 position that this Data Identification is corresponding in n bit digital sequence, H2 position, H3 position, ... the numeral of Hk position be set to 0 be clearly improper, this is because after other Data Identifications k hash function of input, being likely to also can corresponding H1 position, H2 position, H3 position, ... in Hk position some or certain several, therefore, in the embodiment of the present application, also can adopt follow-on Bloom filter, each numeral in n bit digital sequence is mainly put the number of times of 1 and is recorded by follow-on Bloom filter, when " deletion " data, the number of times that these data put 1 in each numeral that n bit digital sequence pair is answered can be subtracted 1, for n bit digital sequence one-bit digital, if it is 0 that this bit data is set to the number of times of 1, then this bit digital is changed to 0, so can delete data easily from Bloom filter.
In the step S103 shown in Fig. 1, after server determines that the data that the Data Identification carried in inquiry request is corresponding are present in data base, when obtaining and return these data, first can search these data in the buffer memory of self, if finding, then obtain and return this data, if not finding, in data base, then search these data, and the data found are returned to client.Searching the speed of data from own cache due to server will far faster than the speed searching data from data base, and therefore, server priority searches data from the buffer memory of self, can further improve the efficiency searching data.
Certainly, when server does not find data in the buffer memory of self, but when finding these data in data base, also the data found can be written in the buffer memory of self, in order to when next time inquires about these data, directly can find from the buffer memory of self.
Further, when server priority searches data in the buffer memory of self, make a look up also dependent on pre-saving the second Bloom filter, this second Bloom filter is previously according to all data genaration of storage in buffer memory, concrete, server can according to the Data Identification carried in inquiry request, and the second Bloom filter pre-saved, judge whether the data that this Data Identification is corresponding are present in buffer memory, if, from buffer memory, then obtain these data and return to client, otherwise, data base searches these data, and the data found are returned to client.Certainly, if according to the second Bloom filter determines that these data are not present in buffer memory, and when finding these data from data base, directly can find from buffer memory during for the ease of searching these data next time, the data found also can be written in the buffer memory of self by server, and according to all data stored in the buffer memory after writing these data, update the second Bloom filter.
The generation method of above-mentioned second Bloom filter is all similar with the first Bloom filter with using method, the two differs only in the first Bloom filter is according to the data genaration of storage in data base, second Bloom filter is according to the data genaration of storage in server buffer, repeats with regard to no longer generation and using method to the second Bloom filter here.
It should be noted that, the data query method that the embodiment of the present application provides can be applicable to height and concurrently inquires about more ecommerce scene, then the inquiry request described in the embodiment of the present application includes but not limited to querying commodity information request, transaction record inquiry request etc., described Data Identification includes but not limited to trade name, commercial product identification identification code (IDentity, ID) etc., described server includes but not limited to electricity business's Website server, paying server etc..
The detailed process of the data query that Fig. 2 provides for the embodiment of the present application, specifically includes following steps:
S201: server receives inquiry request.
S202: according to the Data Identification carried in inquiry request, and the first Bloom filter pre-saved, it is judged that whether the data that this Data Identification is corresponding exist, if so, perform step S203, otherwise performs step S206.
Wherein, this first Bloom filter is according to all data genaration of storage in data base.
S203: according to this Data Identification, and the second Bloom filter pre-saved, it is judged that whether the data that this Data Identification is corresponding are present in buffer memory, if so, perform step S204, otherwise performs step S205.
S204: obtain these data from buffer memory and return.
Wherein, this second Bloom filter is according to all data genaration of storage in buffer memory.
The data found are write in buffer memory by S205: search these data in data base and return, and according to all data stored in the buffer memory after writing these data, update the second Bloom filter.
S206: determine and inquire about unsuccessfully.
The data query method provided for the embodiment of the present application above, based on same thinking, the embodiment of the present application additionally provides a kind of data query arrangement, as shown in Figure 3.
The data query arrangement structural representation that Fig. 3 provides for the embodiment of the present application, specifically includes:
Receiver module 301, is used for receiving inquiry request;
Memory module 302, is used for storing the first Bloom filter;
Judge module 303, is used for according to the Data Identification carried in described inquiry request, and the first Bloom filter pre-saved, it is judged that whether the data that described Data Identification is corresponding exist;
Enquiry module 304, for when the judged result of described judge module 303 is for being, obtaining and return described data, when the judged result at described judge module 303 is no, it is determined that inquire about unsuccessfully.
Described memory module 302 specifically for, previously according to all data of storage in data base, generate the first corresponding Bloom filter and preserve.
Described enquiry module 304 specifically for, when the judged result of described judge module 303 is for being, search described data in the buffer, if finding, then obtain and return described data, if not finding, in data base, then search described data, and the data found are returned.
Described enquiry module 304 is additionally operable to, and when finding described data in the database, the data found is write in described buffer memory.
Described enquiry module 304 specifically for, when the judged result of described judge module 303 is for being, according to described Data Identification, and the second Bloom filter pre-saved, judge whether the data that described Data Identification is corresponding are present in buffer memory, if so, from buffer memory, then obtain described data and return, otherwise, data base searches described data, and the data found are returned, wherein, described second Bloom filter is according to all data genaration of storage in described buffer memory.
Described enquiry module 304 is additionally operable to, and when finding described data in the database, writes in described buffer memory by the data found, according to all data stored in the buffer memory after writing described data, updates the second Bloom filter.
A kind of data query method and apparatus that the embodiment of the present application provides, when the method server receives inquiry request, only need according to the Bloom filter prestored, judge whether the data that the Data Identification carried in this inquiry request is corresponding exist, and only search when it exists and return this data, inquire about without to the Data Identification carried in each inquiry request, look into thus sky can effectively be filtered, avoid sky to check data base and cause unnecessary pressure, thus reducing database overhead, promoting the purpose of search efficiency.
Those skilled in the art are it should be appreciated that embodiments herein can be provided as method, system or computer program.Therefore, the application can adopt the form of complete hardware embodiment, complete software implementation or the embodiment in conjunction with software and hardware aspect.And, the application can adopt the form at one or more upper computer programs implemented of computer-usable storage medium (including but not limited to disk memory, CD-ROM, optical memory etc.) wherein including computer usable program code.
The application describes with reference to flow chart and/or the block diagram according to the method for the embodiment of the present application, equipment (system) and computer program.It should be understood that can by the combination of the flow process in each flow process in computer program instructions flowchart and/or block diagram and/or square frame and flow chart and/or block diagram and/or square frame.These computer program instructions can be provided to produce a machine to the processor of general purpose computer, special-purpose computer, Embedded Processor or other programmable data processing device so that the instruction performed by the processor of computer or other programmable data processing device is produced for realizing the device of function specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame.
These computer program instructions may be alternatively stored in and can guide in the computer-readable memory that computer or other programmable data processing device work in a specific way, the instruction making to be stored in this computer-readable memory produces to include the manufacture of command device, and this command device realizes the function specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame.
These computer program instructions also can be loaded in computer or other programmable data processing device, make on computer or other programmable devices, to perform sequence of operations step to produce computer implemented process, thus the instruction performed on computer or other programmable devices provides for realizing the step of function specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame.
In a typical configuration, computing equipment includes one or more processor (CPU), input/output interface, network interface and internal memory.
Internal memory potentially includes the forms such as the volatile memory in computer-readable medium, random access memory (RAM) and/or Nonvolatile memory, such as read only memory (ROM) or flash memory (flashRAM).Internal memory is the example of computer-readable medium.
Computer-readable medium includes permanent and impermanency, removable and non-removable media can by any method or technology to realize information storage.Information can be computer-readable instruction, data structure, the module of program or other data.The example of the storage medium of computer includes, but it is not limited to phase transition internal memory (PRAM), static RAM (SRAM), dynamic random access memory (DRAM), other kinds of random access memory (RAM), read only memory (ROM), Electrically Erasable Read Only Memory (EEPROM), fast flash memory bank or other memory techniques, read-only optical disc read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tape, the storage of tape magnetic rigid disk or other magnetic storage apparatus or any other non-transmission medium, can be used for the information that storage can be accessed by a computing device.According to defining herein, computer-readable medium does not include temporary computer readable media (transitorymedia), such as data signal and the carrier wave of modulation.
It can further be stated that, term " includes ", " comprising " or its any other variant are intended to comprising of nonexcludability, so that include the process of a series of key element, method, commodity or equipment not only include those key elements, but also include other key elements being not expressly set out, or also include the key element intrinsic for this process, method, commodity or equipment.When there is no more restriction, statement " including ... " key element limited, it is not excluded that there is also other identical element in including the process of described key element, method, commodity or equipment.
It will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer program.Therefore, the application can adopt the form of complete hardware embodiment, complete software implementation or the embodiment in conjunction with software and hardware aspect.And, the application can adopt the form at one or more upper computer programs implemented of computer-usable storage medium (including but not limited to disk memory, CD-ROM, optical memory etc.) wherein including computer usable program code.
The foregoing is only embodiments herein, be not limited to the application.To those skilled in the art, the application can have various modifications and variations.All make within spirit herein and principle any amendment, equivalent replacement, improvement etc., should be included within claims hereof scope.